Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Sep 16, 2024
1 parent 8aef37c commit 3a68d1f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

import java.util.Optional;

import static bisq.bisq_easy.BisqEasyTradeAmountLimits.*;
import static bisq.presentation.formatters.AmountFormatter.formatAmountWithCode;

@Slf4j
public class TakeOfferAmountController implements Controller {
private final TakeOfferAmountModel model;
Expand Down Expand Up @@ -83,7 +86,7 @@ public void init(BisqEasyOffer bisqEasyOffer, Optional<Monetary> optionalReputat
Monetary maxAmount;
if (optionalReputationBasedQuoteSideAmount.isPresent()) {
// Range amounts seller case with provided reputationBasedQuoteSideAmount
Monetary reputationBasedQuoteSideAmount = optionalReputationBasedQuoteSideAmount.get();
Monetary reputationBasedQuoteSideAmount = optionalReputationBasedQuoteSideAmount.get().round(0);
maxAmount = reputationBasedQuoteSideAmount.isGreaterThan(offersQuoteSideMaxOrFixedAmount)
? offersQuoteSideMaxOrFixedAmount
: reputationBasedQuoteSideAmount;
Expand Down Expand Up @@ -169,20 +172,22 @@ private void applyQuoteSideMinMaxRange(Monetary minRangeValue, Monetary maxRange
amountComponent.setMinMaxRange(minRangeValue, maxRangeValue);

BisqEasyOffer bisqEasyOffer = model.getBisqEasyOffer();
Market market = bisqEasyOffer.getMarket();
if (bisqEasyOffer.getTakersDirection().isBuy()) {
// Buyer case
model.setAmountLimitInfoLink(Res.get("bisqEasy.takeOffer.amount.buyer.limitInfo.learnMore"));
model.setLinkToWikiText(Res.get("bisqEasy.takeOffer.amount.buyer.limitInfo.overlay.linkToWikiText"));
model.getAmountLimitInfoAmount().set("");

if (model.getSellersReputationBasedQuoteSideAmount() == null) {
long sellersReputationScore = reputationService.getReputationScore(bisqEasyOffer.getMakersUserProfileId()).getTotalScore();
model.setSellersReputationScore(sellersReputationScore);
Monetary reputationBasedQuoteSideAmount = BisqEasyTradeAmountLimits.getReputationBasedQuoteSideAmount(marketPriceService, bisqEasyOffer.getMarket(), sellersReputationScore)
Monetary reputationBasedQuoteSideAmount = BisqEasyTradeAmountLimits.getReputationBasedQuoteSideAmount(marketPriceService, market, sellersReputationScore)
.orElseThrow().round(0);
model.setSellersReputationBasedQuoteSideAmount(reputationBasedQuoteSideAmount);
}
long sellersReputationScore = model.getSellersReputationScore();
Monetary reputationBasedQuoteSideAmount = model.getSellersReputationBasedQuoteSideAmount();
Monetary reputationBasedQuoteSideAmount = model.getSellersReputationBasedQuoteSideAmount().round(0);

if (reputationBasedQuoteSideAmount.isLessThan(maxRangeValue)) {
model.getIsAmountLimitInfoVisible().set(true);
Expand All @@ -203,19 +208,47 @@ private void applyQuoteSideMinMaxRange(Monetary minRangeValue, Monetary maxRange
model.getIsAmountLimitInfoVisible().set(false);
}
} else {
// Seller case
model.setLinkToWikiText(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.linkToWikiText"));
String myProfileId = userIdentityService.getSelectedUserIdentity().getUserProfile().getId();
long myReputationScore = reputationService.getReputationScore(myProfileId).getTotalScore();
BisqEasyTradeAmountLimits.getReputationBasedQuoteSideAmount(marketPriceService, bisqEasyOffer.getMarket(), myReputationScore)
Monetary quoteSideAmount = amountComponent.getQuoteSideAmount().get();

BisqEasyTradeAmountLimits.getReputationBasedQuoteSideAmount(marketPriceService, market, myReputationScore)
.ifPresent(myReputationBasedQuoteSideAmount -> {
myReputationBasedQuoteSideAmount = myReputationBasedQuoteSideAmount.round(0);
model.getIsAmountHyperLinkDisabled().set(myReputationBasedQuoteSideAmount.isGreaterThan(maxRangeValue));
amountComponent.setRightMarkerQuoteSideValue(myReputationBasedQuoteSideAmount);
String formattedAmount = AmountFormatter.formatAmountWithCode(myReputationBasedQuoteSideAmount);
model.getIsAmountLimitInfoVisible().set(true);
model.getAmountLimitInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo", myReputationScore));
model.getAmountLimitInfoAmount().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfoAmount", formattedAmount));
model.setAmountLimitInfoLink(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.link"));
model.getAmountLimitInfoOverlayInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.info.sufficientScore", myReputationScore, formattedAmount)+"\n\n");

Monetary amountWithoutReputationNeeded = BisqEasyTradeAmountLimits.usdToFiat(marketPriceService, market, MAX_USD_TRADE_AMOUNT_WITHOUT_REPUTATION)
.orElseThrow().round(0);
String formattedAmountWithoutReputationNeeded = formatAmountWithCode(amountWithoutReputationNeeded);
if (myReputationBasedQuoteSideAmount.isLessThan(maxRangeValue)) {
if (myReputationScore <= MIN_REPUTAION_SCORE) {
model.getAmountLimitInfo().set(Res.get("bisqEasy.takeOffer.amount.seller.limitInfo.scoreTooLow", myReputationScore));
model.getAmountLimitInfoOverlayInfo().set(Res.get("bisqEasy.takeOffer.amount.seller.limitInfo.overlay.info.scoreTooLow", formattedAmountWithoutReputationNeeded, myReputationScore) + "\n\n");
} else {
model.getAmountLimitInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.sufficientScore", myReputationScore));
model.getAmountLimitInfoOverlayInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.wizard.limitInfo.overlay.info", myReputationScore, formattedAmount));
}
} else {
Monetary offersQuoteSideMaxOrFixedAmount = OfferAmountUtil.findQuoteSideMaxOrFixedAmount(marketPriceService, bisqEasyOffer).orElseThrow().round(0);
if (myReputationBasedQuoteSideAmount.isGreaterThan(offersQuoteSideMaxOrFixedAmount)) {
model.getAmountLimitInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.sufficientScore", myReputationScore));
model.getAmountLimitInfoOverlayInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.info.sufficientScore", myReputationScore, formattedAmount) + "\n\n");
} else if (myReputationScore <= MIN_REPUTAION_SCORE) {
model.getAmountLimitInfoAmount().set(null);
model.getAmountLimitInfo().set(Res.get("bisqEasy.takeOffer.amount.seller.limitInfo.lowToleratedAmount", formattedAmountWithoutReputationNeeded));
model.getAmountLimitInfoOverlayInfo().set(Res.get("bisqEasy.takeOffer.amount.seller.limitInfo.overlay.info.scoreTooLow", formattedAmountWithoutReputationNeeded, myReputationScore) + "\n\n");
} else {
model.getAmountLimitInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.sufficientScore", myReputationScore));
model.getAmountLimitInfoOverlayInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.wizard.limitInfo.overlay.info", myReputationScore, formattedAmount));
}
}
});
applyReputationBasedQuoteSideAmount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@Slf4j
public class TakeOfferAmountView extends View<StackPane, TakeOfferAmountModel, TakeOfferAmountController> {
private final Label headlineLabel, amountLimitInfo, amountLimitInfoOverlayInfo, linkToWikiText, warningIcon;
private final Hyperlink amountLimitInfoAmount, showOverlayHyperLink, linkToWiki;
private final Hyperlink amountLimitInfoAmount, learnMore, linkToWiki;
private final VBox content, amountLimitInfoOverlay;
private final Button closeOverlayButton;
private Subscription isAmountLimitInfoVisiblePin;
Expand All @@ -64,15 +64,15 @@ public TakeOfferAmountView(TakeOfferAmountModel model,
amountLimitInfoAmount = new Hyperlink();
amountLimitInfoAmount.getStyleClass().add("trade-wizard-amount-limit-info-overlay-link");

showOverlayHyperLink = new Hyperlink();
showOverlayHyperLink.getStyleClass().add("trade-wizard-amount-limit-info-overlay-link");
learnMore = new Hyperlink();
learnMore.getStyleClass().add("trade-wizard-amount-limit-info-overlay-link");

warningIcon = new Label();
Icons.getIconForLabel(AwesomeIcon.WARNING_SIGN, warningIcon, "1.15em");
warningIcon.getStyleClass().add("overlay-icon-warning");

HBox.setMargin(warningIcon, new Insets(0, 5, 0, 0));
HBox amountLimitInfoHBox = new HBox(5, warningIcon, amountLimitInfo, amountLimitInfoAmount, showOverlayHyperLink);
HBox amountLimitInfoHBox = new HBox(5, warningIcon, amountLimitInfo, amountLimitInfoAmount, learnMore);
amountLimitInfoHBox.setAlignment(Pos.BASELINE_CENTER);

// VBox.setMargin(headlineLabel, new Insets(-30, 0, 10, 0));
Expand All @@ -96,7 +96,7 @@ public TakeOfferAmountView(TakeOfferAmountModel model,
protected void onViewAttached() {
warningIcon.visibleProperty().bind(model.getIsWarningIconVisible());
headlineLabel.setText(model.getHeadline());
showOverlayHyperLink.setText(model.getAmountLimitInfoLink());
learnMore.setText(model.getAmountLimitInfoLink());
linkToWikiText.setText(model.getLinkToWikiText());

amountLimitInfo.textProperty().bind(model.getAmountLimitInfo());
Expand All @@ -106,8 +106,8 @@ protected void onViewAttached() {

amountLimitInfoAmount.managedProperty().bind(model.getIsAmountLimitInfoVisible().and(model.getAmountLimitInfoAmount().isEmpty().not()));
amountLimitInfoAmount.visibleProperty().bind(amountLimitInfoAmount.managedProperty());
showOverlayHyperLink.managedProperty().bind(model.getIsAmountLimitInfoVisible());
showOverlayHyperLink.visibleProperty().bind(model.getIsAmountLimitInfoVisible());
learnMore.managedProperty().bind(model.getIsAmountLimitInfoVisible());
learnMore.visibleProperty().bind(model.getIsAmountLimitInfoVisible());

isAmountLimitInfoVisiblePin = EasyBind.subscribe(model.getIsAmountLimitInfoOverlayVisible(),
isAmountLimitInfoVisible -> {
Expand All @@ -126,7 +126,7 @@ protected void onViewAttached() {
});

amountLimitInfoAmount.setOnAction(e -> controller.onSetReputationBasedAmount());
showOverlayHyperLink.setOnAction(e -> controller.onShowAmountLimitInfoOverlay());
learnMore.setOnAction(e -> controller.onShowAmountLimitInfoOverlay());
linkToWiki.setOnAction(e -> controller.onOpenWiki(linkToWiki.getText()));
closeOverlayButton.setOnAction(e -> controller.onCloseAmountLimitInfoOverlay());
}
Expand All @@ -141,13 +141,13 @@ protected void onViewDetached() {

amountLimitInfoAmount.managedProperty().unbind();
amountLimitInfoAmount.visibleProperty().unbind();
showOverlayHyperLink.managedProperty().unbind();
showOverlayHyperLink.visibleProperty().unbind();
learnMore.managedProperty().unbind();
learnMore.visibleProperty().unbind();

isAmountLimitInfoVisiblePin.unsubscribe();

amountLimitInfoAmount.setOnAction(null);
showOverlayHyperLink.setOnAction(null);
learnMore.setOnAction(null);
linkToWiki.setOnAction(null);
closeOverlayButton.setOnAction(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private void quoteSideAmountsChanged(boolean maxAmountChanged) {
}
} else {
// Seller
Monetary reputationBasedMaxAmount = model.getReputationBasedMaxAmount();
Monetary reputationBasedMaxAmount = model.getReputationBasedMaxAmount().round(0);
if (model.isCreateOfferMode()) {
// Create offer
long myReputationScore = model.getMyReputationScore();
Expand Down
14 changes: 7 additions & 7 deletions i18n/src/main/resources/bisq_easy.properties
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bisqEasy.tradeWizard.amount.limitInfo.overlay.headline=Reputation-based trade am
bisqEasy.tradeWizard.amount.limitInfo.overlay.close=Close overlay

bisqEasy.tradeWizard.amount.seller.wizard.numMatchingOffers.info=There {0} matching the chosen trade amount.
bisqEasy.tradeWizard.amount.seller.wizard.limitInfo=With your reputation score of {0} you can trade up to
bisqEasy.tradeWizard.amount.seller.wizard.limitInfo=With your reputation score of {0}, you can trade up to
bisqEasy.tradeWizard.amount.seller.wizard.limitInfo.overlay.info=With a reputation score of {0}, you provide security for trades up to {1}.\n\n\
You can find information on how to increase your reputation at ''Reputation/Build Reputation''.

Expand All @@ -166,6 +166,12 @@ bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.info.scoreTooLow=Your reput
Buyers who consider to take your offer will receive a warning about potential risks when taking your offer.\n\n\
You can find information on how to increase your reputation at ''Reputation/Build Reputation''.

bisqEasy.takeOffer.amount.seller.limitInfo.lowToleratedAmount=As the trade amount is below {0}, reputation requirements are relaxed.
bisqEasy.takeOffer.amount.seller.limitInfo.scoreTooLow=As your reputation score is only {0} your trade amount is restricted to
bisqEasy.takeOffer.amount.seller.limitInfo.overlay.info.scoreTooLow=For amounts up to {0} the reputation requirements are relaxed.\n\n\
Your reputation score of {1} doesn''t offer sufficient security for the buyer. However, given the low trade amount the buyer accepted to take the risk.\n\n\
You can find information on how to increase your reputation at ''Reputation/Build Reputation''.

bisqEasy.tradeWizard.amount.seller.limitInfo.sufficientScore=Your reputation score of {0} provides security for offers up to
bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.info.sufficientScore=With a reputation score of {0}, you provide security for trades up to {1}.

Expand All @@ -174,23 +180,17 @@ bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.info.inSufficientScore=With
You can still create such offers, but buyers will be warned about potential risks when attempting to take your offer.\n\n\
You can find information on how to increase your reputation at ''Reputation/Build Reputation''.

bisqEasy.tradeWizard.amount.seller.limitInfo=Your reputation score of {0} provides security for offers up to
bisqEasy.tradeWizard.amount.seller.limitInfoAmount={0}.
bisqEasy.tradeWizard.amount.seller.limitInfo.link=Learn more



bisqEasy.tradeWizard.amount.seller.limitInfo.overlay.linkToWikiText=For more details about the reputation system, visit the Bisq Wiki at:

bisqEasy.tradeWizard.amount.seller.limitInfo.noReputationNeededForMaxOrFixedAmount=For amounts up to {0} no reputation is required.
bisqEasy.tradeWizard.amount.seller.limitInfo.noReputationNeededForMaxOrFixedAmount.overlay.info.scoreTooLow=For amounts up to {0} the reputation requirements are relaxed.\n\n\
Your reputation score of {1} doesn''t offer sufficient security for buyers. However, given the low amount involved, \
buyers might still consider accepting the offer once they are made aware of the associated risks.\n\n\
You can find information on how to increase your reputation at ''Reputation/Build Reputation''.
bisqEasy.tradeWizard.amount.seller.limitInfo.noReputationNeededForMaxOrFixedAmount.overlay.info.sufficientScore=For amounts up to {0} the reputation requirements are relaxed.\n\
Your reputation score of {1} can provide security for trades up to {2}.\n\n\
For offers exceeding this amount, buyers will receive a warning about potential risks when taking your offer.\n\n\
You can find information on how to increase your reputation at ''Reputation/Build Reputation''.


bisqEasy.tradeWizard.amount.buyer.limitInfo.learnMore=Learn more
Expand Down

0 comments on commit 3a68d1f

Please sign in to comment.