mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-20 22:28:46 +00:00
CAKE-208 | added current balance display mode saving to shared preferences (settings_store.dart); added moneroBalance property, reactions and _onWalletChange() method to balance_view_model.dart
This commit is contained in:
parent
c20d57e9a9
commit
d370c912bb
2 changed files with 50 additions and 4 deletions
|
@ -87,6 +87,11 @@ abstract class SettingsStoreBase with Store {
|
||||||
(_) => languageCode,
|
(_) => languageCode,
|
||||||
(String languageCode) => sharedPreferences.setString(
|
(String languageCode) => sharedPreferences.setString(
|
||||||
PreferencesKey.currentLanguageCode, languageCode));
|
PreferencesKey.currentLanguageCode, languageCode));
|
||||||
|
|
||||||
|
reaction((_) => balanceDisplayMode,
|
||||||
|
(BalanceDisplayMode mode) => sharedPreferences.setInt(
|
||||||
|
PreferencesKey.currentBalanceDisplayModeKey,
|
||||||
|
mode.serialize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const defaultPinLength = 4;
|
static const defaultPinLength = 4;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||||
|
import 'package:cake_wallet/core/wallet_base.dart';
|
||||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||||
|
import 'package:cake_wallet/monero/monero_balance.dart';
|
||||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||||
|
@ -19,7 +21,22 @@ abstract class BalanceViewModelBase with Store {
|
||||||
@required this.appStore,
|
@required this.appStore,
|
||||||
@required this.settingsStore,
|
@required this.settingsStore,
|
||||||
@required this.fiatConvertationStore
|
@required this.fiatConvertationStore
|
||||||
}) : isReversing = false;
|
}) {
|
||||||
|
isReversing = false;
|
||||||
|
|
||||||
|
wallet ??= appStore.wallet;
|
||||||
|
|
||||||
|
_reaction = reaction((_) => appStore.wallet, _onWalletChange);
|
||||||
|
|
||||||
|
final _wallet = wallet;
|
||||||
|
|
||||||
|
if (_wallet is MoneroWallet) {
|
||||||
|
moneroBalance = _wallet.balance;
|
||||||
|
|
||||||
|
_onMoneroBalanceChangeReaction = reaction((_) => _wallet.balance,
|
||||||
|
(MoneroBalance balance) => moneroBalance = balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final AppStore appStore;
|
final AppStore appStore;
|
||||||
final SettingsStore settingsStore;
|
final SettingsStore settingsStore;
|
||||||
|
@ -28,6 +45,12 @@ abstract class BalanceViewModelBase with Store {
|
||||||
@observable
|
@observable
|
||||||
bool isReversing;
|
bool isReversing;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
MoneroBalance moneroBalance;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
WalletBase wallet;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
|
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
|
||||||
|
|
||||||
|
@ -86,12 +109,12 @@ abstract class BalanceViewModelBase with Store {
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
WalletBalance get _walletBalance {
|
WalletBalance get _walletBalance {
|
||||||
final _wallet = appStore.wallet;
|
final _wallet = wallet;
|
||||||
|
|
||||||
if (_wallet is MoneroWallet) {
|
if (_wallet is MoneroWallet) {
|
||||||
return WalletBalance(
|
return WalletBalance(
|
||||||
unlockedBalance: _wallet.balance.formattedUnlockedBalance,
|
unlockedBalance: moneroBalance.formattedUnlockedBalance,
|
||||||
totalBalance: _wallet.balance.formattedFullBalance);
|
totalBalance: moneroBalance.formattedFullBalance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_wallet is BitcoinWallet) {
|
if (_wallet is BitcoinWallet) {
|
||||||
|
@ -106,6 +129,24 @@ abstract class BalanceViewModelBase with Store {
|
||||||
@computed
|
@computed
|
||||||
CryptoCurrency get currency => appStore.wallet.currency;
|
CryptoCurrency get currency => appStore.wallet.currency;
|
||||||
|
|
||||||
|
@action
|
||||||
|
void _onWalletChange(WalletBase wallet) {
|
||||||
|
this.wallet = wallet;
|
||||||
|
|
||||||
|
if (wallet is MoneroWallet) {
|
||||||
|
moneroBalance = wallet.balance;
|
||||||
|
|
||||||
|
_onMoneroBalanceChangeReaction?.reaction?.dispose();
|
||||||
|
|
||||||
|
_onMoneroBalanceChangeReaction = reaction((_) => wallet.balance,
|
||||||
|
(MoneroBalance balance) => moneroBalance = balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReactionDisposer _onMoneroBalanceChangeReaction;
|
||||||
|
|
||||||
|
ReactionDisposer _reaction;
|
||||||
|
|
||||||
String _getFiatBalance({double price, String cryptoAmount}) {
|
String _getFiatBalance({double price, String cryptoAmount}) {
|
||||||
if (cryptoAmount == null) {
|
if (cryptoAmount == null) {
|
||||||
return '0.00';
|
return '0.00';
|
||||||
|
|
Loading…
Reference in a new issue