Skip to content

Commit

Permalink
Merge pull request #1064 from HenrikJannsen/add_simulation_tool_for_r…
Browse files Browse the repository at this point in the history
…eputation

Add simulation tool for reputation
  • Loading branch information
alvasw authored Aug 1, 2023
2 parents 115b28f + 294f4e9 commit 3512833
Show file tree
Hide file tree
Showing 32 changed files with 939 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ private VBox getInfoBox(String title, boolean smaller) {
Label titleLabel = new Label(title.toUpperCase());
titleLabel.getStyleClass().addAll("bisq-text-4", "bisq-text-grey-9", "font-semi-bold");
Label contentLabel = new Label();
contentLabel.setWrapText(true);

contentLabel.getStyleClass().addAll(smaller ? "bisq-text-7" : "bisq-text-6", "wrap-text");
contentLabel.getStyleClass().addAll(smaller ? "bisq-text-7" : "bisq-text-6");
VBox box = new VBox(2, titleLabel, contentLabel);
VBox.setMargin(box, new Insets(2, 0, 0, 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private View(Model model, Controller controller) {
root.setPrefWidth(OverlayModel.WIDTH);

Label headline = new Label(Res.get("chat.reportToModerator.headline"));
headline.getStyleClass().addAll("bisq-text-headline-2", "wrap-text");
headline.getStyleClass().addAll("bisq-text-headline-2");

Label info = new Label(Res.get("chat.reportToModerator.info"));
info.setWrapText(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private Pair<VBox, Button> getWidgetBox(String headline,
String imageId3,
String buttonLabel) {
Label headlineLabel = new Label(headline);
headlineLabel.getStyleClass().addAll("bisq-text-headline-2", "wrap-text");
headlineLabel.getStyleClass().addAll("bisq-text-headline-2");
headlineLabel.setWrapText(true);

Button button = new Button(buttonLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ReputationView(ReputationModel model,

Label info = new Label(Res.get("user.reputation.info"));
info.setWrapText(true);
info.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");
info.setMinHeight(220);

burnBsqButton = new Button(Res.get("user.reputation.burnBsq"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public AccountAgeTab1View(AccountAgeTab1Model model,

Label info = new Label(Res.get("user.reputation.accountAge.info"));
info.setWrapText(true);
info.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");

Label headline2 = new Label(Res.get("user.reputation.accountAge.infoHeadline2"));
headline2.getStyleClass().add("bisq-text-headline-2");

Label info2 = new Label(Res.get("user.reputation.accountAge.info2"));
info2.setWrapText(true);
info2.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info2.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");

nextButton = new Button(Res.get("action.next"));
nextButton.setDefaultButton(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* 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.content.user.reputation.accountAge.tab2;

import bisq.desktop.components.controls.MaterialTextField;
import bisq.desktop.main.content.user.reputation.components.AgeSlider;
import bisq.i18n.Res;
import bisq.user.reputation.AccountAgeService;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

public class AccountAgeScoreSimulation {

private final Controller controller;

public AccountAgeScoreSimulation() {
controller = new Controller();
}

public VBox getViewRoot() {
return controller.getView().getRoot();
}

@Slf4j
public static class Controller implements bisq.desktop.common.view.Controller {
@Getter
private final View view;
private final Model model;
private Subscription agePin, ageAsStringPin, scorePin;

private Controller() {
model = new Model();
view = new View(model, this);

model.getAge().set(0);
model.getAgeAsString().set("0");
}

@Override
public void onActivate() {
agePin = EasyBind.subscribe(model.getAge(), age -> model.getAgeAsString().set(String.valueOf(age)));
ageAsStringPin = EasyBind.subscribe(model.getAgeAsString(), ageAsString -> {
try {
model.getAge().set(Integer.parseInt(ageAsString));
} catch (Exception e) {
}
});

scorePin = EasyBind.subscribe(model.getAge(), age -> model.getScore().set(calculateSimScore(age)));
}

@Override
public void onDeactivate() {
agePin.unsubscribe();
ageAsStringPin.unsubscribe();
scorePin.unsubscribe();
}

private String calculateSimScore(Number age) {
try {
long ageInDays = age.intValue();
long totalScore = AccountAgeService.doCalculateScore(ageInDays);
return String.valueOf(totalScore);
} catch (Exception e) {
return "";
}
}
}

@Getter
private static class Model implements bisq.desktop.common.view.Model {
private final IntegerProperty age = new SimpleIntegerProperty();
private final StringProperty ageAsString = new SimpleStringProperty();
private final StringProperty score = new SimpleStringProperty();
}

private static class View extends bisq.desktop.common.view.View<VBox, Model, Controller> {
private final AgeSlider simAgeSlider;
private final MaterialTextField simScore;
private final MaterialTextField ageField;

private View(Model model,
Controller controller) {
super(new VBox(10), model, controller);

Label simHeadline = new Label(Res.get("user.reputation.sim.headline"));
simHeadline.getStyleClass().addAll("bisq-text-1");
ageField = getInputField("user.reputation.sim.age");
simAgeSlider = new AgeSlider(0, 400, 0);
simScore = getField(Res.get("user.reputation.sim.score"));
VBox.setMargin(simAgeSlider.getView().getRoot(), new Insets(15, 0, 0, 0));
root.getChildren().addAll(simHeadline,
ageField,
simAgeSlider.getView().getRoot(),
simScore);
}

@Override
protected void onViewAttached() {
simAgeSlider.valueProperty().bindBidirectional(model.getAge());
ageField.textProperty().bindBidirectional(model.getAgeAsString());
simScore.textProperty().bind(model.getScore());
}

@Override
protected void onViewDetached() {
simAgeSlider.valueProperty().unbindBidirectional(model.getAge());
ageField.textProperty().unbindBidirectional(model.getAgeAsString());
simScore.textProperty().unbind();
}

private MaterialTextField getField(String description) {
MaterialTextField field = new MaterialTextField(description);
field.setEditable(false);
field.setMinWidth(400);
field.setMaxWidth(400);
return field;
}

private MaterialTextField getInputField(String key) {
MaterialTextField field = new MaterialTextField(Res.get(key), Res.get(key + ".prompt"));
field.setMinWidth(400);
field.setMinWidth(400);
field.setMaxWidth(400);
return field;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class AccountAgeTab2Controller implements Controller {

public AccountAgeTab2Controller(ServiceProvider serviceProvider) {
AccountAgeTab2Model model = new AccountAgeTab2Model();
view = new AccountAgeTab2View(model, this);
AccountAgeScoreSimulation simulation = new AccountAgeScoreSimulation();
view = new AccountAgeTab2View(model, this, simulation.getViewRoot());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.desktop.main.content.user.reputation.accountAge.tab2;

import bisq.desktop.common.threading.UIThread;
import bisq.desktop.common.view.View;
import bisq.desktop.components.containers.Spacer;
import bisq.desktop.components.controls.MaterialTextField;
Expand All @@ -36,8 +37,7 @@ public class AccountAgeTab2View extends View<VBox, AccountAgeTab2Model, AccountA
private final Button backButton, nextButton;
private final Hyperlink learnMore;

public AccountAgeTab2View(AccountAgeTab2Model model,
AccountAgeTab2Controller controller) {
public AccountAgeTab2View(AccountAgeTab2Model model, AccountAgeTab2Controller controller, VBox simulation) {
super(new VBox(), model, controller);

root.setSpacing(20);
Expand All @@ -48,9 +48,13 @@ public AccountAgeTab2View(AccountAgeTab2Model model,

Label info = new Label(Res.get("user.reputation.accountAge.score.info"));
info.setWrapText(true);
info.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");

VBox formula = new VBox(10, getField("weight", String.valueOf(AccountAgeService.WEIGHT)), getField("totalScore"));
Label formulaHeadline = new Label(Res.get("user.reputation.score.formulaHeadline"));
formulaHeadline.getStyleClass().addAll("bisq-text-1");
VBox formulaBox = new VBox(10, formulaHeadline, getField("weight", String.valueOf(AccountAgeService.WEIGHT)), getField("totalScore"));

HBox hBox = new HBox(20, formulaBox, simulation);

backButton = new Button(Res.get("action.back"));

Expand All @@ -64,14 +68,15 @@ public AccountAgeTab2View(AccountAgeTab2Model model,

VBox.setMargin(buttons, new Insets(10, 0, 0, 0));
VBox.setMargin(headline, new Insets(10, 0, 0, 0));
root.getChildren().addAll(headline, info, formula, buttons);
root.getChildren().addAll(headline, info, hBox, buttons);
}

@Override
protected void onViewAttached() {
backButton.setOnAction(e -> controller.onBack());
nextButton.setOnAction(e -> controller.onNext());
learnMore.setOnAction(e -> controller.onLearnMore());
UIThread.runOnNextRenderFrame(root::requestFocus);
}

@Override
Expand All @@ -89,6 +94,7 @@ private MaterialTextField getField(String key, String value) {
MaterialTextField field = new MaterialTextField(Res.get("user.reputation." + key));
field.setEditable(false);
field.setText(value);
field.setMinWidth(400);
field.setMaxWidth(400);
return field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AccountAgeTab3View(AccountAgeTab3Model model,

Label info = new Label(Res.get("user.reputation.accountAge.howTo"));
info.setWrapText(true);
info.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");

Label userProfileSelectLabel = new Label(Res.get("user.bondedRoles.userProfile.select").toUpperCase());
userProfileSelectLabel.getStyleClass().add("bisq-text-4");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public BondedReputationTab1View(BondedReputationTab1Model model,

Label info = new Label(Res.get("user.reputation.bond.info"));
info.setWrapText(true);
info.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");

Label headline2 = new Label(Res.get("user.reputation.bond.infoHeadline2"));
headline2.getStyleClass().add("bisq-text-headline-2");

Label info2 = new Label(Res.get("user.reputation.bond.info2"));
info2.setWrapText(true);
info2.getStyleClass().addAll("bisq-text-13", "wrap-text", "bisq-line-spacing-01");
info2.getStyleClass().addAll("bisq-text-13", "bisq-line-spacing-01");

nextButton = new Button(Res.get("action.next"));
nextButton.setDefaultButton(true);
Expand Down
Loading

0 comments on commit 3512833

Please sign in to comment.