From d58c5e10abd2c4cb736907d90800feb85ab25e61 Mon Sep 17 00:00:00 2001 From: Martin Picco Date: Fri, 17 Nov 2023 11:43:16 -0300 Subject: [PATCH] Fix wormholescan explorer link not showing for gateway chains (#1244) --- sdk/src/types.ts | 4 +- .../routes/cosmosGateway/utils/getMessage.ts | 2 - wormhole-connect/src/routes/utils.ts | 2 +- wormhole-connect/src/views/Redeem/Tag.tsx | 47 ++++++++++--------- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/sdk/src/types.ts b/sdk/src/types.ts index 3fa70e787..61a3c9697 100644 --- a/sdk/src/types.ts +++ b/sdk/src/types.ts @@ -108,8 +108,8 @@ export interface ParsedMessage { tokenAddress: string; tokenChain: ChainName; tokenId: TokenId; - sequence: BigNumber; - emitterAddress: string; + sequence?: BigNumber; + emitterAddress?: string; block: number; gasFee?: BigNumber; payload?: string; diff --git a/wormhole-connect/src/routes/cosmosGateway/utils/getMessage.ts b/wormhole-connect/src/routes/cosmosGateway/utils/getMessage.ts index 1c1fbb170..5eec60e4e 100644 --- a/wormhole-connect/src/routes/cosmosGateway/utils/getMessage.ts +++ b/wormhole-connect/src/routes/cosmosGateway/utils/getMessage.ts @@ -98,8 +98,6 @@ export async function getUnsignedMessageFromCosmos( address: tokenAddress, chain: tokenChain, }, - emitterAddress: '', - sequence: BigNumber.from(0), }); return { diff --git a/wormhole-connect/src/routes/utils.ts b/wormhole-connect/src/routes/utils.ts index 772120ad1..0a5c12ec1 100644 --- a/wormhole-connect/src/routes/utils.ts +++ b/wormhole-connect/src/routes/utils.ts @@ -35,7 +35,7 @@ export const adaptParsedMessage = async ( tokenKey: token?.key || '', tokenDecimals: decimals, receivedTokenKey: token?.key || '', - sequence: parsed.sequence.toString(), + sequence: parsed.sequence?.toString(), gasFee: parsed.gasFee ? parsed.gasFee.toString() : undefined, }; // get wallet address of associated token account for Solana diff --git a/wormhole-connect/src/views/Redeem/Tag.tsx b/wormhole-connect/src/views/Redeem/Tag.tsx index ea4c4797d..b1d7a1d20 100644 --- a/wormhole-connect/src/views/Redeem/Tag.tsx +++ b/wormhole-connect/src/views/Redeem/Tag.tsx @@ -1,10 +1,11 @@ import { CHAIN_ID_WORMCHAIN } from '@certusone/wormhole-sdk'; +import { stripHexPrefix } from '@wormhole-foundation/wormhole-connect-sdk'; import LaunchIcon from '@mui/icons-material/Launch'; import InputContainer from 'components/InputContainer'; import { CHAINS, WORMSCAN, isMainnet } from 'config'; import ArrowRight from 'icons/ArrowRight'; import TokenIcon from 'icons/TokenIcons'; -import React from 'react'; +import React, { useMemo } from 'react'; import { useSelector } from 'react-redux'; import { RootState } from 'store'; import { makeStyles } from 'tss-react/mui'; @@ -36,29 +37,33 @@ const useStyles = makeStyles()((theme) => ({ function ChainsTag() { const { classes } = useStyles(); const txData = useSelector((state: RootState) => state.redeem.txData)!; + const signedMessage = useSelector( + (state: RootState) => state.redeem.signedMessage, + ); const fromChainConfig = CHAINS[txData.fromChain]!; const toChainConfig = CHAINS[txData.toChain]!; - const emitterAddress = txData.emitterAddress - ? txData.emitterAddress.startsWith('0x') - ? txData.emitterAddress.slice(2) - : txData.emitterAddress - : undefined; - // As of 2023-10-12, wormscan only supports tx lookup on EVM chains (before a VAA is generated) - const link = - txData && - (isEvmChain(fromChainConfig.id) && txData.sendTx - ? `${WORMSCAN}tx/${txData.sendTx}${isMainnet ? '' : '?network=TESTNET'}` - : txData.emitterAddress && - txData.sequence && - // Gateway-connected chain VAAs come from gateway - `${WORMSCAN}tx/${ - isGatewayChain(fromChainConfig.id) - ? CHAIN_ID_WORMCHAIN - : fromChainConfig.id - }/${emitterAddress}/${txData.sequence}${ - isMainnet ? '' : '?network=TESTNET' - }`); + const sendTx = txData.sendTx || signedMessage?.sendTx; + const sequence = txData.sequence || signedMessage?.sequence; + const baseEmitter = txData.emitterAddress || signedMessage?.emitterAddress; + + const emitter = baseEmitter ? stripHexPrefix(baseEmitter) : undefined; + + const link = useMemo(() => { + if (!txData) return; + // As of 2023-10-12, wormscan only supports tx lookup on EVM chains (before a VAA is generated) + if (isEvmChain(fromChainConfig.id) && sendTx) { + return `${WORMSCAN}tx/${sendTx}${isMainnet ? '' : '?network=TESTNET'}`; + } + if (!emitter || !sequence) return; + + const chainId = isGatewayChain(fromChainConfig.id) + ? CHAIN_ID_WORMCHAIN + : fromChainConfig.id; + return `${WORMSCAN}tx/${chainId}/${emitter}/${sequence}${ + isMainnet ? '' : '?network=TESTNET' + }`; + }, [txData, sendTx, emitter, sequence, fromChainConfig.id]); return (