Skip to content

Commit

Permalink
Merge pull request #5379 from EdgeApp/matthew/create-item-search
Browse files Browse the repository at this point in the history
Filter CreateWalletItem list by networkLocation instead of tokenId
  • Loading branch information
peachbits authored Dec 4, 2024
2 parents df993ef + 7a9976c commit cff5357
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
17 changes: 12 additions & 5 deletions src/selectors/getCreateWalletList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -142,6 +145,7 @@ export const getCreateWalletList = (account: EdgeAccount, opts: CreateWalletList
key: `create-${currencyInfo.pluginId}-${tokenId}`,
currencyCode,
displayName,
networkLocation,
pluginId,
tokenId,
createWalletIds
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit cff5357

Please sign in to comment.