mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
single coin app wallets list state updating fix
This commit is contained in:
parent
e02b9f43c7
commit
f9dda620a0
3 changed files with 44 additions and 17 deletions
|
@ -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,16 +153,40 @@ class _EthWalletsOverviewState extends ConsumerState<WalletsOverview> {
|
|||
} 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<WalletAddedEvent>().listen((_) {
|
||||
updateWallets();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
|
1
lib/services/event_bus/events/wallet_added_event.dart
Normal file
1
lib/services/event_bus/events/wallet_added_event.dart
Normal file
|
@ -0,0 +1 @@
|
|||
class WalletAddedEvent {}
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue