Merged 4.0.9

This commit is contained in:
M
2020-12-11 20:10:06 +02:00
52 changed files with 986 additions and 126 deletions
@@ -1,5 +1,10 @@
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
import 'package:cake_wallet/entities/transaction_history.dart';
import 'package:cake_wallet/monero/account.dart';
import 'package:cake_wallet/monero/monero_balance.dart';
import 'package:cake_wallet/monero/monero_transaction_history.dart';
import 'package:cake_wallet/monero/monero_transaction_info.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,28 +79,53 @@ 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
final _wallet = wallet;
if (_wallet is MoneroWallet) {
subname = _wallet.account?.label;
_onMoneroAccountChangeReaction = reaction((_) => _wallet.account,
(Account account) => _onMoneroAccountChange(_wallet));
_onMoneroBalanceChangeReaction = reaction((_) => _wallet.balance,
(MoneroBalance balance) => _onMoneroTransactionsUpdate(_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)));
}
connectMapToListWithTransform(
appStore.wallet.transactionHistory.transactions,
transactions,
(TransactionInfo val) => TransactionListItem(
transaction: val,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore));
settingsStore: appStore.settingsStore),
filter: (TransactionInfo tx) {
final wallet = _wallet;
if (tx is MoneroTransactionInfo && wallet is MoneroWallet) {
return tx.accountIndex == wallet.account.id;
}
final _wallet = wallet;
if (_wallet is MoneroWallet) {
subname = _wallet.account?.label;
}
return true;
});
}
@observable
@@ -170,6 +200,10 @@ abstract class DashboardViewModelBase with Store {
ReactionDisposer _reaction;
ReactionDisposer _onMoneroAccountChangeReaction;
ReactionDisposer _onMoneroBalanceChangeReaction;
Future<void> reconnect() async {
final node = appStore.settingsStore.getCurrentNode(wallet.type);
await wallet.connectToNode(node: node);
@@ -180,9 +214,47 @@ abstract class DashboardViewModelBase with Store {
this.wallet = wallet;
type = wallet.type;
name = wallet.name;
if (wallet is MoneroWallet) {
subname = wallet.account?.label;
_onMoneroAccountChangeReaction?.reaction?.dispose();
_onMoneroBalanceChangeReaction?.reaction?.dispose();
_onMoneroAccountChangeReaction = reaction((_) => wallet.account,
(Account account) => _onMoneroAccountChange(wallet));
_onMoneroBalanceChangeReaction = reaction((_) => wallet.balance,
(MoneroBalance balance) => _onMoneroTransactionsUpdate(wallet));
_onMoneroTransactionsUpdate(wallet);
} else {
transactions.clear();
transactions.addAll(wallet.transactionHistory.transactions.values.map(
(transaction) => TransactionListItem(
transaction: transaction,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore)));
}
}
@action
void _onMoneroAccountChange(MoneroWallet wallet) {
subname = wallet.account?.label;
_onMoneroTransactionsUpdate(wallet);
}
@action
void _onMoneroTransactionsUpdate(MoneroWallet wallet) {
transactions.clear();
transactions.addAll(wallet.transactionHistory.transactions.values.map(
(transaction) => TransactionListItem(
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)));
@@ -174,7 +174,7 @@ abstract class ExchangeViewModelBase with Store {
return;
}
final _amount = double.parse(amount.replaceAll(',', '.'));
final _amount = double.parse(amount.replaceAll(',', '.')) ?? 0;
provider
.calculateAmount(
from: depositCurrency,
@@ -247,10 +247,12 @@ abstract class ExchangeViewModelBase with Store {
if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) {
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString()));
} else if (limits.max != null && double.parse(amount) > limits.max) {
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString()));
} else {
@@ -262,11 +264,14 @@ abstract class ExchangeViewModelBase with Store {
await trades.add(trade);
tradeState = TradeIsCreatedSuccessfully(trade: trade);
} catch (e) {
tradeState = TradeIsCreatedFailure(error: e.toString());
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: e.toString());
}
}
} else {
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current
.error_text_limits_loading_failed('${provider.description}'));
}
@@ -13,6 +13,7 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
{AccountListItem accountListItem})
: state = InitialExecutionState(),
isEdit = accountListItem != null,
label = accountListItem?.label??'',
_accountListItem = accountListItem;
final bool isEdit;
@@ -12,7 +12,9 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
abstract class NodeCreateOrEditViewModelBase with Store {
NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
: state = InitialExecutionState();
: state = InitialExecutionState(),
connectionState = InitialExecutionState(),
useSSL = false;
@observable
ExecutionState state;
@@ -29,6 +31,12 @@ abstract class NodeCreateOrEditViewModelBase with Store {
@observable
String password;
@observable
ExecutionState connectionState;
@observable
bool useSSL;
@computed
bool get isReady =>
(address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false);
@@ -54,6 +62,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
port = '';
login = '';
password = '';
useSSL = false;
}
@action
@@ -61,11 +70,25 @@ abstract class NodeCreateOrEditViewModelBase with Store {
try {
state = IsExecutingState();
final node =
Node(uri: uri, type: _wallet.type, login: login, password: password);
Node(uri: uri, type: _wallet.type, login: login, password: password,
useSSL: useSSL);
await _nodeSource.add(node);
state = ExecutedSuccessfullyState();
} catch (e) {
state = FailureState(e.toString());
}
}
@action
Future<void> connect() async {
try {
connectionState = IsExecutingState();
final node =
Node(uri: uri, type: _wallet.type, login: login, password: password);
final isAlive = await node.requestNode();
connectionState = ExecutedSuccessfullyState(payload: isAlive);
} catch (e) {
connectionState = FailureState(e.toString());
}
}
}
@@ -2,10 +2,11 @@ import 'package:flutter/foundation.dart';
import 'package:cake_wallet/utils/list_item.dart';
class WalletAddressListItem extends ListItem {
const WalletAddressListItem({@required this.address, this.name, this.id})
: super();
const WalletAddressListItem({@required this.address, @required this.isPrimary,
this.name, this.id}) : super();
final int id;
final bool isPrimary;
final String address;
final String name;
@@ -97,16 +97,28 @@ abstract class WalletAddressListViewModelBase with Store {
final addressList = ObservableList<ListItem>();
if (wallet is MoneroWallet) {
addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) =>
WalletAddressListItem(
id: subaddress.id,
name: subaddress.label,
address: subaddress.address)));
final primaryAddress = wallet.subaddressList.subaddresses.first;
addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) {
final isPrimary = subaddress == primaryAddress;
return WalletAddressListItem(
id: subaddress.id,
isPrimary: isPrimary,
name: subaddress.label,
address: subaddress.address);
}));
}
if (wallet is BitcoinWallet) {
final bitcoinAddresses = wallet.addresses.map((addr) =>
WalletAddressListItem(name: addr.label, address: addr.address));
final primaryAddress = wallet.addresses.first;
final bitcoinAddresses = wallet.addresses.map((addr) {
final isPrimary = addr == primaryAddress;
return WalletAddressListItem(
isPrimary: isPrimary,
name: addr.label,
address: addr.address);
});
addressList.addAll(bitcoinAddresses);
}