Search in sources :

Example 1 with UtxoEntry

use of com.sparrowwallet.sparrow.wallet.UtxoEntry 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 2 with UtxoEntry

use of com.sparrowwallet.sparrow.wallet.UtxoEntry in project sparrow by sparrowwallet.

the class DateCell method updateItem.

@Override
protected void updateItem(Entry entry, boolean empty) {
    super.updateItem(entry, empty);
    EntryCell.applyRowStyles(this, entry);
    if (empty) {
        setText(null);
        setGraphic(null);
    } else {
        if (entry instanceof UtxoEntry) {
            UtxoEntry utxoEntry = (UtxoEntry) entry;
            if (utxoEntry.getHashIndex().getHeight() <= 0) {
                setText("Unconfirmed " + (utxoEntry.getHashIndex().getHeight() < 0 ? "Parent " : "") + (utxoEntry.getWallet().isWhirlpoolMixWallet() ? "(Not yet mixable)" : (utxoEntry.isSpendable() ? "(Spendable)" : "(Not yet spendable)")));
                setContextMenu(null);
            } else if (utxoEntry.getHashIndex().getDate() != null) {
                String date = DATE_FORMAT.format(utxoEntry.getHashIndex().getDate());
                setText(date);
                setContextMenu(new DateContextMenu(date, utxoEntry.getHashIndex()));
            } else {
                setText("Unknown");
                setContextMenu(null);
            }
            Tooltip tooltip = new Tooltip();
            tooltip.setShowDelay(Duration.millis(250));
            int height = utxoEntry.getHashIndex().getHeight();
            tooltip.setText(height > 0 ? Integer.toString(height) : "Mempool");
            setTooltip(tooltip);
        }
        setGraphic(null);
    }
}
Also used : UtxoEntry(com.sparrowwallet.sparrow.wallet.UtxoEntry)

Example 3 with UtxoEntry

use of com.sparrowwallet.sparrow.wallet.UtxoEntry in project sparrow by sparrowwallet.

the class WhirlpoolController method initializeView.

