From 477dece27ac0617b4e0398be51b1be5645585979 Mon Sep 17 00:00:00 2001 From: Martin Homola Date: Tue, 26 Nov 2024 19:33:43 +0100 Subject: [PATCH] chore(suite): update network symbol naming --- .../components/SelectAssetModal/AssetItem.tsx | 105 ++++++------ .../SelectAssetModal.stories.tsx | 6 +- .../SelectAssetModal.storiesData.ts | 152 +++++++++--------- .../SelectAssetModal/SelectAssetModal.tsx | 14 +- .../modals/ReduxModal/ConfirmAddressModal.tsx | 8 +- .../form/common/useCoinmarketFiatValues.tsx | 20 +-- .../form/common/useCoinmarketFormActions.ts | 6 +- .../useCoinmarketExchangeFormDefaultValues.ts | 7 +- .../useCoinmarketSellFormDefaultValues.ts | 4 +- .../form/useCoinmarketVerifyAccount.tsx | 16 +- .../wallet/coinmarket/useCoinmarketInfo.ts | 4 +- .../suite/src/types/coinmarket/coinmarket.ts | 4 +- .../src/types/coinmarket/coinmarketVerify.ts | 2 +- .../wallet/coinmarket/coinmarketUtils.ts | 14 +- .../common/CoinmarketAddressOptions.tsx | 2 +- .../coinmarket/common/CoinmarketBalance.tsx | 22 ++- .../CoinmarketFormInputAccount.tsx | 2 +- .../CoinmarketFormInputCryptoSelect.tsx | 12 +- .../CoinmarketFormInputCryptoAmount.tsx | 4 +- .../CoinmarketForm/CoinmarketFormInputs.tsx | 4 +- .../CoinmarketFormOfferCryptoAmount.tsx | 6 +- .../CoinmarketVerifyOptionsItem.tsx | 2 +- .../send/Outputs/TokenSelect/TokenSelect.tsx | 10 +- .../__tests__/filterReceiveAccounts.test.ts | 16 +- .../wallet-utils/src/filterReceiveAccounts.ts | 6 +- 25 files changed, 224 insertions(+), 224 deletions(-) diff --git a/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx b/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx index e0e9fa81315..fbb9e7853b8 100644 --- a/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx +++ b/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx @@ -7,6 +7,7 @@ import { getContractAddressForNetwork } from '@suite-common/wallet-utils'; import { CoinLogo } from '../CoinLogo/CoinLogo'; import { AssetOptionBaseProps } from './SelectAssetModal'; +import { COINS } from '../CoinLogo/coins'; const ClickableContainer = styled.div` cursor: pointer; @@ -33,58 +34,62 @@ interface AssetItemProps extends AssetOptionBaseProps { export const AssetItem = ({ cryptoName, - symbol, + ticker, badge, - networkSymbol, + symbolExtended, coingeckoId, shouldTryToFetch, contractAddress, handleClick, -}: AssetItemProps) => ( - - handleClick({ - symbol, - contractAddress: contractAddress ?? null, - networkSymbol, - coingeckoId, - cryptoName, - }) - } - > - - {coingeckoId ? ( - - ) : ( - - )} - - - - - {cryptoName} - - - {badge && ( - - {badge} - - )} - - - {symbol.toUpperCase()} - - - - -); +}: AssetItemProps) => { + const symbol = symbolExtended in COINS ? (symbolExtended as NetworkSymbol) : undefined; + + return ( + + handleClick({ + ticker, + contractAddress: contractAddress ?? null, + symbolExtended, + coingeckoId, + cryptoName, + }) + } + > + + {coingeckoId ? ( + + ) : ( + symbol && + )} + + + + + {cryptoName} + + + {badge && ( + + {badge} + + )} + + + {ticker.toUpperCase()} + + + + + ); +}; diff --git a/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.stories.tsx b/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.stories.tsx index 1937e255483..77a5cd9d1f2 100644 --- a/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.stories.tsx +++ b/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.stories.tsx @@ -35,9 +35,9 @@ const getData = (options: typeof selectAssetModalOptions): AssetProps[] => options .filter(item => item.type === 'currency') .map(item => ({ - symbol: item.label ?? item.symbol, - networkSymbol: item.networkSymbol, - cryptoName: item.cryptoName ?? item.symbol, + ticker: item.label ?? item.ticker, + symbolExtended: item.symbolExtended, + cryptoName: item.cryptoName ?? item.ticker, badge: item.badge ?? item.networkName, coingeckoId: item.coingeckoId, contractAddress: item.contractAddress, diff --git a/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.storiesData.ts b/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.storiesData.ts index f4f5f882a8e..f5c8ef28508 100644 --- a/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.storiesData.ts +++ b/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.storiesData.ts @@ -31,8 +31,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Bitcoin', coingeckoId: 'bitcoin', contractAddress: null, - symbol: 'BTC', - networkSymbol: 'btc', + ticker: 'BTC', + symbolExtended: 'btc', }, { type: 'currency', @@ -41,8 +41,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Litecoin', coingeckoId: 'litecoin', contractAddress: null, - symbol: 'LTC', - networkSymbol: 'ltc', + ticker: 'LTC', + symbolExtended: 'ltc', }, { type: 'currency', @@ -51,8 +51,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Cardano', coingeckoId: 'cardano', contractAddress: null, - symbol: 'ADA', - networkSymbol: 'ada', + ticker: 'ADA', + symbolExtended: 'ada', }, { type: 'currency', @@ -61,8 +61,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Solana', coingeckoId: 'solana', contractAddress: null, - symbol: 'SOL', - networkSymbol: 'sol', + ticker: 'SOL', + symbolExtended: 'sol', }, { type: 'currency', @@ -71,8 +71,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Bitcoin Gold', coingeckoId: 'bitcoin-gold', contractAddress: null, - symbol: 'BTG', - networkSymbol: 'btg', + ticker: 'BTG', + symbolExtended: 'btg', }, { type: 'currency', @@ -81,8 +81,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Zcash', coingeckoId: 'zcash', contractAddress: null, - symbol: 'ZEC', - networkSymbol: 'zec', + ticker: 'ZEC', + symbolExtended: 'zec', }, { type: 'currency', @@ -91,8 +91,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Ethereum Classic', coingeckoId: 'ethereum-classic', contractAddress: null, - symbol: 'ETC', - networkSymbol: 'etc', + ticker: 'ETC', + symbolExtended: 'etc', }, { type: 'currency', @@ -101,8 +101,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Bitcoin Cash', coingeckoId: 'bitcoin-cash', contractAddress: null, - symbol: 'BCH', - networkSymbol: 'bch', + ticker: 'BCH', + symbolExtended: 'bch', }, { type: 'currency', @@ -111,8 +111,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Dash', coingeckoId: 'dash', contractAddress: null, - symbol: 'DASH', - networkSymbol: 'dash', + ticker: 'DASH', + symbolExtended: 'dash', }, { type: 'currency', @@ -121,8 +121,8 @@ export const selectAssetModalOptions: ( cryptoName: 'XRP', coingeckoId: 'ripple', contractAddress: null, - symbol: 'XRP', - networkSymbol: 'xrp', + ticker: 'XRP', + symbolExtended: 'xrp', }, { type: 'currency', @@ -131,8 +131,8 @@ export const selectAssetModalOptions: ( cryptoName: 'DigiByte', coingeckoId: 'digibyte', contractAddress: null, - symbol: 'DGB', - networkSymbol: 'dgb', + ticker: 'DGB', + symbolExtended: 'dgb', }, { type: 'currency', @@ -141,8 +141,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Dogecoin', coingeckoId: 'dogecoin', contractAddress: null, - symbol: 'DOGE', - networkSymbol: 'doge', + ticker: 'DOGE', + symbolExtended: 'doge', }, { type: 'currency', @@ -151,8 +151,8 @@ export const selectAssetModalOptions: ( cryptoName: 'POL (ex-MATIC)', coingeckoId: 'polygon-ecosystem-token', contractAddress: null, - symbol: 'POL', - networkSymbol: 'pol', + ticker: 'POL', + symbolExtended: 'pol', }, { type: 'currency', @@ -161,8 +161,8 @@ export const selectAssetModalOptions: ( cryptoName: 'BNB', coingeckoId: 'binancecoin', contractAddress: null, - symbol: 'BNB', - networkSymbol: 'bnb', + ticker: 'BNB', + symbolExtended: 'bnb', }, { type: 'group', @@ -175,8 +175,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Monero', coingeckoId: 'monero', contractAddress: null, - symbol: 'XMR', - networkSymbol: 'monero', + ticker: 'XMR', + symbolExtended: 'monero', }, { type: 'currency', @@ -185,8 +185,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Verge', coingeckoId: 'verge', contractAddress: null, - symbol: 'XVG', - networkSymbol: 'verge', + ticker: 'XVG', + symbolExtended: 'verge', }, { type: 'currency', @@ -195,8 +195,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Qtum', coingeckoId: 'qtum', contractAddress: null, - symbol: 'QTUM', - networkSymbol: 'qtum', + ticker: 'QTUM', + symbolExtended: 'qtum', }, { type: 'currency', @@ -205,8 +205,8 @@ export const selectAssetModalOptions: ( cryptoName: 'Stellar', coingeckoId: 'stellar', contractAddress: null, - symbol: 'XLM', - networkSymbol: 'stellar', + ticker: 'XLM', + symbolExtended: 'stellar', }, { type: 'currency', @@ -215,8 +215,8 @@ export const selectAssetModalOptions: ( cryptoName: 'NEM', coingeckoId: 'nem', contractAddress: null, - symbol: 'XEM', - networkSymbol: 'nem', + ticker: 'XEM', + symbolExtended: 'nem', }, { type: 'group', @@ -232,8 +232,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0xd26114cd6ee289accf82350c8d8487fedb8a0c07', networkName: 'Ethereum', - symbol: 'OMG', - networkSymbol: 'eth', + ticker: 'OMG', + symbolExtended: 'eth', }, { type: 'currency', @@ -243,8 +243,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0x595832f8fc6bf59c85c527fec3740a1b7a361269', networkName: 'Ethereum', - symbol: 'POWR', - networkSymbol: 'eth', + ticker: 'POWR', + symbolExtended: 'eth', }, { type: 'currency', @@ -254,8 +254,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0x41e5560054824ea6b0732e656e3ad64e20e94e45', networkName: 'Ethereum', - symbol: 'CVC', - networkSymbol: 'eth', + ticker: 'CVC', + symbolExtended: 'eth', }, { type: 'currency', @@ -265,8 +265,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac', networkName: 'Ethereum', - symbol: 'STORJ', - networkSymbol: 'eth', + ticker: 'STORJ', + symbolExtended: 'eth', }, { type: 'currency', @@ -276,8 +276,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0x744d70fdbe2ba4cf95131626614a1763df805b9e', networkName: 'Ethereum', - symbol: 'SNT', - networkSymbol: 'eth', + ticker: 'SNT', + symbolExtended: 'eth', }, { type: 'currency', @@ -287,8 +287,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498', networkName: 'Ethereum', - symbol: 'ZRX', - networkSymbol: 'eth', + ticker: 'ZRX', + symbolExtended: 'eth', }, { type: 'currency', @@ -298,8 +298,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0xbbbbca6a901c926f240b89eacb641d8aec7aeafd', networkName: 'Ethereum', - symbol: 'LRC', - networkSymbol: 'eth', + ticker: 'LRC', + symbolExtended: 'eth', }, { type: 'currency', @@ -309,8 +309,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0xade00c28244d5ce17d72e40330b1c318cd12b7c3', networkName: 'Ethereum', - symbol: 'ADX', - networkSymbol: 'eth', + ticker: 'ADX', + symbolExtended: 'eth', }, { type: 'currency', @@ -320,8 +320,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'ethereum', contractAddress: '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c', networkName: 'Ethereum', - symbol: 'BNT', - networkSymbol: 'eth', + ticker: 'BNT', + symbolExtended: 'eth', }, { type: 'group', @@ -337,8 +337,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'solana', contractAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', networkName: 'Solana', - symbol: 'USDT', - networkSymbol: 'sol', + ticker: 'USDT', + symbolExtended: 'sol', }, { type: 'currency', @@ -348,8 +348,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'solana', contractAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', networkName: 'Solana', - symbol: 'USDC', - networkSymbol: 'sol', + ticker: 'USDC', + symbolExtended: 'sol', }, { type: 'currency', @@ -359,8 +359,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'solana', contractAddress: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R', networkName: 'Solana', - symbol: 'RAY', - networkSymbol: 'sol', + ticker: 'RAY', + symbolExtended: 'sol', }, { type: 'currency', @@ -370,8 +370,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'solana', contractAddress: '7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx', networkName: 'Solana', - symbol: 'GMT', - networkSymbol: 'sol', + ticker: 'GMT', + symbolExtended: 'sol', }, { type: 'group', @@ -387,8 +387,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'binance-smart-chain', contractAddress: '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82', networkName: 'BNB Smart Chain', - symbol: 'CAKE', - networkSymbol: 'binance-smart-chain', + ticker: 'CAKE', + symbolExtended: 'binance-smart-chain', }, { type: 'currency', @@ -398,8 +398,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'binance-smart-chain', contractAddress: '0xe02df9e3e622debdd69fb838bb799e3f168902c5', networkName: 'BNB Smart Chain', - symbol: 'BAKE', - networkSymbol: 'binance-smart-chain', + ticker: 'BAKE', + symbolExtended: 'binance-smart-chain', }, { type: 'currency', @@ -409,8 +409,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'binance-smart-chain', contractAddress: '0xfd7b3a77848f1c2d67e05e54d78d174a0c850335', networkName: 'BNB Smart Chain', - symbol: 'ONT', - networkSymbol: 'binance-smart-chain', + ticker: 'ONT', + symbolExtended: 'binance-smart-chain', }, { type: 'currency', @@ -420,8 +420,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'binance-smart-chain', contractAddress: '0xe9e7cea3dedca5984780bafc599bd69add087d56', networkName: 'BNB Smart Chain', - symbol: 'BUSD', - networkSymbol: 'binance-smart-chain', + ticker: 'BUSD', + symbolExtended: 'binance-smart-chain', }, { type: 'group', @@ -437,8 +437,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'base', contractAddress: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', networkName: 'Base', - symbol: 'USDC', - networkSymbol: 'base', + ticker: 'USDC', + symbolExtended: 'base', }, { type: 'currency', @@ -448,8 +448,8 @@ export const selectAssetModalOptions: ( coingeckoId: 'base', contractAddress: '0x532f27101965dd16442e59d40670faf5ebb142e4', networkName: 'Base', - symbol: 'BRETT', - networkSymbol: 'base', + ticker: 'BRETT', + symbolExtended: 'base', }, ]; diff --git a/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.tsx b/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.tsx index 9af6945b0e8..150955b7084 100644 --- a/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.tsx +++ b/packages/product-components/src/components/SelectAssetModal/SelectAssetModal.tsx @@ -9,9 +9,9 @@ import { AssetItem } from './AssetItem'; import { AssetItemNotFound } from './AssetItemNotFound'; export interface AssetProps { - symbol: string; + ticker: string; badge?: ReactNode; - networkSymbol: NetworkSymbol | (string & {}); + symbolExtended: NetworkSymbol | (string & {}); cryptoName?: string; coingeckoId?: string; contractAddress: string | null; @@ -82,20 +82,20 @@ export const SelectAssetModal = ({ onScroll={onScroll} renderItem={({ cryptoName, - symbol, + ticker, coingeckoId, - networkSymbol, + symbolExtended, badge, contractAddress, shouldTryToFetch, }: AssetProps) => ( { if (modalCryptoId) { const coinSymbol = cryptoIdToCoinSymbol(modalCryptoId)?.toUpperCase(); - const networkSymbol = cryptoIdToNetworkSymbol(modalCryptoId)?.toUpperCase(); + const symbol = cryptoIdToSymbol(modalCryptoId)?.toUpperCase(); - if (networkSymbol && coinSymbol !== networkSymbol) { + if (symbol && coinSymbol !== symbol) { return ( diff --git a/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFiatValues.tsx b/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFiatValues.tsx index 398e57fe724..d4dbd626fdb 100644 --- a/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFiatValues.tsx +++ b/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFiatValues.tsx @@ -12,7 +12,7 @@ import { useBitcoinAmountUnit } from 'src/hooks/wallet/useBitcoinAmountUnit'; import { selectLocalCurrency } from 'src/reducers/wallet/settingsReducer'; import { CoinmarketAccountOptionsGroupOptionProps } from 'src/types/coinmarket/coinmarket'; import { - cryptoIdToNetworkSymbol, + cryptoIdToSymbol, mapTestnetSymbol, getCoinmarketNetworkDecimals, } from 'src/utils/wallet/coinmarket/coinmarketUtils'; @@ -27,7 +27,7 @@ interface CoinmarketBalanceReturnProps { fiatRate: Rate | undefined; accountBalance: string; formattedBalance: string; - networkSymbol: NetworkSymbol; + symbol: NetworkSymbol; networkDecimals: number; tokenAddress: TokenAddress | undefined; fiatRatesUpdater: (value: FiatCurrencyCode | undefined) => Promise; @@ -39,13 +39,13 @@ export const useCoinmarketFiatValues = ({ }: CoinmarketBalanceProps): CoinmarketBalanceReturnProps | null => { const dispatch = useDispatch(); const defaultCryptoSymbol = 'btc'; - const networkSymbol = sendCryptoSelect - ? cryptoIdToNetworkSymbol(sendCryptoSelect.value) ?? defaultCryptoSymbol + const symbol = sendCryptoSelect + ? cryptoIdToSymbol(sendCryptoSelect.value) ?? defaultCryptoSymbol : defaultCryptoSymbol; const tokenAddressTyped = (sendCryptoSelect?.contractAddress ?? undefined) as | TokenAddress | undefined; - const symbolForFiat = mapTestnetSymbol(networkSymbol); + const symbolForFiat = mapTestnetSymbol(symbol); const localCurrency = useSelector(selectLocalCurrency); const fiatRateKey = getFiatRateKey( symbolForFiat, @@ -55,8 +55,8 @@ export const useCoinmarketFiatValues = ({ const fiatRate = useSelector(state => selectFiatRatesByFiatRateKey(state, fiatRateKey)); const balance = sendCryptoSelect?.balance; - const network = networks[networkSymbol]; - const { shouldSendInSats } = useBitcoinAmountUnit(networkSymbol); + const network = networks[symbol]; + const { shouldSendInSats } = useBitcoinAmountUnit(symbol); const fiatRatesUpdater = useCallback( async (value: FiatCurrencyCode | undefined): Promise => { @@ -66,7 +66,7 @@ export const useCoinmarketFiatValues = ({ updateFiatRatesThunk({ tickers: [ { - symbol: networkSymbol, + symbol, tokenAddress: tokenAddressTyped, }, ], @@ -80,7 +80,7 @@ export const useCoinmarketFiatValues = ({ return updateFiatRatesResult.payload as FiatRatesResult; }, - [dispatch, networkSymbol, tokenAddressTyped], + [dispatch, symbol, tokenAddressTyped], ); // update rates on mount @@ -103,7 +103,7 @@ export const useCoinmarketFiatValues = ({ fiatRate, accountBalance: balance, formattedBalance, - networkSymbol, + symbol, networkDecimals: decimals, tokenAddress: tokenAddressTyped, fiatRatesUpdater, diff --git a/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFormActions.ts b/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFormActions.ts index 5838ab3271b..2ad3e02ebfb 100644 --- a/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFormActions.ts +++ b/packages/suite/src/hooks/wallet/coinmarket/form/common/useCoinmarketFormActions.ts @@ -38,7 +38,7 @@ import { } from 'src/types/coinmarket/coinmarketForm'; import { coinmarketGetSortedAccounts, - cryptoIdToNetworkSymbol, + cryptoIdToSymbol, getCoinmarketNetworkDecimals, } from 'src/utils/wallet/coinmarket/coinmarketUtils'; import { coinmarketGetExchangeReceiveCryptoId } from 'src/utils/wallet/coinmarket/exchangeUtils'; @@ -159,14 +159,14 @@ export const useCoinmarketFormActions = { - const networkSymbol = cryptoIdToNetworkSymbol(selected.value); + const symbol = cryptoIdToSymbol(selected.value); const cryptoSelectedCurrent = getValues(FORM_SEND_CRYPTO_CURRENCY_SELECT); const isSameCryptoSelected = cryptoSelectedCurrent && cryptoSelectedCurrent.descriptor === selected.descriptor && cryptoSelectedCurrent.value === selected.value; const account = accountsSorted.find( - item => item.descriptor === selected.descriptor && item.symbol === networkSymbol, + item => item.descriptor === selected.descriptor && item.symbol === symbol, ); if (!account || isSameCryptoSelected) return; diff --git a/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketExchangeFormDefaultValues.ts b/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketExchangeFormDefaultValues.ts index 9398dcef900..7c5f4df88dd 100644 --- a/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketExchangeFormDefaultValues.ts +++ b/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketExchangeFormDefaultValues.ts @@ -3,10 +3,7 @@ import { useMemo } from 'react'; import { DEFAULT_PAYMENT, DEFAULT_VALUES } from '@suite-common/wallet-constants'; import { FormState, Output } from '@suite-common/wallet-types'; -import { - buildFiatOption, - cryptoIdToNetworkSymbol, -} from 'src/utils/wallet/coinmarket/coinmarketUtils'; +import { buildFiatOption, cryptoIdToSymbol } from 'src/utils/wallet/coinmarket/coinmarketUtils'; import { Account } from 'src/types/wallet'; import { selectLocalCurrency } from 'src/reducers/wallet/settingsReducer'; import { useSelector } from 'src/hooks/suite'; @@ -47,7 +44,7 @@ export const useCoinmarketExchangeFormDefaultValues = ( cryptoOptions.find( option => option.descriptor === account.descriptor && - cryptoIdToNetworkSymbol(option.value) === account.symbol, + cryptoIdToSymbol(option.value) === account.symbol, ), [account.descriptor, account.symbol, cryptoOptions], ); diff --git a/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSellFormDefaultValues.ts b/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSellFormDefaultValues.ts index afe3543873a..186065f8fff 100644 --- a/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSellFormDefaultValues.ts +++ b/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSellFormDefaultValues.ts @@ -6,7 +6,7 @@ import { FormState, Output } from '@suite-common/wallet-types'; import { SellInfo } from 'src/actions/wallet/coinmarketSellActions'; import { buildFiatOption, - cryptoIdToNetworkSymbol, + cryptoIdToSymbol, getDefaultCountry, } from 'src/utils/wallet/coinmarket/coinmarketUtils'; import { Account } from 'src/types/wallet'; @@ -33,7 +33,7 @@ export const useCoinmarketSellFormDefaultValues = ( cryptoOptions.find( option => option.descriptor === account.descriptor && - account.symbol === cryptoIdToNetworkSymbol(option.value), + account.symbol === cryptoIdToSymbol(option.value), ), [account.descriptor, account.symbol, cryptoOptions], ); diff --git a/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketVerifyAccount.tsx b/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketVerifyAccount.tsx index d5ddf2cfd37..512fd1c3e18 100644 --- a/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketVerifyAccount.tsx +++ b/packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketVerifyAccount.tsx @@ -11,7 +11,7 @@ import { useDispatch, useSelector } from 'src/hooks/suite'; import { selectIsDebugModeActive } from 'src/reducers/suite/suiteReducer'; import { openModal } from 'src/actions/suite/modalActions'; import { - cryptoIdToNetworkSymbol, + cryptoIdToSymbol, getUnusedAddressFromAccount, parseCryptoId, } from 'src/utils/wallet/coinmarket/coinmarketUtils'; @@ -67,7 +67,7 @@ const getTranslationIds = ( const getSuiteReceiveAccounts = ({ currency, device, - receiveNetwork, + symbol, isDebug, accounts, }: CoinmarketGetSuiteReceiveAccountsProps): Account[] | undefined => { @@ -77,7 +77,7 @@ const getSuiteReceiveAccounts = ({ // Is the symbol supported by the suite and the device natively? const receiveNetworks = networksCollection.filter( (n: Network) => - n.symbol === receiveNetwork && + n.symbol === symbol && !unavailableCapabilities[n.symbol] && ((n.isDebugOnlyNetwork && isDebug) || !n.isDebugOnlyNetwork), ); @@ -85,7 +85,7 @@ const getSuiteReceiveAccounts = ({ return filterReceiveAccounts({ accounts, deviceState: device?.state?.staticSessionId, - receiveNetwork, + symbol, isDebug, receiveNetworks, }); @@ -113,17 +113,17 @@ const useCoinmarketVerifyAccount = ({ >(); const networkId = currency && parseCryptoId(currency).networkId; - const receiveNetwork = currency && cryptoIdToNetworkSymbol(currency); + const symbol = currency && cryptoIdToSymbol(currency); const suiteReceiveAccounts = useMemo( () => getSuiteReceiveAccounts({ currency, device, - receiveNetwork, + symbol, isDebug, accounts, }), - [accounts, currency, device, isDebug, receiveNetwork], + [accounts, currency, device, isDebug, symbol], ); const selectAccountOptions = useMemo( @@ -161,7 +161,7 @@ const useCoinmarketVerifyAccount = ({ openModal({ type: 'add-account', device, - symbol: receiveNetwork, + symbol, noRedirect: true, isCoinjoinDisabled: true, isBackClickDisabled: true, diff --git a/packages/suite/src/hooks/wallet/coinmarket/useCoinmarketInfo.ts b/packages/suite/src/hooks/wallet/coinmarket/useCoinmarketInfo.ts index 979d65a4107..eb8c6d2f48a 100644 --- a/packages/suite/src/hooks/wallet/coinmarket/useCoinmarketInfo.ts +++ b/packages/suite/src/hooks/wallet/coinmarket/useCoinmarketInfo.ts @@ -27,7 +27,7 @@ function toCryptoOption(cryptoId: CryptoId, coinInfo: CoinInfo): CoinmarketCrypt cryptoName: coinInfo.name, coingeckoId: networkId, contractAddress: contractAddress || null, - networkSymbol: coinInfo.symbol, + symbolExtended: coinInfo.symbol, }; } @@ -162,7 +162,7 @@ export const useCoinmarketInfo = (): CoinmarketInfoProps => { type: 'currency', value: coingeckoId as CryptoId, label: symbol.toUpperCase(), - networkSymbol: symbol.toUpperCase(), + symbolExtended: symbol.toUpperCase(), cryptoName: name, coingeckoId, contractAddress: null, diff --git a/packages/suite/src/types/coinmarket/coinmarket.ts b/packages/suite/src/types/coinmarket/coinmarket.ts index c6bc04ec944..ebdf86e6b32 100644 --- a/packages/suite/src/types/coinmarket/coinmarket.ts +++ b/packages/suite/src/types/coinmarket/coinmarket.ts @@ -176,10 +176,10 @@ export interface CoinmarketCoinLogoProps { } export interface CoinmarketCryptoSelectItemProps - extends Omit { + extends Omit { value: CryptoId; label: string; - symbol?: string; + ticker?: string; } export interface CoinmarketCryptoSelectGroupProps extends SelectAssetOptionGroupProps {} export type CoinmarketCryptoSelectOptionProps = diff --git a/packages/suite/src/types/coinmarket/coinmarketVerify.ts b/packages/suite/src/types/coinmarket/coinmarketVerify.ts index 83692ae36b7..f13562b6de6 100644 --- a/packages/suite/src/types/coinmarket/coinmarketVerify.ts +++ b/packages/suite/src/types/coinmarket/coinmarketVerify.ts @@ -54,7 +54,7 @@ export interface CoinmarketVerifyOptionsItemProps { export interface CoinmarketGetSuiteReceiveAccountsProps { currency: CryptoId | undefined; device: TrezorDevice | undefined; - receiveNetwork: NetworkSymbol | undefined; + symbol: NetworkSymbol | undefined; isDebug: boolean; accounts: Account[]; } diff --git a/packages/suite/src/utils/wallet/coinmarket/coinmarketUtils.ts b/packages/suite/src/utils/wallet/coinmarket/coinmarketUtils.ts index 342a6960d16..71fcf01a3b5 100644 --- a/packages/suite/src/utils/wallet/coinmarket/coinmarketUtils.ts +++ b/packages/suite/src/utils/wallet/coinmarket/coinmarketUtils.ts @@ -57,12 +57,12 @@ export function cryptoIdToNetwork(cryptoId: CryptoId): Network | undefined { : getNetworkByCoingeckoNativeId(networkId); } -export function cryptoIdToNetworkSymbol(cryptoId: CryptoId): NetworkSymbol | undefined { +export function cryptoIdToSymbol(cryptoId: CryptoId): NetworkSymbol | undefined { return cryptoIdToNetwork(cryptoId)?.symbol; } -export function toTokenCryptoId(networkId: NetworkSymbol, contractAddress: string): CryptoId { - return `${getCoingeckoId(networkId)}${cryptoPlatformSeparator}${contractAddress}` as CryptoId; +export function toTokenCryptoId(symbol: NetworkSymbol, contractAddress: string): CryptoId { + return `${getCoingeckoId(symbol)}${cryptoPlatformSeparator}${contractAddress}` as CryptoId; } /** Convert testnet cryptoId to prod cryptoId (test-bitcoin -> bitcoin) */ @@ -73,8 +73,8 @@ export function testnetToProdCryptoId(cryptoId: CryptoId): CryptoId { (contractAddress ? `${cryptoPlatformSeparator}${contractAddress}` : '')) as CryptoId; } -export const getNetworkName = (networkSymbol: NetworkSymbol) => { - return networks[networkSymbol].name; +export const getNetworkName = (symbol: NetworkSymbol) => { + return networks[symbol].name; }; interface CoinmarketGetDecimalsProps { @@ -213,7 +213,9 @@ export const getComposeAddressPlaceholder = async ( } }; -export const mapTestnetSymbol = (symbol: NetworkSymbol) => { +export const mapTestnetSymbol = ( + symbol: NetworkSymbol, +): Exclude => { if (symbol === 'test') return 'btc'; if (symbol === 'tsep') return 'eth'; if (symbol === 'thol') return 'eth'; diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketAddressOptions.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketAddressOptions.tsx index ba512c857a8..339cc29112a 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketAddressOptions.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketAddressOptions.tsx @@ -143,7 +143,7 @@ export const CoinmarketAddressOptions = diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketBalance.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketBalance.tsx index cec17404a85..694d13ed0ee 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketBalance.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketBalance.tsx @@ -15,7 +15,7 @@ import { interface CoinmarketBalanceProps { balance: string | undefined; cryptoSymbolLabel: string | undefined; - networkSymbol: NetworkSymbol; + symbol: NetworkSymbol; tokenAddress?: TokenAddress | undefined; showOnlyAmount?: boolean; amountInCrypto?: boolean; @@ -25,17 +25,17 @@ interface CoinmarketBalanceProps { export const CoinmarketBalance = ({ balance, // expects a value in full units (BTC not sats) cryptoSymbolLabel, - networkSymbol, + symbol, tokenAddress, showOnlyAmount, amountInCrypto, sendCryptoSelect, }: CoinmarketBalanceProps) => { - const { shouldSendInSats } = useBitcoinAmountUnit(networkSymbol); + const { shouldSendInSats } = useBitcoinAmountUnit(symbol); const balanceCurrency = coinmarketGetAccountLabel(cryptoSymbolLabel ?? '', shouldSendInSats); const networkDecimals = getCoinmarketNetworkDecimals({ sendCryptoSelect, - network: networks[networkSymbol], + network: networks[symbol], }); const stringBalance = !isNaN(Number(balance)) ? balance : '0'; const formattedBalance = @@ -45,7 +45,7 @@ export const CoinmarketBalance = ({ const { fiatAmount } = useFiatFromCryptoValue({ amount: stringBalance || '', - symbol: networkSymbol || '', + symbol: symbol ?? '', }); if (showOnlyAmount) { @@ -61,10 +61,10 @@ export const CoinmarketBalance = ({ ) : ( stringBalance && fiatAmount && - networkSymbol && ( + symbol && ( ) @@ -80,15 +80,11 @@ export const CoinmarketBalance = ({ {formattedBalance} {balanceCurrency} - {stringBalance && fiatAmount && networkSymbol && stringBalance !== '0' && ( + {stringBalance && fiatAmount && symbol && stringBalance !== '0' && ( <> {' '} ( - + ) )} diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputAccount.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputAccount.tsx index 45ba01e038f..4b78d3b6eac 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputAccount.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputAccount.tsx @@ -94,7 +94,7 @@ export const CoinmarketFormInputAccount = < fiatValues && ( options .filter(item => item.type === 'currency') .map(item => ({ - symbol: item.label ?? item.symbol, - networkSymbol: item.networkSymbol, - cryptoName: item.cryptoName ?? item.symbol, + ticker: item.label ?? item.ticker, + symbolExtended: item.symbolExtended, + cryptoName: item.cryptoName ?? item.ticker, badge: item.badge ?? item.networkName, coingeckoId: item.coingeckoId, contractAddress: item.contractAddress, @@ -120,7 +120,7 @@ export const CoinmarketFormInputCryptoSelect = < option.type === 'currency' ? { ...option, - symbol: option.symbol || option.label, + ticker: option.ticker || option.label, networkSymbol: getNetworkByCoingeckoNativeId(parseCryptoId(option.value).networkId) ?.symbol || parseCryptoId(option.value).networkId, @@ -183,9 +183,9 @@ export const CoinmarketFormInputCryptoSelect = < return ( searchFor(item.cryptoName) || (typeof item.badge === 'string' && searchFor(item.badge)) || - searchFor(item.symbol) || + searchFor(item.ticker) || searchFor(contractAddress) || - searchFor(item.networkSymbol) + searchFor(item.symbolExtended) ); }); diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputFiatCrypto/CoinmarketFormInputCryptoAmount.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputFiatCrypto/CoinmarketFormInputCryptoAmount.tsx index e1ae599a69e..b1f45f07a3f 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputFiatCrypto/CoinmarketFormInputCryptoAmount.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInput/CoinmarketFormInputFiatCrypto/CoinmarketFormInputCryptoAmount.tsx @@ -72,7 +72,7 @@ export const CoinmarketFormInputCryptoAmount = )?.outputs?.[0]?.amount : (errors as FieldErrors).cryptoInput; - const networkSymbol = cryptoSelect?.value && cryptoIdToCoinSymbol(cryptoSelect?.value); + const symbol = cryptoSelect?.value && cryptoIdToCoinSymbol(cryptoSelect?.value); const decimals = getCoinmarketNetworkDecimals({ sendCryptoSelect: !isCoinmarketBuyContext(context) ? context.getValues()[FORM_SEND_CRYPTO_CURRENCY_SELECT] @@ -132,7 +132,7 @@ export const CoinmarketFormInputCryptoAmount = {coinmarketGetAccountLabel( - cryptoSelect?.value && networkSymbol ? networkSymbol : '', + cryptoSelect?.value && symbol ? symbol : '', shouldSendInSats, )} diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInputs.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInputs.tsx index f0647be0b68..fcd6e98e2dd 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInputs.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketForm/CoinmarketFormInputs.tsx @@ -86,7 +86,7 @@ export const CoinmarketFormInputs = () => { { { const { cryptoIdToCoinSymbol } = useCoinmarketInfo(); - const networkSymbol = cryptoIdToCoinSymbol(cryptoId); + const symbol = cryptoIdToCoinSymbol(cryptoId); - if (!networkSymbol) { + if (!symbol) { return; } @@ -29,7 +29,7 @@ export const CoinmarketFormOfferCryptoAmount = ({ diff --git a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketSelectedOffer/CoinmarketVerify/CoinmarketVerifyOptionsItem.tsx b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketSelectedOffer/CoinmarketVerify/CoinmarketVerifyOptionsItem.tsx index f8b889282c7..29a9f632cf7 100644 --- a/packages/suite/src/views/wallet/coinmarket/common/CoinmarketSelectedOffer/CoinmarketVerify/CoinmarketVerifyOptionsItem.tsx +++ b/packages/suite/src/views/wallet/coinmarket/common/CoinmarketSelectedOffer/CoinmarketVerify/CoinmarketVerifyOptionsItem.tsx @@ -59,7 +59,7 @@ export const CoinmarketVerifyOptionsItem = ({ ({ - symbol: token.symbol ?? '', - networkSymbol: symbol, + ticker: token.symbol ?? '', + symbolExtended: symbol, cryptoName: token.name, badge: shouldTryToFetch ? undefined : , coingeckoId: getCoingeckoId(symbol) ?? '', @@ -80,8 +80,8 @@ const buildTokenOptions = ( if (activeTokenTab === 'tokens') { // this represents native currency result.push({ - symbol, - networkSymbol: symbol, + ticker: symbol, + symbolExtended: symbol, cryptoName: networks[symbol].name, badge: undefined, contractAddress: null, @@ -209,7 +209,7 @@ export const TokenSelect = ({ outputId }: TokenSelectProps) => { const searchFor = (property: string | undefined) => property?.toLocaleLowerCase().includes(search.toLocaleLowerCase()); - return searchFor(item.cryptoName) || searchFor(item.symbol) || searchFor(contractAddress); + return searchFor(item.cryptoName) || searchFor(item.ticker) || searchFor(contractAddress); }); const selectedToken = account.tokens?.find(token => token.contract === tokenContractAddress); diff --git a/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts b/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts index 0abe4d226fd..7cbda314b0f 100644 --- a/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts +++ b/suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts @@ -1,5 +1,5 @@ import { testMocks } from '@suite-common/test-utils'; -import { Network, networksCollection } from '@suite-common/wallet-config'; +import { Network, networksCollection, NetworkSymbol } from '@suite-common/wallet-config'; import { Account } from '@suite-common/wallet-types'; import { isDebugOnlyAccountType, filterReceiveAccounts } from '../filterReceiveAccounts'; @@ -30,14 +30,14 @@ const accountsList: Account[] = [ type RunFilterReceiveAccountsTestParams = { isDebug?: boolean; - receiveNetwork?: string; + symbol?: NetworkSymbol; deviceState?: `${string}@${string}:${number}`; accounts?: Account[]; }; const runFilterReceiveAccouns = ({ isDebug = true, - receiveNetwork = 'eth', + symbol = 'eth', deviceState = '1stTestnetAddress@device_id:0', accounts = accountsList, }: RunFilterReceiveAccountsTestParams) => { @@ -51,7 +51,7 @@ const runFilterReceiveAccouns = ({ const receiveNetworks = networksCollection.filter( (n: Network) => - n.symbol === receiveNetwork && + n.symbol === symbol && !unavailableCapabilities[n.symbol] && ((n.isDebugOnlyNetwork && isDebug) || !n.isDebugOnlyNetwork), ); @@ -59,7 +59,7 @@ const runFilterReceiveAccouns = ({ return filterReceiveAccounts({ accounts, deviceState: device.state?.staticSessionId, - receiveNetwork, + symbol, isDebug, receiveNetworks, }); @@ -82,7 +82,7 @@ describe('filter receive accounts', () => { }); it('returns no results when given a non-existing network in acccounts list', () => { - expect(runFilterReceiveAccouns({ receiveNetwork: 'bnb' })).toEqual([]); + expect(runFilterReceiveAccouns({ symbol: 'bnb' })).toEqual([]); }); it('returns all accounts when debug mode is on', () => { @@ -114,7 +114,7 @@ describe('filter receive accounts', () => { getWalletAccount({ symbol: 'btc', accountType: 'ledger' }), ]; - expect(runFilterReceiveAccouns({ receiveNetwork: 'btc' })).toEqual(filteredAccounts); + expect(runFilterReceiveAccouns({ symbol: 'btc' })).toEqual(filteredAccounts); }); it('returns account when when its either first normal account (no matter is empty or not visible) or it is not empty and visible', () => { @@ -123,6 +123,6 @@ describe('filter receive accounts', () => { getWalletAccount({ symbol: 'sol', accountType: 'ledger' }), ]; - expect(runFilterReceiveAccouns({ receiveNetwork: 'sol' })).toEqual(filteredAccounts); + expect(runFilterReceiveAccouns({ symbol: 'sol' })).toEqual(filteredAccounts); }); }); diff --git a/suite-common/wallet-utils/src/filterReceiveAccounts.ts b/suite-common/wallet-utils/src/filterReceiveAccounts.ts index 969052fa9fa..a7c6468512f 100644 --- a/suite-common/wallet-utils/src/filterReceiveAccounts.ts +++ b/suite-common/wallet-utils/src/filterReceiveAccounts.ts @@ -18,7 +18,7 @@ export const isDebugOnlyAccountType = ( type FilterReceiveAccountsProps = { accounts: Account[]; deviceState?: StaticSessionId; - receiveNetwork?: string; + symbol?: NetworkSymbol; isDebug: boolean; receiveNetworks: Network[]; }; @@ -26,11 +26,11 @@ type FilterReceiveAccountsProps = { export const filterReceiveAccounts = ({ accounts, deviceState, - receiveNetwork, + symbol, isDebug, }: FilterReceiveAccountsProps): Account[] => { const isSameDevice = (account: Account) => account.deviceState === deviceState; - const isSameNetwork = (account: Account) => account.symbol === receiveNetwork; + const isSameNetwork = (account: Account) => account.symbol === symbol; const shouldDisplayDebugOnly = (account: Account) => isDebug || !isDebugOnlyAccountType(account.accountType, account.symbol); const isNotEmptyAccount = (account: Account) => !account.empty;