Add check for open offers and remove them if present at restore from seed

This commit is contained in:
chimp1984 2020-09-09 14:12:03 -05:00
parent 1bea05d8c6
commit 6821c582e9
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
4 changed files with 44 additions and 13 deletions

View file

@ -3036,6 +3036,8 @@ Ideally you should specify the date your wallet seed was created.\n\n\n\
Are you sure you want to go ahead without specifying a wallet date?
seed.restore.success=Wallets restored successfully with the new seed words.\n\nYou need to shut down and restart the application.
seed.restore.error=An error occurred when restoring the wallets with seed words.{0}
seed.restore.openOffers.warn=You have open offers which will be removed if you restore from seed words.\n\
Are you sure that you want to continue?
####################################################################

View file

@ -22,6 +22,7 @@ import bisq.desktop.main.overlays.popups.Popup;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.locale.Res;
import bisq.core.offer.OpenOfferManager;
import bisq.common.UserThread;
import bisq.common.storage.FileUtil;
@ -30,6 +31,8 @@ import org.bitcoinj.wallet.DeterministicSeed;
import java.io.File;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
/**
@ -39,7 +42,28 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
public class SharedPresentation {
public static void restoreSeedWords(DeterministicSeed seed, WalletsManager walletsManager, File storageDir) {
public static void restoreSeedWords(WalletsManager walletsManager,
OpenOfferManager openOfferManager,
DeterministicSeed seed,
File storageDir) {
if (!openOfferManager.getObservableList().isEmpty()) {
UserThread.runAfter(() ->
new Popup().warning(Res.get("seed.restore.openOffers.warn"))
.actionButtonText(Res.get("shared.yes"))
.onAction(() -> {
openOfferManager.removeAllOpenOffers(() -> {
doRestoreSeedWords(walletsManager, seed, storageDir);
});
})
.show(), 100, TimeUnit.MILLISECONDS);
} else {
doRestoreSeedWords(walletsManager, seed, storageDir);
}
}
private static void doRestoreSeedWords(WalletsManager walletsManager,
DeterministicSeed seed,
File storageDir) {
try {
File backup = new File(storageDir, "AddressEntryList_backup_pre_wallet_restore_" + System.currentTimeMillis());
FileUtil.copyFile(new File(storageDir, "AddressEntryList"), backup);

View file

@ -27,6 +27,7 @@ import bisq.desktop.util.Layout;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.locale.Res;
import bisq.core.offer.OpenOfferManager;
import bisq.core.user.DontShowAgainLookup;
import bisq.common.config.Config;
@ -68,6 +69,7 @@ import static javafx.beans.binding.Bindings.createBooleanBinding;
@FxmlView
public class SeedWordsView extends ActivatableView<GridPane, Void> {
private final WalletsManager walletsManager;
private final OpenOfferManager openOfferManager;
private final BtcWalletService btcWalletService;
private final WalletPasswordWindow walletPasswordWindow;
private final File storageDir;
@ -91,10 +93,12 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
@Inject
private SeedWordsView(WalletsManager walletsManager,
OpenOfferManager openOfferManager,
BtcWalletService btcWalletService,
WalletPasswordWindow walletPasswordWindow,
@Named(Config.STORAGE_DIR) File storageDir) {
this.walletsManager = walletsManager;
this.openOfferManager = openOfferManager;
this.btcWalletService = btcWalletService;
this.walletPasswordWindow = walletPasswordWindow;
this.storageDir = storageDir;
@ -166,20 +170,18 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
String key = "showBackupWarningAtSeedPhrase";
if (DontShowAgainLookup.showAgain(key)) {
new Popup().warning(Res.get("account.seed.backup.warning"))
.onAction(() -> {
showSeedPhrase();
})
.actionButtonText(Res.get("shared.iUnderstand"))
.useIUnderstandButton()
.dontShowAgainId(key)
.hideCloseButton()
.show();
.onAction(this::showSeedPhrase)
.actionButtonText(Res.get("shared.iUnderstand"))
.useIUnderstandButton()
.dontShowAgainId(key)
.hideCloseButton()
.show();
} else {
showSeedPhrase();
}
}
public void showSeedPhrase() {
private void showSeedPhrase() {
DeterministicSeed keyChainSeed = btcWalletService.getKeyChainSeed();
// wallet creation date is not encrypted
walletCreationDate = Instant.ofEpochSecond(walletsManager.getChainSeedCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
@ -305,6 +307,6 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
long date = localDateTime.toEpochSecond(ZoneOffset.UTC);
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);
SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir);
SharedPresentation.restoreSeedWords(walletsManager, openOfferManager, seed, storageDir);
}
}

View file

@ -30,6 +30,7 @@ import bisq.desktop.util.Transitions;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.crypto.ScryptUtil;
import bisq.core.locale.Res;
import bisq.core.offer.OpenOfferManager;
import bisq.common.UserThread;
import bisq.common.config.Config;
@ -88,6 +89,7 @@ import static javafx.beans.binding.Bindings.createBooleanBinding;
@Slf4j
public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
private final WalletsManager walletsManager;
private final OpenOfferManager openOfferManager;
private File storageDir;
private Button unlockButton;
@ -115,8 +117,10 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
@Inject
private WalletPasswordWindow(WalletsManager walletsManager,
OpenOfferManager openOfferManager,
@Named(Config.STORAGE_DIR) File storageDir) {
this.walletsManager = walletsManager;
this.openOfferManager = openOfferManager;
this.storageDir = storageDir;
type = Type.Attention;
width = 900;
@ -277,7 +281,6 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
gridPane.getChildren().add(headLine2Label);
seedWordsTextArea = addTextArea(gridPane, ++rowIndex, Res.get("seed.enterSeedWords"), 5);
;
seedWordsTextArea.setPrefHeight(60);
Tuple2<Label, DatePicker> labelDatePickerTuple2 = addTopLabelDatePicker(gridPane, ++rowIndex,
@ -356,6 +359,6 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
//TODO Is ZoneOffset correct?
long date = value != null ? value.atStartOfDay().toEpochSecond(ZoneOffset.UTC) : 0;
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);
SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir);
SharedPresentation.restoreSeedWords(walletsManager, openOfferManager, seed, storageDir);
}
}