diff --git a/lib/di.dart b/lib/di.dart index 4b5f5f077..697e40e22 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -164,7 +164,7 @@ Future setup( () => WalletAddressListViewModel(wallet: getIt.get().wallet)); getIt.registerFactory(() => BalanceViewModel( - wallet: getIt.get().wallet, + appStore: getIt.get(), settingsStore: getIt.get(), fiatConvertationStore: getIt.get())); diff --git a/lib/main.dart b/lib/main.dart index 267afe256..66cca43a5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 initialSetup( @@ -180,12 +179,11 @@ Future 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( 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) { diff --git a/lib/monero/monero_wallet_service.dart b/lib/monero/monero_wallet_service.dart index 9b310f3bb..cb968e08a 100644 --- a/lib/monero/monero_wallet_service.dart +++ b/lib/monero/monero_wallet_service.dart @@ -88,8 +88,6 @@ class MoneroWalletService extends WalletService< Future 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); diff --git a/lib/view_model/dashboard/balance_view_model.dart b/lib/view_model/dashboard/balance_view_model.dart index 8d1e70991..23fd578f1 100644 --- a/lib/view_model/dashboard/balance_view_model.dart +++ b/lib/view_model/dashboard/balance_view_model.dart @@ -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); + } } \ No newline at end of file