Search in sources :

Example 6 with PaymentAccount

use of io.bitsquare.payment.PaymentAccount in project bitsquare by bitsquare.

the class FiatAccountsDataModel method onSaveNewAccount.

///////////////////////////////////////////////////////////////////////////////////////////
// UI actions
///////////////////////////////////////////////////////////////////////////////////////////
public void onSaveNewAccount(PaymentAccount paymentAccount) {
    user.addPaymentAccount(paymentAccount);
    TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
    List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
    if (singleTradeCurrency != null) {
        if (singleTradeCurrency instanceof FiatCurrency)
            preferences.addFiatCurrency((FiatCurrency) singleTradeCurrency);
        else
            preferences.addCryptoCurrency((CryptoCurrency) singleTradeCurrency);
    } else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
        tradeCurrencies.stream().forEach(tradeCurrency -> {
            if (tradeCurrency instanceof FiatCurrency)
                preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
            else
                preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
        });
    }
}
Also used : PaymentMethod(io.bitsquare.payment.PaymentMethod) ActivatableDataModel(io.bitsquare.gui.common.model.ActivatableDataModel) FiatCurrency(io.bitsquare.locale.FiatCurrency) CryptoCurrency(io.bitsquare.locale.CryptoCurrency) Inject(com.google.inject.Inject) SetChangeListener(javafx.collections.SetChangeListener) TradeCurrency(io.bitsquare.locale.TradeCurrency) FXCollections(javafx.collections.FXCollections) Collectors(java.util.stream.Collectors) GUIUtil(io.bitsquare.gui.util.GUIUtil) ArrayList(java.util.ArrayList) PaymentAccount(io.bitsquare.payment.PaymentAccount) TradeManager(io.bitsquare.trade.TradeManager) Preferences(io.bitsquare.user.Preferences) User(io.bitsquare.user.User) List(java.util.List) CryptoCurrencyAccount(io.bitsquare.payment.CryptoCurrencyAccount) Stage(javafx.stage.Stage) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ObservableList(javafx.collections.ObservableList) CryptoCurrency(io.bitsquare.locale.CryptoCurrency) TradeCurrency(io.bitsquare.locale.TradeCurrency) FiatCurrency(io.bitsquare.locale.FiatCurrency)

Example 7 with PaymentAccount

use of io.bitsquare.payment.PaymentAccount in project bitsquare by bitsquare.

the class AltCoinAccountsDataModel method onSaveNewAccount.

///////////////////////////////////////////////////////////////////////////////////////////
// UI actions
///////////////////////////////////////////////////////////////////////////////////////////
public void onSaveNewAccount(PaymentAccount paymentAccount) {
    user.addPaymentAccount(paymentAccount);
    TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
    List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
    if (singleTradeCurrency != null) {
        if (singleTradeCurrency instanceof FiatCurrency)
            preferences.addFiatCurrency((FiatCurrency) singleTradeCurrency);
        else
            preferences.addCryptoCurrency((CryptoCurrency) singleTradeCurrency);
    } else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
        tradeCurrencies.stream().forEach(tradeCurrency -> {
            if (tradeCurrency instanceof FiatCurrency)
                preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
            else
                preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
        });
    }
}
Also used : PaymentMethod(io.bitsquare.payment.PaymentMethod) ActivatableDataModel(io.bitsquare.gui.common.model.ActivatableDataModel) FiatCurrency(io.bitsquare.locale.FiatCurrency) CryptoCurrency(io.bitsquare.locale.CryptoCurrency) Inject(com.google.inject.Inject) SetChangeListener(javafx.collections.SetChangeListener) TradeCurrency(io.bitsquare.locale.TradeCurrency) FXCollections(javafx.collections.FXCollections) Collectors(java.util.stream.Collectors) GUIUtil(io.bitsquare.gui.util.GUIUtil) ArrayList(java.util.ArrayList) PaymentAccount(io.bitsquare.payment.PaymentAccount) TradeManager(io.bitsquare.trade.TradeManager) Preferences(io.bitsquare.user.Preferences) User(io.bitsquare.user.User) List(java.util.List) CryptoCurrencyAccount(io.bitsquare.payment.CryptoCurrencyAccount) Stage(javafx.stage.Stage) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ObservableList(javafx.collections.ObservableList) CryptoCurrency(io.bitsquare.locale.CryptoCurrency) TradeCurrency(io.bitsquare.locale.TradeCurrency) FiatCurrency(io.bitsquare.locale.FiatCurrency)

