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

Fix TradeWizardPriceController throwing exception #1755

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private Model() {

public void reset() {
priceQuote.set(null);
priceString.set(null);
market = null;
isFocused = false;
description.set(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,13 +49,15 @@ 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) {
this.onNextHandler = onNextHandler;
chatService = serviceProvider.getChatService();
bisqEasyOfferbookChannelService = chatService.getBisqEasyOfferbookChannelService();
bisqEasyOfferbookSelectionService = chatService.getBisqEasyOfferbookChannelSelectionService();
marketPriceService = serviceProvider.getBondedRolesService().getMarketPriceService();
model = new TradeWizardMarketModel();
view = new TradeWizardMarketView(model, this);
}
Expand Down Expand Up @@ -88,6 +91,7 @@ public void onActivate() {
}

model.getListItems().setAll(MarketRepository.getAllFiatMarkets().stream()
.filter(market -> marketPriceService.getMarketPriceByCurrencyMap().containsKey(market))
.map(market -> {
Set<BisqEasyOfferbookMessage> allMessages = bisqEasyOfferbookChannelService.getChannels().stream()
.filter(channel -> channel.getMarket().equals(market))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public ReadOnlyObjectProperty<PriceSpec> getPriceSpec() {
}

public void reset() {
priceInput.reset();
model.reset();
}

Expand Down Expand Up @@ -164,18 +165,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<Double> optionalPercentage = PriceSpecUtil.createFloatPriceSpec(marketPriceService, priceQuote).map(FloatPriceSpec::getPercentage);
Optional<Double> optionalPercentage = PriceSpecUtil.createFloatPriceSpec(marketPriceService, priceQuote)
.map(FloatPriceSpec::getPercentage);
if (optionalPercentage.isEmpty()) {
log.error("optionalPercentage not present");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class TradeWizardPriceView extends View<VBox, TradeWizardPriceModel, Trad

public TradeWizardPriceView(TradeWizardPriceModel model, TradeWizardPriceController controller, PriceInput priceInput) {
super(new VBox(10), model, controller);

this.priceInput = priceInput;

root.setAlignment(Pos.TOP_CENTER);
Expand Down Expand Up @@ -90,17 +91,10 @@ protected void onViewAttached() {
Node firstChild = useFixPrice ? priceInput.getRoot() : percentage;
Node lastChild = useFixPrice ? percentage : priceInput.getRoot();
fieldsBox.getChildren().addAll(firstChild, lastChild);
if (useFixPrice) {
percentage.setEditable(false);
percentage.deselect();
priceInput.setEditable(true);
priceInput.requestFocus();
} else {
priceInput.setEditable(false);
priceInput.deselect();
percentage.setEditable(true);
percentage.requestFocus();
}
priceInput.setEditable(false);
priceInput.deselect();
percentage.setEditable(true);
percentage.requestFocus();
});

// Needed to trigger focusOut event on amount components
Expand Down
20 changes: 10 additions & 10 deletions offer/src/main/java/bisq/offer/price/spec/PriceSpecUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@

public class PriceSpecUtil {
public static Optional<FixPriceSpec> 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<FloatPriceSpec> 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<MarketPriceSpec> 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<FloatPriceSpec> createFloatPriceSpec(MarketPriceService marketPriceService, PriceQuote priceQuote) {
Expand All @@ -53,4 +53,4 @@ public static Optional<FloatPriceSpec> createFloatPriceSpec(MarketPriceService m
.map(FloatPriceSpec::new)
.findAny();
}
}
}
Loading