Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine Bisq Easy offer message #2042

Merged
merged 10 commits into from
Apr 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,26 @@ public static boolean offerMatchesMinRequiredReputationScore(ReputationService r
}
}

public static String createOfferBookMessageText(boolean isMyMessage,
String messageOwnerNickName,
MarketPriceService marketPriceService,
Direction direction,
Market market,
List<FiatPaymentMethod> fiatPaymentMethods,
AmountSpec amountSpec,
PriceSpec priceSpec) {
public static String createBasicOfferBookMessage(MarketPriceService marketPriceService,
Market market,
String paymentMethodNames,
AmountSpec amountSpec,
PriceSpec priceSpec) {
String priceInfo = String.format("%s %s", Res.get("bisqEasy.tradeWizard.review.chatMessage.price"), getFormattedPriceSpec(priceSpec));
boolean hasAmountRange = amountSpec instanceof RangeAmountSpec;
String quoteAmountAsString = OfferAmountFormatter.formatQuoteAmount(marketPriceService, amountSpec, priceSpec, market, hasAmountRange, true);
return Res.get("bisqEasy.tradeWizard.review.chatMessage.offerDetails", quoteAmountAsString, paymentMethodNames, priceInfo);
}

public static String createOfferBookMessageFromPeerPerspective(String messageOwnerNickName,
MarketPriceService marketPriceService,
Direction direction,
Market market,
List<FiatPaymentMethod> fiatPaymentMethods,
AmountSpec amountSpec,
PriceSpec priceSpec) {
String paymentMethodNames = PaymentMethodSpecFormatter.fromPaymentMethods(fiatPaymentMethods);
return createOfferBookMessageText(isMyMessage,
messageOwnerNickName,
return createOfferBookMessageFromPeerPerspective(messageOwnerNickName,
marketPriceService,
direction,
market,
Expand All @@ -105,18 +114,18 @@ public static String createOfferBookMessageText(boolean isMyMessage,
priceSpec);
}

public static String createOfferBookMessageText(boolean isMyMessage,
String messageOwnerNickName,
MarketPriceService marketPriceService,
Direction direction,
Market market,
String paymentMethodNames,
AmountSpec amountSpec,
PriceSpec priceSpec) {
public static String createOfferBookMessageFromPeerPerspective(String messageOwnerNickName,
MarketPriceService marketPriceService,
Direction direction,
Market market,
String paymentMethodNames,
AmountSpec amountSpec,
PriceSpec priceSpec) {
String ownerNickName = StringUtils.truncate(messageOwnerNickName, 28);
String priceInfo = String.format("%s %s", Res.get("bisqEasy.tradeWizard.review.chatMessage.price"), getFormattedPriceSpec(priceSpec));
boolean hasAmountRange = amountSpec instanceof RangeAmountSpec;
String quoteAmountAsString = OfferAmountFormatter.formatQuoteAmount(marketPriceService, amountSpec, priceSpec, market, hasAmountRange, true);
return buildOfferBookMessage(isMyMessage, messageOwnerNickName, direction, quoteAmountAsString, paymentMethodNames, priceInfo);
return buildOfferBookMessage(ownerNickName, direction, quoteAmountAsString, paymentMethodNames, priceInfo);
}

public static String getFormattedPriceSpec(PriceSpec priceSpec) {
Expand All @@ -135,17 +144,11 @@ public static String getFormattedPriceSpec(PriceSpec priceSpec) {
return priceInfo;
}

private static String buildOfferBookMessage(boolean isMyMessage,
String messageOwnerNickName,
private static String buildOfferBookMessage(String messageOwnerNickName,
Direction direction,
String quoteAmount,
String paymentMethods,
String price) {
if (isMyMessage) {
String directionString = StringUtils.capitalize(Res.get("offer." + direction.name().toLowerCase()));
return Res.get("bisqEasy.tradeWizard.review.chatMessage.myMessage", directionString, quoteAmount, paymentMethods, price);
}

return direction == Direction.BUY
? Res.get("bisqEasy.tradeWizard.review.chatMessage.peerMessage.sell", messageOwnerNickName, quoteAmount, paymentMethods, price)
: Res.get("bisqEasy.tradeWizard.review.chatMessage.peerMessage.buy", messageOwnerNickName, quoteAmount, paymentMethods, price);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import bisq.common.currency.Market;
import bisq.common.currency.MarketRepository;
import bisq.common.data.Pair;
import bisq.desktop.common.utils.ImageUtil;
import bisq.desktop.components.containers.Spacer;
import bisq.desktop.components.controls.BisqTooltip;
Expand All @@ -22,9 +21,6 @@
import java.util.Comparator;
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Arrays.copyOfRange;

public class BisqEasyOfferbookUtil {
static final List<Market> majorMarkets = MarketRepository.getMajorMarkets();

Expand Down Expand Up @@ -167,13 +163,4 @@ private static String getFormattedTooltip(int numOffers, String quoteCurrencyNam
? Res.get("bisqEasy.offerbook.marketListCell.numOffers.tooltip.many", numOffers, quoteCurrencyName)
: Res.get("bisqEasy.offerbook.marketListCell.numOffers.tooltip.one", numOffers, quoteCurrencyName);
}

public static Pair<String, String> splitOfferBookMessageText(String messageText) {
String[] lines = messageText.split("\n", -1);
checkArgument(lines.length == 4, "Offerbook Message must contain exactly four lines.");

String title = lines[0];
String text = String.join("\n", copyOfRange(lines, 1, lines.length));
return new Pair<>(title, text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ public void setDataForCreateOffer(Direction direction,
PriceSpec priceSpec) {
model.setCreateOfferMode(true);
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
// By default, create the message from the perspective of the peer to be sent as offer message
String chatMessageText = BisqEasyServiceUtil.createOfferBookMessageText(false,
userIdentity.getNickName(),
String chatMessageText = BisqEasyServiceUtil.createOfferBookMessageFromPeerPerspective(userIdentity.getNickName(),
marketPriceService,
direction,
market,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public ChatMessageListItem(M chatMessage,
if (chatMessage instanceof BisqEasyOfferbookMessage &&
((BisqEasyOfferbookMessage) chatMessage).hasBisqEasyOffer()) {
BisqEasyOfferbookMessage bisqEasyOfferbookMessage = (BisqEasyOfferbookMessage) chatMessage;
message = getLocalizedOfferbookMessage(bisqEasyOfferbookMessage);
message = getLocalizedOfferBookMessage(bisqEasyOfferbookMessage);
if (bisqEasyOfferbookMessage.getBisqEasyOffer().isPresent()) {
UserProfile userProfile = userIdentityService.getSelectedUserIdentity().getUserProfile();
NetworkId takerNetworkId = userProfile.getNetworkId();
Expand Down Expand Up @@ -235,13 +235,10 @@ public void clear() {
}));
}

private String getLocalizedOfferbookMessage(BisqEasyOfferbookMessage chatMessage) {
private String getLocalizedOfferBookMessage(BisqEasyOfferbookMessage chatMessage) {
BisqEasyOffer bisqEasyOffer = chatMessage.getBisqEasyOffer().orElseThrow();
String fiatPaymentMethods = PaymentMethodSpecFormatter.fromPaymentMethodSpecs(bisqEasyOffer.getQuoteSidePaymentMethodSpecs());
return BisqEasyServiceUtil.createOfferBookMessageText(isMyMessage(),
getNickName(),
marketPriceService,
bisqEasyOffer.getDirection(),
return BisqEasyServiceUtil.createBasicOfferBookMessage(marketPriceService,
bisqEasyOffer.getMarket(),
fiatPaymentMethods,
bisqEasyOffer.getAmountSpec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,8 @@ protected static Label getIconWithToolTip(AwesomeIcon icon, String tooltipString
protected static void onCopyMessage(ChatMessage chatMessage) {
ClipboardUtil.copyToClipboard(chatMessage.getText());
}

protected static void onCopyMessage(String chatMessageText) {
ClipboardUtil.copyToClipboard(chatMessageText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
import bisq.chat.ChatChannel;
import bisq.chat.ChatMessage;
import bisq.chat.bisqeasy.offerbook.BisqEasyOfferbookMessage;
import bisq.common.data.Pair;
import bisq.common.util.StringUtils;
import bisq.desktop.components.containers.Spacer;
import bisq.desktop.components.controls.DropdownMenu;
import bisq.desktop.components.controls.DropdownMenuItem;
import bisq.desktop.main.content.bisq_easy.offerbook.BisqEasyOfferbookUtil;
import bisq.desktop.main.content.chat.message_container.list.ChatMessageListItem;
import bisq.desktop.main.content.chat.message_container.list.ChatMessagesListController;
import bisq.desktop.main.content.chat.message_container.list.ChatMessagesListModel;
Expand All @@ -43,6 +41,7 @@
import static com.google.common.base.Preconditions.checkArgument;

public final class MyOfferMessageBox extends BubbleMessageBox {
private final Label myOfferTitle;
private DropdownMenuItem removeOffer;
private Label copyIcon;

Expand All @@ -57,15 +56,10 @@ public MyOfferMessageBox(ChatMessageListItem<? extends ChatMessage, ? extends Ch
// Dropdown menu
DropdownMenu dropdownMenu = createAndGetDropdownMenu();

Pair<String, String> splitMessage = BisqEasyOfferbookUtil.splitOfferBookMessageText(message.getText());
String messageTitle = splitMessage.getFirst();
String messageText = splitMessage.getSecond();

// My offer title
Label myOfferTitle = createAndGetMyOfferTitle(messageTitle);
myOfferTitle = createAndGetMyOfferTitle();

// Message
message.setText(messageText);
message.getStyleClass().add("chat-my-offer-message");

// Offer content
Expand Down Expand Up @@ -104,7 +98,7 @@ protected void setUpReactions() {

@Override
protected void addReactionsHandlers() {
copyIcon.setOnMouseClicked(e -> onCopyMessage(item.getChatMessage()));
copyIcon.setOnMouseClicked(e -> onCopyMessage(String.format("%s\n%s", myOfferTitle.getText(), message.getText())));
}

private DropdownMenu createAndGetDropdownMenu() {
Expand All @@ -121,14 +115,17 @@ private DropdownMenu createAndGetDropdownMenu() {
return dropdownMenu;
}

private Label createAndGetMyOfferTitle(String title) {
private Label createAndGetMyOfferTitle() {
BisqEasyOfferbookMessage bisqEasyOfferbookMessage = (BisqEasyOfferbookMessage) item.getChatMessage();
checkArgument(bisqEasyOfferbookMessage.getBisqEasyOffer().isPresent(),
"Bisq Easy Offerbook message must contain an offer");

boolean isBuy = bisqEasyOfferbookMessage.getBisqEasyOffer().get().getDirection() == Direction.BUY;
Direction direction = bisqEasyOfferbookMessage.getBisqEasyOffer().get().getDirection();
String directionString = StringUtils.capitalize(Res.get("offer." + direction.name().toLowerCase()));
String title = Res.get("bisqEasy.tradeWizard.review.chatMessage.myMessageTitle", directionString);
Label label = new Label(title);
label.getStyleClass().addAll("bisq-easy-offer-title", "normal-text", "font-default");
boolean isBuy = direction == Direction.BUY;
label.getStyleClass().add(isBuy ? "bisq-easy-offer-buy-btc-title" : "bisq-easy-offer-sell-btc-title");
return label;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import bisq.chat.ChatMessage;
import bisq.chat.bisqeasy.offerbook.BisqEasyOfferbookMessage;
import bisq.common.data.Pair;
import bisq.common.util.StringUtils;
import bisq.desktop.components.containers.Spacer;
import bisq.desktop.main.content.bisq_easy.offerbook.BisqEasyOfferbookUtil;
import bisq.desktop.main.content.chat.message_container.list.ChatMessageListItem;
import bisq.desktop.main.content.chat.message_container.list.ChatMessagesListController;
import bisq.desktop.main.content.chat.message_container.list.ChatMessagesListModel;
Expand All @@ -42,6 +42,7 @@

public final class PeerOfferMessageBox extends PeerTextMessageBox {
private Button takeOfferButton;
private Label peerNickName;

public PeerOfferMessageBox(ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>> item,
ListView<ChatMessageListItem<? extends ChatMessage, ? extends ChatChannel<? extends ChatMessage>>> list,
Expand All @@ -65,17 +66,12 @@ protected void setUpPeerMessage() {
reputationVBox.setAlignment(Pos.CENTER);
reputationVBox.getStyleClass().add("reputation");

Pair<String, String> splitMessage = BisqEasyOfferbookUtil.splitOfferBookMessageText(message.getText());
String messageTitle = splitMessage.getFirst();
String messageText = splitMessage.getSecond();

// Take offer title and button
Pair<Label, Button> takeOfferLabelAndButton = createAndGetTakeOfferLabelAndButton(messageTitle);
Label takeOfferTitle = takeOfferLabelAndButton.getFirst();
Pair<HBox, Button> takeOfferLabelAndButton = createAndGetTakeOfferTitleBoxAndButton();
HBox takeOfferTitle = takeOfferLabelAndButton.getFirst();
takeOfferButton = takeOfferLabelAndButton.getSecond();

// Message
message.setText(messageText);
message.getStyleClass().add("chat-peer-offer-message");

// Offer content
Expand All @@ -94,18 +90,26 @@ protected void setUpPeerMessage() {
messageBgHBox.setMaxWidth(Control.USE_PREF_SIZE);
}

private Pair<Label, Button> createAndGetTakeOfferLabelAndButton(String title) {
private Pair<HBox, Button> createAndGetTakeOfferTitleBoxAndButton() {
BisqEasyOfferbookMessage bisqEasyOfferbookMessage = (BisqEasyOfferbookMessage) item.getChatMessage();
checkArgument(bisqEasyOfferbookMessage.getBisqEasyOffer().isPresent(),
"Bisq Easy Offerbook message must contain an offer");

boolean isBuy = bisqEasyOfferbookMessage.getBisqEasyOffer().get().getDirection() == Direction.BUY;

// Label
Label label = new Label(title);
label.getStyleClass().addAll("bisq-easy-offer-title", "normal-text", "font-default");
label.getStyleClass().add(isBuy ? "bisq-easy-offer-sell-btc-title" : "bisq-easy-offer-buy-btc-title");
label.setPadding(new Insets(0, 0, 0, 7));
String title = isBuy
? Res.get("bisqEasy.tradeWizard.review.chatMessage.peerMessageTitle.sell")
: Res.get("bisqEasy.tradeWizard.review.chatMessage.peerMessageTitle.buy");
Label messageTitle = new Label(title);
messageTitle.getStyleClass().addAll("bisq-easy-offer-title", "normal-text", "font-default");
messageTitle.setPadding(new Insets(0, 0, 0, 7));
peerNickName = new Label(StringUtils.truncate(item.getNickName(), 28));
peerNickName.getStyleClass().addAll("code-block", "hand-cursor");
peerNickName.setOnMouseClicked(e -> controller.onShowChatUserDetails(item.getChatMessage()));
HBox messageTitleBox = new HBox(5, messageTitle, peerNickName);
messageTitleBox.getStyleClass().add(isBuy ? "bisq-easy-offer-sell-btc-title" : "bisq-easy-offer-buy-btc-title");
messageTitleBox.setAlignment(Pos.BASELINE_LEFT);

// Button
Button button = new Button(isBuy ? Res.get("offer.takeOffer.sell.button") : Res.get("offer.takeOffer.buy.button"));
Expand All @@ -115,13 +119,14 @@ private Pair<Label, Button> createAndGetTakeOfferLabelAndButton(String title) {
button.setDefaultButton(!item.isOfferAlreadyTaken());
VBox.setMargin(button, new Insets(10, 0, 0, 7));

return new Pair<>(label, button);
return new Pair<>(messageTitleBox, button);
}

@Override
public void cleanup() {
super.cleanup();

takeOfferButton.setOnAction(null);
peerNickName.setOnMouseClicked(null);
}
}
1 change: 1 addition & 0 deletions apps/desktop/desktop/src/main/resources/css/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
/* Peer Offer Message */
.chat-peer-offer-message-bg {
-fx-padding: 20 30 20 20;
-fx-min-width: 500;
}

.chat-peer-offer-message-bg .reputation .label {
Expand Down
Loading
Loading