Skip to content

Commit

Permalink
Add special string for lightning and remove bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Nov 10, 2024
1 parent 03d3e33 commit 5101f1f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.desktop.main.content.bisq_easy.open_trades.trade_details;

import bisq.account.payment_method.BitcoinPaymentRail;
import bisq.bisq_easy.NavigationTarget;
import bisq.chat.bisqeasy.open_trades.BisqEasyOpenTradeChannel;
import bisq.contract.bisq_easy.BisqEasyContract;
Expand Down Expand Up @@ -80,36 +81,37 @@ public void initWithData(InitData initData) {

@Override
public void onActivate() {
model.getTradeDate().set(DateFormatter.formatDateTime(contract.getTakeOfferDate()));
model.getMe().set(String.format("%s (%s)", channel.getMyUserIdentity().getNickName(), BisqEasyTradeFormatter.getMakerTakerRole(trade).toLowerCase()));
model.getPeer().set(channel.getPeer().getUserName());
model.getOfferType().set(trade.getOffer().getDirection().isBuy()
model.setTradeDate(DateFormatter.formatDateTime(contract.getTakeOfferDate()));
model.setMe(String.format("%s (%s)", channel.getMyUserIdentity().getNickName(), BisqEasyTradeFormatter.getMakerTakerRole(trade).toLowerCase()));
model.setPeer(channel.getPeer().getUserName());
model.setOfferType(trade.getOffer().getDirection().isBuy()
? Res.get("bisqEasy.openTrades.tradeDetails.offerTypeAndMarket.buyOffer")
: Res.get("bisqEasy.openTrades.tradeDetails.offerTypeAndMarket.sellOffer"));
model.getMarket().set(Res.get("bisqEasy.openTrades.tradeDetails.offerTypeAndMarket.fiatMarket",
model.setMarket(Res.get("bisqEasy.openTrades.tradeDetails.offerTypeAndMarket.fiatMarket",
trade.getOffer().getMarket().getQuoteCurrencyCode()));
model.getFiatAmount().set(BisqEasyTradeFormatter.formatQuoteSideAmount(trade));
model.getFiatCurrency().set(trade.getOffer().getMarket().getQuoteCurrencyCode());
model.getBtcAmount().set(BisqEasyTradeFormatter.formatBaseSideAmount(trade));
model.getPrice().set(PriceFormatter.format(BisqEasyTradeUtils.getPriceQuote(contract)));
model.getPriceCodes().set(trade.getOffer().getMarket().getMarketCodes());
model.getPriceSpec().set(trade.getOffer().getPriceSpec() instanceof FixPriceSpec
model.setFiatAmount(BisqEasyTradeFormatter.formatQuoteSideAmount(trade));
model.setFiatCurrency(trade.getOffer().getMarket().getQuoteCurrencyCode());
model.setBtcAmount(BisqEasyTradeFormatter.formatBaseSideAmount(trade));
model.setPrice(PriceFormatter.format(BisqEasyTradeUtils.getPriceQuote(contract)));
model.setPriceCodes(trade.getOffer().getMarket().getMarketCodes());
model.setPriceSpec(trade.getOffer().getPriceSpec() instanceof FixPriceSpec
? ""
: String.format("(%s)", BisqEasyServiceUtil.getFormattedPriceSpec(trade.getOffer().getPriceSpec(), true)));
model.getPaymentMethod().set(contract.getQuoteSidePaymentMethodSpec().getShortDisplayString());
model.getSettlementMethod().set(contract.getBaseSidePaymentMethodSpec().getShortDisplayString());
model.getTradeId().set(trade.getId());
model.getPeerNetworkAddress().set(channel.getPeer().getAddressByTransportDisplayString(50));
model.getBtcPaymentAddress().set(trade.getBitcoinPaymentData().get() == null
model.setPaymentMethod(contract.getQuoteSidePaymentMethodSpec().getShortDisplayString());
model.setSettlementMethod(contract.getBaseSidePaymentMethodSpec().getShortDisplayString());
model.setTradeId(trade.getId());
model.setPeerNetworkAddress(channel.getPeer().getAddressByTransportDisplayString(50));
model.setOnChainSettlement(contract.getBaseSidePaymentMethodSpec().getPaymentMethod().getPaymentRail() == BitcoinPaymentRail.MAIN_CHAIN);
model.setBtcPaymentAddress(trade.getBitcoinPaymentData().get() == null
? Res.get("bisqEasy.openTrades.tradeDetails.dataNotYetProvided")
: trade.getBitcoinPaymentData().get());
model.getIsBtcPaymentDataEmpty().set(trade.getBitcoinPaymentData().get() == null);
model.getPaymentAccountData().set(trade.getPaymentAccountData().get() == null
model.setBtcPaymentDataEmpty(trade.getBitcoinPaymentData().get() == null);
model.setPaymentAccountData(trade.getPaymentAccountData().get() == null
? Res.get("bisqEasy.openTrades.tradeDetails.dataNotYetProvided")
: trade.getPaymentAccountData().get());
model.getIsPaymentAccountDataEmpty().set(trade.getPaymentAccountData().get() == null);
model.getAssignedMediator().set(channel.getMediator().map(UserProfile::getUserName).orElse(""));
model.getHasMediatorBeenAssigned().set(channel.getMediator().isPresent());
model.setPaymentAccountDataEmpty(trade.getPaymentAccountData().get() == null);
model.setAssignedMediator(channel.getMediator().map(UserProfile::getUserName).orElse(""));
model.setHasMediatorBeenAssigned(channel.getMediator().isPresent());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,36 @@

import bisq.bisq_easy.NavigationTarget;
import bisq.desktop.common.view.NavigationModel;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
@Setter
public class TradeDetailsModel extends NavigationModel {
private final SimpleStringProperty tradeDate = new SimpleStringProperty();
private final SimpleStringProperty me = new SimpleStringProperty();
private final SimpleStringProperty peer = new SimpleStringProperty();
private final SimpleStringProperty offerType = new SimpleStringProperty();
private final SimpleStringProperty market = new SimpleStringProperty();
private final SimpleStringProperty fiatAmount = new SimpleStringProperty();
private final SimpleStringProperty fiatCurrency = new SimpleStringProperty();
private final SimpleStringProperty btcAmount = new SimpleStringProperty();
private final SimpleStringProperty price = new SimpleStringProperty();
private final SimpleStringProperty priceCodes = new SimpleStringProperty();
private final SimpleStringProperty priceSpec = new SimpleStringProperty();
private final SimpleStringProperty paymentMethod = new SimpleStringProperty();
private final SimpleStringProperty settlementMethod = new SimpleStringProperty();
private final SimpleStringProperty tradeId = new SimpleStringProperty();
private final SimpleStringProperty peerNetworkAddress = new SimpleStringProperty();
private final SimpleStringProperty btcPaymentAddress = new SimpleStringProperty();
private final SimpleBooleanProperty isBtcPaymentDataEmpty = new SimpleBooleanProperty();
private final SimpleStringProperty paymentAccountData = new SimpleStringProperty();
private final SimpleBooleanProperty isPaymentAccountDataEmpty = new SimpleBooleanProperty();
private final SimpleStringProperty assignedMediator = new SimpleStringProperty();
private final SimpleBooleanProperty hasMediatorBeenAssigned = new SimpleBooleanProperty();
private String tradeDate;
private String me;
private String peer;
private String offerType;
private String market;
private String fiatAmount;
private String fiatCurrency;
private String btcAmount;
private String price;
private String priceCodes;
private String priceSpec;
private String paymentMethod;
private String settlementMethod;
private String tradeId;
private String peerNetworkAddress;
private boolean isOnChainSettlement;
private String btcPaymentAddress;
private boolean isBtcPaymentDataEmpty;
private String paymentAccountData;
private boolean isPaymentAccountDataEmpty;
private String assignedMediator;
private boolean hasMediatorBeenAssigned;

@Override
public NavigationTarget getDefaultNavigationTarget() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

import java.util.Optional;

Expand All @@ -44,12 +42,11 @@ public class TradeDetailsView extends NavigationView<VBox, TradeDetailsModel, Tr
private final Button closeButton;
private final Label tradeDateLabel, meLabel, peerLabel, offerTypeLabel, marketLabel, fiatAmountLabel,
fiatCurrencyLabel, btcAmountLabel, priceLabel, priceCodesLabel, priceSpecLabel, paymentMethodLabel,
settlementMethodLabel, tradeIdLabel, peerNetworkAddressLabel, btcPaymentAddressLabel,
settlementMethodLabel, tradeIdLabel, peerNetworkAddressLabel, btcPaymentAddressTitleLabel, btcPaymentAddressDetailsLabel,
paymentAccountDataLabel, assignedMediatorLabel;
private final HBox assignedMediatorBox;
private final BisqMenuItem tradersAndRoleCopyButton, tradeIdCopyButton, peerNetworkAddressCopyButton,
btcPaymentAddressCopyButton, paymentAccountDataCopyButton;
private Subscription isBtcPaymentAddressEmptyPin, isPaymentAccountDataEmptyPin;

public TradeDetailsView(TradeDetailsModel model, TradeDetailsController controller) {
super(new VBox(), model, controller);
Expand Down Expand Up @@ -158,12 +155,12 @@ public TradeDetailsView(TradeDetailsModel model, TradeDetailsController controll
peerNetworkAddressLabel, Optional.of(peerNetworkAddressCopyButton));

// BTC payment address
btcPaymentAddressLabel = new Label();
btcPaymentAddressLabel.getStyleClass().addAll("normal-text");
btcPaymentAddressTitleLabel = new Label();
btcPaymentAddressDetailsLabel = new Label();
btcPaymentAddressDetailsLabel.getStyleClass().addAll("normal-text");
btcPaymentAddressCopyButton = new BisqMenuItem("copy-grey", "copy-white");
btcPaymentAddressCopyButton.setTooltip(Res.get("bisqEasy.openTrades.tradeDetails.btcPaymentAddress.copy"));
HBox btcPaymentAddressBox = createAndGetTitleAndDetailsBox("bisqEasy.openTrades.tradeDetails.btcPaymentAddress",
btcPaymentAddressLabel, Optional.of(btcPaymentAddressCopyButton));
HBox btcPaymentAddressBox = createAndGetTitleAndDetailsBox(btcPaymentAddressTitleLabel,
btcPaymentAddressDetailsLabel, Optional.of(btcPaymentAddressCopyButton));

// Payment account data
paymentAccountDataLabel = new Label();
Expand Down Expand Up @@ -204,11 +201,16 @@ public TradeDetailsView(TradeDetailsModel model, TradeDetailsController controll
}

private HBox createAndGetTitleAndDetailsBox(String title, Node detailsNode) {
return createAndGetTitleAndDetailsBox(title, detailsNode, Optional.empty());
Label titleLabel = new Label(Res.get(title));
return createAndGetTitleAndDetailsBox(titleLabel, detailsNode, Optional.empty());
}

private HBox createAndGetTitleAndDetailsBox(String title, Node detailsNode, Optional<BisqMenuItem> button) {
Label titleLabel = new Label(Res.get(title));
return createAndGetTitleAndDetailsBox(titleLabel, detailsNode, button);
}

private HBox createAndGetTitleAndDetailsBox(Label titleLabel, Node detailsNode, Optional<BisqMenuItem> button) {
double width = 180;
titleLabel.setMaxWidth(width);
titleLabel.setMinWidth(width);
Expand All @@ -228,72 +230,58 @@ private HBox createAndGetTitleAndDetailsBox(String title, Node detailsNode, Opti

@Override
protected void onViewAttached() {
tradeDateLabel.textProperty().bind(model.getTradeDate());
meLabel.textProperty().bind(model.getMe());
peerLabel.textProperty().bind(model.getPeer());
offerTypeLabel.textProperty().bind(model.getOfferType());
marketLabel.textProperty().bind(model.getMarket());
fiatAmountLabel.textProperty().bind(model.getFiatAmount());
fiatCurrencyLabel.textProperty().bind(model.getFiatCurrency());
btcAmountLabel.textProperty().bind(model.getBtcAmount());
priceLabel.textProperty().bind(model.getPrice());
priceCodesLabel.textProperty().bind(model.getPriceCodes());
priceSpecLabel.textProperty().bind(model.getPriceSpec());
paymentMethodLabel.textProperty().bind(model.getPaymentMethod());
settlementMethodLabel.textProperty().bind(model.getSettlementMethod());
tradeIdLabel.textProperty().bind(model.getTradeId());
peerNetworkAddressLabel.textProperty().bind(model.getPeerNetworkAddress());
btcPaymentAddressLabel.textProperty().bind(model.getBtcPaymentAddress());
paymentAccountDataLabel.textProperty().bind(model.getPaymentAccountData());
assignedMediatorLabel.textProperty().bind(model.getAssignedMediator());
assignedMediatorBox.visibleProperty().bind(model.getHasMediatorBeenAssigned());
assignedMediatorBox.managedProperty().bind(model.getHasMediatorBeenAssigned());

isBtcPaymentAddressEmptyPin = EasyBind.subscribe(model.getIsBtcPaymentDataEmpty(), isEmpty -> {
btcPaymentAddressLabel.getStyleClass().remove("text-fill-grey-dimmed");
btcPaymentAddressLabel.getStyleClass().remove("text-fill-white");
btcPaymentAddressLabel.getStyleClass().add(isEmpty ? "text-fill-grey-dimmed" : "text-fill-white");
});
isPaymentAccountDataEmptyPin = EasyBind.subscribe(model.getIsPaymentAccountDataEmpty(), isEmpty -> {
tradeDateLabel.setText(model.getTradeDate());
meLabel.setText(model.getMe());
peerLabel.setText(model.getPeer());
offerTypeLabel.setText(model.getOfferType());
marketLabel.setText(model.getMarket());
fiatAmountLabel.setText(model.getFiatAmount());
fiatCurrencyLabel.setText(model.getFiatCurrency());
btcAmountLabel.setText(model.getBtcAmount());
priceLabel.setText(model.getPrice());
priceCodesLabel.setText(model.getPriceCodes());
priceSpecLabel.setText(model.getPriceSpec());
paymentMethodLabel.setText(model.getPaymentMethod());
settlementMethodLabel.setText(model.getSettlementMethod());
tradeIdLabel.setText(model.getTradeId());
peerNetworkAddressLabel.setText(model.getPeerNetworkAddress());
btcPaymentAddressTitleLabel.setText(model.isOnChainSettlement()
? Res.get("bisqEasy.openTrades.tradeDetails.btcPaymentAddress")
: Res.get("bisqEasy.openTrades.tradeDetails.lightningInvoice"));
btcPaymentAddressDetailsLabel.setText(model.getBtcPaymentAddress());
btcPaymentAddressCopyButton.setTooltip(model.isOnChainSettlement()
? Res.get("bisqEasy.openTrades.tradeDetails.btcPaymentAddress.copy")
: Res.get("bisqEasy.openTrades.tradeDetails.lightningInvoice.copy"));
paymentAccountDataLabel.setText(model.getPaymentAccountData());
assignedMediatorLabel.setText(model.getAssignedMediator());
assignedMediatorBox.setVisible(model.isHasMediatorBeenAssigned());
assignedMediatorBox.setManaged(model.isHasMediatorBeenAssigned());

if (model.isBtcPaymentDataEmpty()) {
btcPaymentAddressDetailsLabel.getStyleClass().remove("text-fill-grey-dimmed");
btcPaymentAddressDetailsLabel.getStyleClass().remove("text-fill-white");
btcPaymentAddressDetailsLabel.getStyleClass().add(model.isBtcPaymentDataEmpty()
? "text-fill-grey-dimmed"
: "text-fill-white");
}
if (model.isPaymentAccountDataEmpty()) {
paymentAccountDataLabel.getStyleClass().remove("text-fill-grey-dimmed");
paymentAccountDataLabel.getStyleClass().remove("text-fill-white");
paymentAccountDataLabel.getStyleClass().add(isEmpty ? "text-fill-grey-dimmed" : "text-fill-white");
});
paymentAccountDataLabel.getStyleClass().add(model.isPaymentAccountDataEmpty()
? "text-fill-grey-dimmed"
: "text-fill-white");
}

closeButton.setOnAction(e -> controller.onClose());
tradersAndRoleCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getPeer().get()));
tradeIdCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getTradeId().get()));
peerNetworkAddressCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getPeerNetworkAddress().get()));
btcPaymentAddressCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getBtcPaymentAddress().get()));
paymentAccountDataCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getPaymentAccountData().get()));
tradersAndRoleCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getPeer()));
tradeIdCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getTradeId()));
peerNetworkAddressCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getPeerNetworkAddress()));
btcPaymentAddressCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getBtcPaymentAddress()));
paymentAccountDataCopyButton.setOnAction(e -> ClipboardUtil.copyToClipboard(model.getPaymentAccountData()));
}

