Merge branch '4.1.0' into CAKE-208-bug-after-balance-changing

# Conflicts:
#	lib/store/settings_store.dart
#	lib/view_model/dashboard/balance_view_model.dart
This commit is contained in:
OleksandrSobol
2020-12-18 21:33:43 +02:00
110 changed files with 4383 additions and 1203 deletions
@@ -17,11 +17,11 @@ part 'balance_view_model.g.dart';
class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel;
abstract class BalanceViewModelBase with Store {
BalanceViewModelBase({
@required this.appStore,
@required this.settingsStore,
@required this.fiatConvertationStore
}) {
BalanceViewModelBase(
{@required this.appStore,
@required this.settingsStore,
@required this.fiatConvertationStore}){
isReversing = false;
wallet ??= appStore.wallet;
@@ -42,6 +42,9 @@ abstract class BalanceViewModelBase with Store {
final SettingsStore settingsStore;
final FiatConversionStore fiatConvertationStore;
bool get canReverse =>
(appStore.wallet.balance.availableModes as List).length > 1;
@observable
bool isReversing;
@@ -51,18 +54,18 @@ abstract class BalanceViewModelBase with Store {
@observable
WalletBase wallet;
@computed
double get price => fiatConvertationStore.prices[appStore.wallet.currency];
@computed
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed
BalanceDisplayMode get displayMode => isReversing
? (savedDisplayMode == BalanceDisplayMode.availableBalance
? BalanceDisplayMode.fullBalance
: BalanceDisplayMode.availableBalance)
: savedDisplayMode;
@computed
double get price => fiatConvertationStore.price;
? (savedDisplayMode == BalanceDisplayMode.availableBalance
? BalanceDisplayMode.fullBalance
: BalanceDisplayMode.availableBalance)
: savedDisplayMode;
@computed
String get cryptoBalance {
@@ -86,15 +89,11 @@ abstract class BalanceViewModelBase with Store {
final fiatCurrency = settingsStore.fiatCurrency;
var balance = '---';
final totalBalance = _getFiatBalance(
price: price,
cryptoAmount: walletBalance.totalBalance
);
final totalBalance =
_getFiatBalance(price: price, cryptoAmount: walletBalance.totalBalance);
final unlockedBalance = _getFiatBalance(
price: price,
cryptoAmount: walletBalance.unlockedBalance
);
price: price, cryptoAmount: walletBalance.unlockedBalance);
if (displayMode == BalanceDisplayMode.availableBalance) {
balance = fiatCurrency.toString() + ' ' + unlockedBalance ?? '0.00';
@@ -119,7 +118,7 @@ abstract class BalanceViewModelBase with Store {
if (_wallet is BitcoinWallet) {
return WalletBalance(
unlockedBalance: _wallet.balance.totalFormatted,
unlockedBalance: _wallet.balance.availableBalanceFormatted,
totalBalance: _wallet.balance.totalFormatted);
}
@@ -186,6 +186,8 @@ abstract class DashboardViewModelBase with Store {
@observable
WalletBase wallet;
bool get hasRescan => wallet.type == WalletType.monero;
BalanceViewModel balanceViewModel;
AppStore appStore;
@@ -212,6 +214,7 @@ abstract class DashboardViewModelBase with Store {
@action
void _onWalletChange(WalletBase wallet) {
this.wallet = wallet;
type = wallet.type;
name = wallet.name;
if (wallet is MoneroWallet) {
@@ -236,6 +239,21 @@ abstract class DashboardViewModelBase with Store {
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore)));
}
connectMapToListWithTransform(
appStore.wallet.transactionHistory.transactions,
transactions,
(TransactionInfo val) => TransactionListItem(
transaction: val,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore),
filter: (TransactionInfo tx) {
if (tx is MoneroTransactionInfo && wallet is MoneroWallet) {
return tx.accountIndex == wallet.account.id;
}
return true;
});
}
@action
@@ -13,16 +13,18 @@ part 'node_list_view_model.g.dart';
class NodeListViewModel = NodeListViewModelBase with _$NodeListViewModel;
abstract class NodeListViewModelBase with Store {
NodeListViewModelBase(this._nodeSource, this._wallet, this.settingsStore)
NodeListViewModelBase(this._nodeSource, this.wallet, this.settingsStore)
: nodes = ObservableList<Node>() {
_nodeSource.bindToList(nodes,
filter: (Node val) => val?.type == _wallet.type, initialFire: true);
filter: (Node val) => val?.type == wallet.type, initialFire: true);
}
@computed
Node get currentNode => settingsStore.nodes[wallet.type];
final ObservableList<Node> nodes;
final SettingsStore settingsStore;
final WalletBase _wallet;
final WalletBase wallet;
final Box<Node> _nodeSource;
Future<void> reset() async {
@@ -30,14 +32,12 @@ abstract class NodeListViewModelBase with Store {
Node node;
switch (_wallet.type) {
switch (wallet.type) {
case WalletType.bitcoin:
node = getBitcoinDefaultElectrumServer(nodes: _nodeSource);
break;
case WalletType.monero:
node = getMoneroDefaultNode(
nodes: _nodeSource,
);
node = getMoneroDefaultNode(nodes: _nodeSource);
break;
default:
break;
@@ -50,5 +50,5 @@ abstract class NodeListViewModelBase with Store {
Future<void> delete(Node node) async => node.delete();
Future<void> setAsCurrent(Node node) async =>
settingsStore.currentNode = node;
settingsStore.nodes[wallet.type] = node;
}
+7 -15
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/transaction_description.dart';
import 'package:hive/hive.dart';
import 'package:intl/intl.dart';
@@ -77,19 +78,9 @@ abstract class SendViewModelBase with Store {
PendingTransaction pendingTransaction;
@computed
String get balance {
String balance = '0.0';
if (_wallet is MoneroWallet) {
balance = _wallet.balance.formattedUnlockedBalance as String ?? '';
}
if (_wallet is BitcoinWallet) {
balance = _wallet.balance.confirmedFormatted as String ?? '';
}
return balance;
}
String get balance =>
_wallet.balance.formattedBalance(BalanceDisplayMode.availableBalance)
as String ?? '0.0';
@computed
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
@@ -97,6 +88,7 @@ abstract class SendViewModelBase with Store {
@computed
ObservableList<Template> get templates => _sendTemplateStore.templates;
WalletType get walletType => _wallet.type;
final WalletBase _wallet;
final SettingsStore _settingsStore;
final SendTemplateStore _sendTemplateStore;
@@ -175,7 +167,7 @@ abstract class SendViewModelBase with Store {
void _updateFiatAmount() {
try {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.price,
price: _fiatConversationStore.prices[_wallet.currency],
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) {
fiatAmount = fiat;
@@ -189,7 +181,7 @@ abstract class SendViewModelBase with Store {
void _updateCryptoAmount() {
try {
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
_fiatConversationStore.price;
_fiatConversationStore.prices[_wallet.currency];
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
if (cryptoAmount != cryptoAmountTmp) {
@@ -1,3 +1,5 @@
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/themes/theme_list.dart';
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobx/mobx.dart';
@@ -35,12 +37,13 @@ abstract class SettingsViewModelBase with Store {
(PackageInfo packageInfo) => currentVersion = packageInfo.version);
sections = [
[
PickerListItem(
title: S.current.settings_display_balance_as,
items: BalanceDisplayMode.all,
selectedItem: () => balanceDisplayMode,
onItemSelected: (BalanceDisplayMode mode) =>
_settingsStore.balanceDisplayMode = mode),
if ((wallet.balance.availableModes as List).length > 1)
PickerListItem(
title: S.current.settings_display_balance_as,
items: BalanceDisplayMode.all,
selectedItem: () => balanceDisplayMode,
onItemSelected: (BalanceDisplayMode mode) =>
_settingsStore.balanceDisplayMode = mode),
PickerListItem(
title: S.current.settings_currency,
items: FiatCurrency.all,
@@ -50,7 +53,7 @@ abstract class SettingsViewModelBase with Store {
setFiatCurrency(currency)),
PickerListItem(
title: S.current.settings_fee_priority,
items: _transactionPriorities(wallet.type),
items: TransactionPriority.forWalletType(wallet.type),
selectedItem: () => transactionPriority,
isAlwaysShowScrollThumb: true,
onItemSelected: (TransactionPriority priority) =>
@@ -106,11 +109,12 @@ abstract class SettingsViewModelBase with Store {
setAllowBiometricalAuthentication(value);
}
}),
SwitcherListItem(
title: S.current.settings_dark_mode,
value: () => _settingsStore.isDarkTheme,
onValueChange: (_, bool value) =>
_settingsStore.isDarkTheme = value)
PickerListItem(
title: S.current.color_theme,
items: ThemeList.all,
selectedItem: () => theme,
onItemSelected: (ThemeBase theme) =>
_settingsStore.currentTheme = theme)
],
[
LinkListItem(
@@ -186,6 +190,9 @@ abstract class SettingsViewModelBase with Store {
bool get allowBiometricalAuthentication =>
_settingsStore.allowBiometricalAuthentication;
@computed
ThemeBase get theme => _settingsStore.currentTheme;
final Map<String, String> itemHeaders;
List<List<SettingsListItem>> sections;
final SettingsStore _settingsStore;
@@ -234,19 +241,4 @@ abstract class SettingsViewModelBase with Store {
@action
void _showTrades() => actionlistDisplayMode.add(ActionListDisplayMode.trades);
static List<TransactionPriority> _transactionPriorities(WalletType type) {
switch (type) {
case WalletType.monero:
return TransactionPriority.all;
case WalletType.bitcoin:
return [
TransactionPriority.slow,
TransactionPriority.regular,
TransactionPriority.fast
];
default:
return [];
}
}
}
@@ -31,7 +31,7 @@ class MoneroURI extends PaymentURI {
var base = 'monero:' + address;
if (amount?.isNotEmpty ?? false) {
base += '?tx_amount=$amount';
base += '?tx_amount=${amount.replaceAll(',', '.')}';
}
return base;
@@ -47,7 +47,7 @@ class BitcoinURI extends PaymentURI {
var base = 'bitcoin:' + address;
if (amount?.isNotEmpty ?? false) {
base += '?amount=$amount';
base += '?amount=${amount.replaceAll(',', '.')}';
}
return base;
@@ -57,10 +57,13 @@ class BitcoinURI extends PaymentURI {
abstract class WalletAddressListViewModelBase with Store {
WalletAddressListViewModelBase(
{@required AppStore appStore}) {
hasAccounts = _wallet is MoneroWallet;
_appStore = appStore;
_wallet = _appStore.wallet;
_onWalletChangeReaction = reaction((_) => _appStore.wallet, (WalletBase wallet) => _wallet = wallet);
hasAccounts = _wallet?.type == WalletType.monero;
_onWalletChangeReaction = reaction((_) => _appStore.wallet, (WalletBase wallet) {
_wallet = wallet;
hasAccounts = _wallet.type == WalletType.monero;
});
_init();
}
@@ -125,6 +128,7 @@ abstract class WalletAddressListViewModelBase with Store {
return addressList;
}
@observable
bool hasAccounts;
@observable
+2 -2
View File
@@ -27,7 +27,7 @@ abstract class WalletCreationVMBase with Store {
@observable
ExecutionState state;
final WalletType type;
WalletType type;
final bool isRecovery;
final Box<WalletInfo> _walletInfoSource;
final AppStore _appStore;
@@ -51,7 +51,7 @@ abstract class WalletCreationVMBase with Store {
credentials.walletInfo = walletInfo;
final wallet = await process(credentials);
await _walletInfoSource.add(walletInfo);
_appStore.wallet = wallet;
_appStore.changeCurrentWallet(wallet);
_appStore.authenticationStore.allowed();
state = ExecutedSuccessfullyState();
} catch (e) {
@@ -32,7 +32,8 @@ abstract class WalletListViewModelBase with Store {
final password =
await _keyService.getWalletPassword(walletName: wallet.name);
final walletService = getIt.get<WalletService>(param1: wallet.type);
_appStore.wallet = await walletService.openWallet(wallet.name, password);
final loadedWallet = await walletService.openWallet(wallet.name, password);
_appStore.changeCurrentWallet(loadedWallet);
_updateList();
}
+4 -2
View File
@@ -43,6 +43,8 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
}
@override
Future<WalletBase> process(WalletCredentials credentials) async =>
_walletCreationService.create(credentials);
Future<WalletBase> process(WalletCredentials credentials) async {
_walletCreationService.changeWalletType(type: type);
return _walletCreationService.create(credentials);
}
}
+24 -5
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
@@ -22,10 +23,16 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
WalletRestoreViewModelBase(AppStore appStore, this._walletCreationService,
Box<WalletInfo> walletInfoSource,
{@required WalletType type})
: super(appStore, walletInfoSource, type: type, isRecovery: true) {
isButtonEnabled = false;
: availableModes = type == WalletType.monero
? WalletRestoreMode.values
: [WalletRestoreMode.seed],
hasSeedLanguageSelector = type == WalletType.monero,
hasBlockchainHeightLanguageSelector = type == WalletType.monero,
super(appStore, walletInfoSource, type: type, isRecovery: true) {
isButtonEnabled =
!hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
mode = WalletRestoreMode.seed;
_walletCreationService.changeWalletType(type: WalletType.monero);
_walletCreationService.changeWalletType(type: type);
}
@observable
@@ -34,6 +41,10 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
@observable
bool isButtonEnabled;
final List<WalletRestoreMode> availableModes;
final bool hasSeedLanguageSelector;
final bool hasBlockchainHeightLanguageSelector;
final WalletCreationService _walletCreationService;
@override
@@ -44,8 +55,16 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
if (mode == WalletRestoreMode.seed) {
final seed = options['seed'] as String;
return MoneroRestoreWalletFromSeedCredentials(
name: name, height: height, mnemonic: seed, password: password);
switch (type) {
case WalletType.monero:
return MoneroRestoreWalletFromSeedCredentials(
name: name, height: height, mnemonic: seed, password: password);
case WalletType.bitcoin:
return BitcoinRestoreWalletFromSeedCredentials(
name: name, mnemonic: seed, password: password);
default:
break;
}
}
if (mode == WalletRestoreMode.keys) {