Repository navigation
Unify asset list sort order - #6843
SeniorZhai wants to merge 12 commits into
Conversation
|
AI review done for Quality: Needs fixes before merging. The affected call paths were traced and checked with isolated SQLite and Kotlin runs.
|
There was a problem hiding this comment.
AI review · Claude + Codex · cd22a78
Needs changes: the shared comparator drops two ranking rules that other code still relies on. Nothing was compiled or run in this checkout because there is no Java runtime; Gradle failed to start for both reviewers, so the Android build, unit test and lint are unverified, though Codex's scratch Kotlin harness passed both new test assertions against the production comparator. The loss of prefix/contains symbol ranking in swap search is left out because the new test's name (exact symbol, then value, then level) indicates it is intended.
| }.sortedByDescending { | ||
| it.name.equalsIgnoreCase(s) || it.symbol.equalsIgnoreCase(s) | ||
| }) | ||
| }.sortedWith( |
There was a problem hiding this comment.
This drops the exact name match. The old sort was it.name.equalsIgnoreCase(s) || it.symbol.equalsIgnoreCase(s), but assetListComparator only tests the symbol.
The filter just above also matches chainName and getChainDisplayName(), so searching "Solana" returns every token on that chain. SOL used to be on top through its name; now it sorts by value, so $100 of USDC on Solana ranks above $5 of SOL. With no balances, any higher-priced token on the chain can outrank it. Web3TokenDao.fuzzySearchAsset still orders by t.symbol = :query OR t.name = :query, so the exact-name rule is still expected for this data.
Suggested fix: keep an exact-name tier here, e.g. compareByDescending<Web3TokenItem> { it.name.equals(s, ignoreCase = true) }.then(assetListComparator(...)), or add an exact-name check to the comparator's first tier.
| name: (T) -> String, | ||
| chainName: (T) -> String, | ||
| ): Comparator<T> = | ||
| compareByDescending<T> { !query.isNullOrBlank() && symbol(it).equals(query, ignoreCase = true) } |
There was a problem hiding this comment.
The comparator drops the DEFAULT_ICON_URL-last rule that both sortQueryAsset and sortByKeywordAndBalance applied first. The new level tier does not replace it in wallet search: PREFIX_ASSET_ITEM selects no level column and Token.toAssetItem passes null, so every TokenItem compares as UNKNOWN. Unowned results then fall through to price descending, so a placeholder-icon asset with a higher price ranks above real assets.
It also leaves the order un-unified: POSTFIX_ASSET_ITEM and the Web3TokenDao list queries still sort default icons last.
Suggested fix: restore a has-icon tier in the shared comparator, e.g. add an iconUrl: (T) -> String? selector and sort placeholder icons last, ahead of or right after the exact-symbol tier to match the old behaviour.
Add the level column to tokens in database version 74 so asset lists and search keep the remote level instead of dropping it.
There was a problem hiding this comment.
AI review · Claude + Codex · 9e6f428
Needs changes: the follow-up commits persist token level, and that part looks sound, but they don't touch the two ranking regressions from the previous review, so both are still present. Gradle could not run for either reviewer (no Java runtime for one, wrapper and network failures for the other), so the Android build, unit tests, Room integration tests and lint are unverified. Codex's scratch harness compiled the production sort code with Android stubs: the comparator test assertions passed and both findings reproduced. Its SQLite check of the 73→74 migration also passed for both flavors.
| }.sortedByDescending { | ||
| it.name.equalsIgnoreCase(s) || it.symbol.equalsIgnoreCase(s) | ||
| }) | ||
| }.sortedWith( |
There was a problem hiding this comment.
Still present from the previous review: exact name matches lost their top ranking. The old sort was it.name.equalsIgnoreCase(s) || it.symbol.equalsIgnoreCase(s), but assetListComparator only tests the symbol.
The filter just above also matches chainName and getChainDisplayName(), so searching "Solana" returns every token on that chain, and SOL now sorts by value. With $100 of USDC on Solana and $5 of SOL, the comparator returns [USDC, SOL] (reproduced in a harness using the production comparator). Web3TokenDao.fuzzySearchAsset and TokenDao still rank symbol = query OR name = query first, so this also disagrees with the DAO search order.
Fix: keep an exact-name tier here, e.g. compareByDescending<Web3TokenItem> { it.name.equals(s, ignoreCase = true) }.then(assetListComparator(...)), or make the comparator's first tier match symbol or name.
| name: (T) -> String, | ||
| chainName: (T) -> String, | ||
| ): Comparator<T> = | ||
| compareByDescending<T> { !query.isNullOrBlank() && symbol(it).equals(query, ignoreCase = true) } |
There was a problem hiding this comment.
Still present from the previous review: the comparator drops the DEFAULT_ICON_URL-last rule that sortQueryAsset and sortByKeywordAndBalance applied first.
Persisting level does not replace it, because MIGRATION_73_74 gives every existing token level 11 and PREFIX_ASSET_ITEM turns NULL into 11. Unowned results at the same level fall through to price descending, so a higher-priced placeholder-icon asset ranks above real assets. Calling production sortQueryAsset with two exact-symbol matches, zero balances and level 11 returned [placeholder, real]. POSTFIX_ASSET_ITEM and the Web3TokenDao list queries still sort default icons last, so search and list order remain un-unified.
Fix: add an iconUrl: (T) -> String? selector and sort DEFAULT_ICON_URL last as the first tier, matching the old behaviour and the DAO ordering.
Drop the default-icon sort tier, rank exact symbol matches first, include visible or level >= unknown tokens in local search, and merge local with remote results in wallet search.
There was a problem hiding this comment.
AI review · Claude + Codex · feaf035
Needs changes. The follow-up commits removed the :defaultIconUrl parameter from POSTFIX_ASSET_ITEM, but one raw query still binds it, so the Privacy wallet crashes when it opens. Gradle could not run for either reviewer (no Java runtime for one; wrapper download and network failures for the other), so the build, unit tests, Room tests and lint are unverified. A SQLite reproduction confirmed the statement now has 0 parameters and rejects 1 binding, in both flavors. The two ranking points from the last review are still there: an exact-name match no longer ranks first, and placeholder-icon assets no longer sort last. This commit also removed both rules from the DAO SQL, so the Kotlin and SQL orders now agree and the change looks intentional; please just confirm that is the intended product behaviour.
| " ORDER BY COALESCE(ae.balance * a1.price_usd, 0) DESC, COALESCE(a1.level, 11) DESC, COALESCE(cast(ae.balance AS REAL), 0) DESC, cast(a1.price_usd AS REAL) DESC, a1.name ASC" | ||
| const val POSTFIX_ASSET_ITEM = | ||
| " ORDER BY (CASE WHEN a1.icon_url = :defaultIconUrl THEN 1 ELSE 0 END) ASC, COALESCE(ae.balance * a1.price_usd, 0) DESC, COALESCE(cast(ae.balance AS REAL), 0) DESC, cast(a1.price_usd AS REAL) DESC, a1.name ASC, c.name ASC" | ||
| " ORDER BY COALESCE(ae.balance * a1.price_usd, 0) DESC, COALESCE(a1.level, 11) DESC, COALESCE(cast(ae.balance AS REAL), 0) DESC, cast(a1.price_usd AS REAL) DESC, a1.name ASC, c.name ASC" |
There was a problem hiding this comment.
Crash: the Privacy wallet crashes on open. Removing :defaultIconUrl here leaves "$PREFIX_ASSET_ITEM $POSTFIX_ASSET_ITEM_NOT_HIDDEN" with no parameters. TokenRepository.assetItemsNotHiddenRaw() (TokenRepository.kt:529-534) still calls it.bindText(1, Constants.DEFAULT_ICON_URL) on that raw query. The framework SQLiteProgram.bind rejects index 1 on a statement with 0 parameters and throws IllegalArgumentException.
Call path: PrivacyWalletFragment.onViewCreated → lifecycleScope.launch { walletViewModel.assetItemsNotHiddenRaw() }. Nothing catches the exception, so the crash happens every time the screen opens. A SQLite reproduction gives "statement uses 0, and there are 1 supplied". grep DEFAULT_ICON_URL app/src/main/java now finds this binding and nothing else outside Constants.kt.
Fix: drop the onBindStatement binding in assetItemsNotHiddenRaw(), as you already did for Web3Repository.web3TokensExcludeHiddenRaw.
| if (query.length < 2) { | ||
| binding.pb.isVisible = false | ||
| binding.rvVa.displayedChild = POS_EMPTY | ||
| if (searchAdapter.currentList.isEmpty()) binding.rvVa.displayedChild = POS_EMPTY |
There was a problem hiding this comment.
1-character queries with no match can show a blank list instead of the empty state. search() calls searchAdapter.submitList(localTokens) and then goes straight into searchRemote(query). For query.length < 2, searchRemote only shows POS_EMPTY when searchAdapter.currentList.isEmpty().
SearchWeb3Adapter is a ListAdapter. When a non-empty list is replaced, AsyncListDiffer computes the diff on a background thread, so currentList still holds the old list at this point. Example: the screen opens with loadAllTokens() showing every token, and the user types one character that matches nothing locally. POS_EMPTY is never set, and the user sees an empty RecyclerView with no "no results" view. Before this commit, an empty localTokens always ended in POS_EMPTY.
Fix: base the decision on localTokens (pass it or its emptiness into searchRemote), not on the adapter's asynchronously updated currentList. The later currentList reads at ~242/256/261 can use the same value.
There was a problem hiding this comment.
AI review · Claude + Codex · 976fff2
Both issues from the last review are fixed. assetItemsNotHiddenRaw() no longer binds anything to the raw query, which now has no parameters. Grepping app/src/main/java finds DEFAULT_ICON_URL only in Constants.kt and finds no :defaultIconUrl anywhere. In WalletSearchWeb3Fragment, the empty-state checks and the remote merge now use localTokens instead of the adapter's currentList, which updates asynchronously. A SQLite check showed the raw asset query runs with zero bindings against the committed v74 schemas in both flavors, and git diff --check passed. Gradle could not run in either sandbox, so compilation, unit tests and lint are still unverified. The changed ranking behaviour (exact-name matches no longer rank first, placeholder-icon assets no longer sort last) is a product decision for you to confirm, not a defect.
…t-order # Conflicts: # app/src/main/java/one/mixin/android/ui/wallet/WalletSearchWeb3Fragment.kt
There was a problem hiding this comment.
AI review · Codex · f7c4a63
git diff --check, SQLite migration and query checks for both flavors, and three sort tests in an isolated Kotlin harness passed. Scratch checks reproduced the reported regressions. Android compilation, the full unit suite, and lint remain unverified because offline Gradle could not resolve the Foojay plugin.
| balance = item.balance, | ||
| balance = local?.balance ?: item.balance, | ||
| priceUsd = item.priceUsd, | ||
| changeUsd = item.changeUsd, |
There was a problem hiding this comment.
Searching for a held token in the Web3 Receive picker can show a 5% price change as 0.05%. queryAsset converts cached Web3 changes to fractional TokenItem values, and this merge copies the fraction into a Web3TokenItem that the adapter displays directly as a percent. Convert back with toWeb3TokenItem() before overlaying the wallet fields.
| primitiveAssetId = remote.primitiveAssetId ?: local.primitiveAssetId, | ||
| level = remote.level ?: local.level, | ||
| ) | ||
| } ?: remote.copy(level = remote.level ?: Constants.AssetLevel.VERIFIED) |
There was a problem hiding this comment.
When /assets/search omits level, this default prevents the Web3 pickers from falling back to the wallet's stored level. A visible asset marked SPAM locally can lose its warning badge when the API returns the same asset without a level. Preserve null for Web3 results so callers can use the stored level before applying a default.
| }) | ||
| val filtered = total.filter { | ||
| it.name.containsIgnoreCase(s) || | ||
| it.symbol.containsIgnoreCase(s) |
There was a problem hiding this comment.
The Web3 Send picker can no longer find held assets by network name. For example, typing Polygon used to find USDC on Polygon. Send search only uses local rows, so the new name and symbol filter drops that match entirely. Keep the existing network-name predicates while changing the sort order.
| token.symbol.contains(text, ignoreCase = true) | ||
| } | ||
| resultTokens = if (localTokens.isNotEmpty() || text.length < 2) { | ||
| resultTokens = if (text.length < 2) { |
There was a problem hiding this comment.
An existing wallet match now stays behind the loading spinner until the API responds. With a slow connection, searching for a held asset like USDC can wait for the network timeout even though the local lookup has already finished. Publish the local matches immediately, then replace them with the API-ordered merge when it arrives.
| val local = localById[remote.assetId] | ||
| if (local != null) { | ||
| remote.copy( | ||
| balance = local.balance, |
There was a problem hiding this comment.
This overwrites a freshly read balance with the snapshot taken before the network request. The token picker loads localAssets first, then explicitly rereads each returned asset's balance after queryAsset completes. If a refresh changes the balance from 1 to 2 during the request, the merge displays 1. Preserve the balance the caller already resolved, or consolidate the lookup so the merge uses the latest local balance.
There was a problem hiding this comment.
AI review · Codex · f663744
All five prior findings remain, and the new SQLite search path introduces a matching regression. git diff --check and three isolated Kotlin sort tests passed, and scratch checks reproduced the regressions. Offline Gradle could not resolve Foojay, leaving Android compilation, the full unit suite, and lint unverified.
| token.chainName?.contains(text, ignoreCase = true) == true | ||
| } | ||
| resultTokens = if (localTokens.isNotEmpty() || text.length < 2) { | ||
| val localTokens = viewModel.fuzzySearchAsset(walletId, text.escapeSql()) |
There was a problem hiding this comment.
Web3 Wallet Search now misses case-insensitive matches for non-ASCII token names. With the DAO query, é fails to find Élan Token, while the previous Kotlin filter matched it. A one-character query never reaches the API, so the wallet shows no results. Preserve Unicode-aware matching for local token names and symbols.
| localTokens | ||
| } else { | ||
| val remoteTokens = walletViewModel.queryAsset(walletId, text, true) | ||
| val remoteTokens = withContext(Dispatchers.IO) { |
There was a problem hiding this comment.
A held token still stays behind the spinner until the API call completes. The local lookup can already have found USDC, but the screen only publishes results after the request returns. Show cached matches while the request runs, then replace them with the merged results in API order.
| if (query.isBlank() || TYPE_FROM_SEND == type) return localTokens | ||
| if (query.isBlank()) return localTokens | ||
| val filteredLocal = localTokens.filter { | ||
| it.name.containsIgnoreCase(query) || |
There was a problem hiding this comment.
Web3 Send search still drops network-name matches. Typing Polygon used to find held USDC on Polygon, but Send returns this name-and-symbol filter without querying the API. Restore the chain-name and chain-display-name checks for Send.
| balance = item.balance, | ||
| balance = local?.balance ?: item.balance, | ||
| priceUsd = item.priceUsd, | ||
| changeUsd = item.changeUsd, |
There was a problem hiding this comment.
A cached Web3 Receive result with a 5% price change still displays 0.05%. queryAsset converts the cached change to a fraction, and the adapter displays this copied value directly as a percentage. Convert the TokenItem back with toWeb3TokenItem() before overlaying the wallet fields.
| primitiveAssetId = remote.primitiveAssetId ?: local.primitiveAssetId, | ||
| level = remote.level ?: local.level, | ||
| ) | ||
| } ?: remote.copy(level = remote.level ?: Constants.AssetLevel.VERIFIED) |
There was a problem hiding this comment.
When the asset search API omits level, Web3 pickers still get VERIFIED here and skip their fallback to the stored level. A visible token marked SPAM locally can lose its warning badge. Preserve the null level for Web3 results so the caller can use the wallet's level before defaulting.
| val local = localById[remote.assetId] | ||
| if (local != null) { | ||
| remote.copy( | ||
| balance = local.balance, |
There was a problem hiding this comment.
This still overwrites the balance the Privacy Wallet picker rereads after the network request. If the balance changes from 1 to 2 during the request, the caller passes 2 and the merge returns 1 from the earlier snapshot. Keep the balance the caller resolved or move the local lookup into the merge.
No description provided.