mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-09 07:02:24 -04:00
support password prompt in legacy ui
Co-authored-by: niyid <neeyeed@gmail.com>
This commit is contained in:
parent
99653fe40d
commit
4dde53f0e8
19 changed files with 357 additions and 272 deletions
|
@ -67,8 +67,8 @@ import javafx.scene.input.KeyCode;
|
|||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.geometry.BoundingBox;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -128,6 +128,7 @@ public class HavenoApp extends Application implements UncaughtExceptionHandler {
|
|||
}
|
||||
|
||||
public void startApplication(Runnable onApplicationStartedHandler) {
|
||||
log.info("Running startApplication...");
|
||||
try {
|
||||
mainView = loadMainView(injector);
|
||||
mainView.setOnApplicationStartedHandler(onApplicationStartedHandler);
|
||||
|
@ -149,7 +150,7 @@ public class HavenoApp extends Application implements UncaughtExceptionHandler {
|
|||
.show();
|
||||
new Thread(() -> {
|
||||
gracefulShutDownHandler.gracefulShutDown(() -> {
|
||||
log.debug("App shutdown complete");
|
||||
log.info("App shutdown complete");
|
||||
});
|
||||
}).start();
|
||||
shutDownRequested = true;
|
||||
|
|
|
@ -20,6 +20,7 @@ package bisq.desktop.app;
|
|||
import bisq.desktop.common.UITimer;
|
||||
import bisq.desktop.common.view.guice.InjectorViewFactory;
|
||||
import bisq.desktop.setup.DesktopPersistedDataHost;
|
||||
import bisq.desktop.util.ImageUtil;
|
||||
|
||||
import bisq.core.app.AvoidStandbyModeService;
|
||||
import bisq.core.app.HavenoExecutable;
|
||||
|
@ -27,10 +28,25 @@ import bisq.core.app.HavenoExecutable;
|
|||
import bisq.common.UserThread;
|
||||
import bisq.common.app.AppModule;
|
||||
import bisq.common.app.Version;
|
||||
|
||||
import bisq.common.crypto.IncorrectPasswordException;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import javafx.scene.control.ButtonBar;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Dialog;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
|
@ -139,4 +155,86 @@ public class HavenoAppMain extends HavenoExecutable {
|
|||
// Therefore, calling this as part of onApplicationStarted()
|
||||
log.info("Using JavaFX {}", System.getProperty("javafx.version"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<Boolean> loginAccount() {
|
||||
|
||||
// attempt default login
|
||||
CompletableFuture<Boolean> result = super.loginAccount();
|
||||
try {
|
||||
if (result.get()) return result;
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
// login using dialog
|
||||
CompletableFuture<Boolean> dialogResult = new CompletableFuture<>();
|
||||
Platform.setImplicitExit(false);
|
||||
Platform.runLater(() -> {
|
||||
|
||||
// show password dialog until account open
|
||||
String errorMessage = null;
|
||||
while (!accountService.isAccountOpen()) {
|
||||
|
||||
// create the password dialog
|
||||
PasswordDialog passwordDialog = new PasswordDialog(errorMessage);
|
||||
|
||||
// wait for user to enter password
|
||||
Optional<String> passwordResult = passwordDialog.showAndWait();
|
||||
if (passwordResult.isPresent()) {
|
||||
try {
|
||||
accountService.openAccount(passwordResult.get());
|
||||
dialogResult.complete(accountService.isAccountOpen());
|
||||
} catch (IncorrectPasswordException e) {
|
||||
errorMessage = "Incorrect password";
|
||||
}
|
||||
} else {
|
||||
// if the user cancelled the dialog, complete the passwordFuture exceptionally
|
||||
dialogResult.completeExceptionally(new Exception("Password dialog cancelled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return dialogResult;
|
||||
}
|
||||
|
||||
private class PasswordDialog extends Dialog<String> {
|
||||
|
||||
public PasswordDialog(String errorMessage) {
|
||||
setTitle("Enter Password");
|
||||
setHeaderText("Please enter your Haveno password:");
|
||||
|
||||
// Add an icon to the dialog
|
||||
Stage stage = (Stage) getDialogPane().getScene().getWindow();
|
||||
stage.getIcons().add(ImageUtil.getImageByPath("lock.png"));
|
||||
|
||||
// Create the password field
|
||||
PasswordField passwordField = new PasswordField();
|
||||
passwordField.setPromptText("Password");
|
||||
|
||||
// Create the error message field
|
||||
Label errorMessageField = new Label(errorMessage);
|
||||
errorMessageField.setTextFill(Color.color(1, 0, 0));
|
||||
|
||||
// Set the dialog content
|
||||
VBox vbox = new VBox(10);
|
||||
vbox.getChildren().addAll(new ImageView(ImageUtil.getImageByPath("logo_splash.png")), passwordField, errorMessageField);
|
||||
getDialogPane().setContent(vbox);
|
||||
|
||||
// Add OK and Cancel buttons
|
||||
ButtonType okButton = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
|
||||
ButtonType cancelButton = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||
getDialogPane().getButtonTypes().addAll(okButton, cancelButton);
|
||||
|
||||
// Convert the result to a string when the OK button is clicked
|
||||
setResultConverter(buttonType -> {
|
||||
if (buttonType == okButton) {
|
||||
return passwordField.getText();
|
||||
} else {
|
||||
new Thread(() -> HavenoApp.getShutDownHandler().run()).start();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package bisq.desktop.main;
|
||||
|
||||
import bisq.desktop.Navigation;
|
||||
import bisq.desktop.app.HavenoApp;
|
||||
import bisq.desktop.common.model.ViewModel;
|
||||
import bisq.desktop.components.TxIdTextField;
|
||||
import bisq.desktop.main.account.AccountView;
|
||||
|
@ -109,7 +108,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
|
||||
@Slf4j
|
||||
public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener {
|
||||
private final HavenoSetup bisqSetup;
|
||||
private final HavenoSetup havenoSetup;
|
||||
private final CoreMoneroConnectionsService connectionService;
|
||||
private final User user;
|
||||
private final BalancePresentation balancePresentation;
|
||||
|
@ -154,7 +153,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public MainViewModel(HavenoSetup bisqSetup,
|
||||
public MainViewModel(HavenoSetup havenoSetup,
|
||||
CoreMoneroConnectionsService connectionService,
|
||||
XmrWalletService xmrWalletService,
|
||||
User user,
|
||||
|
@ -179,7 +178,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
TorNetworkSettingsWindow torNetworkSettingsWindow,
|
||||
CorruptedStorageFileHandler corruptedStorageFileHandler,
|
||||
Navigation navigation) {
|
||||
this.bisqSetup = bisqSetup;
|
||||
this.havenoSetup = havenoSetup;
|
||||
this.connectionService = connectionService;
|
||||
this.user = user;
|
||||
this.balancePresentation = balancePresentation;
|
||||
|
@ -211,7 +210,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
GUIUtil.setPreferences(preferences);
|
||||
|
||||
setupHandlers();
|
||||
bisqSetup.addHavenoSetupListener(this);
|
||||
havenoSetup.addHavenoSetupListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -303,7 +302,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
}
|
||||
|
||||
void onOpenDownloadWindow() {
|
||||
bisqSetup.displayAlertIfPresent(user.getDisplayedAlert(), true);
|
||||
havenoSetup.displayAlertIfPresent(user.getDisplayedAlert(), true);
|
||||
}
|
||||
|
||||
void setPriceFeedComboBoxItem(PriceFeedComboBoxItem item) {
|
||||
|
@ -316,34 +315,30 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void setupHandlers() {
|
||||
bisqSetup.setDisplayTacHandler(acceptedHandler -> UserThread.runAfter(() -> {
|
||||
havenoSetup.setDisplayTacHandler(acceptedHandler -> UserThread.runAfter(() -> {
|
||||
//noinspection FunctionalExpressionCanBeFolded
|
||||
tacWindow.onAction(acceptedHandler::run).show();
|
||||
}, 1));
|
||||
|
||||
bisqSetup.setDisplayTorNetworkSettingsHandler(show -> {
|
||||
havenoSetup.setDisplayTorNetworkSettingsHandler(show -> {
|
||||
if (show) {
|
||||
torNetworkSettingsWindow.show();
|
||||
} else if (torNetworkSettingsWindow.isDisplayed()) {
|
||||
torNetworkSettingsWindow.hide();
|
||||
}
|
||||
});
|
||||
bisqSetup.setSpvFileCorruptedHandler(msg -> new Popup().warning(msg)
|
||||
havenoSetup.setSpvFileCorruptedHandler(msg -> new Popup().warning(msg)
|
||||
.actionButtonText(Res.get("settings.net.reSyncSPVChainButton"))
|
||||
.onAction(() -> GUIUtil.reSyncSPVChain(preferences))
|
||||
.show());
|
||||
|
||||
bisqSetup.setChainFileLockedExceptionHandler(msg -> new Popup().warning(msg)
|
||||
havenoSetup.setChainFileLockedExceptionHandler(msg -> new Popup().warning(msg)
|
||||
.useShutDownButton()
|
||||
.show());
|
||||
bisqSetup.setLockedUpFundsHandler(msg -> new Popup().width(850).warning(msg).show());
|
||||
bisqSetup.setShowFirstPopupIfResyncSPVRequestedHandler(this::showFirstPopupIfResyncSPVRequested);
|
||||
bisqSetup.setRequestWalletPasswordHandler(aesKeyHandler -> walletPasswordWindow
|
||||
.onAesKey(aesKeyHandler::accept)
|
||||
.onClose(() -> HavenoApp.getShutDownHandler().run())
|
||||
.show());
|
||||
havenoSetup.setLockedUpFundsHandler(msg -> new Popup().width(850).warning(msg).show());
|
||||
havenoSetup.setShowFirstPopupIfResyncSPVRequestedHandler(this::showFirstPopupIfResyncSPVRequested);
|
||||
|
||||
bisqSetup.setDisplayUpdateHandler((alert, key) -> new DisplayUpdateDownloadWindow(alert, config)
|
||||
havenoSetup.setDisplayUpdateHandler((alert, key) -> new DisplayUpdateDownloadWindow(alert, config)
|
||||
.actionButtonText(Res.get("displayUpdateDownloadWindow.button.downloadLater"))
|
||||
.onAction(() -> {
|
||||
preferences.dontShowAgain(key, false); // update later
|
||||
|
@ -353,19 +348,19 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
preferences.dontShowAgain(key, true); // ignore update
|
||||
})
|
||||
.show());
|
||||
bisqSetup.setDisplayAlertHandler(alert -> new DisplayAlertMessageWindow()
|
||||
havenoSetup.setDisplayAlertHandler(alert -> new DisplayAlertMessageWindow()
|
||||
.alertMessage(alert)
|
||||
.closeButtonText(Res.get("shared.close"))
|
||||
.onClose(() -> user.setDisplayedAlert(alert))
|
||||
.show());
|
||||
bisqSetup.setDisplayPrivateNotificationHandler(privateNotification ->
|
||||
havenoSetup.setDisplayPrivateNotificationHandler(privateNotification ->
|
||||
new Popup().headLine(Res.get("popup.privateNotification.headline"))
|
||||
.attention(privateNotification.getMessage())
|
||||
.onClose(privateNotificationManager::removePrivateNotification)
|
||||
.useIUnderstandButton()
|
||||
.show());
|
||||
bisqSetup.setDisplaySecurityRecommendationHandler(key -> {});
|
||||
bisqSetup.setDisplayLocalhostHandler(key -> {
|
||||
havenoSetup.setDisplaySecurityRecommendationHandler(key -> {});
|
||||
havenoSetup.setDisplayLocalhostHandler(key -> {
|
||||
if (!DevEnv.isDevMode()) {
|
||||
Popup popup = new Popup().backgroundInfo(Res.get("popup.bitcoinLocalhostNode.msg"))
|
||||
.dontShowAgainId(key);
|
||||
|
@ -373,31 +368,31 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
popupQueue.add(popup);
|
||||
}
|
||||
});
|
||||
bisqSetup.setDisplaySignedByArbitratorHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
havenoSetup.setDisplaySignedByArbitratorHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
key, "popup.accountSigning.signedByArbitrator"));
|
||||
bisqSetup.setDisplaySignedByPeerHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
havenoSetup.setDisplaySignedByPeerHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
key, "popup.accountSigning.signedByPeer", String.valueOf(SignedWitnessService.SIGNER_AGE_DAYS)));
|
||||
bisqSetup.setDisplayPeerLimitLiftedHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
havenoSetup.setDisplayPeerLimitLiftedHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
key, "popup.accountSigning.peerLimitLifted"));
|
||||
bisqSetup.setDisplayPeerSignerHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
havenoSetup.setDisplayPeerSignerHandler(key -> accountPresentation.showOneTimeAccountSigningPopup(
|
||||
key, "popup.accountSigning.peerSigner"));
|
||||
|
||||
bisqSetup.setWrongOSArchitectureHandler(msg -> new Popup().warning(msg).show());
|
||||
havenoSetup.setWrongOSArchitectureHandler(msg -> new Popup().warning(msg).show());
|
||||
|
||||
bisqSetup.setRejectedTxErrorMessageHandler(msg -> new Popup().width(850).warning(msg).show());
|
||||
havenoSetup.setRejectedTxErrorMessageHandler(msg -> new Popup().width(850).warning(msg).show());
|
||||
|
||||
bisqSetup.setShowPopupIfInvalidBtcConfigHandler(this::showPopupIfInvalidBtcConfig);
|
||||
havenoSetup.setShowPopupIfInvalidBtcConfigHandler(this::showPopupIfInvalidBtcConfig);
|
||||
|
||||
bisqSetup.setRevolutAccountsUpdateHandler(revolutAccountList -> {
|
||||
havenoSetup.setRevolutAccountsUpdateHandler(revolutAccountList -> {
|
||||
// We copy the array as we will mutate it later
|
||||
showRevolutAccountUpdateWindow(new ArrayList<>(revolutAccountList));
|
||||
});
|
||||
bisqSetup.setAmazonGiftCardAccountsUpdateHandler(amazonGiftCardAccountList -> {
|
||||
havenoSetup.setAmazonGiftCardAccountsUpdateHandler(amazonGiftCardAccountList -> {
|
||||
// We copy the array as we will mutate it later
|
||||
showAmazonGiftCardAccountUpdateWindow(new ArrayList<>(amazonGiftCardAccountList));
|
||||
});
|
||||
bisqSetup.setOsxKeyLoggerWarningHandler(() -> { });
|
||||
bisqSetup.setQubesOSInfoHandler(() -> {
|
||||
havenoSetup.setOsxKeyLoggerWarningHandler(() -> { });
|
||||
havenoSetup.setQubesOSInfoHandler(() -> {
|
||||
String key = "qubesOSSetupInfo";
|
||||
if (preferences.showAgain(key)) {
|
||||
new Popup().information(Res.get("popup.info.qubesOSSetupInfo"))
|
||||
|
@ -407,14 +402,14 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
}
|
||||
});
|
||||
|
||||
bisqSetup.setDownGradePreventionHandler(lastVersion -> {
|
||||
havenoSetup.setDownGradePreventionHandler(lastVersion -> {
|
||||
new Popup().warning(Res.get("popup.warn.downGradePrevention", lastVersion, Version.VERSION))
|
||||
.useShutDownButton()
|
||||
.hideCloseButton()
|
||||
.show();
|
||||
});
|
||||
|
||||
bisqSetup.setTorAddressUpgradeHandler(() -> new Popup().information(Res.get("popup.info.torMigration.msg"))
|
||||
havenoSetup.setTorAddressUpgradeHandler(() -> new Popup().information(Res.get("popup.info.torMigration.msg"))
|
||||
.actionButtonTextWithGoTo("navigation.account.backup")
|
||||
.onAction(() -> {
|
||||
navigation.setReturnPath(navigation.getCurrentPath());
|
||||
|
@ -430,9 +425,9 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
.warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage))
|
||||
.show());
|
||||
|
||||
bisqSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());
|
||||
havenoSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> updateBtcSyncProgress());
|
||||
|
||||
bisqSetup.setFilterWarningHandler(warning -> new Popup().warning(warning).show());
|
||||
havenoSetup.setFilterWarningHandler(warning -> new Popup().warning(warning).show());
|
||||
|
||||
this.footerVersionInfo.setValue("v" + Version.VERSION);
|
||||
this.getNewVersionAvailableProperty().addListener((observable, oldValue, newValue) -> {
|
||||
|
@ -538,10 +533,10 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
private void showFirstPopupIfResyncSPVRequested() {
|
||||
Popup firstPopup = new Popup();
|
||||
firstPopup.information(Res.get("settings.net.reSyncSPVAfterRestart")).show();
|
||||
if (bisqSetup.getBtcSyncProgress().get() == 1) {
|
||||
if (havenoSetup.getBtcSyncProgress().get() == 1) {
|
||||
showSecondPopupIfResyncSPVRequested(firstPopup);
|
||||
} else {
|
||||
bisqSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> {
|
||||
havenoSetup.getBtcSyncProgress().addListener((observable, oldValue, newValue) -> {
|
||||
if ((double) newValue == 1)
|
||||
showSecondPopupIfResyncSPVRequested(firstPopup);
|
||||
});
|
||||
|
@ -596,7 +591,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
}
|
||||
|
||||
private void updateBtcSyncProgress() {
|
||||
final DoubleProperty btcSyncProgress = bisqSetup.getBtcSyncProgress();
|
||||
final DoubleProperty btcSyncProgress = havenoSetup.getBtcSyncProgress();
|
||||
|
||||
combinedSyncProgress.set(btcSyncProgress.doubleValue());
|
||||
}
|
||||
|
@ -635,7 +630,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BooleanProperty getNewVersionAvailableProperty() {
|
||||
return bisqSetup.getNewVersionAvailableProperty();
|
||||
return havenoSetup.getNewVersionAvailableProperty();
|
||||
}
|
||||
|
||||
StringProperty getNumOpenSupportTickets() {
|
||||
|
@ -670,7 +665,7 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
// Wallet
|
||||
StringProperty getBtcInfo() {
|
||||
final StringProperty combinedInfo = new SimpleStringProperty();
|
||||
combinedInfo.bind(bisqSetup.getBtcInfo());
|
||||
combinedInfo.bind(havenoSetup.getBtcInfo());
|
||||
return combinedInfo;
|
||||
}
|
||||
|
||||
|
@ -685,44 +680,44 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
|
|||
}
|
||||
|
||||
StringProperty getWalletServiceErrorMsg() {
|
||||
return bisqSetup.getWalletServiceErrorMsg();
|
||||
return havenoSetup.getWalletServiceErrorMsg();
|
||||
}
|
||||
|
||||
StringProperty getBtcSplashSyncIconId() {
|
||||
return bisqSetup.getBtcSplashSyncIconId();
|
||||
return havenoSetup.getBtcSplashSyncIconId();
|
||||
}
|
||||
|
||||
BooleanProperty getUseTorForBTC() {
|
||||
return bisqSetup.getUseTorForBTC();
|
||||
return havenoSetup.getUseTorForBTC();
|
||||
}
|
||||
|
||||
// P2P
|
||||
StringProperty getP2PNetworkInfo() {
|
||||
return bisqSetup.getP2PNetworkInfo();
|
||||
return havenoSetup.getP2PNetworkInfo();
|
||||
}
|
||||
|
||||
BooleanProperty getSplashP2PNetworkAnimationVisible() {
|
||||
return bisqSetup.getSplashP2PNetworkAnimationVisible();
|
||||
return havenoSetup.getSplashP2PNetworkAnimationVisible();
|
||||
}
|
||||
|
||||
StringProperty getP2pNetworkWarnMsg() {
|
||||
return bisqSetup.getP2pNetworkWarnMsg();
|
||||
return havenoSetup.getP2pNetworkWarnMsg();
|
||||
}
|
||||
|
||||
StringProperty getP2PNetworkIconId() {
|
||||
return bisqSetup.getP2PNetworkIconId();
|
||||
return havenoSetup.getP2PNetworkIconId();
|
||||
}
|
||||
|
||||
StringProperty getP2PNetworkStatusIconId() {
|
||||
return bisqSetup.getP2PNetworkStatusIconId();
|
||||
return havenoSetup.getP2PNetworkStatusIconId();
|
||||
}
|
||||
|
||||
BooleanProperty getUpdatedDataReceived() {
|
||||
return bisqSetup.getUpdatedDataReceived();
|
||||
return havenoSetup.getUpdatedDataReceived();
|
||||
}
|
||||
|
||||
StringProperty getP2pNetworkLabelId() {
|
||||
return bisqSetup.getP2pNetworkLabelId();
|
||||
return havenoSetup.getP2pNetworkLabelId();
|
||||
}
|
||||
|
||||
// marketPricePresentation
|
||||
|
|
|
@ -27,16 +27,15 @@ import bisq.desktop.components.TitledGroupBg;
|
|||
import bisq.desktop.main.MainView;
|
||||
import bisq.desktop.main.account.AccountView;
|
||||
import bisq.desktop.main.account.content.backup.BackupView;
|
||||
import bisq.desktop.main.account.content.seedwords.SeedWordsView;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
import bisq.desktop.util.Layout;
|
||||
import bisq.desktop.util.validation.PasswordValidator;
|
||||
|
||||
import bisq.core.api.CoreAccountService;
|
||||
import bisq.core.btc.wallet.WalletsManager;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.common.crypto.ScryptUtil;
|
||||
import bisq.common.util.Tuple4;
|
||||
|
||||
import org.bitcoinj.crypto.KeyCrypterScrypt;
|
||||
import bisq.common.util.Tuple4;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -61,6 +60,7 @@ public class PasswordView extends ActivatableView<GridPane, Void> {
|
|||
private final WalletsManager walletsManager;
|
||||
private final PasswordValidator passwordValidator;
|
||||
private final Navigation navigation;
|
||||
private final CoreAccountService accountService;
|
||||
|
||||
private PasswordTextField passwordField;
|
||||
private PasswordTextField repeatedPasswordField;
|
||||
|
@ -77,10 +77,11 @@ public class PasswordView extends ActivatableView<GridPane, Void> {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
private PasswordView(WalletsManager walletsManager, PasswordValidator passwordValidator, Navigation navigation) {
|
||||
private PasswordView(CoreAccountService accountService, WalletsManager walletsManager, PasswordValidator passwordValidator, Navigation navigation) {
|
||||
this.walletsManager = walletsManager;
|
||||
this.passwordValidator = passwordValidator;
|
||||
this.navigation = navigation;
|
||||
this.accountService = accountService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,41 +142,38 @@ public class PasswordView extends ActivatableView<GridPane, Void> {
|
|||
deriveStatusLabel.setText(Res.get("password.deriveKey"));
|
||||
busyAnimation.play();
|
||||
|
||||
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
|
||||
ScryptUtil.deriveKeyWithScrypt(keyCrypterScrypt, password, aesKey -> {
|
||||
deriveStatusLabel.setText("");
|
||||
busyAnimation.stop();
|
||||
|
||||
if (walletsManager.areWalletsEncrypted()) {
|
||||
if (walletsManager.checkAESKey(aesKey)) {
|
||||
walletsManager.decryptWallets(aesKey);
|
||||
new Popup()
|
||||
.feedback(Res.get("password.walletDecrypted"))
|
||||
.show();
|
||||
backupWalletAndResetFields();
|
||||
} else {
|
||||
pwButton.setDisable(false);
|
||||
new Popup()
|
||||
.warning(Res.get("password.wrongPw"))
|
||||
.show();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
walletsManager.encryptWallets(keyCrypterScrypt, aesKey);
|
||||
new Popup()
|
||||
.feedback(Res.get("password.walletEncrypted"))
|
||||
.show();
|
||||
backupWalletAndResetFields();
|
||||
walletsManager.clearBackup();
|
||||
} catch (Throwable t) {
|
||||
new Popup()
|
||||
.warning(Res.get("password.walletEncryptionFailed"))
|
||||
.show();
|
||||
}
|
||||
if (walletsManager.areWalletsEncrypted()) {
|
||||
try {
|
||||
accountService.changePassword(password, null);
|
||||
new Popup()
|
||||
.feedback(Res.get("password.walletDecrypted"))
|
||||
.show();
|
||||
backupWalletAndResetFields();
|
||||
} catch (Throwable t) {
|
||||
pwButton.setDisable(false);
|
||||
new Popup()
|
||||
.warning(Res.get("password.wrongPw"))
|
||||
.show();
|
||||
}
|
||||
setText();
|
||||
updatePasswordListeners();
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
accountService.changePassword(accountService.getPassword(), password);
|
||||
new Popup()
|
||||
.feedback(Res.get("password.walletEncrypted"))
|
||||
.show();
|
||||
backupWalletAndResetFields();
|
||||
walletsManager.clearBackup();
|
||||
} catch (Throwable t) {
|
||||
new Popup()
|
||||
.warning(Res.get("password.walletEncryptionFailed"))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
setText();
|
||||
updatePasswordListeners();
|
||||
|
||||
deriveStatusLabel.setText("");
|
||||
busyAnimation.stop();
|
||||
}
|
||||
|
||||
private void backupWalletAndResetFields() {
|
||||
|
|
|
@ -218,7 +218,7 @@ public class SeedWordsView extends ActivatableView<GridPane, Void> {
|
|||
}
|
||||
|
||||
private void askForPassword() {
|
||||
walletPasswordWindow.headLine(Res.get("account.seed.enterPw")).onAesKey(aesKey -> {
|
||||
walletPasswordWindow.headLine(Res.get("account.seed.enterPw")).onSuccess(() -> {
|
||||
initSeedWords(xmrWalletService.getWallet().getMnemonic());
|
||||
showSeedScreen();
|
||||
}).hideForgotPasswordButton().show();
|
||||
|
|
|
@ -121,14 +121,7 @@ public final class BtcEmptyWalletWindow extends Overlay<BtcEmptyWalletWindow> {
|
|||
emptyWalletButton.setDisable(!isBalanceSufficient && addressInputTextField.getText().length() > 0);
|
||||
emptyWalletButton.setOnAction(e -> {
|
||||
if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) {
|
||||
if (btcWalletService.isEncrypted()) {
|
||||
walletPasswordWindow
|
||||
.onAesKey(this::doEmptyWallet)
|
||||
.onClose(this::blurAgain)
|
||||
.show();
|
||||
} else {
|
||||
doEmptyWallet(null);
|
||||
}
|
||||
log.warn(getClass().getSimpleName() + ".addContent() needs updated for XMR");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import bisq.core.btc.wallet.BtcWalletService;
|
|||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import bisq.core.support.dispute.agent.DisputeAgentLookupMap;
|
||||
import bisq.core.support.dispute.arbitration.ArbitrationManager;
|
||||
import bisq.core.trade.Contract;
|
||||
import bisq.core.trade.Trade;
|
||||
|
|
|
@ -25,18 +25,15 @@ import bisq.desktop.main.SharedPresentation;
|
|||
import bisq.desktop.main.overlays.Overlay;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
import bisq.desktop.util.Layout;
|
||||
import bisq.desktop.util.Transitions;
|
||||
|
||||
import bisq.core.api.CoreAccountService;
|
||||
import bisq.core.btc.wallet.WalletsManager;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.OpenOfferManager;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.crypto.ScryptUtil;
|
||||
import bisq.common.crypto.IncorrectPasswordException;
|
||||
import bisq.common.util.Tuple2;
|
||||
|
||||
import org.bitcoinj.crypto.KeyCrypterScrypt;
|
||||
import org.bitcoinj.crypto.MnemonicCode;
|
||||
import org.bitcoinj.crypto.MnemonicException;
|
||||
import org.bitcoinj.wallet.DeterministicSeed;
|
||||
|
@ -65,8 +62,6 @@ import javafx.beans.property.BooleanProperty;
|
|||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
|
@ -75,8 +70,6 @@ import java.time.ZoneOffset;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static bisq.desktop.util.FormBuilder.addPasswordTextField;
|
||||
|
@ -88,12 +81,13 @@ import static javafx.beans.binding.Bindings.createBooleanBinding;
|
|||
|
||||
@Slf4j
|
||||
public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
||||
private final CoreAccountService accountService;
|
||||
private final WalletsManager walletsManager;
|
||||
private final OpenOfferManager openOfferManager;
|
||||
private File storageDir;
|
||||
|
||||
private Button unlockButton;
|
||||
private AesKeyHandler aesKeyHandler;
|
||||
private WalletPasswordHandler passwordHandler;
|
||||
private PasswordTextField passwordTextField;
|
||||
private Button forgotPasswordButton;
|
||||
private Button restoreButton;
|
||||
|
@ -111,14 +105,16 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
|||
// Interface
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public interface AesKeyHandler {
|
||||
void onAesKey(KeyParameter aesKey);
|
||||
public interface WalletPasswordHandler {
|
||||
void onSuccess();
|
||||
}
|
||||
|
||||
@Inject
|
||||
private WalletPasswordWindow(WalletsManager walletsManager,
|
||||
private WalletPasswordWindow(CoreAccountService accountService,
|
||||
WalletsManager walletsManager,
|
||||
OpenOfferManager openOfferManager,
|
||||
@Named(Config.STORAGE_DIR) File storageDir) {
|
||||
this.accountService = accountService;
|
||||
this.walletsManager = walletsManager;
|
||||
this.openOfferManager = openOfferManager;
|
||||
this.storageDir = storageDir;
|
||||
|
@ -149,8 +145,8 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
|||
display();
|
||||
}
|
||||
|
||||
public WalletPasswordWindow onAesKey(AesKeyHandler aesKeyHandler) {
|
||||
this.aesKeyHandler = aesKeyHandler;
|
||||
public WalletPasswordWindow onSuccess(WalletPasswordHandler passwordHandler) {
|
||||
this.passwordHandler = passwordHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -213,27 +209,16 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
|
|||
unlockButton.setOnAction(e -> {
|
||||
String password = passwordTextField.getText();
|
||||
checkArgument(password.length() < 500, Res.get("password.tooLong"));
|
||||
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
|
||||
if (keyCrypterScrypt != null) {
|
||||
busyAnimation.play();
|
||||
deriveStatusLabel.setText(Res.get("password.deriveKey"));
|
||||
ScryptUtil.deriveKeyWithScrypt(keyCrypterScrypt, password, aesKey -> {
|
||||
if (walletsManager.checkAESKey(aesKey)) {
|
||||
if (aesKeyHandler != null)
|
||||
aesKeyHandler.onAesKey(aesKey);
|
||||
|
||||
hide();
|
||||
} else {
|
||||
busyAnimation.stop();
|
||||
deriveStatusLabel.setText("");
|
||||
|
||||
UserThread.runAfter(() -> new Popup()
|
||||
.warning(Res.get("password.wrongPw"))
|
||||
.onClose(this::blurAgain).show(), Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.error("wallet.getKeyCrypter() is null, that must not happen.");
|
||||
try {
|
||||
accountService.verifyPassword(password);
|
||||
if (passwordHandler != null) passwordHandler.onSuccess();
|
||||
hide();
|
||||
} catch (IncorrectPasswordException e2) {
|
||||
busyAnimation.stop();
|
||||
deriveStatusLabel.setText("");
|
||||
new Popup()
|
||||
.warning(Res.get("password.wrongPw"))
|
||||
.onClose(this::blurAgain).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -70,6 +70,10 @@ public class ImageUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static Image getImageByPath(String imagePath) {
|
||||
return getImageByUrl("/images/" + imagePath);
|
||||
}
|
||||
|
||||
// determine if this is a MacOS retina display
|
||||
// https://stackoverflow.com/questions/20767708/how-do-you-detect-a-retina-display-in-java#20767802
|
||||
public static boolean isRetina() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue