Skip to content

Commit 1a19e14

Browse files
committed
SDK: Fix getNFT tests, Playground: Fix build (#8242)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR primarily focuses on updating the `tokenAddress` format in the tests and modifying the instantiation of the `thirdwebAI` and `thirdwebClient` to use a consistent `SECRET_KEY` variable for better readability and maintainability. ### Detailed summary - Updated `tokenAddress` format in `getNFT.test.ts` and `getNFTs.test.ts`. - Changed `thirdwebAI` instantiation in `route.ts` to use `SECRET_KEY` variable. - Modified `thirdwebClient` instantiation in `paywall/route.ts` to use `SECRET_KEY` variable. - Maintained existing environment variable usage for wallet addresses and API URLs. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a new public GET paywall endpoint. * **Tests** * Updated NFT test snapshots to correct token address casing. * Removed an obsolete single-line test comment. * **Chores** * API handlers now initialize needed services per request and read required environment secrets. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 464af6a commit 1a19e14

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

apps/playground-web/src/app/api/chat/route.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { convertToModelMessages, streamText, type UIMessage } from "ai";
44
// Allow streaming responses up to 5 minutes
55
export const maxDuration = 300;
66

7-
const thirdwebAI = createThirdwebAI({
8-
baseURL: `https://${process.env.NEXT_PUBLIC_API_URL}`,
9-
secretKey: process.env.THIRDWEB_SECRET_KEY,
10-
});
11-
127
export async function POST(req: Request) {
8+
const SECRET_KEY = process.env.THIRDWEB_SECRET_KEY as string;
9+
10+
const thirdwebAI = createThirdwebAI({
11+
baseURL: `https://${process.env.NEXT_PUBLIC_API_URL}`,
12+
secretKey: SECRET_KEY,
13+
});
14+
1315
const body = await req.json();
1416
const { messages, id }: { messages: UIMessage[]; id: string } = body;
1517

apps/playground-web/src/app/api/paywall/route.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ import { token } from "../../payments/x402/components/constants";
77
// Allow streaming responses up to 5 minutes
88
export const maxDuration = 300;
99

10-
const client = createThirdwebClient({
11-
secretKey: process.env.THIRDWEB_SECRET_KEY as string,
12-
});
10+
export async function GET(request: NextRequest) {
11+
const SECRET_KEY = process.env.THIRDWEB_SECRET_KEY as string;
1312

14-
const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string;
15-
// const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_SMART_WALLET as string;
16-
const ENGINE_VAULT_ACCESS_TOKEN = process.env
17-
.ENGINE_VAULT_ACCESS_TOKEN as string;
18-
// const API_URL = `https://${process.env.NEXT_PUBLIC_API_URL || "api.thirdweb.com"}`;
19-
const API_URL = "http://localhost:3030";
13+
const client = createThirdwebClient({
14+
secretKey: SECRET_KEY,
15+
});
2016

21-
const twFacilitator = facilitator({
22-
baseUrl: `${API_URL}/v1/payments/x402`,
23-
client,
24-
serverWalletAddress: BACKEND_WALLET_ADDRESS,
25-
vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN,
26-
});
17+
const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string;
18+
// const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_SMART_WALLET as string;
19+
const ENGINE_VAULT_ACCESS_TOKEN = process.env
20+
.ENGINE_VAULT_ACCESS_TOKEN as string;
21+
// const API_URL = `https://${process.env.NEXT_PUBLIC_API_URL || "api.thirdweb.com"}`;
22+
const API_URL = "http://localhost:3030";
23+
24+
const twFacilitator = facilitator({
25+
baseUrl: `${API_URL}/v1/payments/x402`,
26+
client,
27+
serverWalletAddress: BACKEND_WALLET_ADDRESS,
28+
vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN,
29+
});
2730

28-
export async function GET(request: NextRequest) {
2931
const paymentData = request.headers.get("X-PAYMENT");
3032
const queryParams = request.nextUrl.searchParams;
3133

packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
4444
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
4545
},
4646
"owner": null,
47-
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
47+
"tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
4848
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
4949
"type": "ERC721",
5050
}

packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
1313
});
1414

1515
expect(nfts.length).toBe(5);
16-
// TODO (insight): re-enable once insight fixes the client id caching issue
1716
expect(nfts).toMatchInlineSnapshot(`
1817
[
1918
{
@@ -49,7 +48,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
4948
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/0",
5049
},
5150
"owner": null,
52-
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
51+
"tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
5352
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/0",
5453
"type": "ERC721",
5554
},
@@ -86,7 +85,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
8685
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
8786
},
8887
"owner": null,
89-
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
88+
"tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
9089
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
9190
"type": "ERC721",
9291
},
@@ -123,7 +122,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
123122
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/2",
124123
},
125124
"owner": null,
126-
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
125+
"tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
127126
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/2",
128127
"type": "ERC721",
129128
},
@@ -160,7 +159,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
160159
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/3",
161160
},
162161
"owner": null,
163-
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
162+
"tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
164163
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/3",
165164
"type": "ERC721",
166165
},
@@ -197,7 +196,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
197196
"uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/4",
198197
},
199198
"owner": null,
200-
"tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
199+
"tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
201200
"tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/4",
202201
"type": "ERC721",
203202
},

0 commit comments

Comments
 (0)