Skip to content

Commit

Permalink
Fix: Resume transaction always trigger 'transfer.success' event (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuli-ferna authored May 6, 2024
1 parent 84d2ba9 commit 0aab249
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
9 changes: 9 additions & 0 deletions wormhole-connect/src/store/redeem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface RedeemState {
route: Route | undefined;
transferDestInfo: TransferDestInfo | undefined;
deliveryStatus: DeliveryStatus | undefined;
isResumeTx: boolean;
}

const initialState: RedeemState = {
Expand All @@ -33,6 +34,7 @@ const initialState: RedeemState = {
route: undefined,
transferDestInfo: undefined,
deliveryStatus: undefined,
isResumeTx: false,
};

export const redeemSlice = createSlice({
Expand Down Expand Up @@ -100,6 +102,12 @@ export const redeemSlice = createSlice({
) => {
state.isInvalidVaa = payload;
},
setIsResumeTx: (
state: RedeemState,
{ payload }: PayloadAction<boolean>,
) => {
state.isResumeTx = payload;
},
},
});

Expand All @@ -115,6 +123,7 @@ export const {
setRoute,
setSignedMessage,
setDeliveryStatus,
setIsResumeTx,
} = redeemSlice.actions;

export default redeemSlice.reducer;
27 changes: 16 additions & 11 deletions wormhole-connect/src/views/Redeem/Redeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Redeem({
txData,
transferComplete,
isVaaEnqueued,
isResumeTx,
route,
signedMessage,
}: {
Expand All @@ -48,6 +49,7 @@ function Redeem({
txData: ParsedMessage | ParsedRelayerMessage | undefined;
transferComplete: boolean;
isVaaEnqueued: boolean;
isResumeTx: boolean;
route: Route | undefined;
signedMessage: SignedMessage | undefined;
}) {
Expand Down Expand Up @@ -144,17 +146,18 @@ function Redeem({
}
if (isComplete) {
setTransferComplete();

config.triggerEvent({
type: 'transfer.success',
details: {
route,
fromToken: getTokenDetails(txData.tokenKey),
toToken: getTokenDetails(txData.receivedTokenKey),
fromChain: txData.fromChain,
toChain: txData.toChain,
},
});
if (!isResumeTx) {
config.triggerEvent({
type: 'transfer.success',
details: {
route,
fromToken: getTokenDetails(txData.tokenKey),
toToken: getTokenDetails(txData.receivedTokenKey),
fromChain: txData.fromChain,
toChain: txData.toChain,
},
});
}
} else {
await sleep(i < 10 ? 3000 : 30000);
}
Expand Down Expand Up @@ -204,6 +207,7 @@ function mapStateToProps(state: RootState) {
txData,
transferComplete,
isVaaEnqueued,
isResumeTx,
isInvalidVaa,
route,
signedMessage,
Expand All @@ -213,6 +217,7 @@ function mapStateToProps(state: RootState) {
txData,
transferComplete,
isVaaEnqueued,
isResumeTx,
isInvalidVaa,
route,
signedMessage,
Expand Down
7 changes: 6 additions & 1 deletion wormhole-connect/src/views/TxSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { ChainName } from '@wormhole-foundation/wormhole-connect-sdk';
import config from 'config';
import { isValidTxId } from 'utils';
import RouteOperator from 'routes/operator';
import { setTxDetails, setRoute as setRedeemRoute } from 'store/redeem';
import {
setTxDetails,
setRoute as setRedeemRoute,
setIsResumeTx,
} from 'store/redeem';
import { setRoute as setAppRoute } from 'store/router';
import PageHeader from 'components/PageHeader';
import Search from 'components/Search';
Expand Down Expand Up @@ -90,6 +94,7 @@ function TxSearch() {
);
setError('');
dispatch(setTxDetails(message));
dispatch(setIsResumeTx(true)); // To avoid send transfer.success event in Resume Transaction case
dispatch(setRedeemRoute(route));
dispatch(setAppRoute('redeem'));
dispatch(setToChain(message.toChain));
Expand Down

0 comments on commit 0aab249

Please sign in to comment.