use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class TakeOfferDataModel method onTakeOffer.
// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
// errorMessageHandler is used only in the check availability phase. As soon we have a trade we write the error msg in the trade object as we want to
// have it persisted as well.
void onTakeOffer(TradeResultHandler tradeResultHandler) {
checkNotNull(txFeeFromFeeService, "txFeeFromFeeService must not be null");
checkNotNull(getTakerFee(), "takerFee must not be null");
Coin fundsNeededForTrade = getSecurityDeposit().add(txFeeFromFeeService).add(txFeeFromFeeService);
if (isBuyOffer())
fundsNeededForTrade = fundsNeededForTrade.add(amount.get());
if (filterManager.isCurrencyBanned(offer.getCurrencyCode())) {
new Popup<>().warning(Res.get("offerbook.warning.currencyBanned")).show();
} else if (filterManager.isPaymentMethodBanned(offer.getPaymentMethod())) {
new Popup<>().warning(Res.get("offerbook.warning.paymentMethodBanned")).show();
} else if (filterManager.isOfferIdBanned(offer.getId())) {
new Popup<>().warning(Res.get("offerbook.warning.offerBlocked")).show();
} else if (filterManager.isNodeAddressBanned(offer.getMakerNodeAddress())) {
new Popup<>().warning(Res.get("offerbook.warning.nodeBlocked")).show();
} else {
tradeManager.onTakeOffer(amount.get(), txFeeFromFeeService, getTakerFee(), isCurrencyForTakerFeeBtc(), tradePrice.getValue(), fundsNeededForTrade, offer, paymentAccount.getId(), useSavingsWallet, tradeResultHandler, errorMessage -> {
log.warn(errorMessage);
new Popup<>().warning(errorMessage).show();
});
}
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class ContractWindow method addContent.
private void addContent() {
Contract contract = dispute.getContract();
Offer offer = new Offer(contract.getOfferPayload());
List<String> acceptedBanks = offer.getAcceptedBankIds();
boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
int rows = 17;
if (dispute.getDepositTxSerialized() != null)
rows++;
if (dispute.getPayoutTxSerialized() != null)
rows++;
if (showAcceptedCountryCodes)
rows++;
if (showAcceptedBanks)
rows++;
PaymentAccountPayload sellerPaymentAccountPayload = contract.getSellerPaymentAccountPayload();
addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("contractWindow.title"));
addLabelTextFieldWithCopyIcon(gridPane, rowIndex, Res.getWithCol("shared.offerId"), offer.getId(), Layout.FIRST_ROW_DISTANCE).second.setMouseTransparent(false);
addLabelTextField(gridPane, ++rowIndex, Res.get("contractWindow.dates"), formatter.formatDateTime(offer.getDate()) + " / " + formatter.formatDateTime(dispute.getTradeDate()));
String currencyCode = offer.getCurrencyCode();
addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.offerType"), formatter.getDirectionBothSides(offer.getDirection(), currencyCode));
addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradePrice"), formatter.formatPrice(contract.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradeAmount"), formatter.formatCoinWithCode(contract.getTradeAmount()));
addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode, ":"), formatter.formatVolumeWithCode(contract.getTradePrice().getVolumeByAmount(contract.getTradeAmount())));
String securityDeposit = Res.getWithColAndCap("shared.buyer") + " " + formatter.formatCoinWithCode(offer.getBuyerSecurityDeposit()) + " / " + Res.getWithColAndCap("shared.seller") + " " + formatter.formatCoinWithCode(offer.getSellerSecurityDeposit());
addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.securityDeposit"), securityDeposit);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.btcAddresses"), contract.getBuyerPayoutAddressString() + " / " + contract.getSellerPayoutAddressString()).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.onions"), contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress());
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.numDisputes"), disputeManager.getNrOfDisputes(true, contract) + " / " + disputeManager.getNrOfDisputes(false, contract));
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.buyer")), contract.getBuyerPaymentAccountPayload().getPaymentDetails()).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.seller")), sellerPaymentAccountPayload.getPaymentDetails()).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.arbitrator"), contract.getArbitratorNodeAddress().getFullAddress());
if (showAcceptedCountryCodes) {
String countries;
Tooltip tooltip = null;
if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
countries = Res.getWithCol("shared.allEuroCountries");
} else {
countries = CountryUtil.getCodesString(acceptedCountryCodes);
tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
}
TextField acceptedCountries = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.acceptedTakerCountries"), countries).second;
if (tooltip != null)
acceptedCountries.setTooltip(new Tooltip());
}
if (showAcceptedBanks) {
if (offer.getPaymentMethod().equals(PaymentMethod.SAME_BANK)) {
addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.bankName"), acceptedBanks.get(0));
} else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) {
String value = Joiner.on(", ").join(acceptedBanks);
Tooltip tooltip = new Tooltip(Res.getWithCol("shared.acceptedBanks") + value);
TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.acceptedBanks"), value).second;
acceptedBanksTextField.setMouseTransparent(false);
acceptedBanksTextField.setTooltip(tooltip);
}
}
addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.makerFeeTxId"), offer.getOfferFeePaymentTxId());
addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.takerFeeTxId"), contract.getTakerFeeTxID());
if (dispute.getDepositTxSerialized() != null)
addLabelTxIdTextField(gridPane, ++rowIndex, Res.getWithCol("shared.depositTransactionId"), dispute.getDepositTxId());
if (dispute.getPayoutTxSerialized() != null)
addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.payoutTxId"), dispute.getPayoutTxId());
if (dispute.getContractHash() != null)
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.contractHash"), Utils.HEX.encode(dispute.getContractHash())).second.setMouseTransparent(false);
Button viewContractButton = addLabelButton(gridPane, ++rowIndex, Res.get("shared.contractAsJson"), Res.get("shared.viewContractAsJson"), 0).second;
viewContractButton.setDefaultButton(false);
viewContractButton.setOnAction(e -> {
TextArea textArea = new TextArea();
String contractAsJson = dispute.getContractAsJson();
contractAsJson += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getBuyerMultiSigPubKey());
contractAsJson += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getSellerMultiSigPubKey());
textArea.setText(contractAsJson);
textArea.setPrefHeight(50);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setPrefSize(800, 600);
Scene viewContractScene = new Scene(textArea);
Stage viewContractStage = new Stage();
viewContractStage.setTitle(Res.get("shared.contract.title", dispute.getShortTradeId()));
viewContractStage.setScene(viewContractScene);
if (owner == null)
owner = MainView.getRootContainer();
Scene rootScene = owner.getScene();
viewContractStage.initOwner(rootScene.getWindow());
viewContractStage.initModality(Modality.NONE);
viewContractStage.initStyle(StageStyle.UTILITY);
viewContractStage.show();
Window window = rootScene.getWindow();
double titleBarHeight = window.getHeight() - rootScene.getHeight();
viewContractStage.setX(Math.round(window.getX() + (owner.getWidth() - viewContractStage.getWidth()) / 2) + 200);
viewContractStage.setY(Math.round(window.getY() + titleBarHeight + (owner.getHeight() - viewContractStage.getHeight()) / 2) + 50);
});
Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close"));
// TODO app wide focus
// closeButton.requestFocus();
closeButton.setOnAction(e -> {
closeHandlerOptional.ifPresent(Runnable::run);
hide();
});
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class BSFormatterTest method testFormatDifferentVolume.
@Test
public void testFormatDifferentVolume() {
Offer offer = mock(Offer.class);
Volume btcMin = Volume.parse("0.10", "BTC");
Volume btcMax = Volume.parse("0.25", "BTC");
when(offer.isRange()).thenReturn(true);
when(offer.getMinVolume()).thenReturn(btcMin);
when(offer.getVolume()).thenReturn(btcMax);
assertEquals("0.10000000 - 0.25000000", formatter.formatVolume(offer, false, 0));
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class BSFormatterTest method testFormatNullVolume.
@Test
public void testFormatNullVolume() {
Offer offer = mock(Offer.class);
when(offer.getMinVolume()).thenReturn(null);
when(offer.getVolume()).thenReturn(null);
assertEquals("", formatter.formatVolume(offer.getVolume()));
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class BSFormatterTest method testFormatAmountWithAlignmenWithDecimalsNoRange.
@Test
public void testFormatAmountWithAlignmenWithDecimalsNoRange() {
OfferPayload offerPayload = mock(OfferPayload.class);
Offer offer = new Offer(offerPayload);
when(offerPayload.getMinAmount()).thenReturn(10000000L);
when(offerPayload.getAmount()).thenReturn(10000000L);
assertEquals(" 0.1000", formatter.formatAmount(offer, 4, true, 15));
}
Aggregations