Skip to content

Commit 2ca81a0

Browse files
committed
[MNY-256] SDK: Update onSuccess prop of BuyWidget, CheckoutWidget, BridgeWidget components
1 parent e830109 commit 2ca81a0

File tree

8 files changed

+48
-10
lines changed

8 files changed

+48
-10
lines changed

.changeset/strong-buses-love.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Update `onSuccess` prop on `BuyWidget`, `CheckoutWidget` and `BridgeWidget` components to include `statuses` and `quote` objects instead of just `quote`.
6+
7+
```tsx
8+
<BuyWidget
9+
onSuccess={(data) => {
10+
console.log(data.statuses);
11+
console.log(data.quote);
12+
}}
13+
/>
14+
```

apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function BuyAndSwapEmbed(props: {
147147
});
148148
}
149149
}}
150-
onSuccess={(quote) => {
150+
onSuccess={({ quote }) => {
151151
reportTokenBuySuccessful({
152152
buyTokenChainId:
153153
quote.type === "buy"

apps/portal/src/app/bridge/bridge-widget-script/page.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ type Options = {
132132
error: Error,
133133
quote: BuyOrOnrampPrepareResult | undefined,
134134
) => void;
135-
onSuccess?: (quote: BuyOrOnrampPrepareResult) => void;
135+
onSuccess?: (data: {
136+
quote: BuyOrOnrampPrepareResult;
137+
statuses: CompletedStatusResult[];
138+
}) => void;
136139
className?: string;
137140
country?: string;
138141
presetOptions?: [number, number, number];

packages/thirdweb/src/exports/react.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ export type {
7373
SendTransactionPayModalConfig,
7474
} from "../react/core/hooks/transaction/useSendTransaction.js";
7575
export { useSimulateTransaction } from "../react/core/hooks/transaction/useSimulateTransaction.js";
76+
export type { BridgePrepareResult } from "../react/core/hooks/useBridgePrepare.js";
7677
export {
7778
type UseBridgeRoutesParams,
7879
useBridgeRoutes,
7980
} from "../react/core/hooks/useBridgeRoutes.js";
81+
export type { CompletedStatusResult } from "../react/core/hooks/useStepExecutor.js";
8082
export { useActiveAccount } from "../react/core/hooks/wallets/useActiveAccount.js";
8183
// wallet hooks
8284
export { useActiveWallet } from "../react/core/hooks/wallets/useActiveWallet.js";
@@ -133,7 +135,7 @@ export { useProfiles } from "../react/web/hooks/wallets/useProfiles.js";
133135
export { useUnlinkProfile } from "../react/web/hooks/wallets/useUnlinkProfile.js";
134136
export { ThirdwebProvider } from "../react/web/providers/thirdweb-provider.js";
135137
export { AutoConnect } from "../react/web/ui/AutoConnect/AutoConnect.js";
136-
138+
export type { BuyOrOnrampPrepareResult } from "../react/web/ui/Bridge/BuyWidget.js";
137139
export {
138140
BuyWidget,
139141
type BuyWidgetProps,
@@ -276,7 +278,6 @@ export { SiteEmbed } from "../react/web/ui/SiteEmbed.js";
276278
export { SiteLink } from "../react/web/ui/SiteLink.js";
277279
export { TransactionButton } from "../react/web/ui/TransactionButton/index.js";
278280
export type { LocaleId } from "../react/web/ui/types.js";
279-
280281
// Utils
281282
export { getLastAuthProvider } from "../react/web/utils/storage.js";
282283
export type {

packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ export type BuyWidgetProps = {
158158
/**
159159
* Callback triggered when the purchase is successful.
160160
*/
161-
onSuccess?: (quote: BuyOrOnrampPrepareResult) => void;
161+
onSuccess?: (data: {
162+
quote: BuyOrOnrampPrepareResult;
163+
statuses: CompletedStatusResult[];
164+
}) => void;
162165

163166
/**
164167
* Callback triggered when the purchase encounters an error.
@@ -616,7 +619,10 @@ function BridgeWidgetContent(
616619
screen.preparedQuote.type === "buy" ||
617620
screen.preparedQuote.type === "onramp"
618621
) {
619-
props.onSuccess?.(screen.preparedQuote);
622+
props.onSuccess?.({
623+
quote: screen.preparedQuote,
624+
statuses: completedStatuses,
625+
});
620626
}
621627
setScreen({
622628
id: "6:success",

packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ export type CheckoutWidgetProps = {
170170
/**
171171
* Callback triggered when the purchase is successful.
172172
*/
173-
onSuccess?: (quote: BridgePrepareResult) => void;
173+
onSuccess?: (data: {
174+
quote: BridgePrepareResult;
175+
statuses: CompletedStatusResult[];
176+
}) => void;
174177

175178
/**
176179
* Callback triggered when the purchase encounters an error.
@@ -660,7 +663,10 @@ function CheckoutWidgetContent(
660663
handleCancel(screen.preparedQuote);
661664
}}
662665
onComplete={(completedStatuses) => {
663-
props.onSuccess?.(screen.preparedQuote);
666+
props.onSuccess?.({
667+
quote: screen.preparedQuote,
668+
statuses: completedStatuses,
669+
});
664670
setScreen({
665671
id: "6:success",
666672
preparedQuote: screen.preparedQuote,

packages/thirdweb/src/react/web/ui/Bridge/bridge-widget/bridge-widget.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
spacing,
1414
type Theme,
1515
} from "../../../../core/design-system/index.js";
16+
import type { CompletedStatusResult } from "../../../../core/hooks/useStepExecutor.js";
1617
import { EmbedContainer } from "../../ConnectWallet/Modal/ConnectEmbed.js";
1718
import { Container } from "../../components/basic.js";
1819
import { Button } from "../../components/buttons.js";
@@ -172,7 +173,10 @@ export type BridgeWidgetProps = {
172173
quote: BuyOrOnrampPrepareResult | undefined,
173174
) => void;
174175
/** Callback triggered when the purchase is successful. */
175-
onSuccess?: (quote: BuyOrOnrampPrepareResult) => void;
176+
onSuccess?: (data: {
177+
quote: BuyOrOnrampPrepareResult;
178+
statuses: CompletedStatusResult[];
179+
}) => void;
176180
/** Optional class name applied to the Buy tab content container. */
177181
className?: string;
178182
/** The user's ISO 3166 alpha-2 country code. Used to determine onramp provider support. */

packages/thirdweb/src/script-exports/bridge-widget-script.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type Theme,
88
type ThemeOverrides,
99
} from "../react/core/design-system/index.js";
10+
import type { CompletedStatusResult } from "../react/core/hooks/useStepExecutor.js";
1011
import type { BuyOrOnrampPrepareResult } from "../react/web/ui/Bridge/BuyWidget.js";
1112
import { BridgeWidget } from "../react/web/ui/Bridge/bridge-widget/bridge-widget.js";
1213
import type { SwapPreparedQuote } from "../react/web/ui/Bridge/swap-widget/types.js";
@@ -51,7 +52,10 @@ export type BridgeWidgetScriptProps = {
5152
error: Error,
5253
quote: BuyOrOnrampPrepareResult | undefined,
5354
) => void;
54-
onSuccess?: (quote: BuyOrOnrampPrepareResult) => void;
55+
onSuccess?: (data: {
56+
quote: BuyOrOnrampPrepareResult;
57+
statuses: CompletedStatusResult[];
58+
}) => void;
5559
className?: string;
5660
country?: string;
5761
presetOptions?: [number, number, number];

0 commit comments

Comments
 (0)