|
1 | 1 | import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
2 |
| -import { ChainName, Context } from '@wormhole-foundation/wormhole-connect-sdk'; |
| 2 | +import { |
| 3 | + ChainName, |
| 4 | + ChainId, |
| 5 | + Context, |
| 6 | +} from '@wormhole-foundation/wormhole-connect-sdk'; |
3 | 7 | import { BigNumber } from 'ethers';
|
4 | 8 | import config from 'config';
|
5 | 9 | import { Route, TokenConfig } from 'config/types';
|
@@ -55,6 +59,19 @@ export const getNativeVersionOfToken = (
|
55 | 59 | );
|
56 | 60 | };
|
57 | 61 |
|
| 62 | +// get the token key for the NTT token for a given group and chain |
| 63 | +export const getNttToken = ( |
| 64 | + groupId: string, |
| 65 | + chain: ChainName | ChainId, |
| 66 | +): string => { |
| 67 | + return ( |
| 68 | + Object.entries(config.tokens) |
| 69 | + .map(([key, t]) => t) |
| 70 | + .find((t) => t.ntt?.groupId === groupId && t.nativeChain === chain) |
| 71 | + ?.key || '' |
| 72 | + ); |
| 73 | +}; |
| 74 | + |
58 | 75 | export const accessChainBalances = (
|
59 | 76 | balances: WalletBalances | undefined,
|
60 | 77 | walletAddress: WalletAddress | undefined,
|
@@ -200,7 +217,7 @@ const performModificationsIfFromChainChanged = (state: TransferInputState) => {
|
200 | 217 | state.token = getNativeVersionOfToken(tokenConfig.symbol, fromChain!);
|
201 | 218 | }
|
202 | 219 | } else if (tokenConfig.ntt && tokenConfig.nativeChain !== fromChain) {
|
203 |
| - state.token = getNativeVersionOfToken(tokenConfig.symbol, fromChain!); |
| 220 | + state.token = getNttToken(tokenConfig.ntt.groupId, fromChain!); |
204 | 221 | }
|
205 | 222 | }
|
206 | 223 | };
|
@@ -228,7 +245,7 @@ const performModificationsIfToChainChanged = (state: TransferInputState) => {
|
228 | 245 | state.destToken = getNativeVersionOfToken(tokenConfig.symbol, toChain!);
|
229 | 246 | }
|
230 | 247 | } else if (tokenConfig.ntt && tokenConfig.nativeChain !== toChain) {
|
231 |
| - state.destToken = getNativeVersionOfToken(tokenConfig.symbol, toChain!); |
| 248 | + state.destToken = getNttToken(tokenConfig.ntt.groupId, toChain!); |
232 | 249 | }
|
233 | 250 | }
|
234 | 251 | };
|
|
0 commit comments