diff --git a/cw_core/lib/wallet_base.dart b/cw_core/lib/wallet_base.dart index 85f180a09..a895b3537 100644 --- a/cw_core/lib/wallet_base.dart +++ b/cw_core/lib/wallet_base.dart @@ -103,5 +103,6 @@ abstract class WalletBase closeWallet() async {} + // TODO: use proxy layer + Future reopenWallet() async {} } diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index b01d76565..9eedcb134 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -233,6 +233,10 @@ void closeCurrentWallet() { monero.Wallet_stop(wptr!); } +void stopWallet() { + monero.Wallet_stop(wptr!); +} + String getSecretViewKey() => monero.Wallet_secretViewKey(wptr!); String getPublicViewKey() => monero.Wallet_publicViewKey(wptr!); diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 629778c8f..99c821fa7 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -39,6 +39,7 @@ import 'package:hive/hive.dart'; import 'package:ledger_flutter_plus/ledger_flutter_plus.dart'; import 'package:mobx/mobx.dart'; import 'package:monero/monero.dart' as monero; +import 'package:cw_monero/api/transaction_history.dart' as transaction_history; part 'monero_wallet.g.dart'; @@ -175,6 +176,7 @@ abstract class MoneroWalletBase _onAccountChangeReaction?.reaction.dispose(); _onTxHistoryChangeReaction?.reaction.dispose(); _autoSaveTimer?.cancel(); + monero_wallet.stopWallet(); } @override @@ -268,6 +270,7 @@ abstract class MoneroWalletBase _listener?.stop(); if (isBackgroundSync) { isBackgroundSyncing = false; + monero_wallet.stopWallet(); monero_wallet.stopBackgroundSync(password); return; } @@ -277,7 +280,7 @@ abstract class MoneroWalletBase } @override - Future closeWallet() async { + Future reopenWallet() async { printV("closing wallet"); final currentWalletDirPath = await pathForWalletDir(name: name, type: type); final wmaddr = wmPtr.address; @@ -286,7 +289,10 @@ abstract class MoneroWalletBase monero.WalletManager_closeWallet( Pointer.fromAddress(wmaddr), Pointer.fromAddress(waddr), true); }); - await init(); + wptr = monero.WalletManager_openWallet(wmPtr, path: currentWalletDirPath, password: password); + openedWalletsByPath["$currentWalletDirPath/$name"] = wptr!; + transaction_history.txhistory = null; + } @override diff --git a/lib/entities/background_tasks.dart b/lib/entities/background_tasks.dart index ac3f696c9..f3d9e486d 100644 --- a/lib/entities/background_tasks.dart +++ b/lib/entities/background_tasks.dart @@ -164,17 +164,16 @@ Future onStart(ServiceInstance service) async { for (int i = 0; i < syncingWallets.length; i++) { final wallet = syncingWallets[i]; await wallet.stopSync(isBackgroundSync: true); - await wallet.close(); } // stop all standby wallets (just in case): for (int i = 0; i < standbyWallets.length; i++) { final wallet = standbyWallets[i]; await wallet.stopSync(isBackgroundSync: true); - await wallet.close(); } } catch (e) { printV("error stopping sync: $e"); } + printV("done stopping sync"); } service.on("stopService").listen((event) async { diff --git a/lib/src/screens/root/root.dart b/lib/src/screens/root/root.dart index 9de133543..ae7a4b9ea 100644 --- a/lib/src/screens/root/root.dart +++ b/lib/src/screens/root/root.dart @@ -180,10 +180,18 @@ class RootState extends State with WidgetsBindingObserver { return; } - await wallet?.stopSync(isBackgroundSync: true); // await wallet?.closeWallet(); // restart the background service if it was running before: await getIt.get().serviceForeground(); + + await Future.delayed(const Duration(seconds: 10)); + + await wallet?.stopSync(isBackgroundSync: true); + + await Future.delayed(const Duration(seconds: 10)); + + await wallet?.reopenWallet(); + break; case AppLifecycleState.hidden: case AppLifecycleState.inactive: