Fixes for load wallet from wallet list. Fixed updating of balance after current wallet change
M committed
Sep 24, 2020 at 12:16 UTC
73991e1c9c62604a200804dac84d679c9f0e1a7c
4 files changed
+38
-42
lib/di.dart
+1
-1
@@ -164,7 +164,7 @@ Future setup(
164
() => WalletAddressListViewModel(wallet: getIt.get<AppStore>().wallet));
165
166
getIt.registerFactory(() => BalanceViewModel(
167
- wallet: getIt.get<AppStore>().wallet,
167
+ appStore: getIt.get<AppStore>(),
168
settingsStore: getIt.get<SettingsStore>(),
169
fiatConvertationStore: getIt.get<FiatConversionStore>()));
170
lib/main.dart
+6
-9
@@ -126,8 +126,8 @@ void main() async {
126
// final exchangeTemplateStore =
127
// ExchangeTemplateStore(templateSource: exchangeTemplates);
128
129
- final walletCreationService = WalletCreationService();
130
- final authService = AuthService();
129
+ // final walletCreationService = WalletCreationService();
130
+ // final authService = AuthService();
131
132
await initialSetup(
133
sharedPreferences: await SharedPreferences.getInstance(),
@@ -147,8 +147,7 @@ void main() async {
147
// walletService: walletService,
148
// // authenticationStore: authenticationStore,
149
// loginStore: loginStore);
150
- final initialLanguage = await Language.localeDetection();
151
- runApp(CakeWalletApp(initialLanguage));
150
+ runApp(CakeWalletApp());
151
}
152
153
Future<void> initialSetup(
@@ -180,12 +179,11 @@ Future<void> initialSetup(
179
}
180
181
class CakeWalletApp extends StatelessWidget {
183
- CakeWalletApp(this.initialLanguage) {
182
+ CakeWalletApp() {
183
SystemChrome.setPreferredOrientations(
184
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
185
}
186
188
- final String initialLanguage;
187
188
@override
189
Widget build(BuildContext context) {
@@ -197,13 +195,12 @@ class CakeWalletApp extends StatelessWidget {
195
settingsStore.isDarkTheme ? Themes.darkTheme : Themes.lightTheme),
196
child: ChangeNotifierProvider<Language>(
197
create: (_) => Language(settingsStore.languageCode),
200
- child: MaterialAppWithTheme(initialLanguage)));
198
+ child: MaterialAppWithTheme()));
199
}
200
}
201
202
class MaterialAppWithTheme extends StatelessWidget {
205
- MaterialAppWithTheme(this.initialLanguage);
206
- final String initialLanguage;
203
+ MaterialAppWithTheme();
204
205
@override
206
Widget build(BuildContext context) {
lib/monero/monero_wallet_service.dart
-2
@@ -88,8 +88,6 @@ class MoneroWalletService extends WalletService<
88
Future<MoneroWallet> openWallet(String name, String password) async {
89
try {
90
final path = await pathForWallet(name: name, type: WalletType.monero);
91
- final file = File(path);
92
- final stat = await file.stat();
91
monero_wallet_manager.openWallet(path: path, password: password);
92
final walletInfo = walletInfoSource.values.firstWhere(
93
(info) => info.id == WalletBase.idFor(name, WalletType.monero), orElse: () => null);
lib/view_model/dashboard/balance_view_model.dart
+31
-30
@@ -3,6 +3,7 @@ import 'package:cake_wallet/core/wallet_base.dart';
3
import 'package:cake_wallet/monero/monero_wallet.dart';
4
import 'package:cake_wallet/entities/balance_display_mode.dart';
5
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
6
+import 'package:cake_wallet/store/app_store.dart';
7
import 'package:cake_wallet/view_model/dashboard/wallet_balance.dart';
8
import 'package:cake_wallet/store/settings_store.dart';
9
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
@@ -15,47 +16,21 @@ class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel;
16
17
abstract class BalanceViewModelBase with Store {
18
BalanceViewModelBase({
18
- @required this.wallet,
19
+ @required this.appStore,
20
@required this.settingsStore,
21
@required this.fiatConvertationStore
22
});
23
23
- final WalletBase wallet;
24
+ final AppStore appStore;
25
final SettingsStore settingsStore;
26
final FiatConversionStore fiatConvertationStore;
27
27
- WalletBalance _getWalletBalance() {
28
- final _wallet = wallet;
29
-
30
- if (_wallet is MoneroWallet) {
31
- return WalletBalance(
32
- unlockedBalance: _wallet.balance.formattedUnlockedBalance,
33
- totalBalance: _wallet.balance.formattedFullBalance);
34
- }
35
-
36
- if (_wallet is BitcoinWallet) {
37
- return WalletBalance(
38
- unlockedBalance: _wallet.balance.totalFormatted,
39
- totalBalance: _wallet.balance.totalFormatted);
40
- }
41
-
42
- return null;
43
- }
44
-
45
- String _getFiatBalance({double price, String cryptoAmount}) {
46
- if (cryptoAmount == null) {
47
- return '0.00';
48
- }
49
-
50
- return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
51
- }
52
-
28
@computed
29
double get price => fiatConvertationStore.price;
30
31
@computed
32
String get cryptoBalance {
58
- final walletBalance = _getWalletBalance();
33
+ final walletBalance = _walletBalance;
34
final displayMode = settingsStore.balanceDisplayMode;
35
var balance = '---';
36
@@ -72,7 +47,7 @@ abstract class BalanceViewModelBase with Store {
47
48
@computed
49
String get fiatBalance {
75
- final walletBalance = _getWalletBalance();
50
+ final walletBalance = _walletBalance;
51
final displayMode = settingsStore.balanceDisplayMode;
52
final fiatCurrency = settingsStore.fiatCurrency;
53
var balance = '---';
@@ -98,4 +73,30 @@ abstract class BalanceViewModelBase with Store {
73
return balance;
74
}
75
76
+ @computed
77
+ WalletBalance get _walletBalance {
78
+ final _wallet = appStore.wallet;
79
+
80
+ if (_wallet is MoneroWallet) {
81
+ return WalletBalance(
82
+ unlockedBalance: _wallet.balance.formattedUnlockedBalance,
83
+ totalBalance: _wallet.balance.formattedFullBalance);
84
+ }
85
+
86
+ if (_wallet is BitcoinWallet) {
87
+ return WalletBalance(
88
+ unlockedBalance: _wallet.balance.totalFormatted,
89
+ totalBalance: _wallet.balance.totalFormatted);
90
+ }
91
+
92
+ return null;
93
+ }
94
+
95
+ String _getFiatBalance({double price, String cryptoAmount}) {
96
+ if (cryptoAmount == null) {
97
+ return '0.00';
98
+ }
99
+
100
+ return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
101
+ }
102
}
\ No newline at end of file