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

User defined trade limit, Part II. #6433

Merged
merged 2 commits into from Dec 9, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import bisq.core.trade.model.bisq_v1.Contract;
import bisq.core.trade.model.bisq_v1.Trade;
import bisq.core.trade.protocol.bisq_v1.model.TradingPeer;
import bisq.core.user.Preferences;
import bisq.core.user.User;

import bisq.network.p2p.BootstrapListener;
Expand Down Expand Up @@ -143,6 +144,7 @@ public boolean isLimitLifted() {
private final ChargeBackRisk chargeBackRisk;
private final AccountAgeWitnessStorageService accountAgeWitnessStorageService;
private final Clock clock;
private final Preferences preferences;
private final FilterManager filterManager;
@Getter
private final AccountAgeWitnessUtils accountAgeWitnessUtils;
Expand All @@ -169,6 +171,7 @@ public AccountAgeWitnessService(KeyRing keyRing,
AccountAgeWitnessStorageService accountAgeWitnessStorageService,
AppendOnlyDataStoreService appendOnlyDataStoreService,
Clock clock,
Preferences preferences,
FilterManager filterManager) {
this.keyRing = keyRing;
this.p2PService = p2PService;
Expand All @@ -177,6 +180,7 @@ public AccountAgeWitnessService(KeyRing keyRing,
this.chargeBackRisk = chargeBackRisk;
this.accountAgeWitnessStorageService = accountAgeWitnessStorageService;
this.clock = clock;
this.preferences = preferences;
this.filterManager = filterManager;

accountAgeWitnessUtils = new AccountAgeWitnessUtils(
Expand Down Expand Up @@ -513,7 +517,10 @@ public long getMyTradeLimit(PaymentAccount paymentAccount, String currencyCode,
return 0;

AccountAgeWitness accountAgeWitness = getMyWitness(paymentAccount.getPaymentAccountPayload());
Coin maxTradeLimit = paymentAccount.getPaymentMethod().getMaxTradeLimitAsCoin(currencyCode);
// maxTradeLimit is the smaller of the payment method and the user preference setting (GH proposal #398)
Coin maxTradeLimit = Coin.valueOf(Math.min(
paymentAccount.getPaymentMethod().getMaxTradeLimitAsCoin(currencyCode).value,
preferences.getUserDefinedTradeLimit()));
if (hasTradeLimitException(accountAgeWitness)) {
return maxTradeLimit.value;
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/bisq/core/offer/OfferFilterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ public boolean isMyInsufficientTradeLimit(Offer offer) {
accountOptional.isPresent() ? accountOptional.get().getAccountName() : "null",
Coin.valueOf(myTradeLimit).toFriendlyString(),
Coin.valueOf(offerMinAmount).toFriendlyString());
boolean result = offer.isFiatOffer() &&
accountOptional.isPresent() &&
myTradeLimit < offerMinAmount;
boolean result = accountOptional.isPresent() && myTradeLimit < offerMinAmount;
myInsufficientTradeLimitCache.put(offerId, result);
return result;
}

public void resetTradeLimitCache() {
myInsufficientTradeLimitCache.clear();
}
}
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 @@ -408,6 +408,7 @@ popup.warning.tradeLimitDueAccountAgeRestriction.seller=The allowed trade amount
- The time since signing of the buyer''s account is not at least 30 days\n\
- The payment method for this offer is considered risky for bank chargebacks\n\n{1}
popup.warning.tradeLimitDueAccountAgeRestriction.buyer=The allowed trade amount is limited to {0} because of security restrictions based on the following criteria:\n\
- User-defined trade limit\n\
- Your account has not been signed by an arbitrator or a peer\n\
- The time since signing of your account is not at least 30 days\n\
- The payment method for this offer is considered risky for bank chargebacks\n\n{1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void setupService(KeyRing keyRing) {
AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class);
filterManager = mock(FilterManager.class);
signedWitnessService = new SignedWitnessService(keyRing, p2pService, arbitratorManager, null, appendOnlyDataStoreService, null, filterManager);
service = new AccountAgeWitnessService(null, null, null, signedWitnessService, chargeBackRisk, null, dataStoreService, null, filterManager);
service = new AccountAgeWitnessService(null, null, null, signedWitnessService, chargeBackRisk, null, dataStoreService, null, null, filterManager);
}

private File makeDir(String name) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import bisq.core.locale.LanguageUtil;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.OfferFilterService;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.TradeLimits;
import bisq.core.payment.payload.PaymentMethod;
Expand Down Expand Up @@ -142,8 +143,8 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private ChangeListener<Boolean> transactionFeeFocusedListener, autoConfServiceAddressFocusOutListener, autoConfRequiredConfirmationsFocusOutListener;
private final Preferences preferences;
private final FeeService feeService;
//private final ReferralIdService referralIdService;
private final AssetService assetService;
private final OfferFilterService offerFilterService;
private final FilterManager filterManager;
private final DaoFacade daoFacade;
private final File storageDir;
Expand Down Expand Up @@ -182,6 +183,7 @@ public PreferencesView(PreferencesViewModel model,
Preferences preferences,
FeeService feeService,
AssetService assetService,
OfferFilterService offerFilterService,
FilterManager filterManager,
DaoFacade daoFacade,
Config config,
Expand All @@ -197,6 +199,7 @@ public PreferencesView(PreferencesViewModel model,
this.preferences = preferences;
this.feeService = feeService;
this.assetService = assetService;
this.offerFilterService = offerFilterService;
this.filterManager = filterManager;
this.daoFacade = daoFacade;
this.storageDir = storageDir;
Expand Down Expand Up @@ -880,6 +883,7 @@ private void initializeTradeLimitOptions() {
if (!newValue.equals(oldValue) && tradeLimitTf.getValidator().validate(newValue).isValid) {
Coin amountAsCoin = ParsingUtils.parseToCoin(newValue, formatter);
preferences.setUserDefinedTradeLimit(amountAsCoin.value);
offerFilterService.resetTradeLimitCache();
}
};
}
Expand Down