From f704bdc864488f6ff42735129aaa82b366879a06 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Fri, 13 Nov 2020 20:29:01 +0200 Subject: [PATCH] CAKE-158 | added calculating balance to _onAccountChangeReaction in the monero wallet; created _onMoneroAccountChange method in the dashboard_view_model.dart; added _onMoneroAccountChangeReaction and account filter to transaction list in the dashboard_view_model.dart --- lib/monero/monero_wallet.dart | 4 + .../dashboard/dashboard_view_model.dart | 85 ++++++++++++++----- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 4b9dd1cfc..1eaab9b18 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -40,6 +40,10 @@ abstract class MoneroWalletBase extends WalletBase with Store { fullBalance: monero_wallet.getFullBalance(accountIndex: 0), unlockedBalance: monero_wallet.getFullBalance(accountIndex: 0)); _onAccountChangeReaction = reaction((_) => account, (Account account) { + balance = MoneroBalance( + fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), + unlockedBalance: + monero_wallet.getUnlockedBalance(accountIndex: account.id)); subaddressList.update(accountIndex: account.id); subaddress = subaddressList.subaddresses.first; address = subaddress.address; diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index e76a663ec..62742d848 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart'; import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart'; +import 'package:cake_wallet/monero/account.dart'; import 'package:cake_wallet/monero/monero_wallet.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/crypto_currency.dart'; @@ -74,27 +75,41 @@ abstract class DashboardViewModelBase with Store { wallet ??= appStore.wallet; type = wallet.type; - transactions = ObservableList.of(wallet - .transactionHistory.transactions.values - .map((transaction) => TransactionListItem( - transaction: transaction, - balanceViewModel: balanceViewModel, - settingsStore: appStore.settingsStore))); - _reaction = reaction((_) => appStore.wallet, _onWalletChange); - // FIXME: fixme - connectMapToListWithTransform( - appStore.wallet.transactionHistory.transactions, - transactions, - (TransactionInfo val) => TransactionListItem( - transaction: val, - balanceViewModel: balanceViewModel, - settingsStore: appStore.settingsStore)); final _wallet = wallet; if (_wallet is MoneroWallet) { subname = _wallet.account?.label; + + _onMoneroAccountChangeReaction = reaction((_) => _wallet.account, + (Account account) => _onMoneroAccountChange(_wallet)); + + final _accountTransactions = _wallet + .transactionHistory.transactions.values + .where((tx) => tx.accountIndex == _wallet.account.id).toList(); + + transactions = ObservableList.of(_accountTransactions + .map((transaction) => TransactionListItem( + transaction: transaction, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore))); + } else { + transactions = ObservableList.of(wallet + .transactionHistory.transactions.values + .map((transaction) => TransactionListItem( + transaction: transaction, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore))); + + // FIXME: fixme + connectMapToListWithTransform( + appStore.wallet.transactionHistory.transactions, + transactions, + (TransactionInfo val) => TransactionListItem( + transaction: val, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore)); } } @@ -170,6 +185,8 @@ abstract class DashboardViewModelBase with Store { ReactionDisposer _reaction; + ReactionDisposer _onMoneroAccountChangeReaction; + Future reconnect() async { final node = appStore.settingsStore.getCurrentNode(wallet.type); await wallet.connectToNode(node: node); @@ -180,10 +197,38 @@ abstract class DashboardViewModelBase with Store { this.wallet = wallet; name = wallet.name; transactions.clear(); - transactions.addAll(wallet.transactionHistory.transactions.values.map( - (transaction) => TransactionListItem( - transaction: transaction, - balanceViewModel: balanceViewModel, - settingsStore: appStore.settingsStore))); + + if (wallet is MoneroWallet) { + final _accountTransactions = wallet + .transactionHistory.transactions.values + .where((tx) => tx.accountIndex == wallet.account.id).toList(); + + transactions.addAll(_accountTransactions + .map((transaction) => TransactionListItem( + transaction: transaction, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore))); + } else { + transactions.addAll(wallet.transactionHistory.transactions.values.map( + (transaction) => TransactionListItem( + transaction: transaction, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore))); + } + } + + @action + void _onMoneroAccountChange(MoneroWallet wallet) { + transactions.clear(); + + final _accountTransactions = wallet + .transactionHistory.transactions.values + .where((tx) => tx.accountIndex == wallet.account.id).toList(); + + transactions.addAll(_accountTransactions + .map((transaction) => TransactionListItem( + transaction: transaction, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore))); } }