Search in sources :

Example 1 with BitcoinUnit

use of com.sparrowwallet.drongo.BitcoinUnit in project sparrow by sparrowwallet.

the class BalanceChart method initialize.

public void initialize(WalletTransactionsEntry walletTransactionsEntry) {
    managedProperty().bind(visibleProperty());
    balanceSeries = new XYChart.Series<>();
    getData().add(balanceSeries);
    update(walletTransactionsEntry);
    BitcoinUnit unit = Config.get().getBitcoinUnit();
    setBitcoinUnit(walletTransactionsEntry.getWallet(), unit);
}
Also used : BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit)

Example 2 with BitcoinUnit

use of com.sparrowwallet.drongo.BitcoinUnit in project sparrow by sparrowwallet.

the class CoinCell method updateItem.

@Override
protected void updateItem(Number amount, boolean empty) {
    super.updateItem(amount, empty);
    if (empty || amount == null) {
        setText(null);
        setGraphic(null);
        setTooltip(null);
    } else {
        Entry entry = getTreeTableView().getTreeItem(getIndex()).getValue();
        EntryCell.applyRowStyles(this, entry);
        CoinTreeTable coinTreeTable = (CoinTreeTable) getTreeTableView();
        BitcoinUnit unit = coinTreeTable.getBitcoinUnit();
        String satsValue = String.format(Locale.ENGLISH, "%,d", amount.longValue());
        DecimalFormat decimalFormat = (amount.longValue() == 0L ? CoinLabel.getBTCFormat() : TABLE_BTC_FORMAT);
        final String btcValue = decimalFormat.format(amount.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN);
        if (unit.equals(BitcoinUnit.BTC)) {
            tooltip.setText(satsValue + " " + BitcoinUnit.SATOSHIS.getLabel());
            setText(btcValue);
        } else {
            tooltip.setText(btcValue + " " + BitcoinUnit.BTC.getLabel());
            setText(satsValue);
        }
        setTooltip(tooltip);
        String tooltipValue = tooltip.getText();
        if (entry instanceof TransactionEntry) {
            TransactionEntry transactionEntry = (TransactionEntry) entry;
            tooltip.setText(tooltipValue + " (" + transactionEntry.getConfirmationsDescription() + ")");
            transactionEntry.confirmationsProperty().addListener((observable, oldValue, newValue) -> {
                tooltip.setText(tooltipValue + " (" + transactionEntry.getConfirmationsDescription() + ")");
            });
            if (transactionEntry.isConfirming()) {
                ConfirmationProgressIndicator arc = new ConfirmationProgressIndicator(transactionEntry.getConfirmations());
                arc.confirmationsProperty().bind(transactionEntry.confirmationsProperty());
                setGraphic(arc);
                setContentDisplay(ContentDisplay.LEFT);
            } else {
                setGraphic(null);
            }
            if (amount.longValue() < 0) {
                getStyleClass().add("negative-amount");
            }
        } else if (entry instanceof UtxoEntry) {
            setGraphic(null);
        } else if (entry instanceof HashIndexEntry) {
            Region node = new Region();
            node.setPrefWidth(10);
            setGraphic(node);
            setContentDisplay(ContentDisplay.RIGHT);
            if (((HashIndexEntry) entry).getType() == HashIndexEntry.Type.INPUT) {
                satsValue = "-" + satsValue;
            }
        } else {
            setGraphic(null);
        }
    }
}
Also used : BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) TransactionEntry(com.sparrowwallet.sparrow.wallet.TransactionEntry) Entry(com.sparrowwallet.sparrow.wallet.Entry) UtxoEntry(com.sparrowwallet.sparrow.wallet.UtxoEntry) HashIndexEntry(com.sparrowwallet.sparrow.wallet.HashIndexEntry) DecimalFormat(java.text.DecimalFormat) Region(javafx.scene.layout.Region) UtxoEntry(com.sparrowwallet.sparrow.wallet.UtxoEntry) HashIndexEntry(com.sparrowwallet.sparrow.wallet.HashIndexEntry) TransactionEntry(com.sparrowwallet.sparrow.wallet.TransactionEntry)

