diff --git a/.changeset/slimy-chefs-buy.md b/.changeset/slimy-chefs-buy.md new file mode 100644 index 00000000000..85dcdbd5c4e --- /dev/null +++ b/.changeset/slimy-chefs-buy.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Fix `onSuccess` callback was not called correctly on `CheckoutWidget`, `BuyWidget` components diff --git a/packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx b/packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx index aba0fe404d5..8371bd1ba6d 100644 --- a/packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +++ b/packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx @@ -180,14 +180,13 @@ export function BridgeOrchestrator({ const [state, send] = usePaymentMachine(adapters, uiOptions.mode); // Handle buy completion - const handleBuyComplete = useCallback(() => { + const handleDoneOrContinueClick = useCallback(() => { if (uiOptions.mode === "transaction") { send({ type: "CONTINUE_TO_TRANSACTION" }); } else { - onComplete?.(); send({ type: "RESET" }); } - }, [onComplete, send, uiOptions.mode]); + }, [send, uiOptions.mode]); // Handle post-buy transaction completion const handlePostBuyTransactionComplete = useCallback(() => { @@ -230,8 +229,11 @@ export function BridgeOrchestrator({ const handleExecutionComplete = useCallback( (completedStatuses: CompletedStatusResult[]) => { send({ completedStatuses, type: "EXECUTION_COMPLETE" }); + if (uiOptions.mode !== "transaction") { + onComplete?.(); + } }, - [send], + [send, onComplete, uiOptions.mode], ); // Handle retry @@ -390,7 +392,7 @@ export function BridgeOrchestrator({