From 72184f5837a8af2b76aa2e7f06e0d9431fb15939 Mon Sep 17 00:00:00 2001 From: cyan Date: Thu, 27 Mar 2025 03:47:45 +0100 Subject: [PATCH] open wallet even when cache file backup is corrupted (#1720) Co-authored-by: Omar Hatem --- cw_monero/lib/monero_wallet_service.dart | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cw_monero/lib/monero_wallet_service.dart b/cw_monero/lib/monero_wallet_service.dart index 598d400e5..d1bfcd936 100644 --- a/cw_monero/lib/monero_wallet_service.dart +++ b/cw_monero/lib/monero_wallet_service.dart @@ -75,6 +75,12 @@ class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials { final String spendKey; } +enum OpenWalletTry { + initial, + cacheRestored, + cacheRemoved, +} + class MoneroWalletService extends WalletService< MoneroNewWalletCredentials, MoneroRestoreWalletFromSeedCredentials, @@ -139,7 +145,7 @@ class MoneroWalletService extends WalletService< } @override - Future openWallet(String name, String password, {bool? retryOnFailure}) async { + Future openWallet(String name, String password, {OpenWalletTry openWalletTry = OpenWalletTry.initial}) async { try { final path = await pathForWallet(name: name, type: getType()); @@ -172,12 +178,16 @@ class MoneroWalletService extends WalletService< } catch (e) { // TODO: Implement Exception for wallet list service. - if (retryOnFailure == false) { - rethrow; + switch (openWalletTry) { + case OpenWalletTry.initial: + await restoreOrResetWalletFiles(name); + return await openWallet(name, password, openWalletTry: OpenWalletTry.cacheRestored); + case OpenWalletTry.cacheRestored: + await removeCache(name); + return await openWallet(name, password, openWalletTry: OpenWalletTry.cacheRemoved); + case OpenWalletTry.cacheRemoved: + rethrow; } - - await restoreOrResetWalletFiles(name); - return await openWallet(name, password, retryOnFailure: false); } }