From c8e680d38349d420bab781ab3da71bb9b845a0c8 Mon Sep 17 00:00:00 2001 From: peachbits Date: Mon, 2 Dec 2024 23:09:46 -0800 Subject: [PATCH] Filter CreateWalletItem list by networkLocation instead of tokenId --- CHANGELOG.md | 1 + .../CreateWalletSelectCryptoScene.test.tsx.snap | 12 ++++++++++++ src/selectors/getCreateWalletList.ts | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ea5bcbed33..0da8f276df0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - added: Show all Zcash addresses on Request scene - changed: Support optional Sideshift private key - changed: Upgrade edge-core-js to v2.21.0 +- changed: Filter CreateWalletItem list by networkLocation instead of tokenId - fixed: Default home/assets scene post-login based on last visited scene - fixed: Receive flip input default currency selection - removed: Keyboard autofocus from `WalletListModal` diff --git a/src/__tests__/scenes/__snapshots__/CreateWalletSelectCryptoScene.test.tsx.snap b/src/__tests__/scenes/__snapshots__/CreateWalletSelectCryptoScene.test.tsx.snap index 370529d99b1..4dfbd96265c 100644 --- a/src/__tests__/scenes/__snapshots__/CreateWalletSelectCryptoScene.test.tsx.snap +++ b/src/__tests__/scenes/__snapshots__/CreateWalletSelectCryptoScene.test.tsx.snap @@ -633,6 +633,9 @@ exports[`CreateWalletSelectCrypto should render with loading props 1`] = ` "currencyCode": "REP", "displayName": "Augur", "key": "create-ethereum-1985365e9f78359a9b6ad760e32412f4a445e862", + "networkLocation": { + "contractAddress": "0x1985365e9f78359a9B6AD760e32412f4a445E862", + }, "pluginId": "ethereum", "tokenId": "1985365e9f78359a9b6ad760e32412f4a445e862", "type": "create", @@ -644,6 +647,9 @@ exports[`CreateWalletSelectCrypto should render with loading props 1`] = ` "currencyCode": "REPV2", "displayName": "Augur v2", "key": "create-ethereum-221657776846890989a759ba2973e427dff5c9bb", + "networkLocation": { + "contractAddress": "0x221657776846890989a759BA2973e427DfF5C9bB", + }, "pluginId": "ethereum", "tokenId": "221657776846890989a759ba2973e427dff5c9bb", "type": "create", @@ -655,6 +661,9 @@ exports[`CreateWalletSelectCrypto should render with loading props 1`] = ` "currencyCode": "HERC", "displayName": "Hercules", "key": "create-ethereum-2e91e3e54c5788e9fdd6a181497fdcea1de1bcc1", + "networkLocation": { + "contractAddress": "0x2e91E3e54C5788e9FdD6A181497FDcEa1De1bcc1", + }, "pluginId": "ethereum", "tokenId": "2e91e3e54c5788e9fdd6a181497fdcea1de1bcc1", "type": "create", @@ -666,6 +675,9 @@ exports[`CreateWalletSelectCrypto should render with loading props 1`] = ` "currencyCode": "DAI", "displayName": "Dai Stablecoin", "key": "create-ethereum-6b175474e89094c44da98b954eedeac495271d0f", + "networkLocation": { + "contractAddress": "0x6B175474E89094C44Da98b954EedeAC495271d0F", + }, "pluginId": "ethereum", "tokenId": "6b175474e89094c44da98b954eedeac495271d0f", "type": "create", diff --git a/src/selectors/getCreateWalletList.ts b/src/selectors/getCreateWalletList.ts index c19766d8cac..bee3bbbc471 100644 --- a/src/selectors/getCreateWalletList.ts +++ b/src/selectors/getCreateWalletList.ts @@ -20,6 +20,9 @@ export interface WalletCreateItem { // Used for creating wallets: keyOptions?: JsonObject walletType?: string + + // Used for filtering + networkLocation?: JsonObject } export interface MainWalletCreateItem extends WalletCreateItem { @@ -132,7 +135,7 @@ export const getCreateWalletList = (account: EdgeAccount, opts: CreateWalletList const createWalletIds = Object.keys(account.currencyWallets).filter(walletId => account.currencyWallets[walletId].currencyInfo.pluginId === pluginId) for (const tokenId of Object.keys(builtinTokens)) { - const { currencyCode, displayName } = builtinTokens[tokenId] + const { currencyCode, displayName, networkLocation } = builtinTokens[tokenId] // Fix for when the token code and chain code are the same (like EOS/TLOS) if (currencyCode === currencyInfo.currencyCode) continue @@ -142,6 +145,7 @@ export const getCreateWalletList = (account: EdgeAccount, opts: CreateWalletList key: `create-${currencyInfo.pluginId}-${tokenId}`, currencyCode, displayName, + networkLocation, pluginId, tokenId, createWalletIds @@ -169,7 +173,7 @@ export const filterWalletCreateItemListBySearchText = (createWalletList: WalletC const out: WalletCreateItem[] = [] const searchTarget = normalizeForSearch(searchText) for (const item of createWalletList) { - const { currencyCode, displayName, pluginId, tokenId, walletType } = item + const { currencyCode, displayName, networkLocation = {}, pluginId, walletType } = item if (normalizeForSearch(currencyCode).includes(searchTarget) || normalizeForSearch(displayName).includes(searchTarget)) { out.push(item) continue @@ -179,9 +183,12 @@ export const filterWalletCreateItemListBySearchText = (createWalletList: WalletC out.push(item) continue } - // See if the search term contains the tokenId because we don't have contract addresses in scope. The tokenId is, in most cases, close enough to a contract address to be useful. - if (tokenId !== null && normalizeForSearch(searchTarget).includes(normalizeForSearch(tokenId))) { - out.push(item) + // See if the search term can be found in the networkLocation object ie. contractAddress + for (const value of Object.values(networkLocation)) { + if (typeof value === 'string' && normalizeForSearch(value).includes(searchTarget)) { + out.push(item) + break + } } } return out