mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Refactoring
- Add SharedPresentation class for methods in GUIUtil which are no utility methods. - Move restoreSeedWords to SharedPresentation
This commit is contained in:
parent
fa987d1461
commit
fa0224550c
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
@ -19,9 +19,9 @@ package bisq.desktop.main.account.content.seedwords;
|
|||||||
|
|
||||||
import bisq.desktop.common.view.ActivatableView;
|
import bisq.desktop.common.view.ActivatableView;
|
||||||
import bisq.desktop.common.view.FxmlView;
|
import bisq.desktop.common.view.FxmlView;
|
||||||
|
import bisq.desktop.main.SharedPresentation;
|
||||||
import bisq.desktop.main.overlays.popups.Popup;
|
import bisq.desktop.main.overlays.popups.Popup;
|
||||||
import bisq.desktop.main.overlays.windows.WalletPasswordWindow;
|
import bisq.desktop.main.overlays.windows.WalletPasswordWindow;
|
||||||
import bisq.desktop.util.GUIUtil;
|
|
||||||
import bisq.desktop.util.Layout;
|
import bisq.desktop.util.Layout;
|
||||||
|
|
||||||
import bisq.core.btc.wallet.BtcWalletService;
|
import bisq.core.btc.wallet.BtcWalletService;
|
||||||
@ -305,6 +305,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);
|
||||||
GUIUtil.restoreSeedWords(seed, walletsManager, storageDir);
|
SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ import bisq.desktop.components.AutoTooltipButton;
|
|||||||
import bisq.desktop.components.AutoTooltipLabel;
|
import bisq.desktop.components.AutoTooltipLabel;
|
||||||
import bisq.desktop.components.BusyAnimation;
|
import bisq.desktop.components.BusyAnimation;
|
||||||
import bisq.desktop.components.PasswordTextField;
|
import bisq.desktop.components.PasswordTextField;
|
||||||
|
import bisq.desktop.main.SharedPresentation;
|
||||||
import bisq.desktop.main.overlays.Overlay;
|
import bisq.desktop.main.overlays.Overlay;
|
||||||
import bisq.desktop.main.overlays.popups.Popup;
|
import bisq.desktop.main.overlays.popups.Popup;
|
||||||
import bisq.desktop.util.GUIUtil;
|
|
||||||
import bisq.desktop.util.Layout;
|
import bisq.desktop.util.Layout;
|
||||||
import bisq.desktop.util.Transitions;
|
import bisq.desktop.util.Transitions;
|
||||||
|
|
||||||
@ -356,6 +356,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);
|
||||||
GUIUtil.restoreSeedWords(seed, walletsManager, storageDir);
|
SharedPresentation.restoreSeedWords(seed, walletsManager, storageDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@ import bisq.desktop.util.validation.RegexValidator;
|
|||||||
import bisq.core.account.witness.AccountAgeWitness;
|
import bisq.core.account.witness.AccountAgeWitness;
|
||||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||||
import bisq.core.btc.setup.WalletsSetup;
|
import bisq.core.btc.setup.WalletsSetup;
|
||||||
import bisq.core.btc.wallet.WalletsManager;
|
|
||||||
import bisq.core.locale.Country;
|
import bisq.core.locale.Country;
|
||||||
import bisq.core.locale.CountryUtil;
|
import bisq.core.locale.CountryUtil;
|
||||||
import bisq.core.locale.CurrencyUtil;
|
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.PersistableList;
|
||||||
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
import bisq.common.proto.persistable.PersistenceProtoResolver;
|
||||||
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
import bisq.common.storage.CorruptedDatabaseFilesHandler;
|
||||||
import bisq.common.storage.FileUtil;
|
|
||||||
import bisq.common.storage.Storage;
|
import bisq.common.storage.Storage;
|
||||||
import bisq.common.util.MathUtils;
|
import bisq.common.util.MathUtils;
|
||||||
import bisq.common.util.Tuple2;
|
import bisq.common.util.Tuple2;
|
||||||
@ -75,7 +73,6 @@ import org.bitcoinj.core.Coin;
|
|||||||
import org.bitcoinj.core.TransactionConfidence;
|
import org.bitcoinj.core.TransactionConfidence;
|
||||||
import org.bitcoinj.uri.BitcoinURI;
|
import org.bitcoinj.uri.BitcoinURI;
|
||||||
import org.bitcoinj.utils.Fiat;
|
import org.bitcoinj.utils.Fiat;
|
||||||
import org.bitcoinj.wallet.DeterministicSeed;
|
|
||||||
|
|
||||||
import com.googlecode.jcsv.CSVStrategy;
|
import com.googlecode.jcsv.CSVStrategy;
|
||||||
import com.googlecode.jcsv.writer.CSVEntryConverter;
|
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) {
|
public static void showSelectableTextModal(String title, String text) {
|
||||||
TextArea textArea = new BisqTextArea();
|
TextArea textArea = new BisqTextArea();
|
||||||
textArea.setText(text);
|
textArea.setText(text);
|
||||||
|
Loading…
Reference in New Issue
Block a user