Skip to content

Commit

Permalink
Merge pull request #930 from cypherstack/testing
Browse files Browse the repository at this point in the history
single coin app wallets list state updating fix
  • Loading branch information
julian-CStack authored Jul 10, 2024
2 parents e02b9f4 + f9dda62 commit aeb7de8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
48 changes: 35 additions & 13 deletions lib/pages/wallets_view/wallets_overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions lib/services/event_bus/events/wallet_added_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class WalletAddedEvent {}
12 changes: 8 additions & 4 deletions lib/services/wallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -59,6 +62,7 @@ class Wallets {
);
}
_wallets[wallet.walletId] = wallet;
GlobalEventBus.instance.fire(WalletAddedEvent());
}

Future<void> deleteWallet(
Expand Down

0 comments on commit aeb7de8

Please sign in to comment.