diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp index b4fa5cc0a..68cf99ee9 100644 --- a/cw_monero/ios/Classes/monero_api.cpp +++ b/cw_monero/ios/Classes/monero_api.cpp @@ -175,6 +175,7 @@ extern "C" Monero::SubaddressAccount *m_account; uint64_t m_last_known_wallet_height; uint64_t m_cached_syncing_blockchain_height = 0; + std::mutex store_mutex; void change_current_wallet(Monero::Wallet *wallet) @@ -293,6 +294,7 @@ extern "C" void load_wallet(char *path, char *password, int32_t nettype) { + nice(19); Monero::NetworkType networkType = static_cast(nettype); Monero::Wallet *wallet = Monero::WalletManagerFactory::getWalletManager()->openWallet(std::string(path), std::string(password), networkType); change_current_wallet(wallet); @@ -429,7 +431,9 @@ extern "C" void store(char *path) { + store_mutex.lock(); get_current_wallet()->store(std::string(path)); + store_mutex.unlock(); } bool transaction_create(char *address, char *payment_id, char *amount, diff --git a/ios/Flutter/.last_build_id b/ios/Flutter/.last_build_id deleted file mode 100644 index 0c913ed64..000000000 --- a/ios/Flutter/.last_build_id +++ /dev/null @@ -1 +0,0 @@ -4dc2ef1ba73deeed13cd85894dacb10b \ No newline at end of file diff --git a/lib/di.dart b/lib/di.dart index d133b6ed0..aac1bfa24 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -61,6 +61,7 @@ import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart'; import 'package:flutter/widgets.dart'; import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; +import 'package:mobx/mobx.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart'; @@ -177,11 +178,25 @@ Future setup( BiometricAuth())); getIt.registerFactory( - () => AuthPage(getIt.get(), - onAuthenticationFinished: (isAuthenticated, __) { - if (isAuthenticated) { - getIt.get().allowed(); + () => AuthPage(getIt.get(), onAuthenticationFinished: + (isAuthenticated, AuthPageState authPageState) { + if (!isAuthenticated) { + return; } + final authStore = getIt.get(); + final appStore = getIt.get(); + + if (appStore.wallet != null) { + authStore.allowed(); + return; + } + + authPageState.changeProcessText('Loading the wallet'); + ReactionDisposer _reaction; + _reaction = reaction((_) => appStore.wallet, (Object _) { + _reaction?.reaction?.dispose(); + authStore.allowed(); + }); }, closable: false), instanceName: 'login'); diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index b1133dd5b..9e59a1264 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -19,6 +19,7 @@ import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/entities/transaction_priority.dart'; + part 'monero_wallet.g.dart'; const moneroBlockSize = 1000; @@ -40,6 +41,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { subaddress = subaddressList.subaddresses.first; address = subaddress.address; }); + _cachedRefreshHeight = 0; } @override @@ -80,6 +82,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { String _filename; SyncListner _listener; ReactionDisposer _onAccountChangeReaction; + int _cachedRefreshHeight; Future init() async { await accountList.update(); @@ -177,7 +180,9 @@ abstract class MoneroWalletBase extends WalletBase with Store { @override Future save() async { + print('SAVE CALLED'); await monero_wallet.store(); + print('SAVE FINISHED'); } Future getNodeHeight() async => monero_wallet.getNodeHeight(); @@ -191,12 +196,15 @@ abstract class MoneroWalletBase extends WalletBase with Store { @override Future rescan({int height}) async { + walletInfo.restoreHeight = height; + walletInfo.isRecovery = true; monero_wallet.setRefreshFromBlockHeight(height: height); monero_wallet.rescanBlockchainAsync(); await startSync(); _askForUpdateBalance(); await _askForUpdateTransactionHistory(); await save(); + await walletInfo.save(); } void _setListeners() { @@ -284,7 +292,10 @@ abstract class MoneroWalletBase extends WalletBase with Store { await setAsRecovered(); } - await save(); + if (currentHeight - _cachedRefreshHeight > moneroBlockSize) { + _cachedRefreshHeight = currentHeight; + await save(); + } } void _onNewTransaction() { diff --git a/lib/src/screens/dashboard/wallet_menu.dart b/lib/src/screens/dashboard/wallet_menu.dart index 3d1d80026..b8639e040 100644 --- a/lib/src/screens/dashboard/wallet_menu.dart +++ b/lib/src/screens/dashboard/wallet_menu.dart @@ -87,8 +87,8 @@ class WalletMenu { rightButtonText: S.of(context).ok, leftButtonText: S.of(context).cancel, actionRightButton: () async { - await reconnect?.call(); Navigator.of(context).pop(); + await reconnect?.call(); }, actionLeftButton: () => Navigator.of(context).pop()); });