Search in sources :

Example 1 with SameBankAccount

use of bisq.core.payment.SameBankAccount in project bisq-desktop by bisq-network.

the class CreateOfferDataModel method createAndGetOffer.

// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("ConstantConditions")
Offer createAndGetOffer() {
    final boolean useMarketBasedPriceValue = marketPriceAvailable && useMarketBasedPrice.get();
    long priceAsLong = price.get() != null && !useMarketBasedPriceValue ? price.get().getValue() : 0L;
    String currencyCode = tradeCurrencyCode.get();
    boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
    String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode();
    String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode;
    double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0;
    long amount = this.amount.get() != null ? this.amount.get().getValue() : 0L;
    long minAmount = this.minAmount.get() != null ? this.minAmount.get().getValue() : 0L;
    ArrayList<String> acceptedCountryCodes = null;
    if (paymentAccount instanceof SepaAccount) {
        acceptedCountryCodes = new ArrayList<>();
        acceptedCountryCodes.addAll(((SepaAccount) paymentAccount).getAcceptedCountryCodes());
    } else if (paymentAccount instanceof SepaInstantAccount) {
        acceptedCountryCodes = new ArrayList<>();
        acceptedCountryCodes.addAll(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes());
    } else if (paymentAccount instanceof CountryBasedPaymentAccount) {
        acceptedCountryCodes = new ArrayList<>();
        acceptedCountryCodes.add(((CountryBasedPaymentAccount) paymentAccount).getCountry().code);
    }
    ArrayList<String> acceptedBanks = null;
    if (paymentAccount instanceof SpecificBanksAccount) {
        acceptedBanks = new ArrayList<>(((SpecificBanksAccount) paymentAccount).getAcceptedBanks());
    } else if (paymentAccount instanceof SameBankAccount) {
        acceptedBanks = new ArrayList<>();
        acceptedBanks.add(((SameBankAccount) paymentAccount).getBankId());
    }
    String bankId = paymentAccount instanceof BankAccount ? ((BankAccount) paymentAccount).getBankId() : null;
    // That is optional and set to null if not supported (AltCoins, OKPay,...)
    String countryCode = paymentAccount instanceof CountryBasedPaymentAccount ? ((CountryBasedPaymentAccount) paymentAccount).getCountry().code : null;
    checkNotNull(p2PService.getAddress(), "Address must not be null");
    checkNotNull(getMakerFee(), "makerFee must not be null");
    long maxTradeLimit = getMaxTradeLimit();
    long maxTradePeriod = paymentAccount.getPaymentMethod().getMaxTradePeriod();
    // reserved for future use cases
    // Use null values if not set
    boolean isPrivateOffer = false;
    boolean useAutoClose = false;
    boolean useReOpenAfterAutoClose = false;
    long lowerClosePrice = 0;
    long upperClosePrice = 0;
    String hashOfChallenge = null;
    HashMap<String, String> extraDataMap = null;
    if (CurrencyUtil.isFiatCurrency(currencyCode)) {
        extraDataMap = new HashMap<>();
        final String myWitnessHashAsHex = accountAgeWitnessService.getMyWitnessHashAsHex(paymentAccount.getPaymentAccountPayload());
        extraDataMap.put(OfferPayload.ACCOUNT_AGE_WITNESS_HASH, myWitnessHashAsHex);
    }
    Coin buyerSecurityDepositAsCoin = buyerSecurityDeposit.get();
    checkArgument(buyerSecurityDepositAsCoin.compareTo(Restrictions.getMaxBuyerSecurityDeposit()) <= 0, "securityDeposit must be not exceed " + Restrictions.getMaxBuyerSecurityDeposit().toFriendlyString());
    checkArgument(buyerSecurityDepositAsCoin.compareTo(Restrictions.getMinBuyerSecurityDeposit()) >= 0, "securityDeposit must be not be less than " + Restrictions.getMinBuyerSecurityDeposit().toFriendlyString());
    checkArgument(!filterManager.isCurrencyBanned(currencyCode), Res.get("offerbook.warning.currencyBanned"));
    checkArgument(!filterManager.isPaymentMethodBanned(paymentAccount.getPaymentMethod()), Res.get("offerbook.warning.paymentMethodBanned"));
    OfferPayload offerPayload = new OfferPayload(offerId, new Date().getTime(), p2PService.getAddress(), keyRing.getPubKeyRing(), OfferPayload.Direction.valueOf(direction.name()), priceAsLong, marketPriceMarginParam, useMarketBasedPriceValue, amount, minAmount, baseCurrencyCode, counterCurrencyCode, Lists.newArrayList(user.getAcceptedArbitratorAddresses()), Lists.newArrayList(user.getAcceptedMediatorAddresses()), paymentAccount.getPaymentMethod().getId(), paymentAccount.getId(), null, countryCode, acceptedCountryCodes, bankId, acceptedBanks, Version.VERSION, btcWalletService.getLastBlockSeenHeight(), txFeeFromFeeService.value, getMakerFee().value, isCurrencyForMakerFeeBtc(), buyerSecurityDepositAsCoin.value, sellerSecurityDeposit.value, maxTradeLimit, maxTradePeriod, useAutoClose, useReOpenAfterAutoClose, upperClosePrice, lowerClosePrice, isPrivateOffer, hashOfChallenge, extraDataMap, Version.TRADE_PROTOCOL_VERSION);
    Offer offer = new Offer(offerPayload);
    offer.setPriceFeedService(priceFeedService);
    return offer;
}
Also used : SepaInstantAccount(bisq.core.payment.SepaInstantAccount) SameBankAccount(bisq.core.payment.SameBankAccount) SepaAccount(bisq.core.payment.SepaAccount) ArrayList(java.util.ArrayList) SameBankAccount(bisq.core.payment.SameBankAccount) BankAccount(bisq.core.payment.BankAccount) Date(java.util.Date) Coin(org.bitcoinj.core.Coin) Offer(bisq.core.offer.Offer) CountryBasedPaymentAccount(bisq.core.payment.CountryBasedPaymentAccount) OfferPayload(bisq.core.offer.OfferPayload) SpecificBanksAccount(bisq.core.payment.SpecificBanksAccount)

