mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-10 07:30:05 -04:00
support cash by atm payment method #626
This commit is contained in:
parent
92fb41fffa
commit
655583477a
22 changed files with 410 additions and 95 deletions
|
@ -81,6 +81,12 @@ public class CurrencyUtil {
|
|||
|
||||
public static List<TradeCurrency> getAllFiatCurrencies() {
|
||||
return getAllTraditionalCurrencies().stream()
|
||||
.filter(currency -> CurrencyUtil.isFiatCurrency(currency.getCode()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<TradeCurrency> getAllSortedFiatCurrencies() {
|
||||
return getAllSortedTraditionalCurrencies().stream()
|
||||
.filter(currency -> CurrencyUtil.isFiatCurrency(currency.getCode()))
|
||||
.collect(Collectors.toList()); // sorted by currency name
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import haveno.core.locale.Res;
|
|||
import haveno.core.monetary.Price;
|
||||
import haveno.core.payment.PaymentAccount;
|
||||
import haveno.core.payment.PaymentAccountUtil;
|
||||
import haveno.core.payment.payload.PaymentMethod;
|
||||
import haveno.core.provider.price.MarketPrice;
|
||||
import haveno.core.provider.price.PriceFeedService;
|
||||
import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
|
||||
|
@ -47,8 +48,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static haveno.core.payment.payload.PaymentMethod.HAL_CASH_ID;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
public class CreateOfferService {
|
||||
|
@ -137,7 +136,7 @@ public class CreateOfferService {
|
|||
boolean useMarketBasedPriceValue = price == null &&
|
||||
useMarketBasedPrice &&
|
||||
isMarketPriceAvailable(currencyCode) &&
|
||||
!paymentAccount.hasPaymentMethodWithId(HAL_CASH_ID);
|
||||
!PaymentMethod.isFixedPriceOnly(paymentAccount.getPaymentMethod().getId());
|
||||
|
||||
// verify price
|
||||
if (price == null && !useMarketBasedPriceValue) {
|
||||
|
|
|
@ -246,10 +246,7 @@ public class Offer implements NetworkPayload, PersistablePayload {
|
|||
return null;
|
||||
}
|
||||
Volume volumeByAmount = price.getVolumeByAmount(amount);
|
||||
if (offerPayload.getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID))
|
||||
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
|
||||
else if (isFiatOffer())
|
||||
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
|
||||
volumeByAmount = VolumeUtil.getAdjustedVolume(volumeByAmount, getPaymentMethod().getId());
|
||||
|
||||
return volumeByAmount;
|
||||
}
|
||||
|
|
|
@ -19,15 +19,14 @@ package haveno.core.offer.takeoffer;
|
|||
|
||||
import haveno.common.taskrunner.Model;
|
||||
import haveno.core.account.witness.AccountAgeWitnessService;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.monetary.Price;
|
||||
import haveno.core.monetary.Volume;
|
||||
import haveno.core.offer.Offer;
|
||||
import haveno.core.offer.OfferUtil;
|
||||
import haveno.core.payment.PaymentAccount;
|
||||
import haveno.core.payment.payload.PaymentMethod;
|
||||
import haveno.core.provider.price.PriceFeedService;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.util.VolumeUtil;
|
||||
import haveno.core.xmr.model.XmrAddressEntry;
|
||||
import haveno.core.xmr.wallet.XmrWalletService;
|
||||
import lombok.Getter;
|
||||
|
@ -41,8 +40,6 @@ import java.util.Objects;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static haveno.core.offer.OfferDirection.SELL;
|
||||
import static haveno.core.util.VolumeUtil.getAdjustedVolumeForHalCash;
|
||||
import static haveno.core.util.VolumeUtil.getRoundedFiatVolume;
|
||||
import static haveno.core.xmr.model.XmrAddressEntry.Context.OFFER_FUNDING;
|
||||
|
||||
@Slf4j
|
||||
|
@ -136,11 +133,7 @@ public class TakeOfferModel implements Model {
|
|||
private void calculateVolume() {
|
||||
Price tradePrice = offer.getPrice();
|
||||
Volume volumeByAmount = Objects.requireNonNull(tradePrice).getVolumeByAmount(amount);
|
||||
|
||||
if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID))
|
||||
volumeByAmount = getAdjustedVolumeForHalCash(volumeByAmount);
|
||||
else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()))
|
||||
volumeByAmount = getRoundedFiatVolume(volumeByAmount);
|
||||
volumeByAmount = VolumeUtil.getAdjustedVolume(volumeByAmount, offer.getPaymentMethod().getId());
|
||||
|
||||
volume = volumeByAmount;
|
||||
|
||||
|
|
64
core/src/main/java/haveno/core/payment/CashByAtmAccount.java
Normal file
64
core/src/main/java/haveno/core/payment/CashByAtmAccount.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of Haveno.
|
||||
*
|
||||
* Haveno is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Haveno is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package haveno.core.payment;
|
||||
|
||||
import haveno.core.api.model.PaymentAccountFormField;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.locale.TradeCurrency;
|
||||
import haveno.core.payment.payload.CashByAtmAccountPayload;
|
||||
import haveno.core.payment.payload.PaymentAccountPayload;
|
||||
import haveno.core.payment.payload.PaymentMethod;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class CashByAtmAccount extends PaymentAccount {
|
||||
|
||||
public static final List<TradeCurrency> SUPPORTED_CURRENCIES = CurrencyUtil.getAllFiatCurrencies();
|
||||
|
||||
private static final List<PaymentAccountFormField.FieldId> INPUT_FIELD_IDS = List.of(
|
||||
PaymentAccountFormField.FieldId.EXTRA_INFO
|
||||
);
|
||||
|
||||
public CashByAtmAccount() {
|
||||
super(PaymentMethod.CASH_BY_ATM);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PaymentAccountPayload createPayload() {
|
||||
return new CashByAtmAccountPayload(paymentMethod.getId(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<TradeCurrency> getSupportedCurrencies() {
|
||||
return SUPPORTED_CURRENCIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<PaymentAccountFormField.FieldId> getInputFieldIds() {
|
||||
return INPUT_FIELD_IDS;
|
||||
}
|
||||
|
||||
public void setExtraInfo(String extraInfo) {
|
||||
((CashByAtmAccountPayload) paymentAccountPayload).setExtraInfo(extraInfo);
|
||||
}
|
||||
|
||||
public String getExtraInfo() {
|
||||
return ((CashByAtmAccountPayload) paymentAccountPayload).getExtraInfo();
|
||||
}
|
||||
}
|
|
@ -76,6 +76,8 @@ public class PaymentAccountFactory {
|
|||
return new F2FAccount();
|
||||
case PaymentMethod.PAY_BY_MAIL_ID:
|
||||
return new PayByMailAccount();
|
||||
case PaymentMethod.CASH_BY_ATM_ID:
|
||||
return new CashByAtmAccount();
|
||||
case PaymentMethod.PROMPT_PAY_ID:
|
||||
return new PromptPayAccount();
|
||||
case PaymentMethod.ADVANCED_CASH_ID:
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* This file is part of Haveno.
|
||||
*
|
||||
* Haveno is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Haveno is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package haveno.core.payment.payload;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import haveno.core.locale.Res;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString
|
||||
@Setter
|
||||
@Getter
|
||||
@Slf4j
|
||||
public final class CashByAtmAccountPayload extends PaymentAccountPayload {
|
||||
private String extraInfo = "";
|
||||
|
||||
public CashByAtmAccountPayload(String paymentMethod, String id) {
|
||||
super(paymentMethod, id);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private CashByAtmAccountPayload(String paymentMethod, String id,
|
||||
String extraInfo,
|
||||
long maxTradePeriod,
|
||||
Map<String, String> excludeFromJsonDataMap) {
|
||||
super(paymentMethod,
|
||||
id,
|
||||
maxTradePeriod,
|
||||
excludeFromJsonDataMap);
|
||||
this.extraInfo = extraInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
return getPaymentAccountPayloadBuilder()
|
||||
.setCashByAtmAccountPayload(protobuf.CashByAtmAccountPayload.newBuilder()
|
||||
.setExtraInfo(extraInfo))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CashByAtmAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
|
||||
return new CashByAtmAccountPayload(proto.getPaymentMethodId(),
|
||||
proto.getId(),
|
||||
proto.getCashByAtmAccountPayload().getExtraInfo(),
|
||||
proto.getMaxTradePeriod(),
|
||||
new HashMap<>(proto.getExcludeFromJsonDataMap()));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getPaymentDetails() {
|
||||
return Res.getWithCol("payment.shared.extraInfo") + " " + extraInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPaymentDetailsForTradePopup() {
|
||||
return Res.getWithCol("payment.shared.extraInfo") + " " + extraInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getAgeWitnessInputData() {
|
||||
return super.getAgeWitnessInputData(ArrayUtils.addAll(id.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ import haveno.core.payment.AmazonGiftCardAccount;
|
|||
import haveno.core.payment.AustraliaPayidAccount;
|
||||
import haveno.core.payment.BizumAccount;
|
||||
import haveno.core.payment.CapitualAccount;
|
||||
import haveno.core.payment.CashByAtmAccount;
|
||||
import haveno.core.payment.PayByMailAccount;
|
||||
import haveno.core.payment.CashDepositAccount;
|
||||
import haveno.core.payment.CelPayAccount;
|
||||
|
@ -162,6 +163,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
|
|||
public static final String AMAZON_GIFT_CARD_ID = "AMAZON_GIFT_CARD";
|
||||
public static final String BLOCK_CHAINS_INSTANT_ID = "BLOCK_CHAINS_INSTANT";
|
||||
public static final String PAY_BY_MAIL_ID = "PAY_BY_MAIL";
|
||||
public static final String CASH_BY_ATM_ID = "CASH_BY_ATM";
|
||||
public static final String CAPITUAL_ID = "CAPITUAL";
|
||||
public static final String CELPAY_ID = "CELPAY";
|
||||
public static final String MONESE_ID = "MONESE";
|
||||
|
@ -224,6 +226,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
|
|||
public static PaymentMethod AMAZON_GIFT_CARD;
|
||||
public static PaymentMethod BLOCK_CHAINS_INSTANT;
|
||||
public static PaymentMethod PAY_BY_MAIL;
|
||||
public static PaymentMethod CASH_BY_ATM;
|
||||
public static PaymentMethod CAPITUAL;
|
||||
public static PaymentMethod CELPAY;
|
||||
public static PaymentMethod MONESE;
|
||||
|
@ -271,6 +274,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
|
|||
// Global
|
||||
CASH_DEPOSIT = new PaymentMethod(CASH_DEPOSIT_ID, 4 * DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK, getAssetCodes(CashDepositAccount.SUPPORTED_CURRENCIES)),
|
||||
PAY_BY_MAIL = new PaymentMethod(PAY_BY_MAIL_ID, 8 * DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK, getAssetCodes(PayByMailAccount.SUPPORTED_CURRENCIES)),
|
||||
CASH_BY_ATM = new PaymentMethod(CASH_BY_ATM_ID, 4 * DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK, getAssetCodes(CashByAtmAccount.SUPPORTED_CURRENCIES)),
|
||||
MONEY_GRAM = new PaymentMethod(MONEY_GRAM_ID, 4 * DAY, DEFAULT_TRADE_LIMIT_MID_RISK, getAssetCodes(MoneyGramAccount.SUPPORTED_CURRENCIES)),
|
||||
WESTERN_UNION = new PaymentMethod(WESTERN_UNION_ID, 4 * DAY, DEFAULT_TRADE_LIMIT_MID_RISK, getAssetCodes(WesternUnionAccount.SUPPORTED_CURRENCIES)),
|
||||
NATIONAL_BANK = new PaymentMethod(NATIONAL_BANK_ID, 4 * DAY, DEFAULT_TRADE_LIMIT_HIGH_RISK, getAssetCodes(NationalBankAccount.SUPPORTED_CURRENCIES)),
|
||||
|
@ -560,4 +564,14 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
|
|||
id.equals(PaymentMethod.MONEY_BEAM_ID) ||
|
||||
id.equals(PaymentMethod.UPHOLD_ID);
|
||||
}
|
||||
|
||||
public static boolean isRoundedForAtmCash(String id) {
|
||||
return id.equals(PaymentMethod.CASH_BY_ATM_ID) ||
|
||||
id.equals(PaymentMethod.HAL_CASH_ID);
|
||||
}
|
||||
|
||||
public static boolean isFixedPriceOnly(String id) {
|
||||
return id.equals(PaymentMethod.CASH_BY_ATM_ID) ||
|
||||
id.equals(PaymentMethod.HAL_CASH_ID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import haveno.core.payment.payload.AustraliaPayidAccountPayload;
|
|||
import haveno.core.payment.payload.BizumAccountPayload;
|
||||
import haveno.core.payment.payload.CapitualAccountPayload;
|
||||
import haveno.core.payment.payload.CashAppAccountPayload;
|
||||
import haveno.core.payment.payload.CashByAtmAccountPayload;
|
||||
import haveno.core.payment.payload.PayByMailAccountPayload;
|
||||
import haveno.core.payment.payload.CashDepositAccountPayload;
|
||||
import haveno.core.payment.payload.CelPayAccountPayload;
|
||||
|
@ -201,6 +202,8 @@ public class CoreProtoResolver implements ProtoResolver {
|
|||
return USPostalMoneyOrderAccountPayload.fromProto(proto);
|
||||
case PAY_BY_MAIL_ACCOUNT_PAYLOAD:
|
||||
return PayByMailAccountPayload.fromProto(proto);
|
||||
case CASH_BY_ATM_ACCOUNT_PAYLOAD:
|
||||
return CashByAtmAccountPayload.fromProto(proto);
|
||||
case PROMPT_PAY_ACCOUNT_PAYLOAD:
|
||||
return PromptPayAccountPayload.fromProto(proto);
|
||||
case ADVANCED_CASH_ACCOUNT_PAYLOAD:
|
||||
|
|
|
@ -22,7 +22,6 @@ import haveno.common.crypto.PubKeyRing;
|
|||
import haveno.common.proto.network.NetworkPayload;
|
||||
import haveno.common.util.JsonExclude;
|
||||
import haveno.common.util.Utilities;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.monetary.Price;
|
||||
import haveno.core.monetary.Volume;
|
||||
import haveno.core.offer.OfferPayload;
|
||||
|
@ -204,12 +203,7 @@ public final class Contract implements NetworkPayload {
|
|||
|
||||
public Volume getTradeVolume() {
|
||||
Volume volumeByAmount = getPrice().getVolumeByAmount(getTradeAmount());
|
||||
|
||||
if (getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID))
|
||||
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
|
||||
else if (CurrencyUtil.isFiatCurrency(getOfferPayload().getCurrencyCode()))
|
||||
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
|
||||
|
||||
volumeByAmount = VolumeUtil.getAdjustedVolume(volumeByAmount, getPaymentMethodId());
|
||||
return volumeByAmount;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,13 +28,11 @@ import haveno.common.proto.ProtoUtil;
|
|||
import haveno.common.taskrunner.Model;
|
||||
import haveno.common.util.Utilities;
|
||||
import haveno.core.api.CoreMoneroConnectionsService;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.monetary.Price;
|
||||
import haveno.core.monetary.Volume;
|
||||
import haveno.core.offer.Offer;
|
||||
import haveno.core.offer.OfferDirection;
|
||||
import haveno.core.payment.payload.PaymentAccountPayload;
|
||||
import haveno.core.payment.payload.PaymentMethod;
|
||||
import haveno.core.proto.CoreProtoResolver;
|
||||
import haveno.core.proto.network.CoreNetworkProtoResolver;
|
||||
import haveno.core.support.dispute.Dispute;
|
||||
|
@ -1438,14 +1436,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
try {
|
||||
if (getAmount() != null && getPrice() != null) {
|
||||
Volume volumeByAmount = getPrice().getVolumeByAmount(getAmount());
|
||||
if (offer != null) {
|
||||
if (offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID))
|
||||
volumeByAmount = VolumeUtil.getAdjustedVolumeForHalCash(volumeByAmount);
|
||||
else if (CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()))
|
||||
volumeByAmount = VolumeUtil.getRoundedFiatVolume(volumeByAmount);
|
||||
else if (CurrencyUtil.isTraditionalCurrency(offer.getCurrencyCode()))
|
||||
volumeByAmount = VolumeUtil.getRoundedTraditionalVolume(volumeByAmount);
|
||||
}
|
||||
if (offer != null) volumeByAmount = VolumeUtil.getAdjustedVolume(volumeByAmount, offer.getPaymentMethod().getId());
|
||||
return volumeByAmount;
|
||||
} else {
|
||||
return null;
|
||||
|
|
|
@ -26,6 +26,7 @@ import haveno.core.monetary.TraditionalMoney;
|
|||
import haveno.core.monetary.TraditionalExchangeRate;
|
||||
import haveno.core.monetary.Volume;
|
||||
import haveno.core.offer.Offer;
|
||||
import haveno.core.payment.payload.PaymentMethod;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import org.bitcoinj.core.Monetary;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
|
@ -42,23 +43,33 @@ public class VolumeUtil {
|
|||
|
||||
private static double EXPONENT = Math.pow(10, TraditionalMoney.SMALLEST_UNIT_EXPONENT); // 1000000000000 with precision 8
|
||||
|
||||
public static Volume getAdjustedVolume(Volume volumeByAmount, String paymentMethodId) {
|
||||
if (PaymentMethod.isRoundedForAtmCash(paymentMethodId))
|
||||
return VolumeUtil.getRoundedAtmCashVolume(volumeByAmount);
|
||||
else if (CurrencyUtil.isFiatCurrency(volumeByAmount.getCurrencyCode()))
|
||||
return VolumeUtil.getRoundedFiatVolume(volumeByAmount);
|
||||
else if (CurrencyUtil.isTraditionalCurrency(volumeByAmount.getCurrencyCode()))
|
||||
return VolumeUtil.getRoundedTraditionalVolume(volumeByAmount);
|
||||
return volumeByAmount;
|
||||
}
|
||||
|
||||
public static Volume getRoundedFiatVolume(Volume volumeByAmount) {
|
||||
// We want to get rounded to 1 unit of the fiat currency, e.g. 1 EUR.
|
||||
return getAdjustedFiatVolume(volumeByAmount, 1);
|
||||
}
|
||||
|
||||
private static Volume getRoundedAtmCashVolume(Volume volumeByAmount) {
|
||||
// EUR has precision TraditionalMoney.SMALLEST_UNIT_EXPONENT and we want multiple of 10 so we divide by EXPONENT then
|
||||
// round and multiply with 10
|
||||
return getAdjustedFiatVolume(volumeByAmount, 10);
|
||||
}
|
||||
|
||||
public static Volume getRoundedTraditionalVolume(Volume volumeByAmount) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.####");
|
||||
double roundedVolume = Double.parseDouble(decimalFormat.format(Double.parseDouble(volumeByAmount.toString())));
|
||||
return Volume.parse(String.valueOf(roundedVolume), volumeByAmount.getCurrencyCode());
|
||||
}
|
||||
|
||||
public static Volume getAdjustedVolumeForHalCash(Volume volumeByAmount) {
|
||||
// EUR has precision TraditionalMoney.SMALLEST_UNIT_EXPONENT and we want multiple of 10 so we divide by EXPONENT then
|
||||
// round and multiply with 10
|
||||
return getAdjustedFiatVolume(volumeByAmount, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param volumeByAmount The volume generated from an amount
|
||||
|
|
|
@ -19,14 +19,17 @@ package haveno.core.util.coin;
|
|||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import haveno.common.util.MathUtils;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.monetary.Price;
|
||||
import haveno.core.monetary.Volume;
|
||||
import haveno.core.payment.payload.PaymentMethod;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.xmr.wallet.Restrictions;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static haveno.core.util.VolumeUtil.getAdjustedFiatVolume;
|
||||
|
@ -76,6 +79,21 @@ public class CoinUtil {
|
|||
return BigDecimal.valueOf(percent).multiply(new BigDecimal(amount)).toBigInteger();
|
||||
}
|
||||
|
||||
public static BigInteger getRoundedAmount(BigInteger amount, Price price, long maxTradeLimit, String currencyCode, String paymentMethodId) {
|
||||
if (PaymentMethod.isRoundedForAtmCash(paymentMethodId)) {
|
||||
return getRoundedAtmCashAmount(amount, price, maxTradeLimit);
|
||||
} else if (CurrencyUtil.isFiatCurrency(currencyCode)) {
|
||||
return getRoundedFiatAmount(amount, price, maxTradeLimit);
|
||||
} else if (CurrencyUtil.isTraditionalCurrency(currencyCode)) {
|
||||
return getRoundedTraditionalAmount(amount, price, maxTradeLimit);
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static BigInteger getRoundedAtmCashAmount(BigInteger amount, Price price, long maxTradeLimit) {
|
||||
return getAdjustedAmount(amount, price, maxTradeLimit, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the possibly adjusted amount for {@code amount}, taking into account the
|
||||
* {@code price} and {@code maxTradeLimit} and {@code factor}.
|
||||
|
@ -88,9 +106,11 @@ public class CoinUtil {
|
|||
public static BigInteger getRoundedFiatAmount(BigInteger amount, Price price, long maxTradeLimit) {
|
||||
return getAdjustedAmount(amount, price, maxTradeLimit, 1);
|
||||
}
|
||||
|
||||
public static BigInteger getAdjustedAmountForHalCash(BigInteger amount, Price price, long maxTradeLimit) {
|
||||
return getAdjustedAmount(amount, price, maxTradeLimit, 10);
|
||||
|
||||
public static BigInteger getRoundedTraditionalAmount(BigInteger amount, Price price, long maxTradeLimit) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.####");
|
||||
double roundedXmrAmount = Double.parseDouble(decimalFormat.format(HavenoUtils.atomicUnitsToXmr(amount)));
|
||||
return HavenoUtils.xmrToAtomicUnits(roundedXmrAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue