From e666bfda9391be327d085fdf9ed448b5c1313c27 Mon Sep 17 00:00:00 2001 From: Daniel Isaac Geslin Date: Fri, 19 Jul 2024 10:48:08 +0200 Subject: [PATCH] Update VAA Repair/Redeem to support newest protocols in advanced tool --- src/components/Recovery.tsx | 31 +++++++++++++++++++++++-------- src/utils/consts.ts | 6 ++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/components/Recovery.tsx b/src/components/Recovery.tsx index 999297dda..cce679ddb 100644 --- a/src/components/Recovery.tsx +++ b/src/components/Recovery.tsx @@ -37,6 +37,7 @@ import { uint8ArrayToHex, CHAIN_ID_SUI, getForeignAssetSui, + CHAIN_ID_TO_NAME, } from "@certusone/wormhole-sdk"; import { repairVaa } from "../utils/repairVaa"; import { @@ -94,6 +95,7 @@ import { CLUSTER, ALGORAND_INDEXER, DISABLED_CHAINS, + getTxFromVaaApiRef, } from "../utils/consts"; import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry"; import { @@ -948,9 +950,10 @@ export default function Recovery() { } }, [recoverySignedVAA]); const parsedPayloadTargetChain = parsedPayload?.targetChain; - const enableRecovery = + const enableAdvToolsRecovery = isTokenBridgetAttest || (recoverySignedVAA && parsedPayloadTargetChain); //&& (isNFTTransfer || isTokenBridgeTransfer); + const enableRecovery = !!recoveryParsedVAA?.emitterChain; const handleRecoverClickBase = useCallback( (useRelayer: boolean) => { @@ -960,7 +963,7 @@ export default function Recovery() { dispatch(setSignedVAAHex(recoverySignedVAA)); push("/register"); } else if ( - enableRecovery && + enableAdvToolsRecovery && recoverySignedVAA && parsedPayloadTargetChain ) { @@ -1001,7 +1004,7 @@ export default function Recovery() { }, [ dispatch, - enableRecovery, + enableAdvToolsRecovery, recoverySignedVAA, parsedPayloadTargetChain, parsedPayload, @@ -1012,9 +1015,21 @@ export default function Recovery() { ] ); - const handleRecoverClick = useCallback(() => { - handleRecoverClickBase(false); - }, [handleRecoverClickBase]); + const handleRecoverClick = useCallback(async () => { + if (enableAdvToolsRecovery) return handleRecoverClickBase(false); + const { emitterChain, emitterAddress, sequence } = recoveryParsedVAA!; + const txDetails = await fetch( + getTxFromVaaApiRef( + [emitterChain, emitterAddress.toString("hex"), sequence].join("/") + ) + ).then((res) => res.json()); + const txHash = txDetails?.sourceChain?.transaction?.txHash; + const sourceChain = CHAIN_ID_TO_NAME[emitterChain as ChainId]; + + if ([sourceChain, txHash].every((i) => typeof i === "string")) { + window.location.href = `${window.location.origin}?txHash=${txHash}&sourceChain=${sourceChain}`; + } + }, [enableAdvToolsRecovery, handleRecoverClickBase, recoveryParsedVAA]); const handleRecoverWithRelayerClick = useCallback(() => { handleRecoverClickBase(true); @@ -1074,7 +1089,7 @@ export default function Recovery() { fullWidth margin="normal" /> - {enableRecovery && ( + {enableAdvToolsRecovery && ( <> )} - {recoverySignedVAA !== "" && + {!enableRecovery && !(isNFTTransfer || isTokenBridgeTransfer || isTokenBridgetAttest) && ( {NOT_SUPPORTED_VAA_WARNING_MESSAGE} diff --git a/src/utils/consts.ts b/src/utils/consts.ts index 3c9883e70..be3823c2c 100644 --- a/src/utils/consts.ts +++ b/src/utils/consts.ts @@ -2244,3 +2244,9 @@ export const getWormholescanLink = (tx: string) => { process.env.REACT_APP_CLUSTER === "mainnet" ? "MAINNET" : "TESTNET" }`; }; + +export const getTxFromVaaApiRef = (vaaID: string) => { + return `https://api.${ + process.env.REACT_APP_CLUSTER === "mainnet" ? "" : "testnet." + }wormholescan.io/api/v1/operations/${vaaID}`; +};