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);
}
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);
}
}
}
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);
}
}
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));
}
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);
}
Aggregations