Example 2 with SameBankAccount

use of bisq.core.payment.SameBankAccount in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method getSameBankAccount.

private PaymentAccount getSameBankAccount(String currencyCode, String countryCode, String bankId) {
    SameBankAccount paymentAccount = new SameBankAccount();
    paymentAccount.setSingleTradeCurrency(new FiatCurrency(currencyCode));
    paymentAccount.setCountry(new Country(countryCode, null, null));
    ((SameBankAccountPayload) paymentAccount.getPaymentAccountPayload()).setBankId(bankId);
    return paymentAccount;
}
Also used : SameBankAccount(bisq.core.payment.SameBankAccount) Country(bisq.core.locale.Country) SameBankAccountPayload(bisq.core.payment.payload.SameBankAccountPayload) FiatCurrency(bisq.core.locale.FiatCurrency)

Aggregations

SameBankAccount (bisq.core.payment.SameBankAccount)2 Country (bisq.core.locale.Country)1 FiatCurrency (bisq.core.locale.FiatCurrency)1 Offer (bisq.core.offer.Offer)1 OfferPayload (bisq.core.offer.OfferPayload)1 BankAccount (bisq.core.payment.BankAccount)1 CountryBasedPaymentAccount (bisq.core.payment.CountryBasedPaymentAccount)1 SepaAccount (bisq.core.payment.SepaAccount)1 SepaInstantAccount (bisq.core.payment.SepaInstantAccount)1 SpecificBanksAccount (bisq.core.payment.SpecificBanksAccount)1 SameBankAccountPayload (bisq.core.payment.payload.SameBankAccountPayload)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Coin (org.bitcoinj.core.Coin)1