diff --git a/lib/pages/wallets_view/wallets_overview.dart b/lib/pages/wallets_view/wallets_overview.dart index 786ce78f6..b5d73dbaf 100644 --- a/lib/pages/wallets_view/wallets_overview.dart +++ b/lib/pages/wallets_view/wallets_overview.dart @@ -12,7 +12,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:isar/isar.dart'; -import 'package:tuple/tuple.dart'; import '../../app_config.dart'; import '../../models/add_wallet_list_entity/sub_classes/coin_entity.dart'; @@ -60,6 +59,8 @@ class WalletsOverview extends ConsumerStatefulWidget { ConsumerState createState() => _EthWalletsOverviewState(); } +typedef WalletListItemData = ({Wallet wallet, List contracts}); + class _EthWalletsOverviewState extends ConsumerState { final isDesktop = Util.isDesktop; @@ -68,28 +69,29 @@ class _EthWalletsOverviewState extends ConsumerState { String _searchString = ""; - final List>> wallets = []; + final Map wallets = {}; - List>> _filter(String searchTerm) { + List _filter(String searchTerm) { if (searchTerm.isEmpty) { - return wallets; + return wallets.values.toList() + ..sort((a, b) => a.wallet.info.name.compareTo(b.wallet.info.name)); } - final List>> results = []; + final Map results = {}; final term = searchTerm.toLowerCase(); - for (final tuple in wallets) { + for (final entry in wallets.entries) { bool includeManager = false; // search wallet name and total balance - includeManager |= _elementContains(tuple.item1.info.name, term); + includeManager |= _elementContains(entry.value.wallet.info.name, term); includeManager |= _elementContains( - tuple.item1.info.cachedBalance.total.decimal.toString(), + entry.value.wallet.info.cachedBalance.total.decimal.toString(), term, ); final List contracts = []; - for (final contract in tuple.item2) { + for (final contract in entry.value.contracts) { if (_elementContains(contract.name, term)) { contracts.add(contract); } else if (_elementContains(contract.symbol, term)) { @@ -102,11 +104,12 @@ class _EthWalletsOverviewState extends ConsumerState { } if (includeManager || contracts.isNotEmpty) { - results.add(Tuple2(tuple.item1, contracts)); + results.addEntries([entry]); } } - return results; + return results.values.toList() + ..sort((a, b) => a.wallet.info.name.compareTo(b.wallet.info.name)); } bool _elementContains(String element, String term) { @@ -141,13 +144,11 @@ class _EthWalletsOverviewState extends ConsumerState { } // add tuple to list - wallets.add( - Tuple2( - ref.read(pWallets).getWallet( - data.walletId, - ), - contracts, - ), + wallets[data.walletId] = ( + wallet: ref.read(pWallets).getWallet( + data.walletId, + ), + contracts: contracts, ); } } else { @@ -155,13 +156,11 @@ class _EthWalletsOverviewState extends ConsumerState { for (final data in walletsData) { // desktop single coin apps may cause issues so lets just ignore the error and move on try { - wallets.add( - Tuple2( - ref.read(pWallets).getWallet( - data.walletId, - ), - [], - ), + wallets[data.walletId] = ( + wallet: ref.read(pWallets).getWallet( + data.walletId, + ), + contracts: [], ); } catch (_) { // lol bandaid for single coin based apps @@ -315,24 +314,27 @@ class _EthWalletsOverviewState extends ConsumerState { final data = _filter(_searchString); return ListView.separated( itemBuilder: (_, index) { - final element = data[index]; + final entry = data[index]; + final wallet = entry.wallet; - if (element.item1.cryptoCurrency.hasTokenSupport) { + if (wallet.cryptoCurrency.hasTokenSupport) { if (isDesktop) { return DesktopExpandingWalletCard( key: Key( - "${element.item1.info.name}_${element.item2.map((e) => e.address).join()}", + "${wallet.walletId}_${entry.contracts.map((e) => e.address).join()}", ), - data: element, + data: entry, navigatorState: widget.navigatorState!, ); } else { return MasterWalletCard( - walletId: element.item1.walletId, + key: Key(wallet.walletId), + walletId: wallet.walletId, ); } } else { return ConditionalParent( + key: Key(wallet.walletId), condition: isDesktop, builder: (child) => RoundedWhiteContainer( padding: const EdgeInsets.symmetric( @@ -345,7 +347,7 @@ class _EthWalletsOverviewState extends ConsumerState { child: child, ), child: SimpleWalletCard( - walletId: element.item1.walletId, + walletId: wallet.walletId, popPrevious: widget .overrideSimpleWalletCardPopPreviousValueWith == null diff --git a/lib/pages_desktop_specific/my_stack_view/dialogs/desktop_expanding_wallet_card.dart b/lib/pages_desktop_specific/my_stack_view/dialogs/desktop_expanding_wallet_card.dart index 5246a6b16..aa3244ece 100644 --- a/lib/pages_desktop_specific/my_stack_view/dialogs/desktop_expanding_wallet_card.dart +++ b/lib/pages_desktop_specific/my_stack_view/dialogs/desktop_expanding_wallet_card.dart @@ -11,19 +11,18 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/svg.dart'; -import '../../../models/isar/models/ethereum/eth_contract.dart'; + +import '../../../pages/wallets_view/wallets_overview.dart'; import '../../../themes/stack_colors.dart'; import '../../../utilities/assets.dart'; import '../../../utilities/constants.dart'; import '../../../utilities/text_styles.dart'; -import '../../../wallets/wallet/wallet.dart'; import '../../../widgets/animated_widgets/rotate_icon.dart'; import '../../../widgets/expandable.dart'; import '../../../widgets/rounded_white_container.dart'; import '../../../widgets/wallet_card.dart'; import '../../../widgets/wallet_info_row/sub_widgets/wallet_info_row_balance.dart'; import '../../../widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart'; -import 'package:tuple/tuple.dart'; class DesktopExpandingWalletCard extends StatefulWidget { const DesktopExpandingWalletCard({ @@ -32,7 +31,7 @@ class DesktopExpandingWalletCard extends StatefulWidget { required this.navigatorState, }); - final Tuple2> data; + final WalletListItemData data; final NavigatorState navigatorState; @override @@ -48,9 +47,9 @@ class _DesktopExpandingWalletCardState @override void initState() { - if (widget.data.item1.cryptoCurrency.hasTokenSupport) { + if (widget.data.wallet.cryptoCurrency.hasTokenSupport) { tokenContractAddresses.addAll( - widget.data.item2.map((e) => e.address), + widget.data.contracts.map((e) => e.address), ); } @@ -63,7 +62,7 @@ class _DesktopExpandingWalletCardState padding: EdgeInsets.zero, borderColor: Theme.of(context).extension()!.backgroundAppBar, child: Expandable( - initialState: widget.data.item1.cryptoCurrency.hasTokenSupport + initialState: widget.data.wallet.cryptoCurrency.hasTokenSupport ? ExpandableState.expanded : ExpandableState.collapsed, controller: expandableController, @@ -89,13 +88,13 @@ class _DesktopExpandingWalletCardState child: Row( children: [ WalletInfoCoinIcon( - coin: widget.data.item1.info.coin, + coin: widget.data.wallet.info.coin, ), const SizedBox( width: 12, ), Text( - widget.data.item1.info.name, + widget.data.wallet.info.name, style: STextStyles.desktopTextExtraSmall(context) .copyWith( color: Theme.of(context) @@ -109,7 +108,7 @@ class _DesktopExpandingWalletCardState Expanded( flex: 4, child: WalletInfoRowBalance( - walletId: widget.data.item1.walletId, + walletId: widget.data.wallet.walletId, ), ), ], @@ -173,7 +172,7 @@ class _DesktopExpandingWalletCardState bottom: 14, ), child: SimpleWalletCard( - walletId: widget.data.item1.walletId, + walletId: widget.data.wallet.walletId, popPrevious: true, desktopNavigatorState: widget.navigatorState, ), @@ -187,7 +186,7 @@ class _DesktopExpandingWalletCardState bottom: 14, ), child: SimpleWalletCard( - walletId: widget.data.item1.walletId, + walletId: widget.data.wallet.walletId, contractAddress: e, popPrevious: true, desktopNavigatorState: widget.navigatorState,