From 13f124566cd9facb64939149eb8df1d76ae96527 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 2 May 2024 16:04:20 +0700 Subject: [PATCH 1/2] Apply patch from @jmacxx (https://github.com/bisq-network/bisq/issues/7066#issuecomment-2087336098) Signed-off-by: HenrikJannsen --- .../resources/i18n/displayStrings.properties | 1 + .../fiataccounts/FiatAccountsView.java | 63 +++++++----- .../windows/ImportBisq2ProfileIdWindow.java | 97 +++++++++++++++++++ 3 files changed, 136 insertions(+), 25 deletions(-) create mode 100644 desktop/src/main/java/bisq/desktop/main/overlays/windows/ImportBisq2ProfileIdWindow.java diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 4fb0b29e4da..3cadf6ce651 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -1942,6 +1942,7 @@ account.fiat.signedWitness=Export signed witness for Bisq 2 account.fiat.signedWitness.popup=Your 'signed account age witness' and Bisq 2 profile ID got signed and the data is copied \ to the clipboard.\n\n\This is the data in json format:\n\n\{0}\n\n\ Go back to Bisq 2 and follow the instructions there. +account.fiat.bisq2profileId=Profile ID from Bisq 2 account.backup.title=Backup wallet account.backup.location=Backup location account.backup.selectLocation=Select backup location diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java index bbf46734951..b8dba522364 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java @@ -75,6 +75,7 @@ import bisq.desktop.components.paymentmethods.WesternUnionForm; import bisq.desktop.main.account.content.PaymentAccountsView; import bisq.desktop.main.overlays.popups.Popup; +import bisq.desktop.main.overlays.windows.ImportBisq2ProfileIdWindow; import bisq.desktop.util.FormBuilder; import bisq.desktop.util.GUIUtil; import bisq.desktop.util.Layout; @@ -530,34 +531,46 @@ protected void onSelectAccount(PaymentAccount previous, PaymentAccount current) private void onExportAccountAgeForBisq2(PaymentAccount paymentAccount) { String prefix = "BISQ2_ACCOUNT_AGE:"; - try { - String profileId = getProfileIdFromClipBoard(prefix); - AccountAgeWitnessUtils.signAccountAgeAndBisq2ProfileId(accountAgeWitnessService, paymentAccount, keyRing, profileId) - .ifPresent(json -> { - Utilities.copyToClipboard(prefix + json); - new Popup().information(Res.get("account.fiat.exportAccountAge.popup", json)) - .width(900).show(); - }); - } catch (Exception e) { - String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); - new Popup().warning(error).show(); - } + ImportBisq2ProfileIdWindow popup = new ImportBisq2ProfileIdWindow(); + popup.headLine(Res.get("account.fiat.exportAccountAge")) + .setProfileId(getProfileIdFromClipBoard(prefix)) + .onAction(() -> { + try { + AccountAgeWitnessUtils.signAccountAgeAndBisq2ProfileId( + accountAgeWitnessService, paymentAccount, keyRing, popup.getProfileId()) + .ifPresent(json -> { + Utilities.copyToClipboard(prefix + json); + new Popup().information(Res.get("account.fiat.exportAccountAge.popup", json)) + .width(900).show(); + }); + } catch (Exception e) { + String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); + new Popup().warning(error).show(); + } + }) + .show(); } private void onExportSignedWitnessForBisq2(PaymentAccount paymentAccount) { String prefix = "BISQ2_SIGNED_WITNESS:"; - try { - String profileId = getProfileIdFromClipBoard(prefix); - AccountAgeWitnessUtils.signSignedWitnessAndBisq2ProfileId(accountAgeWitnessService, paymentAccount, keyRing, profileId) - .ifPresent(json -> { - Utilities.copyToClipboard(prefix + json); - new Popup().information(Res.get("account.fiat.signedWitness.popup", json)) - .width(900).show(); - }); - } catch (Exception e) { - String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); - new Popup().warning(error).show(); - } + ImportBisq2ProfileIdWindow popup = new ImportBisq2ProfileIdWindow(); + popup.headLine(Res.get("account.fiat.signedWitness")) + .setProfileId(getProfileIdFromClipBoard(prefix)) + .onAction(() -> { + try { + AccountAgeWitnessUtils.signSignedWitnessAndBisq2ProfileId( + accountAgeWitnessService, paymentAccount, keyRing, popup.getProfileId()) + .ifPresent(json -> { + Utilities.copyToClipboard(prefix + json); + new Popup().information(Res.get("account.fiat.signedWitness.popup", json)) + .width(900).show(); + }); + } catch (Exception e) { + String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); + new Popup().warning(error).show(); + } + }) + .show(); } private String getProfileIdFromClipBoard(String prefix) { @@ -569,7 +582,7 @@ private String getProfileIdFromClipBoard(String prefix) { return profileId; } } - throw new RuntimeException("Clipboard text not in expected format. " + clipboardText); + return ""; // clipboard did not contain the expected hash, user will have option to enter it manually } diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/ImportBisq2ProfileIdWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/ImportBisq2ProfileIdWindow.java new file mode 100644 index 00000000000..33295d72950 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/ImportBisq2ProfileIdWindow.java @@ -0,0 +1,97 @@ +/* + * 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.overlays.windows; + +import bisq.desktop.components.InputTextField; +import bisq.desktop.main.overlays.Overlay; + +import bisq.core.locale.Res; +import bisq.core.util.validation.RegexValidator; + +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; + +import javafx.geometry.HPos; +import javafx.geometry.Insets; + +import lombok.Getter; + +import javax.annotation.Nullable; + +import static bisq.desktop.util.FormBuilder.addInputTextField; +import static javafx.beans.binding.Bindings.createBooleanBinding; + +public class ImportBisq2ProfileIdWindow extends Overlay { + + private String profileId; + private InputTextField profileIdTextField; + @Getter + private RegexValidator regexValidator; + + public ImportBisq2ProfileIdWindow() { + type = Type.Attention; + } + + public void show() { + width = 868; + createGridPane(); + addHeadLine(); + addContent(); + addButtons(); + + regexValidator = new RegexValidator(); + regexValidator.setPattern("[a-fA-F0-9]{40}"); + profileIdTextField.setValidator(regexValidator); + actionButton.disableProperty().bind( + createBooleanBinding(() -> !profileIdTextField.getValidator().validate(profileIdTextField.getText()).isValid, + profileIdTextField.textProperty())); + + applyStyles(); + display(); + } + + @Override + protected void createGridPane() { + gridPane = new GridPane(); + gridPane.setHgap(5); + gridPane.setVgap(5); + gridPane.setPadding(new Insets(64, 64, 64, 64)); + gridPane.setPrefWidth(width); + + ColumnConstraints columnConstraints1 = new ColumnConstraints(); + columnConstraints1.setHalignment(HPos.RIGHT); + columnConstraints1.setHgrow(Priority.SOMETIMES); + gridPane.getColumnConstraints().addAll(columnConstraints1); + } + + @Nullable + public String getProfileId() { + return profileIdTextField != null ? profileIdTextField.getText() : null; + } + + public ImportBisq2ProfileIdWindow setProfileId(String x) { + this.profileId = x; + return this; + } + + private void addContent() { + profileIdTextField = addInputTextField(gridPane, ++rowIndex, Res.get("account.fiat.bisq2profileId"), 10); + profileIdTextField.setText(profileId); + } +} From efdd9c68c430ee60f830f3ba4924061d70093a40 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 2 May 2024 16:10:45 +0700 Subject: [PATCH 2/2] Change button text Signed-off-by: HenrikJannsen --- .../account/content/fiataccounts/FiatAccountsView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java index b8dba522364..6c70db3ad62 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsView.java @@ -534,6 +534,7 @@ private void onExportAccountAgeForBisq2(PaymentAccount paymentAccount) { ImportBisq2ProfileIdWindow popup = new ImportBisq2ProfileIdWindow(); popup.headLine(Res.get("account.fiat.exportAccountAge")) .setProfileId(getProfileIdFromClipBoard(prefix)) + .actionButtonText(Res.get("shared.nextStep")) .onAction(() -> { try { AccountAgeWitnessUtils.signAccountAgeAndBisq2ProfileId( @@ -541,7 +542,8 @@ private void onExportAccountAgeForBisq2(PaymentAccount paymentAccount) { .ifPresent(json -> { Utilities.copyToClipboard(prefix + json); new Popup().information(Res.get("account.fiat.exportAccountAge.popup", json)) - .width(900).show(); + .width(900) + .show(); }); } catch (Exception e) { String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); @@ -556,6 +558,7 @@ private void onExportSignedWitnessForBisq2(PaymentAccount paymentAccount) { ImportBisq2ProfileIdWindow popup = new ImportBisq2ProfileIdWindow(); popup.headLine(Res.get("account.fiat.signedWitness")) .setProfileId(getProfileIdFromClipBoard(prefix)) + .actionButtonText(Res.get("shared.nextStep")) .onAction(() -> { try { AccountAgeWitnessUtils.signSignedWitnessAndBisq2ProfileId( @@ -563,7 +566,8 @@ private void onExportSignedWitnessForBisq2(PaymentAccount paymentAccount) { .ifPresent(json -> { Utilities.copyToClipboard(prefix + json); new Popup().information(Res.get("account.fiat.signedWitness.popup", json)) - .width(900).show(); + .width(900) + .show(); }); } catch (Exception e) { String error = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();