Skip to content

Commit 3a2a852

Browse files
committed
SDK: Fix onSuccess prop not called properly on CheckoutWidget and BuyWidget
1 parent 210f631 commit 3a2a852

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.changeset/slimy-chefs-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix `onSuccess` callback was not called correctly on `CheckoutWidget`, `BuyWidget` components

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@ export function BridgeOrchestrator({
180180
const [state, send] = usePaymentMachine(adapters, uiOptions.mode);
181181

182182
// Handle buy completion
183-
const handleBuyComplete = useCallback(() => {
183+
const handleDoneOrContinueClick = useCallback(() => {
184184
if (uiOptions.mode === "transaction") {
185185
send({ type: "CONTINUE_TO_TRANSACTION" });
186186
} else {
187-
onComplete?.();
188187
send({ type: "RESET" });
189188
}
190-
}, [onComplete, send, uiOptions.mode]);
189+
}, [send, uiOptions.mode]);
191190

192191
// Handle post-buy transaction completion
193192
const handlePostBuyTransactionComplete = useCallback(() => {
@@ -230,8 +229,11 @@ export function BridgeOrchestrator({
230229
const handleExecutionComplete = useCallback(
231230
(completedStatuses: CompletedStatusResult[]) => {
232231
send({ completedStatuses, type: "EXECUTION_COMPLETE" });
232+
if (uiOptions.mode !== "transaction") {
233+
onComplete?.();
234+
}
233235
},
234-
[send],
236+
[send, onComplete, uiOptions.mode],
235237
);
236238

237239
// Handle retry
@@ -390,7 +392,7 @@ export function BridgeOrchestrator({
390392
<SuccessScreen
391393
client={client}
392394
completedStatuses={state.context.completedStatuses}
393-
onDone={handleBuyComplete}
395+
onDone={handleDoneOrContinueClick}
394396
preparedQuote={state.context.quote}
395397
uiOptions={uiOptions}
396398
windowAdapter={webWindowAdapter}

0 commit comments

Comments
 (0)