Example 8 with PaymentAccount

use of io.bitsquare.payment.PaymentAccount in project bitsquare by bitsquare.

the class CreateOfferView method onPaymentAccountsComboBoxSelected.

private void onPaymentAccountsComboBoxSelected() {
    PaymentAccount paymentAccount = paymentAccountsComboBox.getSelectionModel().getSelectedItem();
    maybeShowClearXchangeWarning(paymentAccount);
    if (paymentAccount != null) {
        currencyComboBox.setVisible(paymentAccount.hasMultipleCurrencies());
        if (paymentAccount.hasMultipleCurrencies()) {
            currencyComboBox.setItems(FXCollections.observableArrayList(paymentAccount.getTradeCurrencies()));
            // we select combobox following the user currency, if user currency not available in account, we select first
            TradeCurrency tradeCurrency = model.getTradeCurrency();
            if (paymentAccount.getTradeCurrencies().contains(tradeCurrency))
                currencyComboBox.getSelectionModel().select(tradeCurrency);
            else
                currencyComboBox.getSelectionModel().select(paymentAccount.getTradeCurrencies().get(0));
            model.onPaymentAccountSelected(paymentAccount);
        } else {
            currencyTextField.setText(paymentAccount.getSingleTradeCurrency().getNameAndCode());
            model.onPaymentAccountSelected(paymentAccount);
            model.onCurrencySelected(paymentAccount.getSingleTradeCurrency());
        }
    } else {
        currencyComboBox.setVisible(false);
        currencyTextField.setText("");
    }
}
Also used : TradeCurrency(io.bitsquare.locale.TradeCurrency) PaymentAccount(io.bitsquare.payment.PaymentAccount)

Example 9 with PaymentAccount

use of io.bitsquare.payment.PaymentAccount in project bitsquare by bitsquare.

the class TakeOfferDataModel method initWithData.

///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
// called before activate
void initWithData(Offer offer) {
    this.offer = offer;
    tradePrice = offer.getPrice();
    addressEntry = walletService.getOrCreateAddressEntry(offer.getId(), AddressEntry.Context.OFFER_FUNDING);
    checkNotNull(addressEntry, "addressEntry must not be null");
    ObservableList<PaymentAccount> possiblePaymentAccounts = getPossiblePaymentAccounts();
    checkArgument(!possiblePaymentAccounts.isEmpty(), "possiblePaymentAccounts.isEmpty()");
    paymentAccount = possiblePaymentAccounts.get(0);
    amountAsCoin.set(offer.getAmount());
    if (DevFlags.DEV_MODE)
        amountAsCoin.set(offer.getAmount());
    calculateVolume();
    calculateTotalToPay();
    balanceListener = new BalanceListener(addressEntry.getAddress()) {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateBalance();
        /*if (isMainNet.get()) {
                    SettableFuture<Coin> future = blockchainService.requestFee(tx.getHashAsString());
                    Futures.addCallback(future, new FutureCallback<Coin>() {
                        public void onSuccess(Coin fee) {
                            UserThread.execute(() -> setFeeFromFundingTx(fee));
                        }

                        public void onFailure(@NotNull Throwable throwable) {
                            UserThread.execute(() -> new Popup()
                                    .warning("We did not get a response for the request of the mining fee used " +
                                            "in the funding transaction.\n\n" +
                                            "Are you sure you used a sufficiently high fee of at least " +
                                            formatter.formatCoinWithCode(FeePolicy.getMinRequiredFeeForFundingTx()) + "?")
                                    .actionButtonText("Yes, I used a sufficiently high fee.")
                                    .onAction(() -> setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx()))
                                    .closeButtonText("No. Let's cancel that payment.")
                                    .onClose(() -> setFeeFromFundingTx(Coin.NEGATIVE_SATOSHI))
                                    .show());
                        }
                    });
                } else {
                    setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx());
                    isFeeFromFundingTxSufficient.set(feeFromFundingTx.compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0);
                }*/
        }
    };
    offer.resetState();
    if (!preferences.getUseStickyMarketPrice())
        priceFeedService.setCurrencyCode(offer.getCurrencyCode());
}
Also used : Coin(org.bitcoinj.core.Coin) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) PaymentAccount(io.bitsquare.payment.PaymentAccount)

