Skip to content

Commit 45bb790

Browse files
authored
Fix: Include correct client in payment link UI (#7449)
1 parent 102a8c8 commit 45bb790

File tree

4 files changed

+81
-102
lines changed

4 files changed

+81
-102
lines changed

apps/dashboard/src/app/pay/[id]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
44
import { checksumAddress } from "thirdweb/utils";
55
import { getPaymentLink } from "@/api/universal-bridge/links";
66
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
7-
import { PayPageEmbed } from "../components/client/PayPageEmbed.client";
7+
import { PayPageWidget } from "../components/client/PayPageWidget.client";
88

99
const title = "thirdweb Pay";
1010
const description = "Fast, secure, and simple payments.";
@@ -54,7 +54,7 @@ export default async function PayPage({
5454
};
5555

5656
return (
57-
<PayPageEmbed
57+
<PayPageWidget
5858
amount={paymentLink.amount ? BigInt(paymentLink.amount) : undefined}
5959
chainId={Number(paymentLink.destinationToken.chainId)}
6060
clientId={paymentLink.clientId}

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

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"use client";
2+
import { payAppThirdwebClient } from "app/pay/constants";
3+
import { useTheme } from "next-themes";
4+
import { useEffect } from "react";
5+
import { createThirdwebClient, NATIVE_TOKEN_ADDRESS, toTokens } from "thirdweb";
6+
import { AutoConnect, CheckoutWidget } from "thirdweb/react";
7+
import { checksumAddress } from "thirdweb/utils";
8+
import { useV5DashboardChain } from "@/hooks/chains/v5-adapter";
9+
10+
export function PayPageWidget({
11+
chainId,
12+
recipientAddress,
13+
paymentLinkId,
14+
amount,
15+
token,
16+
name,
17+
image,
18+
redirectUri,
19+
theme,
20+
purchaseData,
21+
clientId,
22+
}: {
23+
chainId: number;
24+
recipientAddress: string;
25+
paymentLinkId?: string;
26+
amount?: bigint;
27+
token: { name: string; symbol: string; address: string; decimals: number };
28+
name?: string;
29+
image?: string;
30+
redirectUri?: string;
31+
clientId: string;
32+
theme?: "light" | "dark";
33+
purchaseData: Record<string, unknown> | undefined;
34+
}) {
35+
const { theme: browserTheme, setTheme } = useTheme();
36+
37+
// eslint-disable-next-line no-restricted-syntax
38+
useEffect(() => {
39+
if (theme) {
40+
setTheme(theme);
41+
}
42+
}, [theme, setTheme]);
43+
const chain = useV5DashboardChain(chainId);
44+
45+
return (
46+
<>
47+
<AutoConnect
48+
client={
49+
clientId ? createThirdwebClient({ clientId }) : payAppThirdwebClient
50+
}
51+
/>
52+
<CheckoutWidget
53+
amount={amount ? toTokens(amount, token.decimals) : "0"}
54+
chain={chain}
55+
client={
56+
clientId ? createThirdwebClient({ clientId }) : payAppThirdwebClient
57+
}
58+
image={image}
59+
name={name}
60+
onSuccess={() => {
61+
if (!redirectUri) return;
62+
const url = new URL(redirectUri);
63+
return window.open(url.toString());
64+
}}
65+
paymentLinkId={paymentLinkId}
66+
purchaseData={purchaseData}
67+
seller={checksumAddress(recipientAddress)}
68+
theme={theme ?? (browserTheme === "light" ? "light" : "dark")}
69+
tokenAddress={
70+
token.address === NATIVE_TOKEN_ADDRESS
71+
? undefined
72+
: checksumAddress(token.address)
73+
}
74+
/>
75+
</>
76+
);
77+
}

apps/dashboard/src/app/pay/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createThirdwebClient, defineChain, getContract } from "thirdweb";
33
import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
44
import { checksumAddress } from "thirdweb/utils";
55
import { PaymentLinkForm } from "./components/client/PaymentLinkForm.client";
6-
import { PayPageEmbed } from "./components/client/PayPageEmbed.client";
6+
import { PayPageWidget } from "./components/client/PayPageWidget.client";
77
import type { PayParams } from "./components/types";
88
import { payAppThirdwebClient } from "./constants";
99

@@ -84,7 +84,7 @@ export default async function PayPage({
8484
};
8585

8686
return (
87-
<PayPageEmbed
87+
<PayPageWidget
8888
amount={BigInt(params.amount)}
8989
chainId={Number(params.chainId)}
9090
clientId={client.clientId}

0 commit comments

Comments
 (0)