- {balances[token.key] && walletAddress ? (
+ {balances && balances[token.key] && walletAddress ? (
{balances[token.key]}
) : chain && walletAddress ? (
@@ -266,8 +266,13 @@ function TokensModal(props: Props) {
const [tokens, setTokens] = useState
([]);
const [search, setSearch] = useState('');
- const { balances, supportedSourceTokens, supportedDestTokens, route } =
- useSelector((state: RootState) => state.transferInput);
+ const {
+ balances,
+ supportedSourceTokens,
+ supportedDestTokens,
+ allSupportedDestTokens,
+ route,
+ } = useSelector((state: RootState) => state.transferInput);
const supportedTokens = useMemo(() => {
const supported =
@@ -333,9 +338,12 @@ function TokensModal(props: Props) {
setBalancesLoaded(true);
return;
}
+
+ const queryTokens =
+ type === 'dest' ? allSupportedDestTokens : supportedTokens;
// fetch all N tokens and trigger a single update action
const balancesArr = await Promise.all(
- supportedTokens.map(async (t) => {
+ queryTokens.map(async (t) => {
let balance: BigNumber | null = null;
try {
if (t.tokenId) {
@@ -447,7 +455,7 @@ function TokensModal(props: Props) {
label: 'All Tokens',
panel: (
{
state.supportedDestTokens = payload;
},
+ setAllSupportedDestTokens: (
+ state: TransferInputState,
+ { payload }: PayloadAction,
+ ) => {
+ state.allSupportedDestTokens = payload;
+ },
swapChains: (state: TransferInputState) => {
const tmp = state.fromChain;
state.fromChain = state.toChain;
@@ -335,6 +343,7 @@ export const {
setIsTransactionInProgress,
setReceiverNativeBalance,
setSupportedDestTokens,
+ setAllSupportedDestTokens,
setSupportedSourceTokens,
swapChains,
} = transferInputSlice.actions;
diff --git a/wormhole-connect/src/utils/routes/baseRoute.ts b/wormhole-connect/src/utils/routes/baseRoute.ts
index 9882f8b91..6cbee8985 100644
--- a/wormhole-connect/src/utils/routes/baseRoute.ts
+++ b/wormhole-connect/src/utils/routes/baseRoute.ts
@@ -11,10 +11,10 @@ export abstract class BaseRoute extends RouteAbstract {
sourceChain?: ChainName | ChainId,
): Promise {
if (!token) return false;
- if (destToken) {
- const wrapped = getWrappedToken(token);
- return wrapped.key === destToken.key;
- }
+ // if (destToken) {
+ // const wrapped = getWrappedToken(token);
+ // return wrapped.key === destToken.key;
+ // }
if (!sourceChain) return true;
const chainName = wh.toChainName(sourceChain);
diff --git a/wormhole-connect/src/utils/transferValidation.ts b/wormhole-connect/src/utils/transferValidation.ts
index fd7507267..d5d8e3b0f 100644
--- a/wormhole-connect/src/utils/transferValidation.ts
+++ b/wormhole-connect/src/utils/transferValidation.ts
@@ -3,7 +3,7 @@ import { AnyAction } from '@reduxjs/toolkit';
import { ChainName } from '@wormhole-foundation/wormhole-connect-sdk';
import { BRIDGE_DEFAULTS, CHAINS, TOKENS } from 'config';
-import { Route } from 'config/types';
+import { Route, TokenConfig } from 'config/types';
import { SANCTIONED_WALLETS } from 'consts/wallet';
import { store } from 'store';
import {
@@ -74,6 +74,7 @@ export const validateToken = (
export const validateDestToken = (
token: string,
chain: ChainName | undefined,
+ supportedTokens: TokenConfig[],
): ValidationErr => {
if (!token) return 'Select an asset';
const tokenConfig = TOKENS[token];
@@ -84,6 +85,9 @@ export const validateDestToken = (
if (!tokenConfig.tokenId && tokenConfig.nativeChain !== chain)
return `${token} not available on ${chain}, select a different token`;
}
+ if (!supportedTokens.some((t) => t.key === token)) {
+ return 'No route available for this token, please select another';
+ }
return '';
};
@@ -196,6 +200,7 @@ export const validateAll = async (
foreignAsset,
associatedTokenAddress,
route,
+ supportedDestTokens,
availableRoutes,
} = transferData;
const { maxSwapAmt, toNativeToken } = relayData;
@@ -210,7 +215,7 @@ export const validateAll = async (
fromChain: validateFromChain(fromChain),
toChain: validateToChain(toChain, fromChain),
token: validateToken(token, fromChain),
- destToken: validateDestToken(destToken, toChain),
+ destToken: validateDestToken(destToken, toChain, supportedDestTokens),
amount: validateAmount(amount, sendingTokenBalance, minAmt),
route: validateRoute(route, availableRoutes),
toNativeToken: '',
diff --git a/wormhole-connect/src/views/Bridge/Bridge.tsx b/wormhole-connect/src/views/Bridge/Bridge.tsx
index 2ffe098a2..ac6064662 100644
--- a/wormhole-connect/src/views/Bridge/Bridge.tsx
+++ b/wormhole-connect/src/views/Bridge/Bridge.tsx
@@ -11,6 +11,7 @@ import {
setToken,
setSupportedSourceTokens,
setSupportedDestTokens,
+ setAllSupportedDestTokens,
setTransferRoute,
TransferInputState,
} from 'store/transferInput';
@@ -135,6 +136,12 @@ function Bridge() {
toChain,
);
dispatch(setSupportedDestTokens(supported));
+ const allSupported = await RouteOperator.allSupportedDestTokens(
+ undefined,
+ fromChain,
+ toChain,
+ );
+ dispatch(setAllSupportedDestTokens(allSupported));
const selectedIsSupported = isSupportedToken(destToken, supported);
if (!selectedIsSupported) {
dispatch(setDestToken(''));