Example 3 with BitcoinUnit

use of com.sparrowwallet.drongo.BitcoinUnit in project sparrow by sparrowwallet.

the class CoinLabel method setValueAsText.

private void setValueAsText(Long value, BitcoinUnit bitcoinUnit) {
    setTooltip(tooltip);
    setContextMenu(contextMenu);
    String satsValue = String.format(Locale.ENGLISH, "%,d", value) + " sats";
    String btcValue = BTC_FORMAT.format(value.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC";
    BitcoinUnit unit = bitcoinUnit;
    if (unit == null || unit.equals(BitcoinUnit.AUTO)) {
        unit = (value >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS);
    }
    if (unit.equals(BitcoinUnit.BTC)) {
        tooltip.setText(satsValue);
        setText(btcValue);
    } else {
        tooltip.setText(btcValue);
        setText(satsValue);
    }
}
Also used : BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit)

Example 4 with BitcoinUnit

use of com.sparrowwallet.drongo.BitcoinUnit in project sparrow by sparrowwallet.

the class SendController method initializeView.

@Override
public void initializeView() {
    addValidation();
    addPaymentTab();
    initializeTabHeader(0);
    paymentTabs.getTabs().addListener((ListChangeListener<Tab>) c -> {
        if (tabHeader != null) {
            tabHeader.setVisible(c.getList().size() > 1);
        }
        if (c.getList().size() > 1) {
            if (!paymentTabs.getStyleClass().contains("multiple-tabs")) {
                paymentTabs.getStyleClass().add("multiple-tabs");
            }
            paymentTabs.getTabs().forEach(tab -> {
                tab.setClosable(true);
                ((PaymentController) tab.getUserData()).updateMixOnlyStatus();
            });
        } else {
            paymentTabs.getStyleClass().remove("multiple-tabs");
            Tab remainingTab = paymentTabs.getTabs().get(0);
            remainingTab.setClosable(false);
            remainingTab.setText("1");
        }
        updateTransaction();
    });
    insufficientInputsProperty.addListener((observable, oldValue, newValue) -> {
        for (Tab tab : paymentTabs.getTabs()) {
            PaymentController controller = (PaymentController) tab.getUserData();
            controller.revalidateAmount();
        }
        revalidate(fee, feeListener);
    });
    targetBlocksField.managedProperty().bind(targetBlocksField.visibleProperty());
    targetBlocks.setMin(0);
    targetBlocks.setMax(TARGET_BLOCKS_RANGE.size() - 1);
    targetBlocks.setMajorTickUnit(1);
    targetBlocks.setMinorTickCount(0);
    targetBlocks.setLabelFormatter(new StringConverter<Double>() {

        @Override
        public String toString(Double object) {
            String blocks = Integer.toString(TARGET_BLOCKS_RANGE.get(object.intValue()));
            return (object.intValue() == TARGET_BLOCKS_RANGE.size() - 1) ? blocks + "+" : blocks;
        }

        @Override
        public Double fromString(String string) {
            return (double) TARGET_BLOCKS_RANGE.indexOf(Integer.valueOf(string.replace("+", "")));
        }
    });
    targetBlocks.valueProperty().addListener(targetBlocksListener);
    feeRangeField.managedProperty().bind(feeRangeField.visibleProperty());
    feeRangeField.visibleProperty().bind(targetBlocksField.visibleProperty().not());
    feeRange.setMin(0);
    feeRange.setMax(FEE_RATES_RANGE.size() - 1);
    feeRange.setMajorTickUnit(1);
    feeRange.setMinorTickCount(0);
    feeRange.setLabelFormatter(new StringConverter<Double>() {

        @Override
        public String toString(Double object) {
            return Long.toString(FEE_RATES_RANGE.get(object.intValue()));
        }

        @Override
        public Double fromString(String string) {
            return null;
        }
    });
    feeRange.valueProperty().addListener(feeRangeListener);
    blockTargetFeeRatesChart.managedProperty().bind(blockTargetFeeRatesChart.visibleProperty());
    blockTargetFeeRatesChart.initialize();
    Map<Integer, Double> targetBlocksFeeRates = getTargetBlocksFeeRates();
    if (targetBlocksFeeRates != null) {
        blockTargetFeeRatesChart.update(targetBlocksFeeRates);
    } else {
        feeRate.setText("Unknown");
    }
    mempoolSizeFeeRatesChart.managedProperty().bind(mempoolSizeFeeRatesChart.visibleProperty());
    mempoolSizeFeeRatesChart.visibleProperty().bind(blockTargetFeeRatesChart.visibleProperty().not());
    mempoolSizeFeeRatesChart.initialize();
    Map<Date, Set<MempoolRateSize>> mempoolHistogram = getMempoolHistogram();
    if (mempoolHistogram != null) {
        mempoolSizeFeeRatesChart.update(mempoolHistogram);
    }
    FeeRatesSelection feeRatesSelection = Config.get().getFeeRatesSelection();
    feeRatesSelection = (feeRatesSelection == null ? FeeRatesSelection.MEMPOOL_SIZE : feeRatesSelection);
    cpfpFeeRate.managedProperty().bind(cpfpFeeRate.visibleProperty());
    cpfpFeeRate.setVisible(false);
    setDefaultFeeRate();
    updateFeeRateSelection(feeRatesSelection);
    feeSelectionToggleGroup.selectToggle(feeRatesSelection == FeeRatesSelection.BLOCK_TARGET ? targetBlocksToggle : mempoolSizeToggle);
    feeSelectionToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            FeeRatesSelection newFeeRatesSelection = (FeeRatesSelection) newValue.getUserData();
            Config.get().setFeeRatesSelection(newFeeRatesSelection);
            EventManager.get().post(new FeeRatesSelectionChangedEvent(getWalletForm().getWallet(), newFeeRatesSelection));
        }
        ;
    });
    fee.setTextFormatter(new CoinTextFormatter());
    fee.textProperty().addListener(feeListener);
    BitcoinUnit unit = getBitcoinUnit(Config.get().getBitcoinUnit());
    feeAmountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(unit) ? 0 : 1);
    feeAmountUnit.valueProperty().addListener((observable, oldValue, newValue) -> {
        Long value = getFeeValueSats(oldValue);
        if (value != null) {
            setFeeValueSats(value);
        }
    });
    userFeeSet.addListener((observable, oldValue, newValue) -> {
        blockTargetFeeRatesChart.select(0);
        Node thumb = getSliderThumb();
        if (thumb != null) {
            if (newValue) {
                thumb.getStyleClass().add("inactive");
            } else {
                thumb.getStyleClass().remove("inactive");
            }
        }
    });
    utxoLabelSelectionProperty.addListener((observable, oldValue, newValue) -> {
        clearButton.setText("Clear" + newValue);
    });
    utxoSelectorProperty.addListener((observable, oldValue, utxoSelector) -> {
        updateMaxClearButtons(utxoSelector, utxoFilterProperty.get());
    });
    utxoFilterProperty.addListener((observable, oldValue, utxoFilter) -> {
        updateMaxClearButtons(utxoSelectorProperty.get(), utxoFilter);
    });
    walletTransactionProperty.addListener((observable, oldValue, walletTransaction) -> {
        if (walletTransaction != null) {
            setPayments(walletTransaction.getPayments().stream().filter(payment -> payment.getType() != Payment.Type.FAKE_MIX).collect(Collectors.toList()));
            double feeRate = walletTransaction.getFeeRate();
            if (userFeeSet.get()) {
                setTargetBlocks(getTargetBlocks(feeRate));
                setFeeRangeRate(feeRate);
            } else {
                setFeeValueSats(walletTransaction.getFee());
            }
            setFeeRate(feeRate);
            setEffectiveFeeRate(walletTransaction);
        }
        transactionDiagram.update(walletTransaction);
        updatePrivacyAnalysis(walletTransaction);
        createButton.setDisable(walletTransaction == null || isInsufficientFeeRate() || isPayNymMixOnlyPayment(walletTransaction.getPayments()));
        notificationButton.setDisable(walletTransaction == null || isInsufficientFeeRate() || !AppServices.isConnected());
    });
    transactionDiagram.sceneProperty().addListener((observable, oldScene, newScene) -> {
        if (oldScene == null && newScene != null) {
            transactionDiagram.update(walletTransactionProperty.get());
            newScene.getWindow().heightProperty().addListener((observable1, oldValue, newValue) -> {
                transactionDiagram.update(walletTransactionProperty.get());
            });
        }
    });
    addFeeRangeTrackHighlight(0);
    efficiencyToggle.setOnAction(event -> {
        if (getWalletForm().getWallet().isWhirlpoolMixWallet() && !overrideOptimizationStrategy) {
            AppServices.showWarningDialog("Privacy may be lost!", "It is recommended to optimize for privacy when sending coinjoined outputs.");
            overrideOptimizationStrategy = true;
        }
        Config.get().setSendOptimizationStrategy(OptimizationStrategy.EFFICIENCY);
        updateTransaction();
    });
    privacyToggle.setOnAction(event -> {
        Config.get().setSendOptimizationStrategy(OptimizationStrategy.PRIVACY);
        updateTransaction();
    });
    setPreferredOptimizationStrategy();
    updatePrivacyAnalysis(null);
    optimizationHelp.managedProperty().bind(optimizationHelp.visibleProperty());
    privacyAnalysis.managedProperty().bind(privacyAnalysis.visibleProperty());
    optimizationHelp.visibleProperty().bind(privacyAnalysis.visibleProperty().not());
    createButton.managedProperty().bind(createButton.visibleProperty());
    premixButton.managedProperty().bind(premixButton.visibleProperty());
    notificationButton.managedProperty().bind(notificationButton.visibleProperty());
    createButton.visibleProperty().bind(Bindings.and(premixButton.visibleProperty().not(), notificationButton.visibleProperty().not()));
    premixButton.setVisible(false);
    notificationButton.setVisible(false);
    AppServices.onlineProperty().addListener(new WeakChangeListener<>(broadcastButtonsOnlineListener));
}
Also used : Initializable(javafx.fxml.Initializable) PayNym(com.sparrowwallet.sparrow.paynym.PayNym) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool) com.sparrowwallet.drongo.wallet(com.sparrowwallet.drongo.wallet) javafx.scene.control(javafx.scene.control) URL(java.net.URL) DecimalFormatSymbols(java.text.DecimalFormatSymbols) LoggerFactory(org.slf4j.LoggerFactory) StackPane(javafx.scene.layout.StackPane) ValidationSupport(org.controlsfx.validation.ValidationSupport) Config(com.sparrowwallet.sparrow.io.Config) VBox(javafx.scene.layout.VBox) PayNymAddress(com.sparrowwallet.sparrow.paynym.PayNymAddress) Task(javafx.concurrent.Task) SorobanServices(com.sparrowwallet.sparrow.soroban.SorobanServices) ListChangeListener(javafx.collections.ListChangeListener) CurrencyRate(com.sparrowwallet.sparrow.CurrencyRate) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) com.sparrowwallet.sparrow.net(com.sparrowwallet.sparrow.net) Timeline(javafx.animation.Timeline) Service(javafx.concurrent.Service) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Duration(javafx.util.Duration) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) InitiatorDialog(com.sparrowwallet.sparrow.soroban.InitiatorDialog) Sha256Hash(com.sparrowwallet.drongo.protocol.Sha256Hash) ScriptType(com.sparrowwallet.drongo.protocol.ScriptType) PaymentCode(com.sparrowwallet.drongo.bip47.PaymentCode) WeakChangeListener(javafx.beans.value.WeakChangeListener) Address(com.sparrowwallet.drongo.address.Address) java.util(java.util) Pool(com.samourai.whirlpool.client.whirlpool.beans.Pool) Bindings(javafx.beans.binding.Bindings) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) Glyph(org.controlsfx.glyphfont.Glyph) StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration) FXMLLoader(javafx.fxml.FXMLLoader) ValidationResult(org.controlsfx.validation.ValidationResult) Subscribe(com.google.common.eventbus.Subscribe) Transaction(com.sparrowwallet.drongo.protocol.Transaction) Storage(com.sparrowwallet.sparrow.io.Storage) KeyFrame(javafx.animation.KeyFrame) javafx.beans.property(javafx.beans.property) Modality(javafx.stage.Modality) TransactionOutPoint(com.sparrowwallet.drongo.protocol.TransactionOutPoint) Logger(org.slf4j.Logger) SecretPoint(com.sparrowwallet.drongo.bip47.SecretPoint) PSBT(com.sparrowwallet.drongo.psbt.PSBT) Field(tornadofx.control.Field) SecureString(com.sparrowwallet.drongo.SecureString) Node(javafx.scene.Node) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) StringConverter(javafx.util.StringConverter) BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) ActionEvent(javafx.event.ActionEvent) AppServices(com.sparrowwallet.sparrow.AppServices) EventManager(com.sparrowwallet.sparrow.EventManager) ECKey(com.sparrowwallet.drongo.crypto.ECKey) ObservableValue(javafx.beans.value.ObservableValue) Validator(org.controlsfx.validation.Validator) ChangeListener(javafx.beans.value.ChangeListener) com.sparrowwallet.sparrow.control(com.sparrowwallet.sparrow.control) BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) Node(javafx.scene.Node) SecureString(com.sparrowwallet.drongo.SecureString)

