Skip to content

Commit

Permalink
Fix wormholescan explorer link not showing for gateway chains (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Picco authored Nov 17, 2023
1 parent e5bd463 commit d58c5e1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions wormhole-connect/src/routes/cosmosGateway/utils/getMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ export async function getUnsignedMessageFromCosmos(
address: tokenAddress,
chain: tokenChain,
},
emitterAddress: '',
sequence: BigNumber.from(0),
});

return {
Expand Down
2 changes: 1 addition & 1 deletion wormhole-connect/src/routes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 26 additions & 21 deletions wormhole-connect/src/views/Redeem/Tag.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<div>
<InputContainer>
Expand Down

0 comments on commit d58c5e1

Please sign in to comment.