Skip to content

Commit

Permalink
Merge pull request #3065 from axpoems/fix-max-amount-info
Browse files Browse the repository at this point in the history
Fix issues with max amount info
  • Loading branch information
axpoems authored Dec 29, 2024
2 parents 2397880 + f7c1f8c commit 8708605
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void applyQuoteSideMinMaxRange(Monetary minRangeValue, Monetary maxRange
amountSelectionController.setMaxOrFixedQuoteSideAmount(reputationBasedQuoteSideAmount);
String formattedAmount = AmountFormatter.formatAmountWithCode(reputationBasedQuoteSideAmount);

if (sellersReputationScore <= MIN_REPUTAION_SCORE) {
if (sellersReputationScore <= MIN_REPUTATION_SCORE) {
if (reputationBasedQuoteSideAmount.isLessThan(minRangeValue)) {
// Min amount not covered by security from reputation score
model.getAmountLimitInfo().set(Res.get("bisqEasy.takeOffer.amount.buyer.limitInfo.minAmountNotCovered", sellersReputationScore));
Expand Down Expand Up @@ -246,7 +246,7 @@ private void applyQuoteSideMinMaxRange(Monetary minRangeValue, Monetary maxRange
.orElseThrow().round(0);
String formattedAmountWithoutReputationNeeded = formatAmountWithCode(amountWithoutReputationNeeded);
if (myReputationBasedQuoteSideAmount.isLessThan(maxRangeValue)) {
if (myReputationScore <= MIN_REPUTAION_SCORE) {
if (myReputationScore <= MIN_REPUTATION_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");
Expand All @@ -259,7 +259,7 @@ private void applyQuoteSideMinMaxRange(Monetary minRangeValue, Monetary maxRange
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) {
} else if (myReputationScore <= MIN_REPUTATION_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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ private void quoteSideAmountsChanged(boolean maxAmountChanged) {
long requiredReputationScoreForMinAmount = BisqEasyTradeAmountLimits.findRequiredReputationScoreByFiatAmount(marketPriceService, usdBitcoinMarket, minQuoteSideAmount).orElse(0L);
long numPotentialTakersForMaxOrFixedAmount = reputationService.getScoreByUserProfileId().entrySet().stream()
.filter(e -> userIdentityService.findUserIdentity(e.getKey()).isEmpty())
.filter(e -> e.getValue() >= requiredReputationScoreForMaxOrFixedAmount || requiredReputationScoreForMaxOrFixedAmount <= MIN_REPUTAION_SCORE)
.filter(e -> e.getValue() >= requiredReputationScoreForMaxOrFixedAmount || requiredReputationScoreForMaxOrFixedAmount <= MIN_REPUTATION_SCORE)
.count();
long numPotentialTakersForMinAmount = reputationService.getScoreByUserProfileId().entrySet().stream()
.filter(e -> userIdentityService.findUserIdentity(e.getKey()).isEmpty())
.filter(e -> e.getValue() >= requiredReputationScoreForMinAmount || requiredReputationScoreForMinAmount <= MIN_REPUTAION_SCORE)
.filter(e -> e.getValue() >= requiredReputationScoreForMinAmount || requiredReputationScoreForMinAmount <= MIN_REPUTATION_SCORE)
.count();
model.getAmountLimitInfoLeadLine().set(null);
Monetary amountWithoutReputationNeeded = BisqEasyTradeAmountLimits.usdToFiat(marketPriceService, model.getMarket(), MAX_USD_TRADE_AMOUNT_WITHOUT_REPUTATION)
Expand Down Expand Up @@ -597,7 +597,7 @@ private void quoteSideAmountsChanged(boolean maxAmountChanged) {
long myReputationScore = model.getMyReputationScore();
String formattedReputationBasedMaxAmount = formatAmountWithCode(reputationBasedMaxAmount);
String formattedAmountWithoutReputationNeeded = formatAmountWithCode(amountWithoutReputationNeeded);
boolean isToleratedLowAmount = myReputationScore <= MIN_REPUTAION_SCORE;
boolean isToleratedLowAmount = myReputationScore <= MIN_REPUTATION_SCORE;
if (isToleratedLowAmount) {
if (noReputationNeededForMaxOrFixedAmount) {
model.getAmountLimitInfo().set(Res.get("bisqEasy.tradeWizard.amount.seller.limitInfo.noReputationNeededForMaxOrFixedAmount", formattedAmountWithoutReputationNeeded));
Expand Down Expand Up @@ -644,14 +644,8 @@ private void applyQuoteSideMinMaxRange() {
Monetary minRangeValue = BisqEasyTradeAmountLimits.usdToFiat(marketPriceService, model.getMarket(), DEFAULT_MIN_USD_TRADE_AMOUNT)
.orElseThrow().round(0);

if (model.getReputationBasedMaxAmount() == null) {
String myProfileId = userIdentityService.getSelectedUserIdentity().getUserProfile().getId();
long myReputationScore = reputationService.getReputationScore(myProfileId).getTotalScore();
model.setMyReputationScore(myReputationScore);
model.setReputationBasedMaxAmount(BisqEasyTradeAmountLimits.getReputationBasedQuoteSideAmount(marketPriceService, model.getMarket(), myReputationScore)
.orElse(Fiat.fromValue(0, model.getMarket().getQuoteCurrencyCode()))
);
}
applyMaxAmountBasedOnReputation();

Fiat defaultUsdAmount = MAX_USD_TRADE_AMOUNT_WITHOUT_REPUTATION.multiply(2);
Monetary defaultFiatAmount = BisqEasyTradeAmountLimits.usdToFiat(marketPriceService, model.getMarket(), defaultUsdAmount)
.orElseThrow().round(0);
Expand Down Expand Up @@ -728,6 +722,15 @@ private void applyQuoteSideMinMaxRange() {
}
}

private void applyMaxAmountBasedOnReputation() {
String myProfileId = userIdentityService.getSelectedUserIdentity().getUserProfile().getId();
long myReputationScore = reputationService.getReputationScore(myProfileId).getTotalScore();
model.setMyReputationScore(myReputationScore);
model.setReputationBasedMaxAmount(BisqEasyTradeAmountLimits.getReputationBasedQuoteSideAmount(marketPriceService, model.getMarket(), myReputationScore)
.orElse(Fiat.fromValue(0, model.getMarket().getQuoteCurrencyCode()))
);
}

private void applyMarkerRange() {
Pair<Optional<Monetary>, Optional<Monetary>> availableOfferAmountRange = getLowestAndHighestAmountInAvailableOffers();
amountSelectionController.setLeftMarkerQuoteSideValue(availableOfferAmountRange.getFirst().orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class BisqEasyTradeAmountLimits {
public static final Fiat DEFAULT_MIN_USD_TRADE_AMOUNT = Fiat.fromFaceValue(6, "USD");
public static final Fiat MAX_USD_TRADE_AMOUNT = Fiat.fromFaceValue(600, "USD");
public static final Fiat MAX_USD_TRADE_AMOUNT_WITHOUT_REPUTATION = Fiat.fromFaceValue(25, "USD");
private static final double REQUIRED_REPUTAION_SCORE_PER_USD = 200d;
public static final long MIN_REPUTAION_SCORE = 5000;
private static final double REQUIRED_REPUTATION_SCORE_PER_USD = 200d;
public static final long MIN_REPUTATION_SCORE = 5000;
public static final double TOLERANCE = 0.05;

public static Optional<Monetary> getMinQuoteSideTradeAmount(MarketPriceService marketPriceService, Market market) {
Expand All @@ -68,8 +68,9 @@ public static Optional<Monetary> getReputationBasedQuoteSideAmount(MarketPriceSe
private static Fiat getMaxUsdTradeAmount(long totalScore) {
// A reputation score of 30k gives a max trade amount of 150 USD
// Upper limit is 600 USD
long value = Math.min(MAX_USD_TRADE_AMOUNT.getValue(), MathUtils.roundDoubleToLong(totalScore / REQUIRED_REPUTAION_SCORE_PER_USD));
Fiat maxUsdTradeAmount = Fiat.fromFaceValue(value, "USD");
Monetary maxAmountAllowedByReputation = getUsdAmountFromReputationScore(totalScore);
long value = Math.min(MAX_USD_TRADE_AMOUNT.getValue(), maxAmountAllowedByReputation.getValue());
Fiat maxUsdTradeAmount = Fiat.fromValue(value, "USD");

// We tolerate up to 25 USD trade amount for users with no or low reputation (< 5000)
if (maxUsdTradeAmount.isLessThan(MAX_USD_TRADE_AMOUNT_WITHOUT_REPUTATION)) {
Expand Down Expand Up @@ -134,7 +135,7 @@ private static Result getResult(long sellersReputationScore,
result = Result.MATCH_SCORE;
} else if (withTolerance(sellersReputationScore) >= requiredReputationScore) {
result = Result.MATCH_TOLERATED_SCORE;
} else if (requiredReputationScore <= MIN_REPUTAION_SCORE) {
} else if (requiredReputationScore <= MIN_REPUTATION_SCORE) {
result = Result.MATCH_MIN_SCORE;
} else {
result = Result.SCORE_TOO_LOW;
Expand Down Expand Up @@ -204,11 +205,11 @@ public static Optional<Monetary> fiatToUsd(MarketPriceService marketPriceService

public static long getRequiredReputationScoreByUsdAmount(Monetary usdAmount) {
double faceValue = Monetary.toFaceValue(usdAmount.round(0), 0);
return MathUtils.roundDoubleToLong(faceValue * REQUIRED_REPUTAION_SCORE_PER_USD);
return MathUtils.roundDoubleToLong(faceValue * REQUIRED_REPUTATION_SCORE_PER_USD);
}

public static Monetary getUsdAmountFromReputationScore(long reputationScore) {
long usdAmount = MathUtils.roundDoubleToLong(reputationScore / REQUIRED_REPUTAION_SCORE_PER_USD);
long usdAmount = MathUtils.roundDoubleToLong(reputationScore / REQUIRED_REPUTATION_SCORE_PER_USD);
return Fiat.fromFaceValue(usdAmount, "USD");
}

Expand Down

0 comments on commit 8708605

Please sign in to comment.