Fixes

M committed Jan 5, 2021 at 21:49 UTC 83dd4d9264198bd83adbb69ad4261341c722bcef
1 file changed +21 -24
lib/view_model/dashboard/balance_view_model.dart
+21 -24
@@ -22,8 +22,7 @@ abstract class BalanceViewModelBase with Store {
22 BalanceViewModelBase(
23 {@required this.appStore,
24 @required this.settingsStore,
25 - @required this.fiatConvertationStore
26 - }){
25 + @required this.fiatConvertationStore}) {
26 isReversing = false;
27
28 wallet ??= appStore.wallet;
@@ -34,17 +33,18 @@ abstract class BalanceViewModelBase with Store {
33
34 if (_wallet is MoneroWallet) {
35 balance = _wallet.balance;
37 -
38 - _onMoneroBalanceChangeReaction = reaction((_) => _wallet.balance,
39 - (MoneroBalance moneroBalance) => balance = moneroBalance);
36 }
37
38 if (_wallet is BitcoinWallet) {
39 balance = _wallet.balance;
44 -
45 - _onBitcoinBalanceChangeReaction = reaction((_) => _wallet.balance,
46 - (BitcoinBalance bitcoinBalance) => balance = bitcoinBalance);
40 }
41 +
42 + _onCurrentWalletChangeReaction =
43 + reaction<void>((_) => wallet.balance, (dynamic balance) {
44 + if (balance is Balance) {
45 + this.balance = balance;
46 + }
47 + });
48 }
49
50 final AppStore appStore;
@@ -120,7 +120,7 @@ abstract class BalanceViewModelBase with Store {
120 final _balance = balance;
121
122 if (_balance is MoneroBalance) {
123 - return WalletBalance(
123 + return WalletBalance(
124 unlockedBalance: _balance.formattedUnlockedBalance,
125 totalBalance: _balance.formattedFullBalance);
126 }
@@ -137,32 +137,29 @@ abstract class BalanceViewModelBase with Store {
137 @computed
138 CryptoCurrency get currency => appStore.wallet.currency;
139
140 + ReactionDisposer _onCurrentWalletChangeReaction;
141 + ReactionDisposer _reaction;
142 +
143 @action
144 void _onWalletChange(WalletBase wallet) {
145 this.wallet = wallet;
146
147 if (wallet is MoneroWallet) {
148 balance = wallet.balance;
146 -
147 - _onMoneroBalanceChangeReaction?.reaction?.dispose();
148 -
149 - _onMoneroBalanceChangeReaction = reaction((_) => wallet.balance,
150 - (MoneroBalance moneroBalance) => balance = moneroBalance);
149 }
150
151 if (wallet is BitcoinWallet) {
152 balance = wallet.balance;
155 -
156 - _onBitcoinBalanceChangeReaction?.reaction?.dispose();
157 -
158 - _onBitcoinBalanceChangeReaction = reaction((_) => wallet.balance,
159 - (BitcoinBalance bitcoinBalance) => balance = bitcoinBalance);
153 }
161 - }
154
163 - ReactionDisposer _onMoneroBalanceChangeReaction;
164 - ReactionDisposer _onBitcoinBalanceChangeReaction;
165 - ReactionDisposer _reaction;
155 + _onCurrentWalletChangeReaction?.reaction?.dispose();
156 + _onCurrentWalletChangeReaction =
157 + reaction<void>((_) => wallet.balance, (dynamic balance) {
158 + if (balance is Balance) {
159 + this.balance = balance;
160 + }
161 + });
162 + }
163
164 String _getFiatBalance({double price, String cryptoAmount}) {
165 if (cryptoAmount == null) {
@@ -171,4 +168,4 @@ abstract class BalanceViewModelBase with Store {
168
169 return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
170 }
174 -}
\ No newline at end of file
171 +}