Search in sources :

Example 1 with ExchangeRate

use of org.bitcoinj.utils.ExchangeRate in project bitsquare by bitsquare.

the class DisputeSummaryWindow method addInfoPane.

private void addInfoPane() {
    Contract contract = dispute.getContract();
    addTitledGroupBg(gridPane, ++rowIndex, 16, "Summary");
    addLabelTextField(gridPane, rowIndex, "Trade ID:", dispute.getShortTradeId(), Layout.FIRST_ROW_DISTANCE);
    addLabelTextField(gridPane, ++rowIndex, "Ticket opening date:", formatter.formatDateTime(dispute.getOpeningDate()));
    if (dispute.isDisputeOpenerIsOfferer()) {
        if (dispute.isDisputeOpenerIsBuyer())
            role = "BTC Buyer/offerer";
        else
            role = "BTC Seller/offerer";
    } else {
        if (dispute.isDisputeOpenerIsBuyer())
            role = "BTC Buyer/taker";
        else
            role = "BTC Seller/taker";
    }
    addLabelTextField(gridPane, ++rowIndex, "Trader's role:", role);
    addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
    addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPrice(contract.getTradePrice()));
    addLabelTextField(gridPane, ++rowIndex, "Trade volume:", formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
}
Also used : ExchangeRate(org.bitcoinj.utils.ExchangeRate) Contract(io.bitsquare.trade.Contract)

Example 2 with ExchangeRate

use of org.bitcoinj.utils.ExchangeRate in project bitsquare by bitsquare.

the class ContractWindow method addContent.

private void addContent() {
    Contract contract = dispute.getContract();
    Offer offer = contract.offer;
    List<String> acceptedBanks = offer.getAcceptedBankIds();
    boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
    List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
    boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
    int rows = 16;
    if (dispute.getDepositTxSerialized() != null)
        rows++;
    if (dispute.getPayoutTxSerialized() != null)
        rows++;
    if (showAcceptedCountryCodes)
        rows++;
    if (showAcceptedBanks)
        rows++;
    PaymentAccountContractData sellerPaymentAccountContractData = contract.getSellerPaymentAccountContractData();
    addTitledGroupBg(gridPane, ++rowIndex, rows, "Dispute details");
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, "Offer ID:", offer.getId(), Layout.FIRST_ROW_DISTANCE).second.setMouseTransparent(false);
    addLabelTextField(gridPane, ++rowIndex, "Offer date / Trade date:", formatter.formatDateTime(offer.getDate()) + " / " + formatter.formatDateTime(dispute.getTradeDate()));
    String currencyCode = offer.getCurrencyCode();
    addLabelTextField(gridPane, ++rowIndex, "Trade type:", formatter.getDirectionBothSides(offer.getDirection(), currencyCode));
    addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPrice(contract.getTradePrice()));
    addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
    addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode, ":"), formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Bitcoin address BTC buyer / BTC seller:", contract.getBuyerPayoutAddressString() + " / " + contract.getSellerPayoutAddressString()).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Network address BTC buyer / BTC seller:", contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress());
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "No. of disputes BTC buyer / BTC seller:", disputeManager.getNrOfDisputes(true, contract) + " / " + disputeManager.getNrOfDisputes(false, contract));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "BTC buyer payment details:", BSResources.get(contract.getBuyerPaymentAccountContractData().getPaymentDetails())).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "BTC seller payment details:", BSResources.get(sellerPaymentAccountContractData.getPaymentDetails())).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Selected arbitrator:", contract.arbitratorNodeAddress.getFullAddress());
    if (showAcceptedCountryCodes) {
        String countries;
        Tooltip tooltip = null;
        if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
            countries = "All Euro countries";
        } else {
            countries = CountryUtil.getCodesString(acceptedCountryCodes);
            tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
        }
        TextField acceptedCountries = addLabelTextField(gridPane, ++rowIndex, "Accepted taker countries:", countries).second;
        if (tooltip != null)
            acceptedCountries.setTooltip(new Tooltip());
    }
    if (showAcceptedBanks) {
        if (offer.getPaymentMethod().equals(PaymentMethod.SAME_BANK)) {
            addLabelTextField(gridPane, ++rowIndex, "Bank name:", acceptedBanks.get(0));
        } else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) {
            String value = Joiner.on(", ").join(acceptedBanks);
            Tooltip tooltip = new Tooltip("Accepted banks: " + value);
            TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, "Accepted banks:", value).second;
            acceptedBanksTextField.setMouseTransparent(false);
            acceptedBanksTextField.setTooltip(tooltip);
        }
    }
    addLabelTxIdTextField(gridPane, ++rowIndex, "Offer fee transaction ID:", offer.getOfferFeePaymentTxID());
    addLabelTxIdTextField(gridPane, ++rowIndex, "Trading fee transaction ID:", contract.takeOfferFeeTxID);
    if (dispute.getDepositTxSerialized() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, "Deposit transaction ID:", dispute.getDepositTxId());
    if (dispute.getPayoutTxSerialized() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, "Payout transaction ID:", dispute.getPayoutTxId());
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Contract hash:", Utils.HEX.encode(dispute.getContractHash())).second.setMouseTransparent(false);
    if (contract != null) {
        Button viewContractButton = addLabelButton(gridPane, ++rowIndex, "Contract in JSON format:", "View contract in JSON format", 0).second;
        viewContractButton.setDefaultButton(false);
        viewContractButton.setOnAction(e -> {
            TextArea textArea = new TextArea();
            String contractAsJson = dispute.getContractAsJson();
            contractAsJson += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(dispute.getContract().getBuyerMultiSigPubKey());
            contractAsJson += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(dispute.getContract().getSellerMultiSigPubKey());
            textArea.setText(contractAsJson);
            textArea.setPrefHeight(50);
            textArea.setEditable(false);
            textArea.setWrapText(true);
            textArea.setPrefSize(800, 600);
            Scene viewContractScene = new Scene(textArea);
            Stage viewContractStage = new Stage();
            viewContractStage.setTitle("Contract for trade with ID: " + dispute.getShortTradeId());
            viewContractStage.setScene(viewContractScene);
            if (owner == null)
                owner = MainView.getRootContainer();
            Scene rootScene = owner.getScene();
            viewContractStage.initOwner(rootScene.getWindow());
            viewContractStage.initModality(Modality.NONE);
            viewContractStage.initStyle(StageStyle.UTILITY);
            viewContractStage.show();
            Window window = rootScene.getWindow();
            double titleBarHeight = window.getHeight() - rootScene.getHeight();
            viewContractStage.setX(Math.round(window.getX() + (owner.getWidth() - viewContractStage.getWidth()) / 2) + 200);
            viewContractStage.setY(Math.round(window.getY() + titleBarHeight + (owner.getHeight() - viewContractStage.getHeight()) / 2) + 50);
        });
    }
    Button cancelButton = addButtonAfterGroup(gridPane, ++rowIndex, "Close");
    //TODO app wide focus
    //cancelButton.requestFocus();
    cancelButton.setOnAction(e -> {
        closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run());
        hide();
    });
}
Also used : Window(javafx.stage.Window) PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) ExchangeRate(org.bitcoinj.utils.ExchangeRate) TextArea(javafx.scene.control.TextArea) Tooltip(javafx.scene.control.Tooltip) Scene(javafx.scene.Scene) Offer(io.bitsquare.trade.offer.Offer) Button(javafx.scene.control.Button) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) Contract(io.bitsquare.trade.Contract)

