Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions lib/app_config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,52 @@ String get appTitle => 'Komodo Wallet | Non-Custodial Multi-Coin Wallet & DEX';
String get appShortTitle => 'Komodo Wallet';

Map<String, int> 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
Expand Down Expand Up @@ -129,14 +160,14 @@ const List<String> appWalletOnlyAssetList = [
/// Coins that are enabled by default on restore from seed or registration.
/// This will not affect existing wallets.
List<String> 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',
];
Expand Down
3 changes: 2 additions & 1 deletion lib/bloc/coins_bloc/asset_coin_extension.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -39,7 +40,7 @@ extension AssetCoinExtension on Asset {
swapContractAddress: config.valueOrNull<String>('swap_contract_address'),
fallbackSwapContract:
config.valueOrNull<String>('fallback_swap_contract'),
priority: 0,
priority: priorityCoinsAbbrMap[id.id] ?? 0,
state: CoinState.inactive,
walletOnly: config.valueOrNull<bool>('wallet_only') ?? false,
mode: id.isSegwit ? CoinMode.segwit : CoinMode.standard,
Expand Down
29 changes: 29 additions & 0 deletions lib/model/coin_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Coin> sortByPriorityAndBalance(List<Coin> coins, KomodoDefiSdk sdk) {
final List<Coin> 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<Coin> sortFiatBalance(List<Coin> coins, KomodoDefiSdk sdk) {
final List<Coin> list = List.from(coins);
list.sort((a, b) {
Expand Down
2 changes: 1 addition & 1 deletion lib/views/dex/simple/form/tables/table_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ List<Coin> prepareCoinsForTable(
if (!testCoinsEnabled) coins = removeTestCoins(coins);
coins = removeWalletOnly(coins);
coins = removeSuspended(coins, authBloc.state.isSignedIn);
coins = sortFiatBalance(coins, GetIt.I<KomodoDefiSdk>());
coins = sortByPriorityAndBalance(coins, GetIt.I<KomodoDefiSdk>());
coins = filterCoinsByPhrase(coins, searchString ?? '').toList();
return coins;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class _CoinsManagerListWrapperState extends State<CoinsManagerListWrapper> {
case CoinsManagerSortType.balance:
return sortByUsdBalance(coins, _sortData.sortDirection, context.sdk);
case CoinsManagerSortType.none:
return coins;
return sortByPriorityAndBalance(coins, context.sdk);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ActiveCoinsList extends StatelessWidget {
}

List<Coin> sorted =
sortFiatBalance(displayedCoins.toList(), context.sdk);
sortByPriorityAndBalance(displayedCoins.toList(), context.sdk);

if (!context.read<SettingsBloc>().state.testCoinsEnabled) {
sorted = removeTestCoins(sorted);
Expand Down
Loading