Skip to content

[Dashboard] Fix: Purchase Data #7225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-cougars-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix use of purchaseData in payment links
2 changes: 1 addition & 1 deletion apps/dashboard/src/@/api/universal-bridge/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type PaymentLink = {
chainId: number;
};
amount: bigint | undefined;
purchaseData: unknown;
purchaseData: Record<string, unknown> | undefined;
};

export async function getPaymentLink(props: {
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/src/app/pay/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default async function PayPage({
name={paymentLink.title}
image={paymentLink.imageUrl}
theme={theme}
purchaseData={paymentLink.purchaseData}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function PayPageEmbed({
image,
redirectUri,
theme,
purchaseData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider more specific typing for purchaseData.

The unknown | undefined type is very broad and could lead to type safety issues downstream. Consider defining a more specific interface or using a generic type parameter to provide better type safety and developer experience.

-  purchaseData: unknown | undefined;
+  purchaseData?: Record<string, unknown>;

Or define a specific interface:

interface PurchaseData {
  orderId?: string;
  customFields?: Record<string, unknown>;
  // other expected fields...
}

Also applies to: 31-31

🤖 Prompt for AI Agents
In apps/dashboard/src/app/pay/components/client/PayPageEmbed.client.tsx at lines
19 and 31, the purchaseData prop is typed as unknown | undefined, which is too
broad and unsafe. Define a specific TypeScript interface describing the expected
structure of purchaseData, including fields like orderId and customFields, and
update the typing of purchaseData to use this interface for improved type safety
and clarity.

}: {
chainId: number;
recipientAddress: string;
Expand All @@ -27,6 +28,7 @@ export function PayPageEmbed({
redirectUri?: string;
clientId: string;
theme?: "light" | "dark";
purchaseData: Record<string, unknown> | undefined;
}) {
const { theme: browserTheme, setTheme } = useTheme();

Expand All @@ -51,6 +53,7 @@ export function PayPageEmbed({
image,
},
mode: "direct_payment",
purchaseData,
paymentInfo: {
chain,
sellerAddress: recipientAddress,
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/src/app/pay/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default async function PayPage({
name={params.name}
image={params.image}
theme={params.theme}
purchaseData={undefined}
/>
);
}
10 changes: 8 additions & 2 deletions packages/thirdweb/src/bridge/Webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ describe("parseIncomingWebhook", () => {
receiver: "0x1234567890123456789012345678901234567890",
type: "transfer",
transactions: [
"0x1234567890123456789012345678901234567890",
"0x1234567890123456789012345678901234567890",
{
chainId: 1,
transactionHash: "0x1234567890123456789012345678901234567890",
},
{
chainId: 1,
transactionHash: "0x1234567890123456789012345678901234567890",
},
],
Comment on lines 54 to 63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix transaction hash format and improve test data diversity.

The transaction hashes in the test data appear to be using address format (42 characters) instead of transaction hash format (66 characters). Additionally, both transaction objects use identical values, which reduces test effectiveness.

Apply this diff to fix the transaction hash format and add diversity:

       transactions: [
         {
           chainId: 1,
-          transactionHash: "0x1234567890123456789012345678901234567890",
+          transactionHash: "0x1234567890123456789012345678901234567890123456789012345678901234",
         },
         {
-          chainId: 1,
-          transactionHash: "0x1234567890123456789012345678901234567890",
+          chainId: 137,
+          transactionHash: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
         },
       ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
transactions: [
"0x1234567890123456789012345678901234567890",
"0x1234567890123456789012345678901234567890",
{
chainId: 1,
transactionHash: "0x1234567890123456789012345678901234567890",
},
{
chainId: 1,
transactionHash: "0x1234567890123456789012345678901234567890",
},
],
transactions: [
{
chainId: 1,
transactionHash: "0x1234567890123456789012345678901234567890123456789012345678901234",
},
{
chainId: 137,
transactionHash: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
},
],
🤖 Prompt for AI Agents
In packages/thirdweb/src/bridge/Webhook.test.ts around lines 54 to 63, the
transactionHash values are incorrectly formatted as 42-character addresses
instead of 66-character transaction hashes, and both transactions have identical
data. Update each transactionHash to a valid 66-character hash string and ensure
the two transactions have distinct values to improve test coverage and accuracy.

developerFeeBps: 100,
developerFeeRecipient: "0x1234567890123456789012345678901234567890",
Expand Down
9 changes: 7 additions & 2 deletions packages/thirdweb/src/bridge/Webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ const webhookSchema = z.union([
sender: addressSchema,
receiver: addressSchema,
type: z.string(),
transactions: z.array(hexSchema),
transactions: z.array(
z.object({
chainId: z.coerce.number(),
transactionHash: hexSchema,
}),
),
developerFeeBps: z.coerce.number(),
developerFeeRecipient: addressSchema,
purchaseData: z.record(z.string(), z.unknown()),
purchaseData: z.optional(z.record(z.string(), z.unknown())),
}),
}),
]);
Expand Down
Loading