mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-28 06:28:41 +01:00
Another beautiful day changes
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_balance.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
import 'package:cake_wallet/monero/monero_balance.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/wallet_balance.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -51,8 +50,7 @@ abstract class BalanceViewModelBase with Store {
|
||||
final SettingsStore settingsStore;
|
||||
final FiatConversionStore fiatConvertationStore;
|
||||
|
||||
bool get canReverse =>
|
||||
(appStore.wallet.balance.availableModes as List).length > 1;
|
||||
bool get canReverse => false;
|
||||
|
||||
@observable
|
||||
bool isReversing;
|
||||
@@ -61,7 +59,7 @@ abstract class BalanceViewModelBase with Store {
|
||||
Balance balance;
|
||||
|
||||
@observable
|
||||
WalletBase wallet;
|
||||
WalletBase<Balance> wallet;
|
||||
|
||||
@computed
|
||||
double get price => fiatConvertationStore.prices[appStore.wallet.currency];
|
||||
@@ -77,63 +75,80 @@ abstract class BalanceViewModelBase with Store {
|
||||
: savedDisplayMode;
|
||||
|
||||
@computed
|
||||
String get cryptoBalance {
|
||||
final walletBalance = _walletBalance;
|
||||
var _balance = '---';
|
||||
|
||||
if (displayMode == BalanceDisplayMode.availableBalance) {
|
||||
_balance = walletBalance.unlockedBalance ?? '0.0';
|
||||
String get availableBalanceLabel {
|
||||
if (wallet.type == WalletType.monero) {
|
||||
return S.current.xmr_available_balance;
|
||||
}
|
||||
|
||||
if (displayMode == BalanceDisplayMode.fullBalance) {
|
||||
_balance = walletBalance.totalBalance ?? '0.0';
|
||||
}
|
||||
|
||||
return _balance;
|
||||
return S.current.confirmed;
|
||||
}
|
||||
|
||||
@computed
|
||||
String get fiatBalance {
|
||||
String get additionalBalanceLabel {
|
||||
if (wallet.type == WalletType.monero) {
|
||||
return S.current.xmr_full_balance;
|
||||
}
|
||||
|
||||
return S.current.unconfirmed;
|
||||
}
|
||||
|
||||
@computed
|
||||
String get availableBalance {
|
||||
final walletBalance = _walletBalance;
|
||||
|
||||
if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) {
|
||||
return '---';
|
||||
}
|
||||
|
||||
return walletBalance.formattedAvailableBalance;
|
||||
}
|
||||
|
||||
@computed
|
||||
String get additionalBalance {
|
||||
final walletBalance = _walletBalance;
|
||||
|
||||
if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) {
|
||||
return '---';
|
||||
}
|
||||
|
||||
return walletBalance.formattedAdditionalBalance;
|
||||
}
|
||||
|
||||
@computed
|
||||
String get availableFiatBalance {
|
||||
final walletBalance = _walletBalance;
|
||||
final fiatCurrency = settingsStore.fiatCurrency;
|
||||
var _balance = '---';
|
||||
|
||||
final totalBalance =
|
||||
_getFiatBalance(price: price, cryptoAmount: walletBalance.totalBalance);
|
||||
|
||||
final unlockedBalance = _getFiatBalance(
|
||||
price: price, cryptoAmount: walletBalance.unlockedBalance);
|
||||
|
||||
if (displayMode == BalanceDisplayMode.availableBalance) {
|
||||
_balance = fiatCurrency.toString() + ' ' + unlockedBalance ?? '0.00';
|
||||
if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) {
|
||||
return '---';
|
||||
}
|
||||
|
||||
if (displayMode == BalanceDisplayMode.fullBalance) {
|
||||
_balance = fiatCurrency.toString() + ' ' + totalBalance ?? '0.00';
|
||||
}
|
||||
|
||||
return _balance;
|
||||
return fiatCurrency.toString() +
|
||||
' ' +
|
||||
_getFiatBalance(
|
||||
price: price,
|
||||
cryptoAmount: walletBalance.formattedAvailableBalance);
|
||||
}
|
||||
|
||||
@computed
|
||||
WalletBalance get _walletBalance {
|
||||
final _balance = balance;
|
||||
String get additionalFiatBalance {
|
||||
final walletBalance = _walletBalance;
|
||||
final fiatCurrency = settingsStore.fiatCurrency;
|
||||
|
||||
if (_balance is MoneroBalance) {
|
||||
return WalletBalance(
|
||||
unlockedBalance: _balance.formattedUnlockedBalance,
|
||||
totalBalance: _balance.formattedFullBalance);
|
||||
if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) {
|
||||
return '---';
|
||||
}
|
||||
|
||||
if (_balance is BitcoinBalance) {
|
||||
return WalletBalance(
|
||||
unlockedBalance: _balance.availableBalanceFormatted,
|
||||
totalBalance: _balance.totalFormatted);
|
||||
}
|
||||
|
||||
return null;
|
||||
return fiatCurrency.toString() +
|
||||
' ' +
|
||||
_getFiatBalance(
|
||||
price: price,
|
||||
cryptoAmount: walletBalance.formattedAdditionalBalance);
|
||||
}
|
||||
|
||||
@computed
|
||||
Balance get _walletBalance => wallet.balance;
|
||||
|
||||
@computed
|
||||
CryptoCurrency get currency => appStore.wallet.currency;
|
||||
|
||||
@@ -141,24 +156,14 @@ abstract class BalanceViewModelBase with Store {
|
||||
ReactionDisposer _reaction;
|
||||
|
||||
@action
|
||||
void _onWalletChange(WalletBase wallet) {
|
||||
void _onWalletChange(WalletBase<Balance> wallet) {
|
||||
this.wallet = wallet;
|
||||
|
||||
if (wallet is MoneroWallet) {
|
||||
balance = wallet.balance;
|
||||
}
|
||||
|
||||
if (wallet is BitcoinWallet) {
|
||||
balance = wallet.balance;
|
||||
}
|
||||
balance = wallet.balance;
|
||||
|
||||
_onCurrentWalletChangeReaction?.reaction?.dispose();
|
||||
_onCurrentWalletChangeReaction =
|
||||
reaction<void>((_) => wallet.balance, (dynamic balance) {
|
||||
if (balance is Balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
});
|
||||
_onCurrentWalletChangeReaction = reaction<Balance>(
|
||||
(_) => wallet.balance, (Balance balance) => this.balance = balance);
|
||||
}
|
||||
|
||||
String _getFiatBalance({double price, String cryptoAmount}) {
|
||||
|
||||
@@ -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/entities/balance.dart';
|
||||
import 'package:cake_wallet/entities/transaction_history.dart';
|
||||
import 'package:cake_wallet/monero/account.dart';
|
||||
import 'package:cake_wallet/monero/monero_balance.dart';
|
||||
@@ -184,7 +185,7 @@ abstract class DashboardViewModelBase with Store {
|
||||
}
|
||||
|
||||
@observable
|
||||
WalletBase wallet;
|
||||
WalletBase<Balance> wallet;
|
||||
|
||||
bool get hasRescan => wallet.type == WalletType.monero;
|
||||
|
||||
@@ -212,7 +213,7 @@ abstract class DashboardViewModelBase with Store {
|
||||
}
|
||||
|
||||
@action
|
||||
void _onWalletChange(WalletBase wallet) {
|
||||
void _onWalletChange(WalletBase<Balance> wallet) {
|
||||
this.wallet = wallet;
|
||||
type = wallet.type;
|
||||
name = wallet.name;
|
||||
|
||||
@@ -301,7 +301,7 @@ abstract class ExchangeViewModelBase with Store {
|
||||
@action
|
||||
void calculateDepositAllAmount() {
|
||||
if (wallet is BitcoinWallet) {
|
||||
final availableBalance = wallet.balance.availableBalance as int;
|
||||
final availableBalance = wallet.balance.available;
|
||||
final fee = BitcoinWalletBase.feeAmountForPriority(
|
||||
_settingsStore.transactionPriority);
|
||||
|
||||
|
||||
@@ -134,9 +134,7 @@ abstract class SendViewModelBase with Store {
|
||||
PendingTransaction pendingTransaction;
|
||||
|
||||
@computed
|
||||
String get balance =>
|
||||
_wallet.balance.formattedBalance(BalanceDisplayMode.availableBalance)
|
||||
as String ?? '0.0';
|
||||
String get balance => _wallet.balance.formattedAvailableBalance ?? '0.0';
|
||||
|
||||
@computed
|
||||
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
|
||||
@@ -183,11 +181,12 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
if (pendingTransaction.id?.isNotEmpty ?? false) {
|
||||
_settingsStore.shouldSaveRecipientAddress
|
||||
? await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction.id, recipientAddress: address,
|
||||
transactionNote: note))
|
||||
: await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction.id, transactionNote: note));
|
||||
? await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction.id,
|
||||
recipientAddress: address,
|
||||
transactionNote: note))
|
||||
: await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction.id, transactionNote: note));
|
||||
}
|
||||
|
||||
state = TransactionCommitted();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
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';
|
||||
@@ -28,7 +29,7 @@ part 'settings_view_model.g.dart';
|
||||
class SettingsViewModel = SettingsViewModelBase with _$SettingsViewModel;
|
||||
|
||||
abstract class SettingsViewModelBase with Store {
|
||||
SettingsViewModelBase(this._settingsStore, WalletBase wallet)
|
||||
SettingsViewModelBase(this._settingsStore, WalletBase<Balance> wallet)
|
||||
: itemHeaders = {},
|
||||
_walletType = wallet.type,
|
||||
_biometricAuth = BiometricAuth() {
|
||||
@@ -45,13 +46,12 @@ abstract class SettingsViewModelBase with Store {
|
||||
|
||||
sections = [
|
||||
[
|
||||
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_display_balance_as,
|
||||
items: BalanceDisplayMode.all,
|
||||
selectedItem: () => balanceDisplayMode,
|
||||
onItemSelected: (BalanceDisplayMode mode) =>
|
||||
_settingsStore.balanceDisplayMode = mode),
|
||||
PickerListItem(
|
||||
title: S.current.settings_currency,
|
||||
items: FiatCurrency.all,
|
||||
@@ -120,7 +120,7 @@ abstract class SettingsViewModelBase with Store {
|
||||
items: ThemeList.all,
|
||||
selectedItem: () => theme,
|
||||
onItemSelected: (ThemeBase theme) =>
|
||||
_settingsStore.currentTheme = theme)
|
||||
_settingsStore.currentTheme = theme)
|
||||
],
|
||||
[
|
||||
LinkListItem(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
@@ -60,7 +61,7 @@ abstract class WalletAddressListViewModelBase with Store {
|
||||
_appStore = appStore;
|
||||
_wallet = _appStore.wallet;
|
||||
hasAccounts = _wallet?.type == WalletType.monero;
|
||||
_onWalletChangeReaction = reaction((_) => _appStore.wallet, (WalletBase wallet) {
|
||||
_onWalletChangeReaction = reaction((_) => _appStore.wallet, (WalletBase<Balance> wallet) {
|
||||
_wallet = wallet;
|
||||
hasAccounts = _wallet.type == WalletType.monero;
|
||||
});
|
||||
@@ -145,7 +146,7 @@ abstract class WalletAddressListViewModelBase with Store {
|
||||
bool get hasAddressList => _wallet.type == WalletType.monero;
|
||||
|
||||
@observable
|
||||
WalletBase _wallet;
|
||||
WalletBase<Balance> _wallet;
|
||||
|
||||
List<ListItem> _baseItems;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user