Skip to content

Commit 9668dd2

Browse files
authored
populate trigger price and extra info on duplicate or edit offer
1 parent 9bd4f70 commit 9668dd2

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ protected void doActivate() {
262262

263263
buyerAsTakerWithoutDepositSlider.setSelected(model.dataModel.getBuyerAsTakerWithoutDeposit().get());
264264

265+
triggerPriceInputTextField.setText(model.triggerPrice.get());
265266
extraInfoTextArea.setText(model.dataModel.extraInfo.get());
266267
}
267268
}

desktop/src/main/java/haveno/desktop/main/offer/MutableOfferViewModel.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ private void createListeners() {
501501
};
502502

503503
extraInfoStringListener = (ov, oldValue, newValue) -> {
504-
onExtraInfoTextAreaChanged();
504+
if (newValue != null) {
505+
extraInfo.set(newValue);
506+
onExtraInfoTextAreaChanged();
507+
}
505508
};
506509

507510
isWalletFundedListener = (ov, oldValue, newValue) -> updateButtonDisableState();
@@ -582,6 +585,7 @@ private void removeListeners() {
582585
dataModel.getVolume().removeListener(volumeListener);
583586
dataModel.getSecurityDepositPct().removeListener(securityDepositAsDoubleListener);
584587
dataModel.getBuyerAsTakerWithoutDeposit().removeListener(buyerAsTakerWithoutDepositListener);
588+
dataModel.getExtraInfo().removeListener(extraInfoStringListener);
585589

586590
//dataModel.feeFromFundingTxProperty.removeListener(feeFromFundingTxListener);
587591
dataModel.getIsXmrWalletFunded().removeListener(isWalletFundedListener);
@@ -843,7 +847,7 @@ public void onExtraInfoTextAreaChanged() {
843847
extraInfoValidationResult.set(getExtraInfoValidationResult());
844848
updateButtonDisableState();
845849
if (extraInfoValidationResult.get().isValid) {
846-
dataModel.setExtraInfo(extraInfo.get());
850+
setExtraInfoToModel();
847851
}
848852
}
849853

desktop/src/main/java/haveno/desktop/main/portfolio/duplicateoffer/DuplicateOfferDataModel.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import haveno.core.offer.CreateOfferService;
2727
import haveno.core.offer.Offer;
2828
import haveno.core.offer.OfferUtil;
29+
import haveno.core.offer.OpenOffer;
2930
import haveno.core.offer.OpenOfferManager;
3031
import haveno.core.payment.PaymentAccount;
3132
import haveno.core.provider.price.PriceFeedService;
@@ -89,13 +90,15 @@ public void populateData(Offer offer) {
8990
setPrice(offer.getPrice());
9091
setVolume(offer.getVolume());
9192
setUseMarketBasedPrice(offer.isUseMarketBasedPrice());
92-
setBuyerAsTakerWithoutDeposit(offer.hasBuyerAsTakerWithoutDeposit());
93-
94-
setSecurityDepositPct(getSecurityAsPercent(offer));
95-
9693
if (offer.isUseMarketBasedPrice()) {
9794
setMarketPriceMarginPct(offer.getMarketPriceMarginPct());
9895
}
96+
setBuyerAsTakerWithoutDeposit(offer.hasBuyerAsTakerWithoutDeposit());
97+
setSecurityDepositPct(getSecurityAsPercent(offer));
98+
setExtraInfo(offer.getOfferExtraInfo());
99+
100+
OpenOffer openOffer = openOfferManager.getOpenOffer(offer.getId()).orElse(null);
101+
if (openOffer != null) setTriggerPrice(openOffer.getTriggerPrice());
99102
}
100103

101104
private double getSecurityAsPercent(Offer offer) {

desktop/src/main/java/haveno/desktop/main/portfolio/duplicateoffer/DuplicateOfferViewModel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import haveno.core.provider.price.PriceFeedService;
3030
import haveno.core.user.Preferences;
3131
import haveno.core.util.FormattingUtils;
32+
import haveno.core.util.PriceUtil;
3233
import haveno.core.util.coin.CoinFormatter;
3334
import haveno.core.util.validation.AmountValidator4Decimals;
3435
import haveno.core.util.validation.AmountValidator8Decimals;
@@ -76,6 +77,16 @@ public void initWithData(OfferPayload offerPayload) {
7677
public void activate() {
7778
super.activate();
7879
dataModel.populateData(offer);
80+
81+
long triggerPriceAsLong = dataModel.getTriggerPrice();
82+
dataModel.setTriggerPrice(triggerPriceAsLong);
83+
if (triggerPriceAsLong > 0) {
84+
triggerPrice.set(PriceUtil.formatMarketPrice(triggerPriceAsLong, dataModel.getCurrencyCode()));
85+
} else {
86+
triggerPrice.set("");
87+
}
88+
onTriggerPriceTextFieldChanged();
89+
7990
triggerFocusOutOnAmountFields();
8091
onFocusOutPriceAsPercentageTextField(true, false);
8192
}

desktop/src/main/java/haveno/desktop/main/portfolio/editoffer/EditOfferDataModel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public void applyOpenOffer(OpenOffer openOffer) {
137137
securityDepositPct.set(securityDepositPercent);
138138

139139
allowAmountUpdate = false;
140+
141+
triggerPrice = openOffer.getTriggerPrice();
142+
extraInfo.set(offer.getOfferExtraInfo());
140143
}
141144

142145
@Override
@@ -164,10 +167,10 @@ public void populateData() {
164167
setPrice(offer.getPrice());
165168
setVolume(offer.getVolume());
166169
setUseMarketBasedPrice(offer.isUseMarketBasedPrice());
167-
setTriggerPrice(openOffer.getTriggerPrice());
168170
if (offer.isUseMarketBasedPrice()) {
169171
setMarketPriceMarginPct(offer.getMarketPriceMarginPct());
170172
}
173+
setTriggerPrice(openOffer.getTriggerPrice());
171174
setExtraInfo(offer.getOfferExtraInfo());
172175
}
173176

0 commit comments

Comments
 (0)