Fixes for update fiat rate after change of current wallet type. Fixes for change amount for btc transactions. Changed displaying of balance for btc wallet. General fixes.

This commit is contained in:
M
2020-12-15 18:29:10 +02:00
parent eede39ee7a
commit 8cb9bd15cd
29 changed files with 340 additions and 276 deletions
@@ -15,31 +15,34 @@ 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
}) : isReversing = false;
BalanceViewModelBase(
{@required this.appStore,
@required this.settingsStore,
@required this.fiatConvertationStore})
: isReversing = false;
final AppStore appStore;
final SettingsStore settingsStore;
final FiatConversionStore fiatConvertationStore;
bool get canReverse =>
(appStore.wallet.balance.availableModes as List).length > 1;
@observable
bool isReversing;
@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 {
@@ -63,15 +66,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';
@@ -89,7 +88,7 @@ abstract class BalanceViewModelBase with Store {
final _wallet = appStore.wallet;
if (_wallet is MoneroWallet) {
return WalletBalance(
return WalletBalance(
unlockedBalance: _wallet.balance.formattedUnlockedBalance,
totalBalance: _wallet.balance.formattedFullBalance);
}
@@ -113,4 +112,4 @@ abstract class BalanceViewModelBase with Store {
return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
}
}
}
@@ -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;
}
+6 -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;
@@ -176,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;
@@ -190,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) {
@@ -35,12 +35,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,
+1 -1
View File
@@ -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();
}