Skip to content

Commit

Permalink
Merge pull request #6473 from jmacxx/user_trade_limits_fix
Browse files Browse the repository at this point in the history
Base initial limit from user's max past trade size if applicable.
  • Loading branch information
ripcurlx authored Dec 19, 2022
2 parents c76ee16 + 64e0ab8 commit f66e693
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions core/src/main/java/bisq/core/trade/ClosedTradableManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.time.Instant;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -127,6 +128,7 @@ public void readPersisted(Runnable completeHandler) {
public void onAllServicesInitialized() {
cleanupMailboxMessagesService.handleTrades(getClosedTrades());
maybeClearSensitiveData();
maybeIncreaseTradeLimit();
}

public void add(Tradable tradable) {
Expand Down Expand Up @@ -172,6 +174,24 @@ public Optional<Tradable> getTradableById(String id) {
return closedTradables.stream().filter(e -> e.getId().equals(id)).findFirst();
}

// if user has closed trades of greater size to the default trade limit and has never customized their
// trade limit, then set the limit to the largest amount traded previously.
public void maybeIncreaseTradeLimit() {
if (!preferences.isUserHasRaisedTradeLimit()) {
Optional<Trade> maxTradeSize = closedTradables.stream()
.filter(e -> e instanceof Trade)
.map(e -> (Trade) e)
.max(Comparator.comparing(Trade::getAmountAsLong));
maxTradeSize.ifPresent(trade -> {
if (trade.getAmountAsLong() > preferences.getUserDefinedTradeLimit()) {
log.info("Increasing user trade limit to size of max completed trade: {}", trade.getAmount());
preferences.setUserDefinedTradeLimit(trade.getAmountAsLong());
preferences.setUserHasRaisedTradeLimit(true);
}
});
}
}

public void maybeClearSensitiveData() {
log.info("checking closed trades eligibility for having sensitive data cleared");
closedTradables.stream()
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3735,9 +3735,10 @@ payment.limits.info=Please be aware that all bank transfers carry a certain amou
See more details on the wiki [HYPERLINK:https://bisq.wiki/Account_limits].
# suppress inspection "UnusedProperty"
payment.limits.info.withSigning=To limit chargeback risk, Bisq sets per-trade limits for this payment account type based \
on the following 2 factors:\n\n\
on the following factors:\n\n\
1. General chargeback risk for the payment method\n\
2. Account signing status\n\
3. User-defined trade limit\n\
\n\
This payment account is not yet signed, so it is limited to buying {0} per trade. \
After signing, buy limits will increase as follows:\n\
Expand Down

0 comments on commit f66e693

Please sign in to comment.