Skip to content

Commit 15f0839

Browse files
committed
SDK: Fix onSuccess prop not called properly on CheckoutWidget and BuyWidget (#8054)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR addresses an issue with the `onSuccess` callback not being triggered properly in the `CheckoutWidget` and `BuyWidget` components, improving the handling of buy completion and post-transaction actions. ### Detailed summary - Renamed `handleBuyComplete` to `handleDoneOrContinueClick`. - Adjusted the invocation of `onComplete` to only occur when `uiOptions.mode` is not "transaction". - Updated the dependency array for `handleExecutionComplete` to include `onComplete` and `uiOptions.mode`. - Changed the `onDone` prop in `SuccessScreen` to use `handleDoneOrContinueClick`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed an issue where the success callback in checkout and buy widgets did not fire reliably. * Improved non-transaction flows so completion triggers after execution finishes (instead of on Done), ensuring proper state reset and more consistent behavior. * **Chores** * Added a patch-level changeset entry documenting the fix. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 04862de commit 15f0839

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)