Example 3 with ExchangeRate

use of org.bitcoinj.utils.ExchangeRate in project bitcoin-wallet by bitcoin-wallet.

the class ExchangeRatesAdapter method buildListItems.

public static List<ListItem> buildListItems(final List<ExchangeRateEntry> exchangeRates, final Coin balance, final BlockchainState blockchainState, final String defaultCurrency, final Coin rateBase) {
    final List<ListItem> items = new ArrayList<>(exchangeRates.size());
    for (final ExchangeRateEntry exchangeRate : exchangeRates) {
        final ExchangeRate rate = exchangeRate.exchangeRate();
        final String source = exchangeRate.getSource();
        final String currencyCode = rate.fiat.currencyCode;
        final Fiat baseRateAsFiat = rate.coinToFiat(rateBase);
        final int baseRateMinDecimals = !rateBase.isLessThan(Coin.COIN) ? 2 : 4;
        final Fiat balanceAsFiat = balance != null && (blockchainState == null || !blockchainState.replaying) ? rate.coinToFiat(balance) : null;
        final boolean isDefault = currencyCode.equals(defaultCurrency);
        items.add(new ListItem(source, currencyCode, baseRateAsFiat, baseRateMinDecimals, balanceAsFiat, isDefault));
    }
    return items;
}
Also used : ExchangeRateEntry(de.schildbach.wallet.exchangerate.ExchangeRateEntry) ExchangeRate(org.bitcoinj.utils.ExchangeRate) Fiat(org.bitcoinj.utils.Fiat) ArrayList(java.util.ArrayList)

Example 4 with ExchangeRate

use of org.bitcoinj.utils.ExchangeRate in project bitcoin-wallet by bitcoin-wallet.

the class CoinGecko method parse.

public List<ExchangeRateEntry> parse(final BufferedSource jsonSource) throws IOException {
    final JsonAdapter<Response> jsonAdapter = moshi.adapter(Response.class);
    final Response jsonResponse = jsonAdapter.fromJson(jsonSource);
    final List<ExchangeRateEntry> result = new ArrayList<>(jsonResponse.rates.size());
    for (Map.Entry<String, ExchangeRateJson> entry : jsonResponse.rates.entrySet()) {
        final String symbol = entry.getKey().toUpperCase(Locale.US);
        final ExchangeRateJson exchangeRate = entry.getValue();
        if (exchangeRate.type == Type.FIAT) {
            try {
                final Fiat rate = Fiat.parseFiatInexact(symbol, exchangeRate.value);
                if (rate.signum() > 0)
                    result.add(new ExchangeRateEntry(SOURCE, new ExchangeRate(rate)));
            } catch (final ArithmeticException x) {
                log.warn("problem parsing {} exchange rate from {}: {}", symbol, URL, x.getMessage());
            }
        }
    }
    return result;
}
Also used : ExchangeRate(org.bitcoinj.utils.ExchangeRate) Fiat(org.bitcoinj.utils.Fiat) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

ExchangeRate (org.bitcoinj.utils.ExchangeRate)4 Contract (io.bitsquare.trade.Contract)2 ArrayList (java.util.ArrayList)2 Fiat (org.bitcoinj.utils.Fiat)2 ExchangeRateEntry (de.schildbach.wallet.exchangerate.ExchangeRateEntry)1 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)1 Offer (io.bitsquare.trade.offer.Offer)1 Map (java.util.Map)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 TextArea (javafx.scene.control.TextArea)1 TextField (javafx.scene.control.TextField)1 Tooltip (javafx.scene.control.Tooltip)1 Stage (javafx.stage.Stage)1 Window (javafx.stage.Window)1