From b646159ec2533825d2cbb9217bb3f7878369d2fe Mon Sep 17 00:00:00 2001 From: Albina Nikiforova Date: Thu, 6 Feb 2025 16:12:01 +0100 Subject: [PATCH] chore(suite): fix tests --- .../blockchain-link-utils/src/blockbook.ts | 1 + .../blockchain-link-utils/src/blockfrost.ts | 1 + packages/blockchain-link-utils/src/solana.ts | 4 +++- .../src/tests/fixtures/blockbook.ts | 1 + .../src/tests/fixtures/blockfrost.ts | 4 ++++ .../src/tests/fixtures/solana.ts | 2 ++ .../unit/fixtures/getAccountInfo-blockbook.ts | 4 ++++ .../TokenIconSet/TokenIconSet.stories.tsx | 1 + .../__tests__/tradingCommonActions.test.ts | 1 + .../hooks/wallet/__fixtures__/useSendForm.ts | 9 ++++++++- packages/suite/src/storage/migrations/index.ts | 1 + .../trading/__fixtures__/tradingUtils.ts | 6 ++++++ suite-common/trading/src/__fixtures__/utils.ts | 3 +++ .../src/__fixtures__/cardanoUtils.ts | 2 ++ .../src/__fixtures__/sendFormUtils.ts | 1 + .../src/__tests__/sendFormUtils.test.ts | 18 ++++++++++++++++-- suite-common/wallet-utils/src/accountUtils.ts | 5 +++++ .../wallet-utils/src/reviewTransactionUtils.ts | 1 + .../wallet-utils/src/transactionUtils.ts | 6 +++--- 19 files changed, 64 insertions(+), 7 deletions(-) diff --git a/packages/blockchain-link-utils/src/blockbook.ts b/packages/blockchain-link-utils/src/blockbook.ts index ff744ede65f..dd54eafc827 100644 --- a/packages/blockchain-link-utils/src/blockbook.ts +++ b/packages/blockchain-link-utils/src/blockbook.ts @@ -315,6 +315,7 @@ export const transformTokenInfo = ( { ...token, decimals: token.decimals || 0, + standard: token.standard, }, ]); }, [] as TokenInfo[]); diff --git a/packages/blockchain-link-utils/src/blockfrost.ts b/packages/blockchain-link-utils/src/blockfrost.ts index d7d04eb0b76..35c7903d69f 100644 --- a/packages/blockchain-link-utils/src/blockfrost.ts +++ b/packages/blockchain-link-utils/src/blockfrost.ts @@ -117,6 +117,7 @@ export const transformTokenInfo = ( const info = tokens.map(token => ({ type: 'BLOCKFROST', balance: token.quantity, + standard: 'BLOCKFROST', ...transformToken(token), })); diff --git a/packages/blockchain-link-utils/src/solana.ts b/packages/blockchain-link-utils/src/solana.ts index ff8818bfb1b..f2151e14480 100644 --- a/packages/blockchain-link-utils/src/solana.ts +++ b/packages/blockchain-link-utils/src/solana.ts @@ -160,6 +160,7 @@ export const transformTokenInfo = ( decimals: info.tokenAmount.decimals, ...getTokenNameAndSymbol(info.mint, tokenDetailByMint), address: tokenAccount.pubkey, + standard: tokenProgramsInfo[program].tokenStandard, }; }), A.reduce( @@ -176,9 +177,10 @@ export const transformTokenInfo = ( balance: token.balance || '0', }); } else { - const { type, contract, balance, decimals, name, symbol } = token; + const { type, standard, contract, balance, decimals, name, symbol } = token; acc[token.contract] = { type, + standard, contract, balance, decimals, diff --git a/packages/blockchain-link-utils/src/tests/fixtures/blockbook.ts b/packages/blockchain-link-utils/src/tests/fixtures/blockbook.ts index 288806216d1..f8315ad823a 100644 --- a/packages/blockchain-link-utils/src/tests/fixtures/blockbook.ts +++ b/packages/blockchain-link-utils/src/tests/fixtures/blockbook.ts @@ -21,6 +21,7 @@ const tOut = { const tIn = { name: 'Token name', type: 'ERC20', + standard: 'ERC20', symbol: 'TN', contract: '0x0', value: '0', diff --git a/packages/blockchain-link-utils/src/tests/fixtures/blockfrost.ts b/packages/blockchain-link-utils/src/tests/fixtures/blockfrost.ts index bc53851f919..7a188a9d61e 100644 --- a/packages/blockchain-link-utils/src/tests/fixtures/blockfrost.ts +++ b/packages/blockchain-link-utils/src/tests/fixtures/blockfrost.ts @@ -153,6 +153,7 @@ export default { result: [ { type: 'BLOCKFROST', + standard: 'BLOCKFROST', fingerprint: 'asset1hwnpal5vap799t6kkjmjf6myhse4zl2vu4ahzz', policyId: 'b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f', symbol: 'BerrySapphire', @@ -164,6 +165,7 @@ export default { }, { type: 'BLOCKFROST', + standard: 'BLOCKFROST', decimals: 0, fingerprint: 'asset108xu02ckwrfc8qs9d97mgyh4kn8gdu9w8f5sxk', name: 'Snek', @@ -174,6 +176,7 @@ export default { }, { type: 'BLOCKFROST', + standard: 'BLOCKFROST', fingerprint: 'asset1zvclg2cvj4e5jfz5vswf3sx0lasy79xn8cdap9', policyId: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a', symbol: 'GRIC', @@ -515,6 +518,7 @@ export default { tokens: [ { type: 'BLOCKFROST', + standard: 'BLOCKFROST', fingerprint: 'asset1eevmdlaz5424s3663ypw8w4vyxdlxkm3lefz06', contract: '2f712364ec46f0cf707d412106ce71ef3370f76e27fb56b6bb14708776657465726e696b4e657a6a6564656e79', diff --git a/packages/blockchain-link-utils/src/tests/fixtures/solana.ts b/packages/blockchain-link-utils/src/tests/fixtures/solana.ts index 245881c8111..91a71acc8df 100644 --- a/packages/blockchain-link-utils/src/tests/fixtures/solana.ts +++ b/packages/blockchain-link-utils/src/tests/fixtures/solana.ts @@ -974,6 +974,7 @@ export const fixtures = { expectedOutput: [ { type: 'SPL', + standard: 'SPL', contract: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R', balance: '2000000', decimals: 6, @@ -998,6 +999,7 @@ export const fixtures = { expectedOutput: [ { type: 'SPL', + standard: 'SPL', contract: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R', balance: '3000000', decimals: 6, diff --git a/packages/blockchain-link/tests/unit/fixtures/getAccountInfo-blockbook.ts b/packages/blockchain-link/tests/unit/fixtures/getAccountInfo-blockbook.ts index f3952644137..066cfde071e 100644 --- a/packages/blockchain-link/tests/unit/fixtures/getAccountInfo-blockbook.ts +++ b/packages/blockchain-link/tests/unit/fixtures/getAccountInfo-blockbook.ts @@ -456,6 +456,7 @@ const fixtures: { tokens: [ { type: 'ERC20', + standard: 'ERC20', name: 'Token name', symbol: 'TKNNME', contract: '0x0', @@ -476,6 +477,7 @@ const fixtures: { tokens: [ { type: 'ERC20', + standard: 'ERC20', name: 'Token name', symbol: 'TKNNME', contract: '0x0', @@ -600,6 +602,7 @@ const fixtures: { address: '0x3c205C8B3e02421Da82064646788c82f7bd753B9', contractInfo: { type: 'ERC20', + standard: 'ERC20', contract: '0x3c205C8B3e02421Da82064646788c82f7bd753B9', name: 'PureFi Token', symbol: 'UFI', @@ -619,6 +622,7 @@ const fixtures: { addressAliases: undefined, contractInfo: { type: 'ERC20', + standard: 'ERC20', contract: '0x3c205C8B3e02421Da82064646788c82f7bd753B9', name: 'PureFi Token', symbol: 'UFI', diff --git a/packages/product-components/src/components/TokenIconSet/TokenIconSet.stories.tsx b/packages/product-components/src/components/TokenIconSet/TokenIconSet.stories.tsx index 587ec5ad973..cd4d056ef22 100644 --- a/packages/product-components/src/components/TokenIconSet/TokenIconSet.stories.tsx +++ b/packages/product-components/src/components/TokenIconSet/TokenIconSet.stories.tsx @@ -7,6 +7,7 @@ const getToken = (contract: string, symbol: string, decimals: number) => ({ symbol, decimals, type: 'ERC20', + standard: 'ERC20', }); const TOKEN_1 = getToken('0xaea46a60368a7bd060eec7df8cba43b7ef41ad85', 'FET', 6); diff --git a/packages/suite/src/actions/wallet/trading/__tests__/tradingCommonActions.test.ts b/packages/suite/src/actions/wallet/trading/__tests__/tradingCommonActions.test.ts index acc3be8ef01..178cf574fe7 100644 --- a/packages/suite/src/actions/wallet/trading/__tests__/tradingCommonActions.test.ts +++ b/packages/suite/src/actions/wallet/trading/__tests__/tradingCommonActions.test.ts @@ -110,6 +110,7 @@ describe('Trading Common Actions', () => { estimatedFeeLimit: '123', token: { type: 'abc', + standard: 'ERC20', contract: 'cde', decimals: 0, }, diff --git a/packages/suite/src/hooks/wallet/__fixtures__/useSendForm.ts b/packages/suite/src/hooks/wallet/__fixtures__/useSendForm.ts index e0859cddeca..f160ed7d93a 100644 --- a/packages/suite/src/hooks/wallet/__fixtures__/useSendForm.ts +++ b/packages/suite/src/hooks/wallet/__fixtures__/useSendForm.ts @@ -133,7 +133,14 @@ export const ETH_ACCOUNT = { availableBalance: '10000000000000000000', // 10 ETH misc: { nonce: '0' }, tokens: [ - { type: 'ERC20', contract: '0xABCD', symbol: '0xABCD', decimals: 3, balance: '1' }, + { + type: 'ERC20', + standard: 'ERC20', + contract: '0xABCD', + symbol: '0xABCD', + decimals: 3, + balance: '1', + }, ], }), network: { networkType: 'ethereum', symbol: 'eth', decimals: 18, chainId: 1 }, diff --git a/packages/suite/src/storage/migrations/index.ts b/packages/suite/src/storage/migrations/index.ts index d47b91bb173..2f1ee73f68b 100644 --- a/packages/suite/src/storage/migrations/index.ts +++ b/packages/suite/src/storage/migrations/index.ts @@ -873,6 +873,7 @@ export const migrate: OnUpgradeFunc = async ( fingerprint: token.name, policyId, type: token.type, + standard: token.standard, }; }); } diff --git a/packages/suite/src/utils/wallet/trading/__fixtures__/tradingUtils.ts b/packages/suite/src/utils/wallet/trading/__fixtures__/tradingUtils.ts index 2a1d2e67f97..d0df38b6317 100644 --- a/packages/suite/src/utils/wallet/trading/__fixtures__/tradingUtils.ts +++ b/packages/suite/src/utils/wallet/trading/__fixtures__/tradingUtils.ts @@ -50,6 +50,7 @@ export const FIXTURE_ACCOUNTS: Partial[] = [ decimals: 6, name: 'Tether USD', symbol: 'usdt', + standard: 'ERC20', type: 'ERC20', }, // unknown token @@ -59,6 +60,7 @@ export const FIXTURE_ACCOUNTS: Partial[] = [ decimals: 6, name: 'USDC', symbol: 'usdc', + standard: 'ERC20', type: 'ERC20', }, // supported and known token @@ -68,6 +70,7 @@ export const FIXTURE_ACCOUNTS: Partial[] = [ decimals: 6, name: 'VeChain', symbol: 'VEE', + standard: 'ERC20', type: 'ERC20', }, ], @@ -93,6 +96,7 @@ export const FIXTURE_ACCOUNTS: Partial[] = [ decimals: 6, name: 'Tether USD', symbol: 'usdt', + standard: 'ERC20', type: 'ERC20', }, ], @@ -112,6 +116,7 @@ export const FIXTURE_ACCOUNTS: Partial[] = [ decimals: 6, name: 'USDC', symbol: 'usdc', + standard: 'ERC20', type: 'ERC20', }, ], @@ -131,6 +136,7 @@ export const FIXTURE_ACCOUNTS: Partial[] = [ decimals: 6, name: 'USDC', symbol: 'usdc', + standard: 'ERC20', type: 'ERC20', }, ], diff --git a/suite-common/trading/src/__fixtures__/utils.ts b/suite-common/trading/src/__fixtures__/utils.ts index c6b6c595bde..523e3cee3c0 100644 --- a/suite-common/trading/src/__fixtures__/utils.ts +++ b/suite-common/trading/src/__fixtures__/utils.ts @@ -24,18 +24,21 @@ export const accountEth = { tokens: [ { type: 'ERC20', + standard: 'ERC20', contract: '0x1234123412341234123412341234123412341234', symbol: 'usdt', decimals: 18, }, { type: 'ERC20', + standard: 'ERC20', contract: '0x1234123412341234123412341234123412341235', symbol: 'usdc', decimals: 18, }, { type: 'ERC20', + standard: 'ERC20', contract: '0x1234123412341234123412341234123412341236', symbol: 'other', decimals: 18, diff --git a/suite-common/wallet-utils/src/__fixtures__/cardanoUtils.ts b/suite-common/wallet-utils/src/__fixtures__/cardanoUtils.ts index e511c2e54ff..463911067fc 100644 --- a/suite-common/wallet-utils/src/__fixtures__/cardanoUtils.ts +++ b/suite-common/wallet-utils/src/__fixtures__/cardanoUtils.ts @@ -231,6 +231,7 @@ export const formatMaxOutputAmount = [ name: 'Nuts', symbol: 'NUTS', type: 'BLOCKFROST', + standard: 'BLOCKFROST', }, ], }, @@ -262,6 +263,7 @@ export const formatMaxOutputAmount = [ name: 'Nuts', symbol: 'NUTS', type: 'BLOCKFROST', + standard: 'BLOCKFROST', contract: '57fca08abbaddee36da742a839f7d83a7e1d2419f1507fcbf391652243484f43', }, ], diff --git a/suite-common/wallet-utils/src/__fixtures__/sendFormUtils.ts b/suite-common/wallet-utils/src/__fixtures__/sendFormUtils.ts index e6d705f5716..492936e887f 100644 --- a/suite-common/wallet-utils/src/__fixtures__/sendFormUtils.ts +++ b/suite-common/wallet-utils/src/__fixtures__/sendFormUtils.ts @@ -26,6 +26,7 @@ export const prepareEthereumTransaction = [ txInfo: { token: { type: 'ERC20', + standard: 'ERC20', symbol: 'gnt', decimals: 18, contract: '0xa74476443119A942dE498590Fe1f2454d7D4aC0d', diff --git a/suite-common/wallet-utils/src/__tests__/sendFormUtils.test.ts b/suite-common/wallet-utils/src/__tests__/sendFormUtils.test.ts index f93ed5802f4..40088babd61 100644 --- a/suite-common/wallet-utils/src/__tests__/sendFormUtils.test.ts +++ b/suite-common/wallet-utils/src/__tests__/sendFormUtils.test.ts @@ -239,8 +239,22 @@ describe('sendForm utils', () => { const EthAccount = getWalletAccount({ tokens: [ - { type: 'ERC20', contract: 'A', symbol: 'A', decimals: 2, name: 'A' }, - { type: 'ERC20', contract: 'B', symbol: 'B', decimals: 6, name: 'B' }, + { + type: 'ERC20', + standard: 'ERC20', + contract: 'A', + symbol: 'A', + decimals: 2, + name: 'A', + }, + { + type: 'ERC20', + standard: 'ERC20', + contract: 'B', + symbol: 'B', + decimals: 6, + name: 'B', + }, ], }); const EthNetwork = networks.eth; diff --git a/suite-common/wallet-utils/src/accountUtils.ts b/suite-common/wallet-utils/src/accountUtils.ts index 0322fea259d..246e25f5b8a 100644 --- a/suite-common/wallet-utils/src/accountUtils.ts +++ b/suite-common/wallet-utils/src/accountUtils.ts @@ -1128,6 +1128,11 @@ export const isTokenMatchesSearch = (token: TokenInfo, search: string) => token.fingerprint?.toLowerCase().includes(search) || token.policyId?.toLowerCase().includes(search); +export const isTokenTransferMatchesSearch = (token: TokenTransfer, search: string) => + token.symbol?.toLowerCase().includes(search) || + token.name?.toLowerCase().includes(search) || + token.contract.toLowerCase().includes(search); + export const isNftMatchesSearch = (token: TokenInfo, search: string) => token.symbol?.toLowerCase().includes(search) || token.name?.toLowerCase().includes(search) || diff --git a/suite-common/wallet-utils/src/reviewTransactionUtils.ts b/suite-common/wallet-utils/src/reviewTransactionUtils.ts index da688e3406e..d07aea40759 100644 --- a/suite-common/wallet-utils/src/reviewTransactionUtils.ts +++ b/suite-common/wallet-utils/src/reviewTransactionUtils.ts @@ -67,6 +67,7 @@ const getCardanoTokenBundle = (account: Account, output: CardanoOutput) => { return { type: 'cardano', + standard: 'BLOCKFROST', contract: output.address, balance: token.amount, symbol: token.assetNameBytes diff --git a/suite-common/wallet-utils/src/transactionUtils.ts b/suite-common/wallet-utils/src/transactionUtils.ts index ce90d255b05..24b544f5f55 100644 --- a/suite-common/wallet-utils/src/transactionUtils.ts +++ b/suite-common/wallet-utils/src/transactionUtils.ts @@ -27,7 +27,7 @@ import { import { arrayPartition } from '@trezor/utils'; import { BigNumber } from '@trezor/utils/src/bigNumber'; -import { formatAmount, formatNetworkAmount, isTokenMatchesSearch } from './accountUtils'; +import { formatAmount, formatNetworkAmount, isTokenTransferMatchesSearch } from './accountUtils'; import { getFiatRateKey, roundTimestampToNearestPastHour } from './fiatRatesUtils'; import { getMyInputsFromTransaction } from './getMyInputsFromTransaction'; import { toFiatCurrency } from '../src/fiatConverterUtils'; @@ -491,7 +491,7 @@ export const isNftMultitokenTransfer = (transfer: TokenTransfer) => // TODO: TokenInfo should use TokenStandard type export const isNftToken = (token: TokenInfo) => - ['ERC1155', 'ERC721', 'BEP1155', 'BEP721'].includes(token.type || ''); + ['ERC1155', 'ERC721', 'BEP1155', 'BEP721'].includes(token.standard || ''); export const getNftTokenId = (transfer: TokenTransfer) => // use 0 index, haven't found an example where multiTokenValues.length > 1 @@ -930,7 +930,7 @@ export const simpleSearchTransactions = ( const foundTxsForToken = transactions.flatMap(transaction => { const hasMatchingToken = transaction.tokens.some( token => - isTokenMatchesSearch(token, search.toLowerCase()) || + isTokenTransferMatchesSearch(token, search.toLowerCase()) || token.to?.toLowerCase().includes(search.toLowerCase()) || token.from?.toLowerCase().includes(search.toLowerCase()), );