Example 10 with PaymentAccount

use of io.bitsquare.payment.PaymentAccount in project bitsquare by bitsquare.

the class GUIUtil method importAccounts.

public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(new File(preferences.getDefaultPath()));
    fileChooser.setTitle("Select path to " + fileName);
    File file = fileChooser.showOpenDialog(stage.getOwner());
    if (file != null) {
        String path = file.getAbsolutePath();
        if (Paths.get(path).getFileName().toString().equals(fileName)) {
            String directory = Paths.get(path).getParent().toString();
            preferences.setDefaultPath(directory);
            Storage<ArrayList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory));
            ArrayList<PaymentAccount> persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName);
            if (persisted != null) {
                final StringBuilder msg = new StringBuilder();
                persisted.stream().forEach(paymentAccount -> {
                    final String id = paymentAccount.getId();
                    if (user.getPaymentAccount(id) == null) {
                        user.addPaymentAccount(paymentAccount);
                        msg.append("Trading account with id ").append(id).append("\n");
                    } else {
                        msg.append("We did not import trading account with id ").append(id).append(" because it exists already.\n");
                    }
                });
                new Popup<>().feedback("Trading account imported from path:\n" + path + "\n\nImported accounts:\n" + msg).show();
            } else {
                new Popup<>().warning("No exported trading accounts has been found at path: " + path + ".\n" + "File name is " + fileName + ".").show();
            }
        } else {
            new Popup<>().warning("The selected file is not the expected file for import. The expected file name is: " + fileName + ".").show();
        }
    }
}
Also used : Storage(io.bitsquare.storage.Storage) PaymentAccount(io.bitsquare.payment.PaymentAccount) Popup(io.bitsquare.gui.main.overlays.popups.Popup) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Aggregations

PaymentAccount (io.bitsquare.payment.PaymentAccount)10 Popup (io.bitsquare.gui.main.overlays.popups.Popup)6 PaymentMethod (io.bitsquare.payment.PaymentMethod)6 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 TradeCurrency (io.bitsquare.locale.TradeCurrency)5 UserThread (io.bitsquare.common.UserThread)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 ChangeListener (javafx.beans.value.ChangeListener)4 Inject (com.google.inject.Inject)3 Tuple3 (io.bitsquare.common.util.Tuple3)3 FormBuilder (io.bitsquare.gui.util.FormBuilder)3 GUIUtil (io.bitsquare.gui.util.GUIUtil)3 Layout (io.bitsquare.gui.util.Layout)3 CryptoCurrency (io.bitsquare.locale.CryptoCurrency)3 CryptoCurrencyAccount (io.bitsquare.payment.CryptoCurrencyAccount)3 TradeManager (io.bitsquare.trade.TradeManager)3 OpenOfferManager (io.bitsquare.trade.offer.OpenOfferManager)3 Preferences (io.bitsquare.user.Preferences)3 User (io.bitsquare.user.User)3