From 49ee3b19b1417a5d7fd4a39ac3a0fea9e3827f71 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 17 Jan 2024 20:28:28 -0500 Subject: [PATCH] init offer address entry off user thread to prevent blocking --- .../main/offer/MutableOfferDataModel.java | 18 +++++++++--------- .../main/offer/MutableOfferViewModel.java | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java index 2c1e3a3b..e81c13b2 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java @@ -95,7 +95,6 @@ public abstract class MutableOfferDataModel extends OfferDataModel { private final CoinFormatter btcFormatter; private final Navigation navigation; private final String offerId; - private final XmrBalanceListener xmrBalanceListener; private final SetChangeListener paymentAccountsChangeListener; protected OfferDirection direction; @@ -128,6 +127,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel { protected long triggerPrice; @Getter protected boolean reserveExactAmount; + private XmrBalanceListener xmrBalanceListener; /////////////////////////////////////////////////////////////////////////////////////////// @@ -163,20 +163,12 @@ public abstract class MutableOfferDataModel extends OfferDataModel { offerId = OfferUtil.getRandomOfferId(); shortOfferId = Utilities.getShortId(offerId); - addressEntry = xmrWalletService.getOrCreateAddressEntry(offerId, XmrAddressEntry.Context.OFFER_FUNDING); reserveExactAmount = preferences.getSplitOfferOutput(); useMarketBasedPrice.set(preferences.isUsePercentageBasedPrice()); buyerSecurityDepositPct.set(Restrictions.getMinBuyerSecurityDepositAsPercent()); - xmrBalanceListener = new XmrBalanceListener(getAddressEntry().getSubaddressIndex()) { - @Override - public void onBalanceChanged(BigInteger balance) { - updateBalance(); - } - }; - paymentAccountsChangeListener = change -> fillPaymentAccounts(); } @@ -212,6 +204,14 @@ public abstract class MutableOfferDataModel extends OfferDataModel { // called before activate() public boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrency) { + addressEntry = xmrWalletService.getOrCreateAddressEntry(offerId, XmrAddressEntry.Context.OFFER_FUNDING); + xmrBalanceListener = new XmrBalanceListener(getAddressEntry().getSubaddressIndex()) { + @Override + public void onBalanceChanged(BigInteger balance) { + updateBalance(); + } + }; + this.direction = direction; this.tradeCurrency = tradeCurrency; diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferViewModel.java index 6e486c23..4d41777a 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferViewModel.java @@ -210,9 +210,6 @@ public abstract class MutableOfferViewModel ext paymentLabel = Res.get("createOffer.fundsBox.paymentLabel", dataModel.shortOfferId); - if (dataModel.getAddressEntry() != null) { - addressAsString = dataModel.getAddressEntry().getAddressString(); - } createListeners(); } @@ -568,6 +565,9 @@ public abstract class MutableOfferViewModel ext boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrency) { boolean result = dataModel.initWithData(direction, tradeCurrency); + if (dataModel.getAddressEntry() != null) { + addressAsString = dataModel.getAddressEntry().getAddressString(); + } if (dataModel.paymentAccount != null) xmrValidator.setMaxValue(dataModel.paymentAccount.getPaymentMethod().getMaxTradeLimit(dataModel.getTradeCurrencyCode().get())); xmrValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()));