Skip to content

Commit

Permalink
Fix transfer completion bug in manual transfer claims
Browse files Browse the repository at this point in the history
When claiming a manual transfer, the useTrackTransfer hook sometimes marked the transfer as complete before the async function triggered by the claim button finished. This allowed users to start a new transfer prematurely, causing the new transfer to be erroneously marked as complete. We should rely solely on the useTrackTransfer hook to set the transfer as complete and handle the redeem transaction. This change prevents the bug and moves the transfer.redeem.start event trigger to before the routes redeem function call.
  • Loading branch information
kev1n-peters committed Sep 18, 2024
1 parent 8e6e388 commit 2ef6c98
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions wormhole-connect/src/views/v2/Redeem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { RouteContext } from 'contexts/RouteContext';
import useTrackTransfer from 'hooks/useTrackTransfer';
import PoweredByIcon from 'icons/PoweredBy';
import { SDKv2Signer } from 'routes/sdkv2/signer';
import { setRedeemTx, setTransferComplete } from 'store/redeem';
import { setRoute } from 'store/router';
import { displayAddress, millisToHumanString } from 'utils';
import { interpretTransferError } from 'utils/errors';
Expand Down Expand Up @@ -447,6 +446,11 @@ const Redeem = () => {

let receipt: routes.Receipt | undefined;

config.triggerEvent({
type: 'transfer.redeem.start',
details: transferDetails,
});

if (isTxDestQueued && routes.isFinalizable(route)) {
receipt = await route.finalize(signer, routeContext.receipt);
} else if (!isTxDestQueued && routes.isManual(route)) {
Expand All @@ -461,11 +465,6 @@ const Redeem = () => {
txId = receipt.destinationTxs[receipt.destinationTxs.length - 1].txid;
}

config.triggerEvent({
type: 'transfer.redeem.start',
details: transferDetails,
});

setIsClaimInProgress(false);
setClaimError('');
} catch (e: any) {
Expand All @@ -483,13 +482,6 @@ const Redeem = () => {
console.error(e);
}
if (txId !== undefined) {
dispatch(setRedeemTx(txId));

// Transfer may require an additional step if this is a finalizable route
if (!routes.isFinalizable(route)) {
dispatch(setTransferComplete(true));
}

config.triggerEvent({
type: 'transfer.redeem.success',
details: transferDetails,
Expand Down

0 comments on commit 2ef6c98

Please sign in to comment.