diff --git a/lib/app_config/app_config.dart b/lib/app_config/app_config.dart index b940a7c198..040fce5d49 100644 --- a/lib/app_config/app_config.dart +++ b/lib/app_config/app_config.dart @@ -41,21 +41,52 @@ String get appTitle => 'Komodo Wallet | Non-Custodial Multi-Coin Wallet & DEX'; String get appShortTitle => 'Komodo Wallet'; Map priorityCoinsAbbrMap = { - 'KMD': 30, - 'BTC-segwit': 20, - 'ETH': 20, - 'LTC-segwit': 20, - 'USDT-ERC20': 20, - 'BNB': 11, - 'ETC': 11, - 'DOGE': 11, - 'DASH': 11, - 'MATIC': 10, - 'FTM': 10, - 'ARB': 10, - 'AVAX': 10, - 'HT': 10, - 'MOVR': 10, + // KMD always has highest priority (special case for Komodo ecosystem) + 'KMD': 1000, + + // Top 10 cryptocurrencies by market cap (as of current data) + // Rank 1: Bitcoin (~$2.21 trillion) + 'BTC': 100, + 'BTC-segwit': 100, + + // Rank 2: Ethereum (~$335 billion) + 'ETH': 90, + + // Rank 3: Tether (~$159 billion) + 'USDT': 80, + 'USDT-ERC20': 80, + 'USDT-PLG20': 80, + 'USDT-BEP20': 80, + + // Rank 4: XRP (~$145 billion) + 'XRP': 70, + + // Rank 5: BNB (~$93 billion) + 'BNB': 60, + + // Rank 6: Solana (~$84 billion) + 'SOL': 50, + + // Rank 7: USD Coin (~$63 billion) + 'USDC': 40, + 'USDC-ERC20': 40, + 'USDC-PLG20': 40, + 'USDC-BEP20': 40, + + // Rank 8: TRON (~$27.5 billion) + 'TRX': 30, + + // Rank 9: Dogecoin (~$27.1 billion) + 'DOGE': 20, + + // Rank 10: Cardano (~$22.3 billion) + 'ADA': 10, + + // Additional coins with higher than default priority + 'LTC-segwit': 5, // Litecoin (popular) + 'LTC': 5, + + // All other coins get default priority (0) }; /// List of coins that are excluded from the list of coins displayed on the @@ -129,14 +160,14 @@ const List appWalletOnlyAssetList = [ /// Coins that are enabled by default on restore from seed or registration. /// This will not affect existing wallets. List get enabledByDefaultCoins => [ - 'BTC-segwit', - 'KMD', - 'LTC-segwit', - 'ETH', - 'MATIC', - 'BNB', - 'AVAX', - 'FTM', + 'KMD', // Always included (Komodo ecosystem) + 'BTC-segwit', // Bitcoin (Rank 1, ~$2.21T market cap) + 'ETH', // Ethereum (Rank 2, ~$335B market cap) + 'BNB', // Binance Coin (Rank 5, ~$93B market cap) + 'DOGE', // Dogecoin (Rank 9, ~$27.1B market cap) + 'LTC-segwit', // Litecoin (popular, has segwit support) + 'USDT-ERC20', // Tether on Ethereum (most common stablecoin) + 'XRP', // XRP (Rank 4, ~$145B market cap) if (kDebugMode) 'DOC', if (kDebugMode) 'MARTY', ]; diff --git a/lib/bloc/coins_bloc/asset_coin_extension.dart b/lib/bloc/coins_bloc/asset_coin_extension.dart index 8c49684eef..466cd0d56d 100644 --- a/lib/bloc/coins_bloc/asset_coin_extension.dart +++ b/lib/bloc/coins_bloc/asset_coin_extension.dart @@ -1,6 +1,7 @@ import 'package:decimal/decimal.dart'; import 'package:komodo_defi_types/komodo_defi_type_utils.dart'; import 'package:komodo_defi_types/komodo_defi_types.dart'; +import 'package:web_dex/app_config/app_config.dart'; import 'package:web_dex/model/coin.dart'; import 'package:web_dex/model/coin_type.dart'; import 'package:komodo_defi_sdk/komodo_defi_sdk.dart'; @@ -39,7 +40,7 @@ extension AssetCoinExtension on Asset { swapContractAddress: config.valueOrNull('swap_contract_address'), fallbackSwapContract: config.valueOrNull('fallback_swap_contract'), - priority: 0, + priority: priorityCoinsAbbrMap[id.id] ?? 0, state: CoinState.inactive, walletOnly: config.valueOrNull('wallet_only') ?? false, mode: id.isSegwit ? CoinMode.segwit : CoinMode.standard, diff --git a/lib/model/coin_utils.dart b/lib/model/coin_utils.dart index 6e452dfcfc..a2e649d62b 100644 --- a/lib/model/coin_utils.dart +++ b/lib/model/coin_utils.dart @@ -6,6 +6,35 @@ import 'package:web_dex/model/coin_type.dart'; import 'package:web_dex/model/typedef.dart'; import 'package:web_dex/shared/utils/utils.dart'; +/// Sorts coins according to priority rules: +/// 1. First by balance (non-zero balances come first, sorted by USD value descending) +/// 2. If no balance, sort by priority (higher priority first) +/// 3. If same priority, sort alphabetically +List sortByPriorityAndBalance(List coins, KomodoDefiSdk sdk) { + final List list = List.from(coins); + list.sort((a, b) { + final double usdBalanceA = a.lastKnownUsdBalance(sdk) ?? 0.00; + final double usdBalanceB = b.lastKnownUsdBalance(sdk) ?? 0.00; + + // Both have balance - sort by USD balance descending + if (usdBalanceA > 0 && usdBalanceB > 0) { + return usdBalanceB.compareTo(usdBalanceA); + } + + // Only one has balance - that one comes first + if (usdBalanceA > 0 && usdBalanceB == 0) return -1; + if (usdBalanceB > 0 && usdBalanceA == 0) return 1; + + // Both have no balance - sort by priority then alphabetically + final int priorityA = a.priority; + final int priorityB = b.priority; + if (priorityA != priorityB) return priorityB - priorityA; + + return a.abbr.compareTo(b.abbr); + }); + return list; +} + List sortFiatBalance(List coins, KomodoDefiSdk sdk) { final List list = List.from(coins); list.sort((a, b) { diff --git a/lib/views/dex/simple/form/tables/table_utils.dart b/lib/views/dex/simple/form/tables/table_utils.dart index 6bc5716de1..ac11a02529 100644 --- a/lib/views/dex/simple/form/tables/table_utils.dart +++ b/lib/views/dex/simple/form/tables/table_utils.dart @@ -21,7 +21,7 @@ List prepareCoinsForTable( if (!testCoinsEnabled) coins = removeTestCoins(coins); coins = removeWalletOnly(coins); coins = removeSuspended(coins, authBloc.state.isSignedIn); - coins = sortFiatBalance(coins, GetIt.I()); + coins = sortByPriorityAndBalance(coins, GetIt.I()); coins = filterCoinsByPhrase(coins, searchString ?? '').toList(); return coins; } diff --git a/lib/views/wallet/coins_manager/coins_manager_list_wrapper.dart b/lib/views/wallet/coins_manager/coins_manager_list_wrapper.dart index c88d1bf823..aaa359c963 100644 --- a/lib/views/wallet/coins_manager/coins_manager_list_wrapper.dart +++ b/lib/views/wallet/coins_manager/coins_manager_list_wrapper.dart @@ -110,7 +110,7 @@ class _CoinsManagerListWrapperState extends State { case CoinsManagerSortType.balance: return sortByUsdBalance(coins, _sortData.sortDirection, context.sdk); case CoinsManagerSortType.none: - return coins; + return sortByPriorityAndBalance(coins, context.sdk); } } diff --git a/lib/views/wallet/wallet_page/wallet_main/active_coins_list.dart b/lib/views/wallet/wallet_page/wallet_main/active_coins_list.dart index f0dd4e12d5..a3de48d726 100644 --- a/lib/views/wallet/wallet_page/wallet_main/active_coins_list.dart +++ b/lib/views/wallet/wallet_page/wallet_main/active_coins_list.dart @@ -50,7 +50,7 @@ class ActiveCoinsList extends StatelessWidget { } List sorted = - sortFiatBalance(displayedCoins.toList(), context.sdk); + sortByPriorityAndBalance(displayedCoins.toList(), context.sdk); if (!context.read().state.testCoinsEnabled) { sorted = removeTestCoins(sorted);