Remove market price based fee calculation

This commit is contained in:
Manfred Karrer 2019-01-07 01:52:32 +01:00
parent 1c14b07fa1
commit af439a86ad
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
4 changed files with 16 additions and 49 deletions

View file

@ -73,17 +73,12 @@ public class OfferUtil {
* @param bsqWalletService
* @param preferences preferences are used to see if the user indicated a preference for paying fees in BTC
* @param amount
* @param marketPriceAvailable
* @param marketPriceMargin
* @return
*/
@Nullable
public static Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount, boolean marketPriceAvailable, double marketPriceMargin) {
final boolean isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount, marketPriceAvailable, marketPriceMargin);
return getMakerFee(isCurrencyForMakerFeeBtc,
amount,
marketPriceAvailable,
marketPriceMargin);
public static Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount) {
boolean isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount);
return getMakerFee(isCurrencyForMakerFeeBtc, amount);
}
/**
@ -91,27 +86,13 @@ public class OfferUtil {
*
* @param isCurrencyForMakerFeeBtc
* @param amount
* @param marketPriceAvailable
* @param marketPriceMargin
* @return
*/
@Nullable
public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin amount, boolean marketPriceAvailable, double marketPriceMargin) {
public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin amount) {
if (amount != null) {
Coin feePerBtc = CoinUtil.getFeePerBtc(FeeService.getMakerFeePerBtc(isCurrencyForMakerFeeBtc), amount);
double makerFeeAsDouble = (double) feePerBtc.value;
if (marketPriceAvailable) {
if (marketPriceMargin > 0)
makerFeeAsDouble = makerFeeAsDouble * Math.sqrt(marketPriceMargin * 100);
else
makerFeeAsDouble = 0;
// For BTC we round so min value change is 100 satoshi
if (isCurrencyForMakerFeeBtc)
makerFeeAsDouble = MathUtils.roundDouble(makerFeeAsDouble / 100, 0) * 100;
}
return CoinUtil.maxCoin(Coin.valueOf(MathUtils.doubleToLong(makerFeeAsDouble)), FeeService.getMinMakerFee(isCurrencyForMakerFeeBtc));
return CoinUtil.maxCoin(feePerBtc, FeeService.getMinMakerFee(isCurrencyForMakerFeeBtc));
} else {
return null;
}
@ -124,14 +105,11 @@ public class OfferUtil {
* @param preferences
* @param bsqWalletService
* @param amount
* @param marketPriceAvailable
* @param marketPriceMargin
* @return
*/
public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount,
boolean marketPriceAvailable, double marketPriceMargin) {
public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount) {
boolean payFeeInBtc = preferences.getPayFeeInBtc();
boolean bsqForFeeAvailable = isBsqForMakerFeeAvailable(bsqWalletService, amount, marketPriceAvailable, marketPriceMargin);
boolean bsqForFeeAvailable = isBsqForMakerFeeAvailable(bsqWalletService, amount);
return payFeeInBtc || !bsqForFeeAvailable;
}
@ -140,13 +118,11 @@ public class OfferUtil {
*
* @param bsqWalletService
* @param amount
* @param marketPriceAvailable
* @param marketPriceMargin
* @return
*/
public static boolean isBsqForMakerFeeAvailable(BsqWalletService bsqWalletService, @Nullable Coin amount, boolean marketPriceAvailable, double marketPriceMargin) {
public static boolean isBsqForMakerFeeAvailable(BsqWalletService bsqWalletService, @Nullable Coin amount) {
Coin availableBalance = bsqWalletService.getAvailableBalance();
Coin makerFee = getMakerFee(false, amount, marketPriceAvailable, marketPriceMargin);
Coin makerFee = getMakerFee(false, amount);
// If we don't know yet the maker fee (amount is not set) we return true, otherwise we would disable BSQ
// fee each time we open the create offer screen as there the amount is not set.

View file

@ -53,7 +53,6 @@ import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;
import bisq.network.p2p.P2PService;
@ -110,7 +109,6 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
private final TradeWalletService tradeWalletService;
private final FeeService feeService;
private final ReferralIdService referralIdService;
private final BsqFormatter bsqFormatter;
private final BSFormatter btcFormatter;
private final String offerId;
private final BalanceListener btcBalanceListener;
@ -153,7 +151,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
Preferences preferences, User user, KeyRing keyRing, P2PService p2PService,
PriceFeedService priceFeedService, FilterManager filterManager,
AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService,
FeeService feeService, ReferralIdService referralIdService, BsqFormatter bsqFormatter,
FeeService feeService, ReferralIdService referralIdService,
BSFormatter btcFormatter) {
super(btcWalletService);
@ -169,7 +167,6 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
this.tradeWalletService = tradeWalletService;
this.feeService = feeService;
this.referralIdService = referralIdService;
this.bsqFormatter = bsqFormatter;
this.btcFormatter = btcFormatter;
offerId = Utilities.getRandomPrefix(5, 8) + "-" +
@ -825,23 +822,23 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
}
public Coin getMakerFee(boolean isCurrencyForMakerFeeBtc) {
return OfferUtil.getMakerFee(isCurrencyForMakerFeeBtc, amount.get(), marketPriceAvailable, marketPriceMargin);
return OfferUtil.getMakerFee(isCurrencyForMakerFeeBtc, amount.get());
}
public Coin getMakerFee() {
return OfferUtil.getMakerFee(bsqWalletService, preferences, amount.get(), marketPriceAvailable, marketPriceMargin);
return OfferUtil.getMakerFee(bsqWalletService, preferences, amount.get());
}
public Coin getMakerFeeInBtc() {
return OfferUtil.getMakerFee(true, amount.get(), marketPriceAvailable, marketPriceMargin);
return OfferUtil.getMakerFee(true, amount.get());
}
public Coin getMakerFeeInBsq() {
return OfferUtil.getMakerFee(false, amount.get(), marketPriceAvailable, marketPriceMargin);
return OfferUtil.getMakerFee(false, amount.get());
}
public boolean isCurrencyForMakerFeeBtc() {
return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount.get(), marketPriceAvailable, marketPriceMargin);
return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount.get());
}
public boolean isPreferredFeeCurrencyBtc() {
@ -849,7 +846,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
}
public boolean isBsqForFeeAvailable() {
return OfferUtil.isBsqForMakerFeeAvailable(bsqWalletService, amount.get(), marketPriceAvailable, marketPriceMargin);
return OfferUtil.isBsqForMakerFeeAvailable(bsqWalletService, amount.get());
}
public boolean isHalCashAccount() {

View file

@ -35,7 +35,6 @@ import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;
import bisq.network.p2p.P2PService;
@ -64,7 +63,6 @@ class CreateOfferDataModel extends MutableOfferDataModel {
TradeWalletService tradeWalletService,
FeeService feeService,
ReferralIdService referralIdService,
BsqFormatter bsqFormatter,
BSFormatter btcFormatter) {
super(openOfferManager,
btcWalletService,
@ -79,7 +77,6 @@ class CreateOfferDataModel extends MutableOfferDataModel {
tradeWalletService,
feeService,
referralIdService,
bsqFormatter,
btcFormatter);
}
}

View file

@ -39,7 +39,6 @@ import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;
import bisq.network.p2p.P2PService;
@ -69,7 +68,6 @@ class EditOfferDataModel extends MutableOfferDataModel {
TradeWalletService tradeWalletService,
FeeService feeService,
ReferralIdService referralIdService,
BsqFormatter bsqFormatter,
BSFormatter btcFormatter,
CorePersistenceProtoResolver corePersistenceProtoResolver) {
super(openOfferManager,
@ -85,7 +83,6 @@ class EditOfferDataModel extends MutableOfferDataModel {
tradeWalletService,
feeService,
referralIdService,
bsqFormatter,
btcFormatter);
this.corePersistenceProtoResolver = corePersistenceProtoResolver;
}