Skip to content

Commit 8ef418c

Browse files
authored
Move success URL handling from PayPage to StyledBuyWidget component (#8342)
1 parent b88f75b commit 8ef418c

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

apps/dashboard/src/app/pay/landing/styled-buy-widget.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { payLandingWallets } from "./wallets";
99
const client = getClientThirdwebClient();
1010

1111
export function StyledBuyWidget(
12-
props: Omit<BuyWidgetProps, "client" | "theme">,
12+
props: Omit<
13+
BuyWidgetProps,
14+
"client" | "theme" | "onSuccess" | "onError" | "onCancel"
15+
> & {
16+
successUrl?: string;
17+
},
1318
) {
1419
const { theme } = useTheme();
1520

@@ -22,6 +27,22 @@ export function StyledBuyWidget(
2227
connectOptions={{
2328
wallets: payLandingWallets,
2429
}}
30+
onSuccess={() => {
31+
if (props.successUrl) {
32+
try {
33+
const url = new URL(props.successUrl);
34+
url.searchParams.set("success", "true");
35+
window.location.href = url.toString();
36+
} catch (error) {
37+
// Log URL construction error for debugging
38+
console.error(
39+
"Failed to construct redirect URL:",
40+
props.successUrl,
41+
error,
42+
);
43+
}
44+
}
45+
}}
2546
/>
2647
);
2748
}

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,7 @@ export default async function PayPage(props: {
7676
tokenAddress={token}
7777
receiverAddress={receiver}
7878
amount={amount ? amount.toString() : undefined}
79-
onSuccess={() => {
80-
if (successUrl) {
81-
try {
82-
const url = new URL(successUrl);
83-
url.searchParams.set("success", "true");
84-
window.location.href = url.toString();
85-
} catch (error) {
86-
// Log URL construction error for debugging
87-
console.error(
88-
"Failed to construct redirect URL:",
89-
successUrl,
90-
error,
91-
);
92-
}
93-
}
94-
}}
79+
successUrl={successUrl}
9580
/>
9681
</div>
9782
</div>

0 commit comments

Comments
 (0)