diff --git a/cw_monero/lib/monero_wallet_service.dart b/cw_monero/lib/monero_wallet_service.dart index 7f4672d43..bc5f0de89 100644 --- a/cw_monero/lib/monero_wallet_service.dart +++ b/cw_monero/lib/monero_wallet_service.dart @@ -55,6 +55,12 @@ class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials { final String spendKey; } +enum OpenWalletTry { + initial, + cacheRestored, + cacheRemoved, +} + class MoneroWalletService extends WalletService< MoneroNewWalletCredentials, MoneroRestoreWalletFromSeedCredentials, @@ -117,7 +123,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()); @@ -147,12 +153,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 openWallet(name, password, openWalletTry: OpenWalletTry.cacheRestored); + case OpenWalletTry.cacheRestored: + await removeCache(name); + return openWallet(name, password, openWalletTry: OpenWalletTry.cacheRemoved); + case OpenWalletTry.cacheRemoved: + rethrow; } - - await restoreOrResetWalletFiles(name); - return openWallet(name, password, retryOnFailure: false); } }