This commit is contained in:
Manfred Karrer 2019-04-19 20:26:31 -05:00
commit ad4be15eea
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
15 changed files with 104 additions and 59 deletions

View file

@ -1354,6 +1354,7 @@ message PreferencesPayload {
string take_offer_selected_payment_account_id = 49;
double buyer_security_deposit_as_percent = 50;
int32 ignore_dust_threshold = 51;
double buyer_security_deposit_as_percent_for_crypto = 52;
}
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -18,9 +18,13 @@
package bisq.core.btc.wallet;
import bisq.core.app.BisqEnvironment;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil;
import org.bitcoinj.core.Coin;
import javax.annotation.Nullable;
public class Restrictions {
private static Coin MIN_TRADE_AMOUNT;
private static Coin MIN_BUYER_SECURITY_DEPOSIT;
@ -50,16 +54,25 @@ public class Restrictions {
return MIN_TRADE_AMOUNT;
}
public static double getDefaultBuyerSecurityDepositAsPercent() {
return 0.1; // 10% of trade amount.
public static double getDefaultBuyerSecurityDepositAsPercent(@Nullable PaymentAccount paymentAccount) {
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
return 0.02; // 2% of trade amount.
else
return 0.1; // 10% of trade amount.
}
public static double getMinBuyerSecurityDepositAsPercent() {
return 0.05; // 5% of trade amount.
public static double getMinBuyerSecurityDepositAsPercent(@Nullable PaymentAccount paymentAccount) {
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
return 0.005; // 0.5% of trade amount.
else
return 0.05; // 5% of trade amount.
}
public static double getMaxBuyerSecurityDepositAsPercent() {
return 0.5; // 50% of trade amount. For a 1 BTC trade it is about 800 USD @ 4000 USD/BTC
public static double getMaxBuyerSecurityDepositAsPercent(@Nullable PaymentAccount paymentAccount) {
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
return 0.2; // 20% of trade amount. For a 1 BTC trade it is about 800 USD @ 4000 USD/BTC
else
return 0.5; // 50% of trade amount. For a 1 BTC trade it is about 2000 USD @ 4000 USD/BTC
}
// We use MIN_BUYER_SECURITY_DEPOSIT as well as lower bound in case of small trade amounts.

View file

@ -353,12 +353,12 @@ public class OfferUtil {
Coin makerFeeAsCoin) {
checkNotNull(makerFeeAsCoin, "makerFee must not be null");
checkNotNull(p2PService.getAddress(), "Address must not be null");
checkArgument(buyerSecurityDeposit <= Restrictions.getMaxBuyerSecurityDepositAsPercent(),
checkArgument(buyerSecurityDeposit <= Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount),
"securityDeposit must not exceed " +
Restrictions.getMaxBuyerSecurityDepositAsPercent());
checkArgument(buyerSecurityDeposit >= Restrictions.getMinBuyerSecurityDepositAsPercent(),
Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount));
checkArgument(buyerSecurityDeposit >= Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount),
"securityDeposit must not be less than " +
Restrictions.getMinBuyerSecurityDepositAsPercent());
Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount));
checkArgument(!filterManager.isCurrencyBanned(currencyCode),
Res.get("offerbook.warning.currencyBanned"));
checkArgument(!filterManager.isPaymentMethodBanned(paymentAccount.getPaymentMethod()),

View file

@ -19,6 +19,7 @@ package bisq.core.payment;
import bisq.core.locale.Country;
import bisq.core.offer.Offer;
import bisq.core.payment.payload.PaymentMethod;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@ -114,6 +115,11 @@ public class PaymentAccountUtil {
return null;
}
public static boolean isCryptoCurrencyAccount(PaymentAccount paymentAccount) {
return (paymentAccount != null && paymentAccount.getPaymentMethod().equals(PaymentMethod.BLOCK_CHAINS) ||
paymentAccount != null && paymentAccount.getPaymentMethod().equals(PaymentMethod.BLOCK_CHAINS_INSTANT));
}
// TODO no code duplication found in UI code (added for API)
// That is optional and set to null if not supported (AltCoins,...)
/* public static String getCountryCode(PaymentAccount paymentAccount) {

View file

@ -32,6 +32,7 @@ import bisq.core.locale.FiatCurrency;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil;
import bisq.network.p2p.network.BridgeAddressProvider;
@ -493,10 +494,14 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
withdrawalTxFeeInBytesProperty.set(withdrawalTxFeeInBytes);
}
public void setBuyerSecurityDepositAsPercent(double buyerSecurityDepositAsPercent) {
double max = Restrictions.getMaxBuyerSecurityDepositAsPercent();
double min = Restrictions.getMinBuyerSecurityDepositAsPercent();
prefPayload.setBuyerSecurityDepositAsPercent(Math.min(max, Math.max(min, buyerSecurityDepositAsPercent)));
public void setBuyerSecurityDepositAsPercent(double buyerSecurityDepositAsPercent, PaymentAccount paymentAccount) {
double max = Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount);
double min = Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount);
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
prefPayload.setBuyerSecurityDepositAsPercentForCrypto(Math.min(max, Math.max(min, buyerSecurityDepositAsPercent)));
else
prefPayload.setBuyerSecurityDepositAsPercent(Math.min(max, Math.max(min, buyerSecurityDepositAsPercent)));
persist();
}
@ -715,15 +720,16 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
return withdrawalTxFeeInBytesProperty;
}
public double getBuyerSecurityDepositAsPercent() {
double value = prefPayload.getBuyerSecurityDepositAsPercent();
public double getBuyerSecurityDepositAsPercent(PaymentAccount paymentAccount) {
double value = PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount) ?
prefPayload.getBuyerSecurityDepositAsPercentForCrypto() : prefPayload.getBuyerSecurityDepositAsPercent();
if (value < Restrictions.getMinBuyerSecurityDepositAsPercent()) {
value = Restrictions.getMinBuyerSecurityDepositAsPercent();
setBuyerSecurityDepositAsPercent(value);
if (value < Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount)) {
value = Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount);
setBuyerSecurityDepositAsPercent(value, paymentAccount);
}
return value == 0 ? Restrictions.getDefaultBuyerSecurityDepositAsPercent() : value;
return value == 0 ? Restrictions.getDefaultBuyerSecurityDepositAsPercent(paymentAccount) : value;
}
//TODO remove and use isPayFeeInBtc instead

View file

@ -17,11 +17,11 @@
package bisq.core.user;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.locale.Country;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.CryptoCurrencyAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.proto.CoreProtoResolver;
@ -47,6 +47,8 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent;
@Slf4j
@Data
@AllArgsConstructor
@ -120,8 +122,9 @@ public final class PreferencesPayload implements PersistableEnvelope {
String rpcPw;
@Nullable
String takeOfferSelectedPaymentAccountId;
private double buyerSecurityDepositAsPercent = Restrictions.getDefaultBuyerSecurityDepositAsPercent();
private double buyerSecurityDepositAsPercent = getDefaultBuyerSecurityDepositAsPercent(null);
private int ignoreDustThreshold = 600;
private double buyerSecurityDepositAsPercentForCrypto = getDefaultBuyerSecurityDepositAsPercent(new CryptoCurrencyAccount());
///////////////////////////////////////////////////////////////////////////////////////////
@ -178,8 +181,9 @@ public final class PreferencesPayload implements PersistableEnvelope {
.setUsePriceNotifications(usePriceNotifications)
.setUseStandbyMode(useStandbyMode)
.setIsDaoFullNode(isDaoFullNode)
.setBuyerSecurityDepositAsPercent(buyerSecurityDepositAsPercent).
setIgnoreDustThreshold(ignoreDustThreshold);
.setBuyerSecurityDepositAsPercent(buyerSecurityDepositAsPercent)
.setIgnoreDustThreshold(ignoreDustThreshold)
.setBuyerSecurityDepositAsPercentForCrypto(buyerSecurityDepositAsPercentForCrypto);
Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory);
Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((PB.TradeCurrency) e.toProtoMessage()));
Optional.ofNullable(offerBookChartScreenCurrencyCode).ifPresent(builder::setOfferBookChartScreenCurrencyCode);
@ -262,6 +266,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
proto.getRpcPw().isEmpty() ? null : proto.getRpcPw(),
proto.getTakeOfferSelectedPaymentAccountId().isEmpty() ? null : proto.getTakeOfferSelectedPaymentAccountId(),
proto.getBuyerSecurityDepositAsPercent(),
proto.getIgnoreDustThreshold());
proto.getIgnoreDustThreshold(),
proto.getBuyerSecurityDepositAsPercentForCrypto());
}
}

View file

@ -493,6 +493,7 @@ editOffer.confirmEdit=Confirm: Edit offer
editOffer.publishOffer=Publishing your offer.
editOffer.failed=Editing of offer failed:\n{0}
editOffer.success=Your offer has been successfully edited.
editOffer.invalidDeposit=The buyer's security deposit is not within the constraints defined by the Bisq DAO and can no longer be edited.
####################################################################
# Portfolio

View file

@ -333,6 +333,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
.show());
bisqSetup.setDisplayAlertHandler(alert -> new DisplayAlertMessageWindow()
.alertMessage(alert)
.closeButtonText(Res.get("shared.close"))
.onClose(() -> {
user.setDisplayedAlert(alert);
})

View file

@ -180,7 +180,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
addressEntry = btcWalletService.getOrCreateAddressEntry(offerId, AddressEntry.Context.OFFER_FUNDING);
useMarketBasedPrice.set(preferences.isUsePercentageBasedPrice());
buyerSecurityDeposit.set(preferences.getBuyerSecurityDepositAsPercent());
buyerSecurityDeposit.set(preferences.getBuyerSecurityDepositAsPercent(null));
sellerSecurityDeposit.set(Restrictions.getSellerSecurityDepositAsPercent());
btcBalanceListener = new BalanceListener(getAddressEntry().getAddress()) {
@ -436,6 +436,8 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
setTradeCurrencyFromPaymentAccount(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)));
@ -710,7 +712,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
void setBuyerSecurityDeposit(double value) {
this.buyerSecurityDeposit.set(value);
preferences.setBuyerSecurityDepositAsPercent(value);
preferences.setBuyerSecurityDepositAsPercent(value, getPaymentAccount());
}
protected boolean isUseMarketBasedPriceValue() {

View file

@ -84,7 +84,7 @@ import static javafx.beans.binding.Bindings.createStringBinding;
public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> extends ActivatableWithDataModel<M> {
private final BtcValidator btcValidator;
private final BsqValidator bsqValidator;
private final SecurityDepositValidator securityDepositValidator;
protected final SecurityDepositValidator securityDepositValidator;
private final P2PService p2PService;
private final WalletsSetup walletsSetup;
private final PriceFeedService priceFeedService;
@ -104,7 +104,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
public final StringProperty amount = new SimpleStringProperty();
public final StringProperty minAmount = new SimpleStringProperty();
final StringProperty buyerSecurityDeposit = new SimpleStringProperty();
protected final StringProperty buyerSecurityDeposit = new SimpleStringProperty();
final StringProperty buyerSecurityDepositInBTC = new SimpleStringProperty();
final StringProperty buyerSecurityDepositLabel = new SimpleStringProperty();
@ -599,6 +599,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
amountDescription = Res.get("createOffer.amountPriceBox.amountDescription",
isBuy ? Res.get("shared.buy") : Res.get("shared.sell"));
securityDepositValidator.setPaymentAccount(dataModel.paymentAccount);
buyerSecurityDeposit.set(btcFormatter.formatToPercent(dataModel.getBuyerSecurityDeposit().get()));
buyerSecurityDepositLabel.set(getSecurityDepositLabel());
@ -663,6 +664,8 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
btcValidator.setMaxValue(dataModel.paymentAccount.getPaymentMethod().getMaxTradeLimitAsCoin(dataModel.getTradeCurrencyCode().get()));
btcValidator.setMaxTradeLimit(Coin.valueOf(dataModel.getMaxTradeLimit()));
securityDepositValidator.setPaymentAccount(paymentAccount);
}
public void onCurrencySelected(TradeCurrency tradeCurrency) {
@ -853,7 +856,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
InputValidator.ValidationResult result = securityDepositValidator.validate(buyerSecurityDeposit.get());
buyerSecurityDepositValidationResult.set(result);
if (result.isValid) {
double defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDepositAsPercent();
double defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDepositAsPercent(getPaymentAccount());
String key = "buyerSecurityDepositIsLowerAsDefault";
double depositAsDouble = btcFormatter.parsePercentStringToDouble(buyerSecurityDeposit.get());
if (preferences.showAgain(key) && depositAsDouble < defaultSecurityDeposit) {
@ -1121,7 +1124,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
if (buyerSecurityDeposit.get() != null && !buyerSecurityDeposit.get().isEmpty()) {
dataModel.setBuyerSecurityDeposit(btcFormatter.parsePercentStringToDouble(buyerSecurityDeposit.get()));
} else {
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent());
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent(getPaymentAccount()));
}
}

View file

@ -17,7 +17,6 @@
package bisq.desktop.main.overlays.windows;
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.util.FormBuilder;
@ -25,13 +24,10 @@ import bisq.desktop.util.FormBuilder;
import bisq.core.alert.Alert;
import bisq.core.locale.Res;
import javafx.scene.layout.GridPane;
import javafx.geometry.Insets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static bisq.desktop.util.FormBuilder.addMultilineLabel;
import static com.google.common.base.Preconditions.checkNotNull;
public class DisplayAlertMessageWindow extends Overlay<DisplayAlertMessageWindow> {
@ -50,10 +46,22 @@ public class DisplayAlertMessageWindow extends Overlay<DisplayAlertMessageWindow
public void show() {
width = 768;
// need to set headLine, otherwise the fields will not be created in addHeadLine
headLine = Res.get("displayAlertMessageWindow.headline");
createGridPane();
checkNotNull(alert, "alertMessage must not be null");
if (alert.isUpdateInfo()) {
information("");
headLine = Res.get("displayAlertMessageWindow.update.headline");
} else {
error("");
headLine = Res.get("displayAlertMessageWindow.headline");
}
headLine = Res.get("displayAlertMessageWindow.headline");
addHeadLine();
addContent();
addButtons();
applyStyles();
display();
}
@ -69,28 +77,13 @@ public class DisplayAlertMessageWindow extends Overlay<DisplayAlertMessageWindow
private void addContent() {
checkNotNull(alert, "alertMessage must not be null");
FormBuilder.addMultilineLabel(gridPane, ++rowIndex, alert.getMessage(), 10);
addMultilineLabel(gridPane, ++rowIndex, alert.getMessage(), 10);
if (alert.isUpdateInfo()) {
headLine = Res.get("displayAlertMessageWindow.update.headline");
headLineLabel.getStyleClass().addAll("headline-label", "highlight");
String url = "https://bisq.network/downloads";
HyperlinkWithIcon hyperlinkWithIcon = FormBuilder.addLabelHyperlinkWithIcon(gridPane, ++rowIndex,
Res.get("displayAlertMessageWindow.update.download"), url, url).second;
hyperlinkWithIcon.setMaxWidth(550);
} else {
headLine = Res.get("displayAlertMessageWindow.headline");
headLineLabel.getStyleClass().addAll("headline-label", "error-text");
}
closeButton = new AutoTooltipButton(Res.get("shared.close"));
closeButton.setOnAction(e -> {
hide();
closeHandlerOptional.ifPresent(Runnable::run);
});
GridPane.setRowIndex(closeButton, ++rowIndex);
GridPane.setColumnIndex(closeButton, 1);
gridPane.getChildren().add(closeButton);
GridPane.setMargin(closeButton, new Insets(10, 0, 0, 0));
}

View file

@ -148,11 +148,15 @@ public class EditOfferView extends MutableOfferView<EditOfferViewModel> {
model.onStartEditOffer(errorMessage -> {
log.error(errorMessage);
new Popup<>().warning(Res.get("editOffer.failed", errorMessage))
.onClose(() -> {
close();
})
.onClose(this::close)
.show();
});
if (!model.isSecurityDepositValid()) {
new Popup<>().warning(Res.get("editOffer.invalidDeposit"))
.onClose(this::close)
.show();
}
}
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -80,4 +80,8 @@ class EditOfferViewModel extends MutableOfferViewModel<EditOfferDataModel> {
price.set(btcFormatter.formatPrice(null));
price.set(btcFormatter.formatPrice(dataModel.getPrice().get()));
}
public boolean isSecurityDepositValid() {
return securityDepositValidator.validate(buyerSecurityDeposit.get()).isValid;
}
}

View file

@ -19,6 +19,7 @@ package bisq.desktop.util.validation;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.locale.Res;
import bisq.core.payment.PaymentAccount;
import bisq.core.util.BSFormatter;
import javax.inject.Inject;
@ -26,12 +27,16 @@ import javax.inject.Inject;
public class SecurityDepositValidator extends NumberValidator {
private final BSFormatter formatter;
private PaymentAccount paymentAccount;
@Inject
public SecurityDepositValidator(BSFormatter formatter) {
this.formatter = formatter;
}
public void setPaymentAccount(PaymentAccount paymentAccount) {
this.paymentAccount = paymentAccount;
}
@Override
public ValidationResult validate(String input) {
@ -54,7 +59,7 @@ public class SecurityDepositValidator extends NumberValidator {
private ValidationResult validateIfNotTooLowPercentageValue(String input) {
try {
double percentage = formatter.parsePercentStringToDouble(input);
double minPercentage = Restrictions.getMinBuyerSecurityDepositAsPercent();
double minPercentage = Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount);
if (percentage < minPercentage)
return new ValidationResult(false,
Res.get("validation.inputTooSmall", formatter.formatToPercentWithSymbol(minPercentage)));
@ -68,7 +73,7 @@ public class SecurityDepositValidator extends NumberValidator {
private ValidationResult validateIfNotTooHighPercentageValue(String input) {
try {
double percentage = formatter.parsePercentStringToDouble(input);
double maxPercentage = Restrictions.getMaxBuyerSecurityDepositAsPercent();
double maxPercentage = Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount);
if (percentage > maxPercentage)
return new ValidationResult(false,
Res.get("validation.inputTooLarge", formatter.formatToPercentWithSymbol(maxPercentage)));

View file

@ -66,7 +66,7 @@ public class CreateOfferDataModelTest {
when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
when(preferences.isUsePercentageBasedPrice()).thenReturn(true);
when(preferences.getBuyerSecurityDepositAsPercent()).thenReturn(0.01);
when(preferences.getBuyerSecurityDepositAsPercent(null)).thenReturn(0.01);
model = new CreateOfferDataModel(null, btcWalletService,
null, preferences, user, null,