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

Add check for account age to apply restrictions #2801

Merged
merged 15 commits into from May 3, 2019
Merged
29 changes: 27 additions & 2 deletions core/src/main/java/bisq/core/payment/AccountAgeRestrictions.java
Expand Up @@ -18,7 +18,9 @@
package bisq.core.payment;

import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OfferRestrictions;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.trade.Trade;

import bisq.common.util.Utilities;
Expand Down Expand Up @@ -47,8 +49,31 @@ public static boolean isMyAccountAgeImmature(AccountAgeWitnessService accountAge
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE;
}

public static long getMyTradeLimitAtTakeOffer(AccountAgeWitnessService accountAgeWitnessService, PaymentAccount paymentAccount, String currencyCode) {
if (AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) {
public static long getMyTradeLimitAtCreateOffer(AccountAgeWitnessService accountAgeWitnessService,
PaymentAccount paymentAccount,
String currencyCode,
OfferPayload.Direction direction) {
if (direction == OfferPayload.Direction.BUY &&
PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) &&
AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) {
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value;
} else {
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode);
}
}

public static long getMyTradeLimitAtTakeOffer(AccountAgeWitnessService accountAgeWitnessService,
PaymentAccount paymentAccount,
Offer offer,
String currencyCode,
OfferPayload.Direction direction) {
if (direction == OfferPayload.Direction.BUY && PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) &&
AccountAgeRestrictions.isMakersAccountAgeImmature(accountAgeWitnessService, offer)) {
// Taker is seller
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value;
} else if (direction == OfferPayload.Direction.SELL && PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) &&
AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) {
// Taker is buyer
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value;
} else {
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/payment/PaymentAccountUtil.java
Expand Up @@ -61,7 +61,8 @@ public static boolean isSellOfferAndAnyTakerPaymentAccountForOfferMature(Offer o
private static boolean isTakerAccountForOfferMature(Offer offer,
PaymentAccount takerPaymentAccount,
AccountAgeWitnessService accountAgeWitnessService) {
return !OfferRestrictions.isMinTradeAmountRisky(offer) ||
return !PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) ||
!OfferRestrictions.isMinTradeAmountRisky(offer) ||
(isTakerPaymentAccountValidForOffer(offer, takerPaymentAccount) &&
!AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, takerPaymentAccount));
}
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Expand Up @@ -358,7 +358,10 @@ offerbook.warning.sellOfferAndAnyTakerPaymentAccountForOfferMature=This offer ca
offerbook.warning.newVersionAnnouncement=We needed to deploy this restriction as a short-term measure for enhanced security.\n\n\
The next software release will provide more robust protection tools so that offers with this risk profile can be traded again.

takeOffer.popup.tradeLimitDueAccountAgeRestriction=The allowed trade amount is limited because of security restrictions based on the following criteria:\n\
popup.warning.tradeLimitDueAccountAgeRestriction.seller=The allowed trade amount is limited to 0.01 BTC because of security restrictions based on the following criteria:\n\
- The buyers account was created after March 15th 2019\n\
- The payment method for this offer is considered risky for bank chargebacks\n\n{0}
popup.warning.tradeLimitDueAccountAgeRestriction.buyer=The allowed trade amount is limited to 0.01 BTC because of security restrictions based on the following criteria:\n\
- Your payment account was created after March 15th 2019\n\
- The payment method for this offer is considered risky for bank chargebacks\n\n{0}

Expand Down
Expand Up @@ -35,6 +35,7 @@
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OfferUtil;
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.AccountAgeRestrictions;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.HalCashAccount;
import bisq.core.payment.PaymentAccount;
Expand Down Expand Up @@ -438,9 +439,8 @@ void onPaymentAccountSelected(PaymentAccount paymentAccount) {

buyerSecurityDeposit.set(preferences.getBuyerSecurityDepositAsPercent(getPaymentAccount()));

long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, tradeCurrencyCode.get());
if (amount.get() != null)
this.amount.set(Coin.valueOf(Math.min(amount.get().value, myLimit)));
this.amount.set(Coin.valueOf(Math.min(amount.get().value, getMaxTradeLimit())));
}
}

Expand Down Expand Up @@ -581,7 +581,7 @@ boolean isMakerFeeValid() {

long getMaxTradeLimit() {
if (paymentAccount != null)
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, tradeCurrencyCode.get());
return AccountAgeRestrictions.getMyTradeLimitAtCreateOffer(accountAgeWitnessService, paymentAccount, tradeCurrencyCode.get(), direction);
else
return 0;
}
Expand Down
Expand Up @@ -44,6 +44,7 @@
import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OfferRestrictions;
import bisq.core.offer.OfferUtil;
import bisq.core.payment.PaymentAccount;
import bisq.core.provider.price.MarketPrice;
Expand Down Expand Up @@ -728,6 +729,11 @@ void onFocusOutAmountTextField(boolean oldValue, boolean newValue) {

if (minAmount.get() != null)
minAmountValidationResult.set(isBtcInputValid(minAmount.get()));
} else if (btcValidator.getMaxTradeLimit() != null && btcValidator.getMaxTradeLimit().value == OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value) {
new Popup<>().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.buyer",
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
}
// We want to trigger a recalculation of the volume
UserThread.execute(() -> {
Expand Down
Expand Up @@ -515,7 +515,7 @@ boolean isSellOfferAndAnyTakerPaymentAccountForOfferMature(Offer offer) {
}

boolean isRiskyBuyOfferWithImmatureAccountAge(Offer offer) {
return user.getPaymentAccounts() != null && PaymentAccountUtil.isRiskyBuyOfferWithImmatureAccountAge(offer, accountAgeWitnessService);
return PaymentAccountUtil.isRiskyBuyOfferWithImmatureAccountAge(offer, accountAgeWitnessService);
}

boolean hasPaymentAccountForCurrency() {
Expand Down
Expand Up @@ -430,7 +430,7 @@ boolean hasAcceptedArbitrators() {

long getMaxTradeLimit() {
if (paymentAccount != null)
return AccountAgeRestrictions.getMyTradeLimitAtTakeOffer(accountAgeWitnessService, paymentAccount, getCurrencyCode());
return AccountAgeRestrictions.getMyTradeLimitAtTakeOffer(accountAgeWitnessService, paymentAccount, offer, getCurrencyCode(), getDirection());
else
return 0;
}
Expand Down
Expand Up @@ -373,10 +373,18 @@ void onFocusOutAmountTextField(boolean oldValue, boolean newValue, String userIn
amountValidationResult.set(new InputValidator.ValidationResult(false,
Res.get("takeOffer.validation.amountLargerThanOfferAmountMinusFee")));
} else if (btcValidator.getMaxTradeLimit() != null && btcValidator.getMaxTradeLimit().value == OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value) {
new Popup<>().information(Res.get("takeOffer.popup.tradeLimitDueAccountAgeRestriction",
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
if (dataModel.getDirection() == OfferPayload.Direction.BUY) {
new Popup<>().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.seller",
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
} else {
new Popup<>().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.buyer",
Res.get("offerbook.warning.newVersionAnnouncement")))
.width(900)
.show();
}

}
}
}
Expand Down