Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VAA Repair/Redeem to support newest protocols in advanced tool #939

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions src/components/Recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
uint8ArrayToHex,
CHAIN_ID_SUI,
getForeignAssetSui,
CHAIN_ID_TO_NAME,
} from "@certusone/wormhole-sdk";
import { repairVaa } from "../utils/repairVaa";
import {
Expand Down Expand Up @@ -94,6 +95,7 @@ import {
CLUSTER,
ALGORAND_INDEXER,
DISABLED_CHAINS,
getTxFromVaaApiRef,
} from "../utils/consts";
import { getSignedVAAWithRetry } from "../utils/getSignedVAAWithRetry";
import {
Expand Down Expand Up @@ -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) => {
Expand All @@ -960,7 +963,7 @@ export default function Recovery() {
dispatch(setSignedVAAHex(recoverySignedVAA));
push("/register");
} else if (
enableRecovery &&
enableAdvToolsRecovery &&
recoverySignedVAA &&
parsedPayloadTargetChain
) {
Expand Down Expand Up @@ -1001,7 +1004,7 @@ export default function Recovery() {
},
[
dispatch,
enableRecovery,
enableAdvToolsRecovery,
recoverySignedVAA,
parsedPayloadTargetChain,
parsedPayload,
Expand All @@ -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);
Expand Down Expand Up @@ -1074,7 +1089,7 @@ export default function Recovery() {
fullWidth
margin="normal"
/>
{enableRecovery && (
{enableAdvToolsRecovery && (
<>
<RelayerRecovery
parsedPayload={parsedPayload}
Expand All @@ -1089,7 +1104,7 @@ export default function Recovery() {
/>
</>
)}
{recoverySignedVAA !== "" &&
{!enableRecovery &&
!(isNFTTransfer || isTokenBridgeTransfer || isTokenBridgetAttest) && (
<ChainWarningMessage>
{NOT_SUPPORTED_VAA_WARNING_MESSAGE}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
};
Loading