From f9dda620a087804d80ffeb0191f71d8e856c0c6d Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 10 Jul 2024 13:11:55 -0600 Subject: [PATCH] single coin app wallets list state updating fix --- lib/pages/wallets_view/wallets_overview.dart | 48 ++++++++++++++----- .../event_bus/events/wallet_added_event.dart | 1 + lib/services/wallets.dart | 12 +++-- 3 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 lib/services/event_bus/events/wallet_added_event.dart diff --git a/lib/pages/wallets_view/wallets_overview.dart b/lib/pages/wallets_view/wallets_overview.dart index 6fb6cc718..786ce78f6 100644 --- a/lib/pages/wallets_view/wallets_overview.dart +++ b/lib/pages/wallets_view/wallets_overview.dart @@ -20,6 +20,8 @@ import '../../models/isar/models/ethereum/eth_contract.dart'; import '../../pages_desktop_specific/my_stack_view/dialogs/desktop_expanding_wallet_card.dart'; import '../../providers/db/main_db_provider.dart'; import '../../providers/providers.dart'; +import '../../services/event_bus/events/wallet_added_event.dart'; +import '../../services/event_bus/global_event_bus.dart'; import '../../themes/stack_colors.dart'; import '../../utilities/assets.dart'; import '../../utilities/constants.dart'; @@ -111,11 +113,7 @@ class _EthWalletsOverviewState extends ConsumerState { return element.toLowerCase().contains(term); } - @override - void initState() { - _searchController = TextEditingController(); - searchFieldFocusNode = FocusNode(); - + void updateWallets() { final walletsData = ref.read(mainDBProvider).isar.walletInfo.where().findAllSync(); walletsData.removeWhere((e) => e.coin != widget.coin); @@ -155,16 +153,40 @@ class _EthWalletsOverviewState extends ConsumerState { } else { // add non token wallet tuple to list for (final data in walletsData) { - wallets.add( - Tuple2( - ref.read(pWallets).getWallet( - data.walletId, - ), - [], - ), - ); + // 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, + ), + [], + ), + ); + } catch (_) { + // lol bandaid for single coin based apps + } } } + } + + @override + void initState() { + _searchController = TextEditingController(); + searchFieldFocusNode = FocusNode(); + + updateWallets(); + + if (AppConfig.isSingleCoinApp) { + GlobalEventBus.instance.on().listen((_) { + updateWallets(); + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) { + setState(() {}); + } + }); + }); + } super.initState(); } diff --git a/lib/services/event_bus/events/wallet_added_event.dart b/lib/services/event_bus/events/wallet_added_event.dart new file mode 100644 index 000000000..0407946fc --- /dev/null +++ b/lib/services/event_bus/events/wallet_added_event.dart @@ -0,0 +1 @@ +class WalletAddedEvent {} diff --git a/lib/services/wallets.dart b/lib/services/wallets.dart index 43f0af396..c4e75bde8 100644 --- a/lib/services/wallets.dart +++ b/lib/services/wallets.dart @@ -13,12 +13,10 @@ import 'dart:async'; import 'package:flutter_libmonero/monero/monero.dart' as monero; import 'package:flutter_libmonero/wownero/wownero.dart' as wownero; import 'package:isar/isar.dart'; + +import '../app_config.dart'; import '../db/hive/db.dart'; import '../db/isar/main_db.dart'; -import 'node_service.dart'; -import 'notifications_service.dart'; -import 'trade_sent_from_stack_service.dart'; -import '../app_config.dart'; import '../utilities/enums/sync_type_enum.dart'; import '../utilities/flutter_secure_storage_interface.dart'; import '../utilities/logger.dart'; @@ -28,6 +26,11 @@ import '../wallets/isar/models/wallet_info.dart'; import '../wallets/wallet/impl/epiccash_wallet.dart'; import '../wallets/wallet/wallet.dart'; import '../wallets/wallet/wallet_mixin_interfaces/cw_based_interface.dart'; +import 'event_bus/events/wallet_added_event.dart'; +import 'event_bus/global_event_bus.dart'; +import 'node_service.dart'; +import 'notifications_service.dart'; +import 'trade_sent_from_stack_service.dart'; class Wallets { Wallets._private(); @@ -59,6 +62,7 @@ class Wallets { ); } _wallets[wallet.walletId] = wallet; + GlobalEventBus.instance.fire(WalletAddedEvent()); } Future deleteWallet(