mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Merge pull request #2212 from ManfredKarrer/simplify-fee-model
Simplify fee model
This commit is contained in:
commit
c947b85822
@ -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.
|
||||
|
@ -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;
|
||||
@ -137,10 +135,10 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
|
||||
protected PaymentAccount paymentAccount;
|
||||
protected boolean isTabSelected;
|
||||
protected double marketPriceMargin = 0;
|
||||
protected Coin txFeeFromFeeService = Coin.ZERO;
|
||||
protected boolean marketPriceAvailable;
|
||||
protected int feeTxSize = 260; // size of typical tx with 1 input
|
||||
protected int feeTxSizeEstimationRecursionCounter;
|
||||
private Coin txFeeFromFeeService = Coin.ZERO;
|
||||
private boolean marketPriceAvailable;
|
||||
private int feeTxSize = 260; // size of typical tx with 1 input
|
||||
private int feeTxSizeEstimationRecursionCounter;
|
||||
protected boolean allowAmountUpdate = true;
|
||||
|
||||
|
||||
@ -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) + "-" +
|
||||
@ -328,11 +325,9 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
|
||||
|
||||
ArrayList<String> acceptedCountryCodes = null;
|
||||
if (paymentAccount instanceof SepaAccount) {
|
||||
acceptedCountryCodes = new ArrayList<>();
|
||||
acceptedCountryCodes.addAll(((SepaAccount) paymentAccount).getAcceptedCountryCodes());
|
||||
acceptedCountryCodes = new ArrayList<>(((SepaAccount) paymentAccount).getAcceptedCountryCodes());
|
||||
} else if (paymentAccount instanceof SepaInstantAccount) {
|
||||
acceptedCountryCodes = new ArrayList<>();
|
||||
acceptedCountryCodes.addAll(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes());
|
||||
acceptedCountryCodes = new ArrayList<>(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes());
|
||||
} else if (paymentAccount instanceof CountryBasedPaymentAccount) {
|
||||
acceptedCountryCodes = new ArrayList<>();
|
||||
acceptedCountryCodes.add(((CountryBasedPaymentAccount) paymentAccount).getCountry().code);
|
||||
@ -825,23 +820,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 +844,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() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -49,6 +48,8 @@ import bisq.common.handlers.ResultHandler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class EditOfferDataModel extends MutableOfferDataModel {
|
||||
|
||||
private final CorePersistenceProtoResolver corePersistenceProtoResolver;
|
||||
@ -69,7 +70,6 @@ class EditOfferDataModel extends MutableOfferDataModel {
|
||||
TradeWalletService tradeWalletService,
|
||||
FeeService feeService,
|
||||
ReferralIdService referralIdService,
|
||||
BsqFormatter bsqFormatter,
|
||||
BSFormatter btcFormatter,
|
||||
CorePersistenceProtoResolver corePersistenceProtoResolver) {
|
||||
super(openOfferManager,
|
||||
@ -85,7 +85,6 @@ class EditOfferDataModel extends MutableOfferDataModel {
|
||||
tradeWalletService,
|
||||
feeService,
|
||||
referralIdService,
|
||||
bsqFormatter,
|
||||
btcFormatter);
|
||||
this.corePersistenceProtoResolver = corePersistenceProtoResolver;
|
||||
}
|
||||
@ -117,14 +116,15 @@ class EditOfferDataModel extends MutableOfferDataModel {
|
||||
|
||||
this.initialState = openOffer.getState();
|
||||
PaymentAccount tmpPaymentAccount = user.getPaymentAccount(openOffer.getOffer().getMakerPaymentAccountId());
|
||||
TradeCurrency selectedTradeCurrency = CurrencyUtil.getTradeCurrency(openOffer.getOffer().getCurrencyCode()).get();
|
||||
|
||||
Optional<TradeCurrency> optionalTradeCurrency = CurrencyUtil.getTradeCurrency(openOffer.getOffer().getCurrencyCode());
|
||||
if (optionalTradeCurrency.isPresent() && tmpPaymentAccount != null) {
|
||||
TradeCurrency selectedTradeCurrency = optionalTradeCurrency.get();
|
||||
this.paymentAccount = PaymentAccount.fromProto(tmpPaymentAccount.toProtoMessage(), corePersistenceProtoResolver);
|
||||
|
||||
if (paymentAccount.getSingleTradeCurrency() != null)
|
||||
paymentAccount.setSingleTradeCurrency(selectedTradeCurrency);
|
||||
else
|
||||
paymentAccount.setSelectedTradeCurrency(selectedTradeCurrency);
|
||||
}
|
||||
|
||||
allowAmountUpdate = false;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class CreateOfferViewModelTest {
|
||||
when(bsqFormatter.formatCoin(any())).thenReturn("0");
|
||||
when(bsqWalletService.getAvailableBalance()).thenReturn(Coin.ZERO);
|
||||
|
||||
CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, accountAgeWitnessService, null, feeService, null, bsqFormatter, bsFormatter);
|
||||
CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, accountAgeWitnessService, null, feeService, null, bsFormatter);
|
||||
dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin"));
|
||||
dataModel.activate();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user