Skip to content

Commit

Permalink
WalletApplication: Fix RuntimeException if wallet was auto-restored.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schildbach committed Apr 13, 2018
1 parent 6f9676c commit e3f9c9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 5 additions & 0 deletions wallet/src/de/schildbach/wallet/WalletApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import de.schildbach.wallet.service.BlockchainService;
import de.schildbach.wallet.util.Bluetooth;
import de.schildbach.wallet.util.CrashReporter;
import de.schildbach.wallet.util.Toast;
import de.schildbach.wallet.util.WalletUtils;

import android.app.ActivityManager;
Expand Down Expand Up @@ -192,10 +193,14 @@ private void loadWalletFromProtobuf() {
} catch (final IOException | UnreadableWalletException x) {
log.warn("problem loading wallet, auto-restoring: " + walletFile, x);
wallet = WalletUtils.restoreWalletFromAutoBackup(WalletApplication.this);
if (wallet != null)
new Toast(WalletApplication.this).postLongToast(R.string.toast_wallet_reset);
}
if (!wallet.isConsistent()) {
log.warn("inconsistent wallet, auto-restoring: " + walletFile);
wallet = WalletUtils.restoreWalletFromAutoBackup(WalletApplication.this);
if (wallet != null)
new Toast(WalletApplication.this).postLongToast(R.string.toast_wallet_reset);
}

if (!wallet.getParams().equals(Constants.NETWORK_PARAMETERS))
Expand Down
3 changes: 0 additions & 3 deletions wallet/src/de/schildbach/wallet/util/WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.google.common.base.Stopwatch;

import de.schildbach.wallet.Constants;
import de.schildbach.wallet.R;
import de.schildbach.wallet.service.BlockchainService;

import android.content.Context;
Expand All @@ -69,7 +68,6 @@
import android.text.SpannedString;
import android.text.format.DateUtils;
import android.text.style.TypefaceSpan;
import android.widget.Toast;

/**
* @author Andreas Schildbach
Expand Down Expand Up @@ -216,7 +214,6 @@ public static Wallet restoreWalletFromAutoBackup(final Context context) {
throw new Error("inconsistent backup");

BlockchainService.resetBlockchain(context);
Toast.makeText(context, R.string.toast_wallet_reset, Toast.LENGTH_LONG).show();
log.info("wallet restored from backup: '" + Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + "'");
return wallet;
} catch (final IOException | UnreadableWalletException x) {
Expand Down

0 comments on commit e3f9c9c

Please sign in to comment.