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

OleksandrSobol committed Nov 13, 2020 at 20:29 UTC f704bdc864488f6ff42735129aaa82b366879a06
2 files changed +69 -20
lib/monero/monero_wallet.dart
+4
@@ -40,6 +40,10 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
40 fullBalance: monero_wallet.getFullBalance(accountIndex: 0),
41 unlockedBalance: monero_wallet.getFullBalance(accountIndex: 0));
42 _onAccountChangeReaction = reaction((_) => account, (Account account) {
43 + balance = MoneroBalance(
44 + fullBalance: monero_wallet.getFullBalance(accountIndex: account.id),
45 + unlockedBalance:
46 + monero_wallet.getUnlockedBalance(accountIndex: account.id));
47 subaddressList.update(accountIndex: account.id);
48 subaddress = subaddressList.subaddresses.first;
49 address = subaddress.address;
lib/view_model/dashboard/dashboard_view_model.dart
+65 -20
@@ -1,5 +1,6 @@
1 import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
2 import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
3 +import 'package:cake_wallet/monero/account.dart';
4 import 'package:cake_wallet/monero/monero_wallet.dart';
5 import 'package:cake_wallet/entities/balance_display_mode.dart';
6 import 'package:cake_wallet/entities/crypto_currency.dart';
@@ -74,27 +75,41 @@ abstract class DashboardViewModelBase with Store {
75 wallet ??= appStore.wallet;
76 type = wallet.type;
77
77 - transactions = ObservableList.of(wallet
78 - .transactionHistory.transactions.values
79 - .map((transaction) => TransactionListItem(
80 - transaction: transaction,
81 - balanceViewModel: balanceViewModel,
82 - settingsStore: appStore.settingsStore)));
83 -
78 _reaction = reaction((_) => appStore.wallet, _onWalletChange);
85 - // FIXME: fixme
86 - connectMapToListWithTransform(
87 - appStore.wallet.transactionHistory.transactions,
88 - transactions,
89 - (TransactionInfo val) => TransactionListItem(
90 - transaction: val,
91 - balanceViewModel: balanceViewModel,
92 - settingsStore: appStore.settingsStore));
79
80 final _wallet = wallet;
81
82 if (_wallet is MoneroWallet) {
83 subname = _wallet.account?.label;
84 +
85 + _onMoneroAccountChangeReaction = reaction((_) => _wallet.account,
86 + (Account account) => _onMoneroAccountChange(_wallet));
87 +
88 + final _accountTransactions = _wallet
89 + .transactionHistory.transactions.values
90 + .where((tx) => tx.accountIndex == _wallet.account.id).toList();
91 +
92 + transactions = ObservableList.of(_accountTransactions
93 + .map((transaction) => TransactionListItem(
94 + transaction: transaction,
95 + balanceViewModel: balanceViewModel,
96 + settingsStore: appStore.settingsStore)));
97 + } else {
98 + transactions = ObservableList.of(wallet
99 + .transactionHistory.transactions.values
100 + .map((transaction) => TransactionListItem(
101 + transaction: transaction,
102 + balanceViewModel: balanceViewModel,
103 + settingsStore: appStore.settingsStore)));
104 +
105 + // FIXME: fixme
106 + connectMapToListWithTransform(
107 + appStore.wallet.transactionHistory.transactions,
108 + transactions,
109 + (TransactionInfo val) => TransactionListItem(
110 + transaction: val,
111 + balanceViewModel: balanceViewModel,
112 + settingsStore: appStore.settingsStore));
113 }
114 }
115
@@ -170,6 +185,8 @@ abstract class DashboardViewModelBase with Store {
185
186 ReactionDisposer _reaction;
187
188 + ReactionDisposer _onMoneroAccountChangeReaction;
189 +
190 Future<void> reconnect() async {
191 final node = appStore.settingsStore.getCurrentNode(wallet.type);
192 await wallet.connectToNode(node: node);
@@ -180,10 +197,38 @@ abstract class DashboardViewModelBase with Store {
197 this.wallet = wallet;
198 name = wallet.name;
199 transactions.clear();
183 - transactions.addAll(wallet.transactionHistory.transactions.values.map(
184 - (transaction) => TransactionListItem(
185 - transaction: transaction,
186 - balanceViewModel: balanceViewModel,
187 - settingsStore: appStore.settingsStore)));
200 +
201 + if (wallet is MoneroWallet) {
202 + final _accountTransactions = wallet
203 + .transactionHistory.transactions.values
204 + .where((tx) => tx.accountIndex == wallet.account.id).toList();
205 +
206 + transactions.addAll(_accountTransactions
207 + .map((transaction) => TransactionListItem(
208 + transaction: transaction,
209 + balanceViewModel: balanceViewModel,
210 + settingsStore: appStore.settingsStore)));
211 + } else {
212 + transactions.addAll(wallet.transactionHistory.transactions.values.map(
213 + (transaction) => TransactionListItem(
214 + transaction: transaction,
215 + balanceViewModel: balanceViewModel,
216 + settingsStore: appStore.settingsStore)));
217 + }
218 + }
219 +
220 + @action
221 + void _onMoneroAccountChange(MoneroWallet wallet) {
222 + transactions.clear();
223 +
224 + final _accountTransactions = wallet
225 + .transactionHistory.transactions.values
226 + .where((tx) => tx.accountIndex == wallet.account.id).toList();
227 +
228 + transactions.addAll(_accountTransactions
229 + .map((transaction) => TransactionListItem(
230 + transaction: transaction,
231 + balanceViewModel: balanceViewModel,
232 + settingsStore: appStore.settingsStore)));
233 }
234 }