Search in sources :

Example 1 with HashIndexEntry

use of com.sparrowwallet.sparrow.wallet.HashIndexEntry 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 HashIndexEntry

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

the class HeadersController method walletHistoryChanged.

@Subscribe
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
    // Update tx and input/output reference labels on history changed wallet if this txid matches and label is null
    if (headersForm.getSigningWallet() != null && !(headersForm.getSigningWallet() instanceof FinalizingPSBTWallet)) {
        Sha256Hash txid = headersForm.getTransaction().getTxId();
        List<Entry> changedLabelEntries = new ArrayList<>();
        BlockTransaction blockTransaction = event.getWallet().getWalletTransaction(txid);
        if (blockTransaction != null && blockTransaction.getLabel() == null) {
            blockTransaction.setLabel(headersForm.getName());
            changedLabelEntries.add(new TransactionEntry(event.getWallet(), blockTransaction, Collections.emptyMap(), Collections.emptyMap()));
        }
        for (WalletNode walletNode : event.getHistoryChangedNodes()) {
            for (BlockTransactionHashIndex output : walletNode.getTransactionOutputs()) {
                if (output.getHash().equals(txid) && output.getLabel() == null) {
                    // If we send to ourselves, usually change
                    String label = outputIndexLabels.containsKey((int) output.getIndex()) ? outputIndexLabels.get((int) output.getIndex()) : headersForm.getName();
                    output.setLabel(label + (walletNode.getKeyPurpose() == KeyPurpose.CHANGE ? (walletNode.getWallet().isBip47() ? " (sent)" : " (change)") : " (received)"));
                    changedLabelEntries.add(new HashIndexEntry(event.getWallet(), output, HashIndexEntry.Type.OUTPUT, walletNode.getKeyPurpose()));
                }
                if (output.getSpentBy() != null && output.getSpentBy().getHash().equals(txid) && output.getSpentBy().getLabel() == null) {
                    // The norm - sending out
                    output.getSpentBy().setLabel(headersForm.getName() + " (input)");
                    changedLabelEntries.add(new HashIndexEntry(event.getWallet(), output.getSpentBy(), HashIndexEntry.Type.INPUT, walletNode.getKeyPurpose()));
                }
            }
        }
        if (!changedLabelEntries.isEmpty()) {
            Platform.runLater(() -> EventManager.get().post(new WalletEntryLabelsChangedEvent(event.getWallet(), changedLabelEntries)));
        }
    }
}
Also used : Entry(com.sparrowwallet.sparrow.wallet.Entry) HashIndexEntry(com.sparrowwallet.sparrow.wallet.HashIndexEntry) TransactionEntry(com.sparrowwallet.sparrow.wallet.TransactionEntry) SecureString(com.sparrowwallet.drongo.SecureString) HashIndexEntry(com.sparrowwallet.sparrow.wallet.HashIndexEntry) TransactionEntry(com.sparrowwallet.sparrow.wallet.TransactionEntry) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Entry (com.sparrowwallet.sparrow.wallet.Entry)2 HashIndexEntry (com.sparrowwallet.sparrow.wallet.HashIndexEntry)2 TransactionEntry (com.sparrowwallet.sparrow.wallet.TransactionEntry)2 Subscribe (com.google.common.eventbus.Subscribe)1 BitcoinUnit (com.sparrowwallet.drongo.BitcoinUnit)1 SecureString (com.sparrowwallet.drongo.SecureString)1 UtxoEntry (com.sparrowwallet.sparrow.wallet.UtxoEntry)1 DecimalFormat (java.text.DecimalFormat)1 Region (javafx.scene.layout.Region)1