public void initializeView(String walletId, Wallet wallet, List<UtxoEntry> utxoEntries) {
    this.walletId = walletId;
    this.wallet = wallet;
    this.utxoEntries = utxoEntries;
    this.mixConfig = wallet.getMasterMixConfig();
    step1.managedProperty().bind(step1.visibleProperty());
    step2.managedProperty().bind(step2.visibleProperty());
    step3.managedProperty().bind(step3.visibleProperty());
    step4.managedProperty().bind(step4.visibleProperty());
    step2.setVisible(false);
    step3.setVisible(false);
    step4.setVisible(false);
    scode.setText(mixConfig.getScode() == null ? "" : mixConfig.getScode());
    scode.setTextFormatter(new TextFormatter<>((change) -> {
        change.setText(change.getText().toUpperCase());
        return change;
    }));
    scode.textProperty().addListener((observable, oldValue, newValue) -> {
        pool.setItems(FXCollections.emptyObservableList());
        tx0PreviewProperty.set(null);
        mixConfig.setScode(newValue);
        EventManager.get().post(new WalletMasterMixConfigChangedEvent(wallet));
    });
    premixPriority.setMin(0);
    premixPriority.setMax(FEE_TARGETS.size() - 1);
    premixPriority.setMajorTickUnit(1);
    premixPriority.setMinorTickCount(0);
    premixPriority.setLabelFormatter(new StringConverter<>() {

        @Override
        public String toString(Double object) {
            return object.intValue() == 0 ? "Low" : (object.intValue() == 1 ? "Normal" : "High");
        }

        @Override
        public Double fromString(String string) {
            return null;
        }
    });
    premixPriority.valueProperty().addListener((observable, oldValue, newValue) -> {
        pool.setItems(FXCollections.emptyObservableList());
        tx0Previews = null;
        tx0PreviewProperty.set(null);
        Tx0FeeTarget tx0FeeTarget = FEE_TARGETS.get(newValue.intValue());
        premixFeeRate.setText(SparrowMinerFeeSupplier.getFee(Integer.parseInt(tx0FeeTarget.getFeeTarget().getValue())) + " sats/vB");
    });
    premixPriority.setValue(1);
    if (mixConfig.getScode() != null) {
        step1.setVisible(false);
        step3.setVisible(true);
    }
    pool.setConverter(new StringConverter<Pool>() {

        @Override
        public String toString(Pool selectedPool) {
            if (selectedPool == null) {
                pool.setTooltip(null);
                return "Fetching pools...";
            }
            BitcoinUnit bitcoinUnit = wallet.getAutoUnit();
            String satsValue = String.format(Locale.ENGLISH, "%,d", selectedPool.getDenomination()) + " sats";
            String btcValue = CoinLabel.BTC_FORMAT.format((double) selectedPool.getDenomination() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC";
            pool.setTooltip(bitcoinUnit == BitcoinUnit.BTC ? new Tooltip(satsValue) : new Tooltip(btcValue));
            return bitcoinUnit == BitcoinUnit.BTC ? btcValue : satsValue;
        }

        @Override
        public Pool fromString(String string) {
            return null;
        }
    });
    pool.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == null) {
            selectedPool.setVisible(false);
        } else {
            poolFee.setValue(newValue.getFeeValue());
            poolAnonset.setText(newValue.getMixAnonymitySet() + " UTXOs");
            selectedPool.setVisible(true);
            fetchTx0Preview(newValue);
        }
    });
    step4.visibleProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue && pool.getItems().isEmpty()) {
            fetchPools();
        }
    });
    selectedPool.managedProperty().bind(selectedPool.visibleProperty());
    selectedPool.setVisible(false);
    pool.managedProperty().bind(pool.visibleProperty());
    poolInsufficient.managedProperty().bind(poolInsufficient.visibleProperty());
    poolInsufficient.visibleProperty().bind(pool.visibleProperty().not());
    discountFeeBox.managedProperty().bind(discountFeeBox.visibleProperty());
    discountFeeBox.setVisible(false);
    nbOutputsBox.managedProperty().bind(nbOutputsBox.visibleProperty());
    nbOutputsBox.setVisible(false);
    nbOutputsLoading.managedProperty().bind(nbOutputsLoading.visibleProperty());
    nbOutputs.managedProperty().bind(nbOutputs.visibleProperty());
    nbOutputsLoading.visibleProperty().bind(nbOutputs.visibleProperty().not());
    nbOutputs.setVisible(false);
    tx0PreviewProperty.addListener((observable, oldValue, tx0Preview) -> {
        if (tx0Preview == null) {
            nbOutputsBox.setVisible(true);
            nbOutputsLoading.setText("Calculating...");
            nbOutputs.setVisible(false);
            discountFeeBox.setVisible(false);
        } else {
            discountFeeBox.setVisible(tx0Preview.getPool().getFeeValue() != tx0Preview.getTx0Data().getFeeValue());
            discountFee.setValue(tx0Preview.getTx0Data().getFeeValue());
            nbOutputsBox.setVisible(true);
            nbOutputs.setText(tx0Preview.getNbPremix() + " UTXOs");
            nbOutputs.setVisible(true);
        }
    });
}
Also used : java.util(java.util) Wallet(com.sparrowwallet.drongo.wallet.Wallet) javafx.scene.control(javafx.scene.control) Pool(com.samourai.whirlpool.client.whirlpool.beans.Pool) SparrowMinerFeeSupplier(com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowMinerFeeSupplier) FXCollections(javafx.collections.FXCollections) CopyableCoinLabel(com.sparrowwallet.sparrow.control.CopyableCoinLabel) Config(com.sparrowwallet.sparrow.io.Config) VBox(javafx.scene.layout.VBox) MixConfig(com.sparrowwallet.drongo.wallet.MixConfig) UtxoEntry(com.sparrowwallet.sparrow.wallet.UtxoEntry) Tx0Previews(com.samourai.whirlpool.client.tx0.Tx0Previews) Transaction(com.sparrowwallet.drongo.protocol.Transaction) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Tx0Preview(com.samourai.whirlpool.client.tx0.Tx0Preview) StringConverter(javafx.util.StringConverter) CoinLabel(com.sparrowwallet.sparrow.control.CoinLabel) WalletMasterMixConfigChangedEvent(com.sparrowwallet.sparrow.event.WalletMasterMixConfigChangedEvent) Entry(com.sparrowwallet.sparrow.wallet.Entry) BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) FXML(javafx.fxml.FXML) AppServices(com.sparrowwallet.sparrow.AppServices) CopyableLabel(com.sparrowwallet.sparrow.control.CopyableLabel) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tx0FeeTarget(com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget) EventManager(com.sparrowwallet.sparrow.EventManager) BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) Tx0FeeTarget(com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget) WalletMasterMixConfigChangedEvent(com.sparrowwallet.sparrow.event.WalletMasterMixConfigChangedEvent) Pool(com.samourai.whirlpool.client.whirlpool.beans.Pool)