Example 5 with BitcoinUnit

use of com.sparrowwallet.drongo.BitcoinUnit in project sparrow by sparrowwallet.

the class PaymentController method bitcoinUnitChanged.

@Subscribe
public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) {
    BitcoinUnit unit = sendController.getBitcoinUnit(event.getBitcoinUnit());
    amountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(unit) ? 0 : 1);
}
Also used : BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

BitcoinUnit (com.sparrowwallet.drongo.BitcoinUnit)9 Subscribe (com.google.common.eventbus.Subscribe)3 Pool (com.samourai.whirlpool.client.whirlpool.beans.Pool)2 Transaction (com.sparrowwallet.drongo.protocol.Transaction)2 AppServices (com.sparrowwallet.sparrow.AppServices)2 EventManager (com.sparrowwallet.sparrow.EventManager)2 Config (com.sparrowwallet.sparrow.io.Config)2 Entry (com.sparrowwallet.sparrow.wallet.Entry)2 UtxoEntry (com.sparrowwallet.sparrow.wallet.UtxoEntry)2 DecimalFormat (java.text.DecimalFormat)2 java.util (java.util)2 Tx0Preview (com.samourai.whirlpool.client.tx0.Tx0Preview)1 Tx0Previews (com.samourai.whirlpool.client.tx0.Tx0Previews)1 Tx0FeeTarget (com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget)1 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)1 SecureString (com.sparrowwallet.drongo.SecureString)1 Address (com.sparrowwallet.drongo.address.Address)1 InvalidAddressException (com.sparrowwallet.drongo.address.InvalidAddressException)1 PaymentCode (com.sparrowwallet.drongo.bip47.PaymentCode)1 SecretPoint (com.sparrowwallet.drongo.bip47.SecretPoint)1