Skip to content

Commit

Permalink
Merge pull request #1755 from axpoems/fix-trade-wizard-price
Browse files Browse the repository at this point in the history
Fix `TradeWizardPriceController` throwing exception
  • Loading branch information
alvasw authored Mar 11, 2024
2 parents 5edacfa + e465192 commit aff2aab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
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 @@ -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();
}
}
}

0 comments on commit aff2aab

Please sign in to comment.