From b671bd6277016a6c40d3819afefbaa2db3a4f98d Mon Sep 17 00:00:00 2001 From: DrColver Date: Thu, 7 Mar 2024 14:12:47 +0100 Subject: [PATCH 1/3] Allow only currencies with price feed when creating offers --- .../trade_wizard/market/TradeWizardMarketController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/market/TradeWizardMarketController.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/market/TradeWizardMarketController.java index fb518dbf3f..796ee5cf09 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/market/TradeWizardMarketController.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/market/TradeWizardMarketController.java @@ -17,6 +17,7 @@ package bisq.desktop.main.content.bisq_easy.trade_wizard.market; +import bisq.bonded_roles.market_price.MarketPriceService; import bisq.chat.ChatMessage; import bisq.chat.ChatService; import bisq.chat.bisqeasy.offerbook.BisqEasyOfferbookChannel; @@ -48,6 +49,7 @@ public class TradeWizardMarketController implements Controller { private final Runnable onNextHandler; private final BisqEasyOfferbookChannelService bisqEasyOfferbookChannelService; private final BisqEasyOfferbookSelectionService bisqEasyOfferbookSelectionService; + private final MarketPriceService marketPriceService; private Subscription searchTextPin; public TradeWizardMarketController(ServiceProvider serviceProvider, Runnable onNextHandler) { @@ -55,6 +57,7 @@ public TradeWizardMarketController(ServiceProvider serviceProvider, Runnable onN chatService = serviceProvider.getChatService(); bisqEasyOfferbookChannelService = chatService.getBisqEasyOfferbookChannelService(); bisqEasyOfferbookSelectionService = chatService.getBisqEasyOfferbookChannelSelectionService(); + marketPriceService = serviceProvider.getBondedRolesService().getMarketPriceService(); model = new TradeWizardMarketModel(); view = new TradeWizardMarketView(model, this); } @@ -88,6 +91,7 @@ public void onActivate() { } model.getListItems().setAll(MarketRepository.getAllFiatMarkets().stream() + .filter(market -> marketPriceService.getMarketPriceByCurrencyMap().containsKey(market)) .map(market -> { Set allMessages = bisqEasyOfferbookChannelService.getChannels().stream() .filter(channel -> channel.getMarket().equals(market)) From 51b678f7b1489ccbc53b9765d627a841db26529f Mon Sep 17 00:00:00 2001 From: axpoems <145597137+axpoems@users.noreply.github.com> Date: Sat, 9 Mar 2024 10:33:57 +0100 Subject: [PATCH 2/3] Small refactors --- .../price/TradeWizardPriceController.java | 9 +++------ .../price/TradeWizardPriceView.java | 16 +++++---------- .../bisq/offer/price/spec/PriceSpecUtil.java | 20 +++++++++---------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java index 0f5e94dc9b..28b18e5634 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java @@ -164,18 +164,15 @@ private void applyPercentageFromQuote(PriceQuote priceQuote) { model.getPercentageAsString().set(formatToPercentWithSymbol(percentage)); } - //todo add validator and give feedback private boolean isQuoteValid(PriceQuote priceQuote) { double percentage = getPercentage(priceQuote); - if (percentage >= -0.1 && percentage <= 0.5) { - return true; - } - return false; + return percentage >= -0.1 && percentage <= 0.5; } private double getPercentage(PriceQuote priceQuote) { - Optional optionalPercentage = PriceSpecUtil.createFloatPriceSpec(marketPriceService, priceQuote).map(FloatPriceSpec::getPercentage); + Optional optionalPercentage = PriceSpecUtil.createFloatPriceSpec(marketPriceService, priceQuote) + .map(FloatPriceSpec::getPercentage); if (optionalPercentage.isEmpty()) { log.error("optionalPercentage not present"); } diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java index 033cb4f4f5..1cc24e2d8e 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java @@ -46,6 +46,7 @@ public class TradeWizardPriceView extends View findFixPriceSpec(PriceSpec priceSpec) { - return priceSpec instanceof FixPriceSpec ? - Optional.of((FixPriceSpec) priceSpec) : - Optional.empty(); + return priceSpec instanceof FixPriceSpec + ? Optional.of((FixPriceSpec) priceSpec) + : Optional.empty(); } public static Optional findFloatPriceSpec(PriceSpec priceSpec) { - return priceSpec instanceof FloatPriceSpec ? - Optional.of((FloatPriceSpec) priceSpec) : - Optional.empty(); + return priceSpec instanceof FloatPriceSpec + ? Optional.of((FloatPriceSpec) priceSpec) + : Optional.empty(); } public static Optional findMarketPriceSpec(PriceSpec priceSpec) { - return priceSpec instanceof MarketPriceSpec ? - Optional.of((MarketPriceSpec) priceSpec) : - Optional.empty(); + return priceSpec instanceof MarketPriceSpec + ? Optional.of((MarketPriceSpec) priceSpec) + : Optional.empty(); } public static Optional createFloatPriceSpec(MarketPriceService marketPriceService, PriceQuote priceQuote) { @@ -53,4 +53,4 @@ public static Optional createFloatPriceSpec(MarketPriceService m .map(FloatPriceSpec::new) .findAny(); } -} \ No newline at end of file +} From e4651925d82c4d0bc60537e49eb8c05facb7f3c2 Mon Sep 17 00:00:00 2001 From: axpoems <145597137+axpoems@users.noreply.github.com> Date: Sat, 9 Mar 2024 11:21:07 +0100 Subject: [PATCH 3/3] Fix TradeWizardPriceController throwing exception Price controller was throwing an exception upon percentage validation. It worked well while creating offers in one market, but when switching markets and creating a new offer it failed since it was using the previous quote price. Thus, this resets the missing fields every time we use the TradeWizzard. --- .../desktop/main/content/bisq_easy/components/PriceInput.java | 1 + .../bisq_easy/trade_wizard/price/TradeWizardPriceController.java | 1 + 2 files changed, 2 insertions(+) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java index aedf091965..8fd6f1e86f 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java @@ -195,6 +195,7 @@ private Model() { public void reset() { priceQuote.set(null); + priceString.set(null); market = null; isFocused = false; description.set(null); diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java index 28b18e5634..387d17b031 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceController.java @@ -72,6 +72,7 @@ public ReadOnlyObjectProperty getPriceSpec() { } public void reset() { + priceInput.reset(); model.reset(); }