mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Add check for open offers and remove them if present at restore from seed
This commit is contained in:
parent
1bea05d8c6
commit
6821c582e9
4 changed files with 44 additions and 13 deletions
|
@ -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?
|
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.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.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?
|
||||||
|
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
|
@ -22,6 +22,7 @@ import bisq.desktop.main.overlays.popups.Popup;
|
||||||
|
|
||||||
import bisq.core.btc.wallet.WalletsManager;
|
import bisq.core.btc.wallet.WalletsManager;
|
||||||
import bisq.core.locale.Res;
|
import bisq.core.locale.Res;
|
||||||
|
import bisq.core.offer.OpenOfferManager;
|
||||||
|
|
||||||
import bisq.common.UserThread;
|
import bisq.common.UserThread;
|
||||||
import bisq.common.storage.FileUtil;
|
import bisq.common.storage.FileUtil;
|
||||||
|
@ -30,6 +31,8 @@ import org.bitcoinj.wallet.DeterministicSeed;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +42,28 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SharedPresentation {
|
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 {
|
try {
|
||||||
File backup = new File(storageDir, "AddressEntryList_backup_pre_wallet_restore_" + System.currentTimeMillis());
|
File backup = new File(storageDir, "AddressEntryList_backup_pre_wallet_restore_" + System.currentTimeMillis());
|
||||||
FileUtil.copyFile(new File(storageDir, "AddressEntryList"), backup);
|
FileUtil.copyFile(new File(storageDir, "AddressEntryList"), backup);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import bisq.desktop.util.Layout;
|
||||||
import bisq.core.btc.wallet.BtcWalletService;
|
import bisq.core.btc.wallet.BtcWalletService;
|
||||||
import bisq.core.btc.wallet.WalletsManager;
|
import bisq.core.btc.wallet.WalletsManager;
|
||||||
import bisq.core.locale.Res;
|
import bisq.core.locale.Res;
|
||||||
|
import bisq.core.offer.OpenOfferManager;
|
||||||
import bisq.core.user.DontShowAgainLookup;
|
import bisq.core.user.DontShowAgainLookup;
|
||||||
|
|
||||||
import bisq.common.config.Config;
|
import bisq.common.config.Config;
|
||||||
|
@ -68,6 +69,7 @@ import static javafx.beans.binding.Bindings.createBooleanBinding;
|
||||||
@FxmlView
|
@FxmlView
|
||||||
public class SeedWordsView extends ActivatableView<GridPane, Void> {
|
public class SeedWordsView extends ActivatableView<GridPane, Void> {
|
||||||
private final WalletsManager walletsManager;
|
private final WalletsManager walletsManager;
|
||||||
|
private final OpenOfferManager openOfferManager;
|
||||||
private final BtcWalletService btcWalletService;
|
private final BtcWalletService btcWalletService;
|
||||||
private final WalletPasswordWindow walletPasswordWindow;
|
private final WalletPasswordWindow walletPasswordWindow;
|
||||||
private final File storageDir;
|
private final File storageDir;
|
||||||
|
@ -91,10 +93,12 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SeedWordsView(WalletsManager walletsManager,
|
private SeedWordsView(WalletsManager walletsManager,
|
||||||
|
OpenOfferManager openOfferManager,
|
||||||
BtcWalletService btcWalletService,
|
BtcWalletService btcWalletService,
|
||||||
WalletPasswordWindow walletPasswordWindow,
|
WalletPasswordWindow walletPasswordWindow,
|
||||||
@Named(Config.STORAGE_DIR) File storageDir) {
|
@Named(Config.STORAGE_DIR) File storageDir) {
|
||||||
this.walletsManager = walletsManager;
|
this.walletsManager = walletsManager;
|
||||||
|
this.openOfferManager = openOfferManager;
|
||||||
this.btcWalletService = btcWalletService;
|
this.btcWalletService = btcWalletService;
|
||||||
this.walletPasswordWindow = walletPasswordWindow;
|
this.walletPasswordWindow = walletPasswordWindow;
|
||||||
this.storageDir = storageDir;
|
this.storageDir = storageDir;
|
||||||
|
@ -166,20 +170,18 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
|
||||||
String key = "showBackupWarningAtSeedPhrase";
|
String key = "showBackupWarningAtSeedPhrase";
|
||||||
if (DontShowAgainLookup.showAgain(key)) {
|
if (DontShowAgainLookup.showAgain(key)) {
|
||||||
new Popup().warning(Res.get("account.seed.backup.warning"))
|
new Popup().warning(Res.get("account.seed.backup.warning"))
|
||||||
.onAction(() -> {
|
.onAction(this::showSeedPhrase)
|
||||||
showSeedPhrase();
|
.actionButtonText(Res.get("shared.iUnderstand"))
|
||||||
})
|
.useIUnderstandButton()
|
||||||
.actionButtonText(Res.get("shared.iUnderstand"))
|
.dontShowAgainId(key)
|
||||||
.useIUnderstandButton()
|
.hideCloseButton()
|
||||||
.dontShowAgainId(key)
|
.show();
|
||||||
.hideCloseButton()
|
|
||||||
.show();
|
|
||||||
} else {
|
} else {
|
||||||
showSeedPhrase();
|
showSeedPhrase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSeedPhrase() {
|
private void showSeedPhrase() {
|
||||||
DeterministicSeed keyChainSeed = btcWalletService.getKeyChainSeed();
|
DeterministicSeed keyChainSeed = btcWalletService.getKeyChainSeed();
|
||||||
// wallet creation date is not encrypted
|
// wallet creation date is not encrypted
|
||||||
walletCreationDate = Instant.ofEpochSecond(walletsManager.getChainSeedCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
|
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);
|
long date = localDateTime.toEpochSecond(ZoneOffset.UTC);
|
||||||
|
|
||||||
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);
|
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);
|
||||||
SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir);
|
SharedPresentation.restoreSeedWords(walletsManager, openOfferManager, seed, storageDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import bisq.desktop.util.Transitions;
|
||||||
import bisq.core.btc.wallet.WalletsManager;
|
import bisq.core.btc.wallet.WalletsManager;
|
||||||
import bisq.core.crypto.ScryptUtil;
|
import bisq.core.crypto.ScryptUtil;
|
||||||
import bisq.core.locale.Res;
|
import bisq.core.locale.Res;
|
||||||
|
import bisq.core.offer.OpenOfferManager;
|
||||||
|
|
||||||
import bisq.common.UserThread;
|
import bisq.common.UserThread;
|
||||||
import bisq.common.config.Config;
|
import bisq.common.config.Config;
|
||||||
|
@ -88,6 +89,7 @@ import static javafx.beans.binding.Bindings.createBooleanBinding;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
||||||
private final WalletsManager walletsManager;
|
private final WalletsManager walletsManager;
|
||||||
|
private final OpenOfferManager openOfferManager;
|
||||||
private File storageDir;
|
private File storageDir;
|
||||||
|
|
||||||
private Button unlockButton;
|
private Button unlockButton;
|
||||||
|
@ -115,8 +117,10 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private WalletPasswordWindow(WalletsManager walletsManager,
|
private WalletPasswordWindow(WalletsManager walletsManager,
|
||||||
|
OpenOfferManager openOfferManager,
|
||||||
@Named(Config.STORAGE_DIR) File storageDir) {
|
@Named(Config.STORAGE_DIR) File storageDir) {
|
||||||
this.walletsManager = walletsManager;
|
this.walletsManager = walletsManager;
|
||||||
|
this.openOfferManager = openOfferManager;
|
||||||
this.storageDir = storageDir;
|
this.storageDir = storageDir;
|
||||||
type = Type.Attention;
|
type = Type.Attention;
|
||||||
width = 900;
|
width = 900;
|
||||||
|
@ -277,7 +281,6 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
||||||
gridPane.getChildren().add(headLine2Label);
|
gridPane.getChildren().add(headLine2Label);
|
||||||
|
|
||||||
seedWordsTextArea = addTextArea(gridPane, ++rowIndex, Res.get("seed.enterSeedWords"), 5);
|
seedWordsTextArea = addTextArea(gridPane, ++rowIndex, Res.get("seed.enterSeedWords"), 5);
|
||||||
;
|
|
||||||
seedWordsTextArea.setPrefHeight(60);
|
seedWordsTextArea.setPrefHeight(60);
|
||||||
|
|
||||||
Tuple2<Label, DatePicker> labelDatePickerTuple2 = addTopLabelDatePicker(gridPane, ++rowIndex,
|
Tuple2<Label, DatePicker> labelDatePickerTuple2 = addTopLabelDatePicker(gridPane, ++rowIndex,
|
||||||
|
@ -356,6 +359,6 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
||||||
//TODO Is ZoneOffset correct?
|
//TODO Is ZoneOffset correct?
|
||||||
long date = value != null ? value.atStartOfDay().toEpochSecond(ZoneOffset.UTC) : 0;
|
long date = value != null ? value.atStartOfDay().toEpochSecond(ZoneOffset.UTC) : 0;
|
||||||
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);
|
DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date);
|
||||||
SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir);
|
SharedPresentation.restoreSeedWords(walletsManager, openOfferManager, seed, storageDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue