single coin app wallets list state updating fix

This commit is contained in:
julian 2024-07-10 13:11:55 -06:00
parent e02b9f43c7
commit f9dda620a0
3 changed files with 44 additions and 17 deletions

View file

@ -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<WalletsOverview> {
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,6 +153,8 @@ class _EthWalletsOverviewState extends ConsumerState<WalletsOverview> {
} else {
// add non token wallet tuple to list
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(
@ -163,8 +163,30 @@ class _EthWalletsOverviewState extends ConsumerState<WalletsOverview> {
[],
),
);
} catch (_) {
// lol bandaid for single coin based apps
}
}
}
}
@override
void initState() {
_searchController = TextEditingController();
searchFieldFocusNode = FocusNode();
updateWallets();
if (AppConfig.isSingleCoinApp) {
GlobalEventBus.instance.on<WalletAddedEvent>().listen((_) {
updateWallets();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
setState(() {});
}
});
});
}
super.initState();
}

View file

@ -0,0 +1 @@
class WalletAddedEvent {}

View file

@ -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<void> deleteWallet(