Example 4 with UtxoEntry

use of com.sparrowwallet.sparrow.wallet.UtxoEntry in project sparrow by sparrowwallet.

the class AddressCell method updateItem.

@Override
protected void updateItem(UtxoEntry.AddressStatus addressStatus, boolean empty) {
    super.updateItem(addressStatus, empty);
    UtxoEntry utxoEntry = addressStatus == null ? null : addressStatus.getUtxoEntry();
    EntryCell.applyRowStyles(this, utxoEntry);
    if (empty) {
        setText(null);
        setGraphic(null);
    } else {
        if (utxoEntry != null) {
            Address address = addressStatus.getAddress();
            setText(address.toString());
            setContextMenu(new EntryCell.AddressContextMenu(address, utxoEntry.getOutputDescriptor(), new NodeEntry(utxoEntry.getWallet(), utxoEntry.getNode())));
            Tooltip tooltip = new Tooltip();
            tooltip.setShowDelay(Duration.millis(250));
            tooltip.setText(getTooltipText(utxoEntry, addressStatus.isDuplicate()));
            setTooltip(tooltip);
            if (addressStatus.isDuplicate()) {
                setGraphic(getDuplicateGlyph());
            } else {
                setGraphic(null);
            }
        }
    }
}
Also used : Address(com.sparrowwallet.drongo.address.Address) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) Tooltip(javafx.scene.control.Tooltip) UtxoEntry(com.sparrowwallet.sparrow.wallet.UtxoEntry)

Aggregations

UtxoEntry (com.sparrowwallet.sparrow.wallet.UtxoEntry)4 BitcoinUnit (com.sparrowwallet.drongo.BitcoinUnit)2 Entry (com.sparrowwallet.sparrow.wallet.Entry)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 Pool (com.samourai.whirlpool.client.whirlpool.beans.Pool)1 Address (com.sparrowwallet.drongo.address.Address)1 Transaction (com.sparrowwallet.drongo.protocol.Transaction)1 MixConfig (com.sparrowwallet.drongo.wallet.MixConfig)1 Wallet (com.sparrowwallet.drongo.wallet.Wallet)1 AppServices (com.sparrowwallet.sparrow.AppServices)1 EventManager (com.sparrowwallet.sparrow.EventManager)1 CoinLabel (com.sparrowwallet.sparrow.control.CoinLabel)1 CopyableCoinLabel (com.sparrowwallet.sparrow.control.CopyableCoinLabel)1 CopyableLabel (com.sparrowwallet.sparrow.control.CopyableLabel)1 WalletMasterMixConfigChangedEvent (com.sparrowwallet.sparrow.event.WalletMasterMixConfigChangedEvent)1 Config (com.sparrowwallet.sparrow.io.Config)1 HashIndexEntry (com.sparrowwallet.sparrow.wallet.HashIndexEntry)1 NodeEntry (com.sparrowwallet.sparrow.wallet.NodeEntry)1