Add amount limit to take offer view

This commit is contained in:
Manfred Karrer 2019-05-02 16:22:20 -05:00
parent 9df54372dc
commit 08cf993d0f
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
5 changed files with 33 additions and 11 deletions

View file

@ -18,6 +18,7 @@
package bisq.core.payment;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferRestrictions;
import bisq.core.trade.Trade;
import bisq.common.util.Utilities;
@ -43,8 +44,14 @@ public class AccountAgeRestrictions {
public static boolean isMyAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, PaymentAccount myPaymentAccount) {
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload());
log.error("isMyAccountAgeImmature {}", accountCreationDate > SAFE_ACCOUNT_AGE_DATE);
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE;
}
public static long getMyTradeLimitAtTakeOffer(AccountAgeWitnessService accountAgeWitnessService, PaymentAccount paymentAccount, String currencyCode) {
if (AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) {
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value;
} else {
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode);
}
}
}

View file

@ -345,17 +345,23 @@ offerbook.warning.noTradingAccountForCurrency.msg=You don't have a trading accou
offerbook.warning.noMatchingAccount.headline=No matching trading account.
offerbook.warning.noMatchingAccount.msg=To take this offer, you will need to set up a payment account using this payment method.\n\nWould you like to do this now?
offerbook.warning.riskyBuyOfferWithImmatureAccountAge=This offer cannot be taken because of security restrictions:\n\
offerbook.warning.riskyBuyOfferWithImmatureAccountAge=This offer cannot be taken because of security restrictions based on those criteria:\n\
- The maker''s payment account was created after March 15th 2019\n\
- The min. trade amount is above 0.01 BTC\n\
- The payment method for that offer is considered risky for bank chargebacks\n\n{0}
offerbook.warning.sellOfferAndAnyTakerPaymentAccountForOfferMature=This offer cannot be taken because of security restrictions:\n\
offerbook.warning.sellOfferAndAnyTakerPaymentAccountForOfferMature=This offer cannot be taken because of security restrictions based on those criteria:\n\
- Your payment account was created after March 15th 2019\n\
- The min. trade amount is above 0.01 BTC\n\
- The payment method for that offer is considered risky for bank chargebacks\n\n{0}\
- The payment method for that offer is considered risky for bank chargebacks\n\n{0}
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 those criteria:\n\
- Your payment account was created after March 15th 2019\n\
- The payment method for that offer is considered risky for bank chargebacks\n\n{0}
offerbook.warning.wrongTradeProtocol=That offer requires a different protocol version as the one used in your version of the software.\n\nPlease check if you have the latest version installed, otherwise the user who created the offer has used an older version.\n\nUsers cannot trade with an incompatible trade protocol version.
offerbook.warning.userIgnored=You have added that user's onion address to your ignore list.
offerbook.warning.offerBlocked=That offer was blocked by the Bisq developers.\nProbably there is an unhandled bug causing issues when taking that offer.

View file

@ -35,6 +35,7 @@ import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OfferUtil;
import bisq.core.payment.AccountAgeRestrictions;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.HalCashAccount;
import bisq.core.payment.PaymentAccount;
@ -185,8 +186,7 @@ class TakeOfferDataModel extends OfferDataModel {
checkArgument(!possiblePaymentAccounts.isEmpty(), "possiblePaymentAccounts.isEmpty()");
paymentAccount = getLastSelectedPaymentAccount();
long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode());
this.amount.set(Coin.valueOf(Math.min(offer.getAmount().value, myLimit)));
this.amount.set(Coin.valueOf(Math.min(offer.getAmount().value, getMaxTradeLimit())));
securityDeposit = offer.getDirection() == OfferPayload.Direction.SELL ?
getBuyerSecurityDeposit() :
@ -373,7 +373,7 @@ class TakeOfferDataModel extends OfferDataModel {
if (paymentAccount != null) {
this.paymentAccount = paymentAccount;
long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode());
long myLimit = getMaxTradeLimit();
this.amount.set(Coin.valueOf(Math.max(offer.getMinAmount().value, Math.min(amount.get().value, myLimit))));
preferences.setTakeOfferSelectedPaymentAccountId(paymentAccount.getId());
@ -430,11 +430,12 @@ class TakeOfferDataModel extends OfferDataModel {
long getMaxTradeLimit() {
if (paymentAccount != null)
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode());
return AccountAgeRestrictions.getMyTradeLimitAtTakeOffer(accountAgeWitnessService, paymentAccount, getCurrencyCode());
else
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Bindings, listeners
///////////////////////////////////////////////////////////////////////////////////////////
@ -447,6 +448,7 @@ class TakeOfferDataModel extends OfferDataModel {
btcWalletService.removeBalanceListener(balanceListener);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Utils
///////////////////////////////////////////////////////////////////////////////////////////
@ -468,8 +470,7 @@ class TakeOfferDataModel extends OfferDataModel {
}
void applyAmount(Coin amount) {
long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode());
this.amount.set(Coin.valueOf(Math.min(amount.value, myLimit)));
this.amount.set(Coin.valueOf(Math.min(amount.value, getMaxTradeLimit())));
calculateTotalToPay();
}

View file

@ -34,6 +34,7 @@ import bisq.core.monetary.Price;
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.payment.payload.PaymentMethod;
@ -371,6 +372,11 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
if (dataModel.wouldCreateDustForMaker())
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();
}
}
}

View file

@ -27,6 +27,7 @@ import javax.inject.Inject;
import java.math.BigDecimal;
import lombok.Getter;
import lombok.Setter;
import javax.annotation.Nullable;
@ -45,6 +46,7 @@ public class BtcValidator extends NumberValidator {
@Nullable
@Setter
@Getter
protected Coin maxTradeLimit;
@Inject