Skip to content

Commit

Permalink
Show canonical tokens even when wallet is not connected (#2712)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kev1n-peters committed Sep 24, 2024
1 parent 6046c3b commit b0dc901
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions wormhole-connect/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 15 additions & 2 deletions wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b0dc901

Please sign in to comment.