Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open wallet even when cache file backup is corrupted #1720

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions cw_monero/lib/monero_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials {
final String spendKey;
}

enum OpenWalletTry {
initial,
cacheRestored,
cacheRemoved,
}

class MoneroWalletService extends WalletService<
MoneroNewWalletCredentials,
MoneroRestoreWalletFromSeedCredentials,
Expand Down Expand Up @@ -128,7 +134,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());

Expand Down Expand Up @@ -163,12 +169,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);
}
}

Expand Down
Loading