open wallet even when cache file backup is corrupted

This commit is contained in:
Czarek Nakamoto 2024-10-03 08:18:30 +02:00
parent f8b0c0ad2a
commit b169422a3c

View file

@ -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<MoneroWallet> openWallet(String name, String password, {bool? retryOnFailure}) async {
Future<MoneroWallet> 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);
}
}