From b0dc90169d0def9d12b7e34b050e2ff15aab728f Mon Sep 17 00:00:00 2001 From: kev1n-peters <96065607+kev1n-peters@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:42:45 -0500 Subject: [PATCH] Show canonical tokens even when wallet is not connected (#2712) * Show canonical tokens even when wallet is not connected Wormhole-wrapped Ethereum USDC was not showing with Sui as the source chain, because it's a Wormhole-wrapped token, and we only display those if the user has a balance. However, this token is canonical on Sui, so we want to display it even when the users's wallet isn't connected. Added an `isCanonical` function that the `TokenList` uses. Fixes #2690 * add comments, missed search case --- wormhole-connect/src/utils/index.ts | 6 ++++++ .../views/v2/Bridge/AssetPicker/TokenList.tsx | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/wormhole-connect/src/utils/index.ts b/wormhole-connect/src/utils/index.ts index 1a53ef24a..d465686bd 100644 --- a/wormhole-connect/src/utils/index.ts +++ b/wormhole-connect/src/utils/index.ts @@ -408,6 +408,12 @@ export const isWrappedToken = (token: TokenConfig, chain: Chain) => { return token.nativeChain !== chain; }; +// Canonical tokens may be Wormhole-wrapped tokens that are canonical on the chain +// e.g., Wormhole-wrapped Ethereum USDC is canonical on Sui +export const isCanonicalToken = (token: TokenConfig, chain: Chain) => { + return token.key === 'USDCeth' && chain === 'Sui'; +}; + export const millisToHumanString = (ts: number): string => { if (ts > 60000) { const minutes = Math.ceil(ts / 60000); diff --git a/wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx b/wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx index 5fd0f1821..2742a9f29 100644 --- a/wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx +++ b/wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx @@ -13,7 +13,12 @@ import type { ChainConfig, TokenConfig } from 'config/types'; import type { WalletData } from 'store/wallet'; import SearchableList from 'views/v2/Bridge/AssetPicker/SearchableList'; import TokenItem from 'views/v2/Bridge/AssetPicker/TokenItem'; -import { getDisplayName, isFrankensteinToken, isWrappedToken } from 'utils'; +import { + getDisplayName, + isCanonicalToken, + isFrankensteinToken, + isWrappedToken, +} from 'utils'; import { getTokenBridgeWrappedTokenAddressSync } from 'utils/sdkv2'; const useStyles = makeStyles()((theme) => ({ @@ -89,9 +94,11 @@ const TokenList = (props: Props) => { } // Exclude wormhole-wrapped tokens with no balance + // unless it's canonical if ( props.isSource && isWrappedToken(tokenConfig, selectedChainConfig.key) && + !isCanonicalToken(tokenConfig, selectedChainConfig.key) && !balance ) { return; @@ -209,7 +216,13 @@ const TokenList = (props: Props) => { } // Exclude wormhole-wrapped tokens with no balance - if (props.isSource && isWrappedToken(token, chain) && !balance) { + // unless it's canonical + if ( + props.isSource && + isWrappedToken(token, chain) && + !isCanonicalToken(token, chain) && + !balance + ) { return false; }