mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
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
This commit is contained in:
parent
58280d1bb2
commit
f704bdc864
2 changed files with 69 additions and 20 deletions
|
@ -40,6 +40,10 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> 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;
|
||||
|
|
|
@ -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<void> 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)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue