Merge pull request #7090 from HenrikJannsen/Improve-export-account-reputation-process-for-Bisq-2

Improve export account reputation process for bisq 2
This commit is contained in:
Alejandro García 2024-05-09 18:56:48 +00:00 committed by GitHub
commit 0a5a0f316d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 140 additions and 25 deletions

View File

@ -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

View File

@ -75,6 +75,7 @@ import bisq.desktop.components.paymentmethods.WeChatPayForm;
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,50 @@ public class FiatAccountsView extends PaymentAccountsView<GridPane, FiatAccounts
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))
.actionButtonText(Res.get("shared.nextStep"))
.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))
.actionButtonText(Res.get("shared.nextStep"))
.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 +586,7 @@ public class FiatAccountsView extends PaymentAccountsView<GridPane, FiatAccounts
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<ImportBisq2ProfileIdWindow> {
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);
}
}