fix(subscriptions): do not silently swallow cancel transaction build or signing errors (#16) - #98
Open
ghzhost wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #16 by ensuring
useCancelSubscriptiondoes not silently swallow errors during cancellation transaction building or user signing.Context & Root Cause
Previously,
useCancelSubscriptionwrappedsubscriptionApi.buildCancelTransaction(subscriptionId)andsignTransaction(built.xdr)in a broadtry/catchblock:This conflated the legitimate case where no signature is required (backend returns
{ xdr: undefined }) with actual failure modes:buildCancelTransactionthrew an error (backend 500, network error, invalid subscription state), the error was caught andsubscriptionApi.cancel(subscriptionId, undefined)was executed anyway, potentially marking the subscription cancelled in the database while leaving the on-chain standing order active.signTransactionrejecting), the error was caught and cancellation proceeded without the required authorization against the user's explicit decision.Fix
try/catchswallowing aroundbuildCancelTransactionandsignTransaction.built?.xdris falsy/undefined,signedXdrremainsundefinedandsubscriptionApi.cancel(subscriptionId, undefined)is called.built?.xdrexists,signTransactionis invoked and its signed XDR is passed tosubscriptionApi.cancel.buildCancelTransactionorsignTransactionrejects/throws, the mutation properly throws and aborts without callingcancel.Test Plan
src/hooks/useSubscriptions.test.tsx:built.xdr === undefined).built.xdr === '...'), ensuringsignedXdris passed tosubscriptionApi.cancel.cancelfrom being called.cancelfrom being called.NODE_ENV=development npx vitest run) -> 27 test files passed, 117 tests passed.npm run build) -> TypeScript check and Vite build passed cleanly.