use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.
the class BackupView method activate.
@Override
protected void activate() {
backUpLocationTextField.focusedProperty().addListener(backUpLocationTextFieldFocusListener);
selectBackupDir.setOnAction(e -> {
String path = preferences.getDirectoryChooserPath();
if (!Utilities.isDirectory(path)) {
path = Utilities.getSystemHomeDirectory();
backUpLocationTextField.setText(path);
}
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(new File(path));
directoryChooser.setTitle(Res.get("account.backup.selectLocation"));
try {
File dir = directoryChooser.showDialog(stage);
if (dir != null) {
applyBackupDirectory(dir.getAbsolutePath());
}
} catch (Throwable t) {
showWrongPathWarningAndReset(t);
}
});
openDataDirButton.setOnAction(event -> {
try {
Utilities.openFile(dataDir);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
showWrongPathWarningAndReset(e);
}
});
openLogsButton.setOnAction(event -> {
try {
Utilities.openFile(logFile);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
showWrongPathWarningAndReset(e);
}
});
backupNow.setOnAction(event -> {
String backupDirectory = preferences.getBackupDirectory();
if (backupDirectory != null && backupDirectory.length() > 0) {
try {
String dateString = new SimpleDateFormat("yyyy-MM-dd-HHmmss").format(new Date());
String destination = Paths.get(backupDirectory, "bisq_backup_" + dateString).toString();
FileUtil.copyDirectory(dataDir, new File(destination));
new Popup<>().feedback(Res.get("account.backup.success", destination)).show();
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
showWrongPathWarningAndReset(e);
}
}
});
}
use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.
the class BsqSendView method initialize.
@Override
public void initialize() {
gridRow = bsqBalanceUtil.addGroup(root, gridRow);
addTitledGroupBg(root, ++gridRow, 3, Res.get("dao.wallet.send.sendFunds"), Layout.GROUP_DISTANCE);
receiversAddressInputTextField = addLabelInputTextField(root, gridRow, Res.get("dao.wallet.send.receiverAddress"), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
receiversAddressInputTextField.setPromptText(Res.get("dao.wallet.send.setDestinationAddress"));
receiversAddressInputTextField.setValidator(bsqAddressValidator);
amountInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("dao.wallet.send.amount")).second;
amountInputTextField.setPromptText(Res.get("dao.wallet.send.setAmount", Restrictions.getMinNonDustOutput().value));
amountInputTextField.setValidator(bsqValidator);
focusOutListener = (observable, oldValue, newValue) -> {
if (!newValue)
onUpdateBalances(bsqWalletService.getAvailableBalance(), bsqWalletService.getPendingBalance(), bsqWalletService.getLockedForVotingBalance(), bsqWalletService.getLockedInBondsBalance());
};
sendButton = addButtonAfterGroup(root, ++gridRow, Res.get("dao.wallet.send.send"));
sendButton.setOnAction((event) -> {
// TODO break up in methods
if (GUIUtil.isReadyForTxBroadcast(p2PService, walletsSetup)) {
String receiversAddressString = bsqFormatter.getAddressFromBsqAddress(receiversAddressInputTextField.getText()).toString();
Coin receiverAmount = bsqFormatter.parseToCoin(amountInputTextField.getText());
try {
Transaction preparedSendTx = bsqWalletService.getPreparedSendTx(receiversAddressString, receiverAmount);
Transaction txWithBtcFee = btcWalletService.completePreparedSendBsqTx(preparedSendTx, true);
Transaction signedTx = bsqWalletService.signTx(txWithBtcFee);
Coin miningFee = signedTx.getFee();
int txSize = signedTx.bitcoinSerialize().length;
new Popup<>().headLine(Res.get("dao.wallet.send.sendFunds.headline")).confirmation(Res.get("dao.wallet.send.sendFunds.details", bsqFormatter.formatCoinWithCode(receiverAmount), receiversAddressInputTextField.getText(), btcFormatter.formatCoinWithCode(miningFee), CoinUtil.getFeePerByte(miningFee, txSize), txSize / 1000d, bsqFormatter.formatCoinWithCode(receiverAmount))).actionButtonText(Res.get("shared.yes")).onAction(() -> {
bsqWalletService.commitTx(txWithBtcFee);
// We need to create another instance, otherwise the tx would trigger an invalid state exception
// if it gets committed 2 times
btcWalletService.commitTx(btcWalletService.getClonedTransaction(txWithBtcFee));
bsqWalletService.broadcastTx(signedTx, new FutureCallback<Transaction>() {
@Override
public void onSuccess(@Nullable Transaction transaction) {
if (transaction != null) {
log.debug("Successfully sent tx with id " + transaction.getHashAsString());
}
}
@Override
public void onFailure(@NotNull Throwable t) {
log.error(t.toString());
new Popup<>().warning(t.toString());
}
}, 15);
receiversAddressInputTextField.setText("");
amountInputTextField.setText("");
}).closeButtonText(Res.get("shared.cancel")).show();
} catch (Throwable t) {
if (t instanceof InsufficientMoneyException) {
final Coin missingCoin = ((InsufficientMoneyException) t).missing;
final String missing = missingCoin != null ? missingCoin.toFriendlyString() : "null";
// noinspection unchecked
new Popup<>().warning(Res.get("popup.warning.insufficientBtcFundsForBsqTx", missing)).actionButtonTextWithGoTo("navigation.funds.depositFunds").onAction(() -> navigation.navigateTo(MainView.class, FundsView.class, DepositView.class)).show();
} else {
log.error(t.toString());
t.printStackTrace();
new Popup<>().warning(t.getMessage()).show();
}
}
} else {
GUIUtil.showNotReadyForTxBroadcastPopups(p2PService, walletsSetup);
}
});
}
use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.
the class PaymentMethodForm method addLimitations.
protected void addLimitations() {
long hours = paymentAccount.getPaymentMethod().getMaxTradePeriod() / 3600_000;
final TradeCurrency tradeCurrency;
if (paymentAccount.getSingleTradeCurrency() != null)
tradeCurrency = paymentAccount.getSingleTradeCurrency();
else if (paymentAccount.getSelectedTradeCurrency() != null)
tradeCurrency = paymentAccount.getSelectedTradeCurrency();
else if (!paymentAccount.getTradeCurrencies().isEmpty())
tradeCurrency = paymentAccount.getTradeCurrencies().get(0);
else
tradeCurrency = paymentAccount instanceof CryptoCurrencyAccount ? CurrencyUtil.getAllSortedCryptoCurrencies().get(0) : CurrencyUtil.getDefaultTradeCurrency();
final boolean isAddAccountScreen = paymentAccount.getAccountName() == null;
final long accountAge = !isAddAccountScreen ? accountAgeWitnessService.getMyAccountAge(paymentAccount.getPaymentAccountPayload()) : 0L;
addLabelTextField(gridPane, ++gridRow, Res.get("payment.limitations"), Res.get("payment.maxPeriodAndLimit", getTimeText(hours), formatter.formatCoinWithCode(Coin.valueOf(accountAgeWitnessService.getMyTradeLimit(paymentAccount, tradeCurrency.getCode()))), formatter.formatAccountAge(accountAge)));
if (isAddAccountScreen) {
InputTextField inputTextField = addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.salt"), 0).second;
inputTextField.setText(Utilities.bytesAsHexString(paymentAccount.getPaymentAccountPayload().getSalt()));
inputTextField.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.isEmpty()) {
try {
// test if input is hex
Utilities.decodeFromHex(newValue);
paymentAccount.setSaltAsHex(newValue);
} catch (Throwable t) {
new Popup().warning(Res.get("payment.error.noHexSalt")).show();
inputTextField.setText(Utilities.bytesAsHexString(paymentAccount.getPaymentAccountPayload().getSalt()));
log.warn(t.toString());
}
}
});
} else {
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.salt", Utilities.bytesAsHexString(paymentAccount.getPaymentAccountPayload().getSalt())), Utilities.bytesAsHexString(paymentAccount.getPaymentAccountPayload().getSalt()));
}
}
use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.
the class CreateOfferView method createListeners.
private void createListeners() {
amountFocusedListener = (o, oldValue, newValue) -> {
model.onFocusOutAmountTextField(oldValue, newValue);
amountTextField.setText(model.amount.get());
};
minAmountFocusedListener = (o, oldValue, newValue) -> {
model.onFocusOutMinAmountTextField(oldValue, newValue);
minAmountTextField.setText(model.minAmount.get());
};
priceFocusedListener = (o, oldValue, newValue) -> {
model.onFocusOutPriceTextField(oldValue, newValue);
fixedPriceTextField.setText(model.price.get());
};
priceAsPercentageFocusedListener = (o, oldValue, newValue) -> {
model.onFocusOutPriceAsPercentageTextField(oldValue, newValue);
marketBasedPriceTextField.setText(model.marketPriceMargin.get());
};
volumeFocusedListener = (o, oldValue, newValue) -> {
model.onFocusOutVolumeTextField(oldValue, newValue);
volumeTextField.setText(model.volume.get());
};
buyerSecurityDepositFocusedListener = (o, oldValue, newValue) -> {
model.onFocusOutBuyerSecurityDepositTextField(oldValue, newValue);
buyerSecurityDepositInputTextField.setText(model.buyerSecurityDeposit.get());
};
errorMessageListener = (o, oldValue, newValue) -> {
if (newValue != null)
UserThread.runAfter(() -> new Popup<>().error(Res.get("createOffer.amountPriceBox.error.message", model.errorMessage.get())).show(), 100, TimeUnit.MILLISECONDS);
};
paymentAccountsComboBoxSelectionHandler = e -> onPaymentAccountsComboBoxSelected();
currencyComboBoxSelectionHandler = e -> onCurrencyComboBoxSelected();
tradeCurrencyCodeListener = (observable, oldValue, newValue) -> {
fixedPriceTextField.clear();
marketBasedPriceTextField.clear();
volumeTextField.clear();
};
placeOfferCompletedListener = (o, oldValue, newValue) -> {
if (DevEnv.isDevMode()) {
close();
} else if (newValue) {
// We need a bit of delay to avoid issues with fade out/fade in of 2 popups
String key = "createOfferSuccessInfo";
if (DontShowAgainLookup.showAgain(key)) {
UserThread.runAfter(() -> new Popup<>().headLine(Res.get("createOffer.success.headline")).feedback(Res.get("createOffer.success.info")).dontShowAgainId(key).actionButtonTextWithGoTo("navigation.portfolio.myOpenOffers").onAction(() -> {
// noinspection unchecked
UserThread.runAfter(() -> navigation.navigateTo(MainView.class, PortfolioView.class, OpenOffersView.class), 100, TimeUnit.MILLISECONDS);
close();
}).onClose(this::close).show(), 1);
} else {
close();
}
}
};
marketPriceAvailableListener = (observable, oldValue, newValue) -> updateMarketPriceAvailable();
getShowWalletFundedNotificationListener = (observable, oldValue, newValue) -> {
if (newValue) {
Notification walletFundedNotification = new Notification().headLine(Res.get("notification.walletUpdate.headline")).notification(Res.get("notification.walletUpdate.msg", btcFormatter.formatCoinWithCode(model.dataModel.getTotalToPayAsCoin().get()))).autoClose();
walletFundedNotification.show();
}
};
marketPriceMarginListener = (observable, oldValue, newValue) -> {
if (marketBasedPriceInfoInputTextField != null) {
String tooltip;
if (newValue.equals("0.00")) {
if (model.isSellOffer()) {
tooltip = Res.get("createOffer.info.sellAtMarketPrice");
} else {
tooltip = Res.get("createOffer.info.buyAtMarketPrice");
}
final Label atMarketPriceLabel = createPopoverLabel(tooltip);
marketBasedPriceInfoInputTextField.setContentForInfoPopOver(atMarketPriceLabel);
} else if (newValue.contains("-")) {
if (model.isSellOffer()) {
tooltip = Res.get("createOffer.warning.sellBelowMarketPrice", newValue.substring(1));
} else {
tooltip = Res.get("createOffer.warning.buyAboveMarketPrice", newValue.substring(1));
}
final Label negativePercentageLabel = createPopoverLabel(tooltip);
marketBasedPriceInfoInputTextField.setContentForWarningPopOver(negativePercentageLabel);
} else if (!newValue.equals("")) {
if (model.isSellOffer()) {
tooltip = Res.get("createOffer.info.sellAboveMarketPrice", newValue);
} else {
tooltip = Res.get("createOffer.info.buyBelowMarketPrice", newValue);
}
final Label positivePercentageLabel = createPopoverLabel(tooltip);
marketBasedPriceInfoInputTextField.setContentForInfoPopOver(positivePercentageLabel);
}
}
};
}
use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.
the class CreateOfferViewModel method onFocusOutBuyerSecurityDepositTextField.
void onFocusOutBuyerSecurityDepositTextField(boolean oldValue, boolean newValue) {
if (oldValue && !newValue) {
InputValidator.ValidationResult result = securityDepositValidator.validate(buyerSecurityDeposit.get());
buyerSecurityDepositValidationResult.set(result);
if (result.isValid) {
Coin defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDeposit();
String key = "buyerSecurityDepositLowerAsDefault";
if (preferences.showAgain(key) && btcFormatter.parseToCoin(buyerSecurityDeposit.get()).compareTo(defaultSecurityDeposit) < 0) {
final String postfix = dataModel.isBuyOffer() ? Res.get("createOffer.tooLowSecDeposit.makerIsBuyer") : Res.get("createOffer.tooLowSecDeposit.makerIsSeller");
new Popup<>().warning(Res.get("createOffer.tooLowSecDeposit.warning", btcFormatter.formatCoinWithCode(defaultSecurityDeposit)) + "\n\n" + postfix).width(800).actionButtonText(Res.get("createOffer.resetToDefault")).onAction(() -> {
dataModel.setBuyerSecurityDeposit(defaultSecurityDeposit);
ignoreSecurityDepositStringListener = true;
buyerSecurityDeposit.set(btcFormatter.formatCoin(dataModel.getBuyerSecurityDeposit().get()));
ignoreSecurityDepositStringListener = false;
}).closeButtonText(Res.get("createOffer.useLowerValue")).onClose(this::applyBuyerSecurityDepositOnFocusOut).dontShowAgainId(key).show();
} else {
applyBuyerSecurityDepositOnFocusOut();
}
}
}
}
Aggregations