From 69782a1bb237b8227738fae6e1a9ed5a677cf28f Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 13 Feb 2023 12:35:40 -0600 Subject: [PATCH] sort wallet coins alphabetically --- lib/pages/wallets_sheet/wallets_sheet.dart | 11 +++++--- .../wallets_view/sub_widgets/all_wallets.dart | 5 ++-- .../sub_widgets/wallet_list_item.dart | 13 ++++++--- .../my_stack_view/wallet_summary_table.dart | 27 ++++++++----------- lib/services/wallets.dart | 19 +++++++++---- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/lib/pages/wallets_sheet/wallets_sheet.dart b/lib/pages/wallets_sheet/wallets_sheet.dart index b69971ab5..dbbe371f1 100644 --- a/lib/pages/wallets_sheet/wallets_sheet.dart +++ b/lib/pages/wallets_sheet/wallets_sheet.dart @@ -17,8 +17,13 @@ class WalletsSheet extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final providers = ref.watch(walletsChangeNotifierProvider - .select((value) => value.getManagerProvidersByCoin()))[coin]; + final providers = ref + .watch(walletsChangeNotifierProvider + .select((value) => value.getManagerProvidersByCoin())) + .where((e) => e.item1 == coin) + .map((e) => e.item2) + .expand((e) => e) + .toList(); final maxHeight = MediaQuery.of(context).size.height * 0.60; @@ -70,7 +75,7 @@ class WalletsSheet extends ConsumerWidget { Flexible( child: ListView.builder( shrinkWrap: true, - itemCount: providers!.length, + itemCount: providers.length, itemBuilder: (builderContext, index) { final walletId = ref.watch( providers[index].select((value) => value.walletId)); diff --git a/lib/pages/wallets_view/sub_widgets/all_wallets.dart b/lib/pages/wallets_view/sub_widgets/all_wallets.dart index 4c6e3174f..a8c500501 100644 --- a/lib/pages/wallets_view/sub_widgets/all_wallets.dart +++ b/lib/pages/wallets_view/sub_widgets/all_wallets.dart @@ -44,9 +44,8 @@ class AllWallets extends StatelessWidget { return ListView.builder( itemCount: providersByCoin.length, itemBuilder: (builderContext, index) { - final coin = - providersByCoin.keys.toList(growable: false)[index]; - final int walletCount = providersByCoin[coin]!.length; + final coin = providersByCoin[index].item1; + final int walletCount = providersByCoin[index].item2.length; return Padding( padding: const EdgeInsets.symmetric(vertical: 4), child: WalletListItem( diff --git a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart index 7b9d0b53f..01b78c33f 100644 --- a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart +++ b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart @@ -46,9 +46,14 @@ class WalletListItem extends ConsumerWidget { ), onPressed: () async { if (walletCount == 1) { - final providersByCoin = ref.watch(walletsChangeNotifierProvider - .select((value) => value.getManagerProvidersByCoin())); - final manager = ref.read(providersByCoin[coin]!.first); + final providersByCoin = ref + .watch(walletsChangeNotifierProvider + .select((value) => value.getManagerProvidersByCoin())) + .where((e) => e.item1 == coin) + .map((e) => e.item2) + .expand((e) => e) + .toList(); + final manager = ref.read(providersByCoin.first); if (coin == Coin.monero || coin == Coin.wownero) { await manager.initializeExisting(); } @@ -57,7 +62,7 @@ class WalletListItem extends ConsumerWidget { WalletView.routeName, arguments: Tuple2( manager.walletId, - providersByCoin[coin]!.first, + providersByCoin.first, ), ), ); diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart index 9b98d4aa8..c1fd12542 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart @@ -25,24 +25,19 @@ class _WalletTableState extends ConsumerState { @override Widget build(BuildContext context) { debugPrint("BUILD: $runtimeType"); - final providersByCoin = ref - .watch( - walletsChangeNotifierProvider.select( - (value) => value.getManagerProvidersByCoin(), - ), - ) - .entries - .toList(growable: false); + final providersByCoin = ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManagerProvidersByCoin(), + ), + ); return TableView( rows: [ for (int i = 0; i < providersByCoin.length; i++) Builder( - key: Key("${providersByCoin[i].key.name}_${runtimeType}_key"), + key: Key("${providersByCoin[i].item1.name}_${runtimeType}_key"), builder: (context) { - final providers = ref.watch(walletsChangeNotifierProvider.select( - (value) => value - .getManagerProvidersForCoin(providersByCoin[i].key))); + final providers = providersByCoin[i].item2; VoidCallback? expandOverride; if (providers.length == 1) { @@ -77,7 +72,7 @@ class _WalletTableState extends ConsumerState { child: Row( children: [ SvgPicture.asset( - Assets.svg.iconFor(coin: providersByCoin[i].key), + Assets.svg.iconFor(coin: providersByCoin[i].item1), width: 28, height: 28, ), @@ -85,7 +80,7 @@ class _WalletTableState extends ConsumerState { width: 10, ), Text( - providersByCoin[i].key.prettyName, + providersByCoin[i].item1.prettyName, style: STextStyles.desktopTextExtraSmall(context) .copyWith( color: Theme.of(context) @@ -113,12 +108,12 @@ class _WalletTableState extends ConsumerState { TableViewCell( flex: 6, child: TablePriceInfo( - coin: providersByCoin[i].key, + coin: providersByCoin[i].item1, ), ), ], expandingChild: CoinWalletsTable( - coin: providersByCoin[i].key, + coin: providersByCoin[i].item1, ), ); }, diff --git a/lib/services/wallets.dart b/lib/services/wallets.dart index 9d1b97cee..4d5c07fb9 100644 --- a/lib/services/wallets.dart +++ b/lib/services/wallets.dart @@ -62,15 +62,24 @@ class Wallets extends ChangeNotifier { return result; } - Map>> getManagerProvidersByCoin() { - Map>> result = {}; + List>>> + getManagerProvidersByCoin() { + Map>> map = {}; for (final manager in _managerMap.values) { - if (result[manager.coin] == null) { - result[manager.coin] = []; + if (map[manager.coin] == null) { + map[manager.coin] = []; } - result[manager.coin]!.add(_managerProviderMap[manager.walletId] + map[manager.coin]!.add(_managerProviderMap[manager.walletId] as ChangeNotifierProvider); } + final List>>> result = []; + + for (final coin in map.keys) { + result.add(Tuple2(coin, map[coin]!)); + } + + result.sort((a, b) => a.item1.prettyName.compareTo(b.item1.prettyName)); + return result; }