@Override
protected void onViewDetached() {
tradeDateLabel.textProperty().unbind();
meLabel.textProperty().unbind();
peerLabel.textProperty().unbind();
offerTypeLabel.textProperty().unbind();
marketLabel.textProperty().unbind();
fiatAmountLabel.textProperty().unbind();
fiatCurrencyLabel.textProperty().unbind();
btcAmountLabel.textProperty().unbind();
priceLabel.textProperty().unbind();
priceCodesLabel.textProperty().unbind();
priceSpecLabel.textProperty().unbind();
paymentMethodLabel.textProperty().unbind();
settlementMethodLabel.textProperty().unbind();
tradeIdLabel.textProperty().unbind();
peerNetworkAddressLabel.textProperty().unbind();
btcPaymentAddressLabel.textProperty().unbind();
paymentAccountDataLabel.textProperty().unbind();
assignedMediatorLabel.textProperty().unbind();
assignedMediatorBox.visibleProperty().unbind();
assignedMediatorBox.managedProperty().unbind();

isBtcPaymentAddressEmptyPin.unsubscribe();
isPaymentAccountDataEmptyPin.unsubscribe();

closeButton.setOnAction(null);
tradersAndRoleCopyButton.setOnAction(null);
tradeIdCopyButton.setOnAction(null);
Expand Down
2 changes: 2 additions & 0 deletions i18n/src/main/resources/bisq_easy.properties
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,9 @@ bisqEasy.openTrades.tradeDetails.tradeId.copy=Copy trade ID
bisqEasy.openTrades.tradeDetails.peerNetworkAddress=Peer network address
bisqEasy.openTrades.tradeDetails.peerNetworkAddress.copy=Copy peer network address
bisqEasy.openTrades.tradeDetails.btcPaymentAddress=BTC payment address
bisqEasy.openTrades.tradeDetails.lightningInvoice=Lighting invoice
bisqEasy.openTrades.tradeDetails.btcPaymentAddress.copy=Copy BTC payment address
bisqEasy.openTrades.tradeDetails.lightningInvoice.copy=Copy lighting invoice
bisqEasy.openTrades.tradeDetails.paymentAccountData=Payment account data
bisqEasy.openTrades.tradeDetails.paymentAccountData.copy=Copy payment account data
bisqEasy.openTrades.tradeDetails.assignedMediator=Assigned mediator
Expand Down

0 comments on commit 5101f1f

Please sign in to comment.