Skip to content

Commit 4f506b0

Browse files
committed
Use startsWith matching for asset identification fields
Change search matching for currencyCode, displayName, and assetDisplayName from includes() to startsWith(). This prevents partial substring matches that crowd search results. For example, searching 'eth' now shows Ethereum assets but not Tether (which contains 'eth' in the middle). Context fields like chainDisplayName, wallet name, and contractAddress still use includes() for broader discovery.
1 parent 7718cf4 commit 4f506b0

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/components/services/SortedWalletList.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export function searchWalletList(
274274
// Split search text into individual terms (space-delimited), then normalize
275275
const searchTerms = searchText
276276
.split(/\s+/)
277+
.map(term => normalizeForSearch(term))
277278
.filter(term => term.length > 0)
278279

279280
if (searchTerms.length === 0) return list
@@ -292,14 +293,36 @@ export function searchWalletList(
292293

293294
// All search terms must match at least one field (AND logic)
294295
return searchTerms.every(term => {
295-
return (
296-
normalizeForSearch(currencyCode).includes(term) ||
297-
normalizeForSearch(displayName).includes(term) ||
298-
normalizeForSearch(assetDisplayName).includes(term) ||
299-
normalizeForSearch(chainDisplayName).includes(term) ||
296+
// Asset identification fields use startsWith to avoid partial matches
297+
// (e.g., "eth" matches "Ethereum" but not "Tether")
298+
let startsWithMatch =
299+
normalizeForSearch(currencyCode).startsWith(term) ||
300+
normalizeForSearch(displayName).startsWith(term)
301+
302+
// For mainnet assets (not tokens), also search assetDisplayName and
303+
// chainDisplayName. These fields describe the chain, not individual tokens.
304+
if (token == null) {
305+
if (assetDisplayName != null) {
306+
startsWithMatch =
307+
startsWithMatch ||
308+
normalizeForSearch(assetDisplayName).startsWith(term)
309+
}
310+
311+
// chainDisplayName uses includes for network name discovery
312+
if (
313+
chainDisplayName != null &&
314+
normalizeForSearch(chainDisplayName).includes(term)
315+
) {
316+
return true
317+
}
318+
}
319+
320+
// Context/discovery fields use includes for broader matching
321+
const includesMatch =
300322
normalizeForSearch(name).includes(term) ||
301323
normalizeForSearch(contractAddress).includes(term)
302-
)
324+
325+
return startsWithMatch || includesMatch
303326
})
304327
})
305328
}

src/selectors/getCreateWalletList.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,26 @@ export const filterWalletCreateItemListBySearchText = (
248248

249249
// Check if all search terms match at least one field (AND logic)
250250
const allTermsMatch = searchTerms.every(term => {
251+
// Asset identification fields use startsWith to avoid partial matches
252+
// (e.g., "eth" matches "Ethereum" but not "Tether")
251253
if (
252-
normalizeForSearch(currencyCode).includes(term) ||
253-
normalizeForSearch(displayName).includes(term)
254+
normalizeForSearch(currencyCode).startsWith(term) ||
255+
normalizeForSearch(displayName).startsWith(term)
254256
) {
255257
return true
256258
}
257-
// Search assetDisplayName for mainnet create items
259+
// Search assetDisplayName for mainnet create items (also uses startsWith)
258260
if (
259261
assetDisplayName != null &&
260-
normalizeForSearch(assetDisplayName).includes(term)
262+
normalizeForSearch(assetDisplayName).startsWith(term)
261263
) {
262264
return true
263265
}
264-
// Search pluginId for mainnet create items
266+
// Search pluginId for mainnet create items (uses includes for discovery)
265267
if (walletType != null && normalizeForSearch(pluginId).includes(term)) {
266268
return true
267269
}
268-
// Search networkLocation values (ie. contractAddress)
270+
// Search networkLocation values ie. contractAddress (uses includes)
269271
for (const value of Object.values(networkLocation)) {
270272
if (
271273
typeof value === 'string' &&

0 commit comments

Comments
 (0)