Fixes for load wallet from wallet list. Fixed updating of balance after current wallet change

This commit is contained in:
M 2020-09-24 12:16:13 +03:00
parent 87ef10e807
commit 73991e1c9c
4 changed files with 38 additions and 42 deletions

View file

@ -164,7 +164,7 @@ Future setup(
() => WalletAddressListViewModel(wallet: getIt.get<AppStore>().wallet));
getIt.registerFactory(() => BalanceViewModel(
wallet: getIt.get<AppStore>().wallet,
appStore: getIt.get<AppStore>(),
settingsStore: getIt.get<SettingsStore>(),
fiatConvertationStore: getIt.get<FiatConversionStore>()));

View file

@ -126,8 +126,8 @@ void main() async {
// final exchangeTemplateStore =
// ExchangeTemplateStore(templateSource: exchangeTemplates);
final walletCreationService = WalletCreationService();
final authService = AuthService();
// final walletCreationService = WalletCreationService();
// final authService = AuthService();
await initialSetup(
sharedPreferences: await SharedPreferences.getInstance(),
@ -147,8 +147,7 @@ void main() async {
// walletService: walletService,
// // authenticationStore: authenticationStore,
// loginStore: loginStore);
final initialLanguage = await Language.localeDetection();
runApp(CakeWalletApp(initialLanguage));
runApp(CakeWalletApp());
}
Future<void> initialSetup(
@ -180,12 +179,11 @@ Future<void> initialSetup(
}
class CakeWalletApp extends StatelessWidget {
CakeWalletApp(this.initialLanguage) {
CakeWalletApp() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
}
final String initialLanguage;
@override
Widget build(BuildContext context) {
@ -197,13 +195,12 @@ class CakeWalletApp extends StatelessWidget {
settingsStore.isDarkTheme ? Themes.darkTheme : Themes.lightTheme),
child: ChangeNotifierProvider<Language>(
create: (_) => Language(settingsStore.languageCode),
child: MaterialAppWithTheme(initialLanguage)));
child: MaterialAppWithTheme()));
}
}
class MaterialAppWithTheme extends StatelessWidget {
MaterialAppWithTheme(this.initialLanguage);
final String initialLanguage;
MaterialAppWithTheme();
@override
Widget build(BuildContext context) {

View file

@ -88,8 +88,6 @@ class MoneroWalletService extends WalletService<
Future<MoneroWallet> openWallet(String name, String password) async {
try {
final path = await pathForWallet(name: name, type: WalletType.monero);
final file = File(path);
final stat = await file.stat();
monero_wallet_manager.openWallet(path: path, password: password);
final walletInfo = walletInfoSource.values.firstWhere(
(info) => info.id == WalletBase.idFor(name, WalletType.monero), orElse: () => null);

View file

@ -3,6 +3,7 @@ import 'package:cake_wallet/core/wallet_base.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';
@ -15,47 +16,21 @@ class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel;
abstract class BalanceViewModelBase with Store {
BalanceViewModelBase({
@required this.wallet,
@required this.appStore,
@required this.settingsStore,
@required this.fiatConvertationStore
});
final WalletBase wallet;
final AppStore appStore;
final SettingsStore settingsStore;
final FiatConversionStore fiatConvertationStore;
WalletBalance _getWalletBalance() {
final _wallet = wallet;
if (_wallet is MoneroWallet) {
return WalletBalance(
unlockedBalance: _wallet.balance.formattedUnlockedBalance,
totalBalance: _wallet.balance.formattedFullBalance);
}
if (_wallet is BitcoinWallet) {
return WalletBalance(
unlockedBalance: _wallet.balance.totalFormatted,
totalBalance: _wallet.balance.totalFormatted);
}
return null;
}
String _getFiatBalance({double price, String cryptoAmount}) {
if (cryptoAmount == null) {
return '0.00';
}
return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
}
@computed
double get price => fiatConvertationStore.price;
@computed
String get cryptoBalance {
final walletBalance = _getWalletBalance();
final walletBalance = _walletBalance;
final displayMode = settingsStore.balanceDisplayMode;
var balance = '---';
@ -72,7 +47,7 @@ abstract class BalanceViewModelBase with Store {
@computed
String get fiatBalance {
final walletBalance = _getWalletBalance();
final walletBalance = _walletBalance;
final displayMode = settingsStore.balanceDisplayMode;
final fiatCurrency = settingsStore.fiatCurrency;
var balance = '---';
@ -98,4 +73,30 @@ abstract class BalanceViewModelBase with Store {
return balance;
}
@computed
WalletBalance get _walletBalance {
final _wallet = appStore.wallet;
if (_wallet is MoneroWallet) {
return WalletBalance(
unlockedBalance: _wallet.balance.formattedUnlockedBalance,
totalBalance: _wallet.balance.formattedFullBalance);
}
if (_wallet is BitcoinWallet) {
return WalletBalance(
unlockedBalance: _wallet.balance.totalFormatted,
totalBalance: _wallet.balance.totalFormatted);
}
return null;
}
String _getFiatBalance({double price, String cryptoAmount}) {
if (cryptoAmount == null) {
return '0.00';
}
return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
}
}