Skip to content

Commit 4e46698

Browse files
committed
Refactor purchaseData type in PayPageEmbed and webhook schema for improved type safety
- Updated the purchaseData type in PayPageEmbed component and PaymentLink type to use Record<string, unknown> | undefined for better clarity. - Modified webhook schema to make purchaseData optional, enhancing flexibility in handling webhook data.
1 parent 7eed960 commit 4e46698

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

apps/dashboard/src/@/api/universal-bridge/links.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type PaymentLink = {
1515
chainId: number;
1616
};
1717
amount: bigint | undefined;
18-
purchaseData: unknown;
18+
purchaseData: Record<string, unknown> | undefined;
1919
};
2020

2121
export async function getPaymentLink(props: {

apps/dashboard/src/app/pay/components/client/PayPageEmbed.client.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function PayPageEmbed({
2828
redirectUri?: string;
2929
clientId: string;
3030
theme?: "light" | "dark";
31-
purchaseData: unknown | undefined;
31+
purchaseData: Record<string, unknown> | undefined;
3232
}) {
3333
const { theme: browserTheme, setTheme } = useTheme();
3434

@@ -52,19 +52,8 @@ export function PayPageEmbed({
5252
name,
5353
image,
5454
},
55-
// Validate and sanitize purchaseData
56-
const sanitizedPurchaseData = purchaseData && typeof purchaseData === 'object'
57-
? purchaseData
58-
: undefined;
59-
60-
payOptions={{
61-
metadata: {
62-
name,
63-
image,
64-
},
65-
purchaseData: sanitizedPurchaseData,
66-
}}
6755
mode: "direct_payment",
56+
purchaseData,
6857
paymentInfo: {
6958
chain,
7059
sellerAddress: recipientAddress,

packages/thirdweb/src/bridge/Webhook.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ const webhookSchema = z.union([
4646
sender: addressSchema,
4747
receiver: addressSchema,
4848
type: z.string(),
49-
transactions: z.array(hexSchema),
49+
transactions: z.array(
50+
z.object({
51+
chainId: z.coerce.number(),
52+
transactionHash: hexSchema,
53+
}),
54+
),
5055
developerFeeBps: z.coerce.number(),
5156
developerFeeRecipient: addressSchema,
52-
purchaseData: z.record(z.string(), z.unknown()),
57+
purchaseData: z.optional(z.record(z.string(), z.unknown())),
5358
}),
5459
}),
5560
]);

0 commit comments

Comments
 (0)