Skip to content

Commit

Permalink
init offer address entry off user thread to prevent blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jan 18, 2024
1 parent b33c8cb commit 2a982ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaymentAccount> paymentAccountsChangeListener;

protected OfferDirection direction;
Expand Down Expand Up @@ -128,6 +127,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
protected long triggerPrice;
@Getter
protected boolean reserveExactAmount;
private XmrBalanceListener xmrBalanceListener;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -163,20 +163,12 @@ public MutableOfferDataModel(CreateOfferService createOfferService,

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();
}

Expand Down Expand Up @@ -212,6 +204,14 @@ private void removeListeners() {

// 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ public MutableOfferViewModel(M dataModel,

paymentLabel = Res.get("createOffer.fundsBox.paymentLabel", dataModel.shortOfferId);

if (dataModel.getAddressEntry() != null) {
addressAsString = dataModel.getAddressEntry().getAddressString();
}
createListeners();
}

Expand Down Expand Up @@ -568,6 +565,9 @@ private void removeListeners() {

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()));
Expand Down

0 comments on commit 2a982ae

Please sign in to comment.