From 5277eddb70b3cf7b3dccbb4570c677f49b8dc854 Mon Sep 17 00:00:00 2001 From: gregfromstl Date: Fri, 23 May 2025 23:10:14 +0000 Subject: [PATCH] [SDK] Fix: Webhook Schema (#7151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR focuses on updating the `Webhook` schema in the `thirdweb` package to enhance the structure of `originToken` and `destinationToken` by replacing simple address strings with detailed objects containing additional properties. ### Detailed summary - Updated `originToken` and `destinationToken` to be objects with properties: - `chainId` - `address` - `name` - `symbol` - `decimals` - `priceUsd` - `iconUri` - Adjusted the test file to reflect these changes with appropriate object structures. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit - **Bug Fixes** - Enhanced webhook support to include detailed token information such as chain ID, name, symbol, decimals, price, and icon for origin and destination tokens. - **Tests** - Updated test data to match the new detailed token structure in webhook payloads. - **Chores** - Added a changeset to document this patch update. --- .changeset/purple-wasps-sort.md | 5 +++++ packages/thirdweb/src/bridge/Webhook.test.ts | 20 ++++++++++++++++++-- packages/thirdweb/src/bridge/Webhook.ts | 20 ++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .changeset/purple-wasps-sort.md diff --git a/.changeset/purple-wasps-sort.md b/.changeset/purple-wasps-sort.md new file mode 100644 index 00000000000..6d854cd91e5 --- /dev/null +++ b/.changeset/purple-wasps-sort.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Fix Webhook schema type diff --git a/packages/thirdweb/src/bridge/Webhook.test.ts b/packages/thirdweb/src/bridge/Webhook.test.ts index c5369cc5831..79cfd34b905 100644 --- a/packages/thirdweb/src/bridge/Webhook.test.ts +++ b/packages/thirdweb/src/bridge/Webhook.test.ts @@ -28,9 +28,25 @@ describe("parseIncomingWebhook", () => { clientId: "client123", action: "TRANSFER", status: "COMPLETED", - originToken: "0x1234567890123456789012345678901234567890" as const, + originToken: { + chainId: 1, + address: "0x1234567890123456789012345678901234567890" as const, + name: "Token", + symbol: "TKN", + decimals: 18, + priceUsd: 1.0, + iconUri: "https://example.com/icon.png", + }, originAmount: "1.0", - destinationToken: "0x1234567890123456789012345678901234567890", + destinationToken: { + chainId: 1, + address: "0x1234567890123456789012345678901234567890" as const, + name: "Token", + symbol: "TKN", + decimals: 18, + priceUsd: 1.0, + iconUri: "https://example.com/icon.png", + }, destinationAmount: "1.0", sender: "0x1234567890123456789012345678901234567890", receiver: "0x1234567890123456789012345678901234567890", diff --git a/packages/thirdweb/src/bridge/Webhook.ts b/packages/thirdweb/src/bridge/Webhook.ts index bc9726e912b..a96cdc3642e 100644 --- a/packages/thirdweb/src/bridge/Webhook.ts +++ b/packages/thirdweb/src/bridge/Webhook.ts @@ -23,9 +23,25 @@ const webhookSchema = z.union([ clientId: z.string(), action: z.enum(["TRANSFER", "BUY", "SELL"]), status: z.enum(["PENDING", "FAILED", "COMPLETED"]), - originToken: addressSchema, + originToken: z.object({ + chainId: z.coerce.number(), + address: addressSchema, + name: z.string(), + symbol: z.string(), + decimals: z.coerce.number(), + priceUsd: z.coerce.number(), + iconUri: z.optional(z.string()), + }), originAmount: z.string(), - destinationToken: addressSchema, + destinationToken: z.object({ + chainId: z.coerce.number(), + address: addressSchema, + name: z.string(), + symbol: z.string(), + decimals: z.coerce.number(), + priceUsd: z.coerce.number(), + iconUri: z.optional(z.string()), + }), destinationAmount: z.string(), sender: addressSchema, receiver: addressSchema,