mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-29 21:55:58 +00:00
fix wallets list in ui
This commit is contained in:
parent
982cf99e5c
commit
df4b11e6e0
5 changed files with 38 additions and 32 deletions
|
@ -12,9 +12,9 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart';
|
||||
import 'package:stackwallet/pages/wallets_view/sub_widgets/wallet_list_item.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/all_wallets_info_provider.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||
|
||||
class AllWallets extends StatelessWidget {
|
||||
|
@ -48,7 +48,7 @@ class AllWallets extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Consumer(
|
||||
builder: (_, ref, __) {
|
||||
final walletsByCoin = ref.watch(pWallets).walletsByCoin;
|
||||
final walletsByCoin = ref.watch(pAllWalletsInfoByCoin);
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: walletsByCoin.length,
|
||||
|
|
|
@ -160,9 +160,8 @@ class _DesktopChooseFromStackState
|
|||
builder: (context) {
|
||||
final wallets = ref
|
||||
.watch(pWallets)
|
||||
.walletsByCoin
|
||||
.where((e) => e.coin == widget.coin)
|
||||
.map((e) => e.wallets);
|
||||
.wallets
|
||||
.where((e) => e.info.coin == widget.coin);
|
||||
|
||||
if (wallets.isEmpty) {
|
||||
return Column(
|
||||
|
@ -183,8 +182,7 @@ class _DesktopChooseFromStackState
|
|||
);
|
||||
}
|
||||
|
||||
List<String> walletIds =
|
||||
wallets.first.map((e) => e.walletId).toList();
|
||||
List<String> walletIds = wallets.map((e) => e.walletId).toList();
|
||||
|
||||
walletIds = filter(walletIds, _searchTerm);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:stackwallet/themes/stack_colors.dart';
|
|||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/all_wallets_info_provider.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
||||
|
@ -36,7 +37,7 @@ class _WalletTableState extends ConsumerState<WalletSummaryTable> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
final walletsByCoin = ref.watch(pWallets).walletsByCoin;
|
||||
final walletsByCoin = ref.watch(pAllWalletsInfoByCoin);
|
||||
|
||||
return ListView.separated(
|
||||
itemBuilder: (_, index) {
|
||||
|
|
|
@ -39,27 +39,6 @@ class Wallets {
|
|||
|
||||
List<Wallet> get wallets => _wallets.values.toList();
|
||||
|
||||
List<({Coin coin, List<Wallet> wallets})> get walletsByCoin {
|
||||
final Map<Coin, ({Coin coin, List<Wallet> wallets})> map = {};
|
||||
|
||||
for (final wallet in wallets) {
|
||||
if (map[wallet.info.coin] == null) {
|
||||
map[wallet.info.coin] = (coin: wallet.info.coin, wallets: []);
|
||||
}
|
||||
|
||||
map[wallet.info.coin]!.wallets.add(wallet);
|
||||
}
|
||||
|
||||
final List<({Coin coin, List<Wallet> wallets})> results = [];
|
||||
for (final coin in Coin.values) {
|
||||
if (map[coin] != null) {
|
||||
results.add(map[coin]!);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
static bool hasLoaded = false;
|
||||
|
||||
final Map<String, Wallet> _wallets = {};
|
||||
|
|
|
@ -4,9 +4,39 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
|
||||
final pAllWalletsInfo = Provider((ref) {
|
||||
return ref.watch(_pAllWalletsInfo.select((value) => value.value));
|
||||
});
|
||||
|
||||
final pAllWalletsInfoByCoin = Provider((ref) {
|
||||
final infos = ref.watch(pAllWalletsInfo);
|
||||
|
||||
final Map<Coin, ({Coin coin, List<WalletInfo> wallets})> map = {};
|
||||
|
||||
for (final info in infos) {
|
||||
if (map[info.coin] == null) {
|
||||
map[info.coin] = (coin: info.coin, wallets: []);
|
||||
}
|
||||
|
||||
map[info.coin]!.wallets.add(info);
|
||||
}
|
||||
|
||||
final List<({Coin coin, List<WalletInfo> wallets})> results = [];
|
||||
for (final coin in Coin.values) {
|
||||
if (map[coin] != null) {
|
||||
results.add(map[coin]!);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
});
|
||||
|
||||
_WalletInfoWatcher? _globalInstance;
|
||||
|
||||
final _pAllWalletsInfo = ChangeNotifierProvider((ref) {
|
||||
if (_globalInstance == null) {
|
||||
final isar = ref.watch(mainDBProvider).isar;
|
||||
_globalInstance = _WalletInfoWatcher(
|
||||
|
@ -15,11 +45,9 @@ final pAllWalletsInfo = Provider((ref) {
|
|||
);
|
||||
}
|
||||
|
||||
return _globalInstance!.value;
|
||||
return _globalInstance!;
|
||||
});
|
||||
|
||||
_WalletInfoWatcher? _globalInstance;
|
||||
|
||||
class _WalletInfoWatcher extends ChangeNotifier {
|
||||
late final StreamSubscription<void> _streamSubscription;
|
||||
|
||||
|
|
Loading…
Reference in a new issue