diff --git a/desktop/src/main/java/bisq/desktop/main/SharedPresentation.java b/desktop/src/main/java/bisq/desktop/main/SharedPresentation.java new file mode 100644 index 0000000000..213704c280 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/SharedPresentation.java @@ -0,0 +1,61 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.desktop.main; + +import bisq.desktop.app.BisqApp; +import bisq.desktop.main.overlays.popups.Popup; + +import bisq.core.btc.wallet.WalletsManager; +import bisq.core.locale.Res; + +import bisq.common.UserThread; +import bisq.common.storage.FileUtil; + +import org.bitcoinj.wallet.DeterministicSeed; + +import java.io.File; + +import lombok.extern.slf4j.Slf4j; + +/** + * This serves as shared space for static methods used from different views where no common parent view would fit as + * owner of that code. We keep it strictly static. It should replace GUIUtil for those methods which are not utility + * methods. + */ +@Slf4j +public class SharedPresentation { + public static void restoreSeedWords(DeterministicSeed seed, WalletsManager walletsManager, File storageDir) { + try { + FileUtil.renameFile(new File(storageDir, "AddressEntryList"), new File(storageDir, "AddressEntryList_wallet_restore_" + System.currentTimeMillis())); + } catch (Throwable t) { + new Popup().error(Res.get("error.deleteAddressEntryListFailed", t)).show(); + } + walletsManager.restoreSeedWords( + seed, + () -> UserThread.execute(() -> { + log.info("Wallets restored with seed words"); + new Popup().feedback(Res.get("seed.restore.success")).hideCloseButton().show(); + BisqApp.getShutDownHandler().run(); + }), + throwable -> UserThread.execute(() -> { + log.error(throwable.toString()); + new Popup().error(Res.get("seed.restore.error", Res.get("shared.errorMessageInline", throwable))) + .show(); + })); + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/seedwords/SeedWordsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/seedwords/SeedWordsView.java index a299b5434b..bddbf4ea07 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/seedwords/SeedWordsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/seedwords/SeedWordsView.java @@ -19,9 +19,9 @@ package bisq.desktop.main.account.content.seedwords; import bisq.desktop.common.view.ActivatableView; import bisq.desktop.common.view.FxmlView; +import bisq.desktop.main.SharedPresentation; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.WalletPasswordWindow; -import bisq.desktop.util.GUIUtil; import bisq.desktop.util.Layout; import bisq.core.btc.wallet.BtcWalletService; @@ -305,6 +305,6 @@ public class SeedWordsView extends ActivatableView { long date = localDateTime.toEpochSecond(ZoneOffset.UTC); DeterministicSeed seed = new DeterministicSeed(Splitter.on(" ").splitToList(seedWordsTextArea.getText()), null, "", date); - GUIUtil.restoreSeedWords(seed, walletsManager, storageDir); + SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir); } } diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/WalletPasswordWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/WalletPasswordWindow.java index b5ba8539ff..c203666558 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/WalletPasswordWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/WalletPasswordWindow.java @@ -21,9 +21,9 @@ import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.BusyAnimation; import bisq.desktop.components.PasswordTextField; +import bisq.desktop.main.SharedPresentation; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.main.overlays.popups.Popup; -import bisq.desktop.util.GUIUtil; import bisq.desktop.util.Layout; import bisq.desktop.util.Transitions; @@ -356,6 +356,6 @@ public class WalletPasswordWindow extends Overlay { //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); - GUIUtil.restoreSeedWords(seed, walletsManager, storageDir); + SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir); } } diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index 5fabd2c94a..0d26e80a96 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -32,7 +32,6 @@ import bisq.desktop.util.validation.RegexValidator; import bisq.core.account.witness.AccountAgeWitness; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.setup.WalletsSetup; -import bisq.core.btc.wallet.WalletsManager; import bisq.core.locale.Country; import bisq.core.locale.CountryUtil; import bisq.core.locale.CurrencyUtil; @@ -63,7 +62,6 @@ import bisq.common.config.Config; import bisq.common.proto.persistable.PersistableList; import bisq.common.proto.persistable.PersistenceProtoResolver; import bisq.common.storage.CorruptedDatabaseFilesHandler; -import bisq.common.storage.FileUtil; import bisq.common.storage.Storage; import bisq.common.util.MathUtils; import bisq.common.util.Tuple2; @@ -75,7 +73,6 @@ import org.bitcoinj.core.Coin; import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.uri.BitcoinURI; import org.bitcoinj.utils.Fiat; -import org.bitcoinj.wallet.DeterministicSeed; import com.googlecode.jcsv.CSVStrategy; import com.googlecode.jcsv.writer.CSVEntryConverter; @@ -803,26 +800,6 @@ public class GUIUtil { } } - public static void restoreSeedWords(DeterministicSeed seed, WalletsManager walletsManager, File storageDir) { - try { - FileUtil.renameFile(new File(storageDir, "AddressEntryList"), new File(storageDir, "AddressEntryList_wallet_restore_" + System.currentTimeMillis())); - } catch (Throwable t) { - new Popup().error(Res.get("error.deleteAddressEntryListFailed", t)).show(); - } - walletsManager.restoreSeedWords( - seed, - () -> UserThread.execute(() -> { - log.info("Wallets restored with seed words"); - new Popup().feedback(Res.get("seed.restore.success")).hideCloseButton().show(); - BisqApp.getShutDownHandler().run(); - }), - throwable -> UserThread.execute(() -> { - log.error(throwable.toString()); - new Popup().error(Res.get("seed.restore.error", Res.get("shared.errorMessageInline", throwable))) - .show(); - })); - } - public static void showSelectableTextModal(String title, String text) { TextArea textArea = new BisqTextArea(); textArea.setText(text);