Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve export account reputation process for bisq 2 #7090

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -530,34 +531,50 @@ 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))
.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) {
Expand All @@ -569,7 +586,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
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading