update offer state on same thread to fix blocking

This commit is contained in:
woodser 2024-04-06 17:39:21 -04:00
parent 6fea58c197
commit 59fbd805a5
4 changed files with 76 additions and 70 deletions

View file

@ -265,7 +265,7 @@ public class Offer implements NetworkPayload, PersistablePayload {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void setState(Offer.State state) { public void setState(Offer.State state) {
UserThread.await(() -> stateProperty().set(state)); stateProperty.set(state);
} }
public ObjectProperty<Offer.State> stateProperty() { public ObjectProperty<Offer.State> stateProperty() {

View file

@ -200,6 +200,7 @@ public class MarketView extends ActivatableView<TabPane, Void> {
} }
private String getAllOffersWithReferralId() { private String getAllOffersWithReferralId() {
synchronized (offerBook.getOfferBookListItems()) {
List<String> list = offerBook.getOfferBookListItems().stream() List<String> list = offerBook.getOfferBookListItems().stream()
.map(OfferBookListItem::getOffer) .map(OfferBookListItem::getOffer)
.filter(offer -> offer.getExtraDataMap() != null) .filter(offer -> offer.getExtraDataMap() != null)
@ -219,3 +220,4 @@ public class MarketView extends ActivatableView<TabPane, Void> {
return Joiner.on("\n\n").join(list); return Joiner.on("\n\n").join(list);
} }
} }
}

View file

@ -147,6 +147,7 @@ class OfferBookChartViewModel extends ActivatableViewModel {
private void fillTradeCurrencies() { private void fillTradeCurrencies() {
// Don't use a set as we need all entries // Don't use a set as we need all entries
synchronized (offerBookListItems) {
List<TradeCurrency> tradeCurrencyList = offerBookListItems.stream() List<TradeCurrency> tradeCurrencyList = offerBookListItems.stream()
.map(e -> { .map(e -> {
String currencyCode = e.getOffer().getCurrencyCode(); String currencyCode = e.getOffer().getCurrencyCode();
@ -158,6 +159,7 @@ class OfferBookChartViewModel extends ActivatableViewModel {
currencyListItems.updateWithCurrencies(tradeCurrencyList, null); currencyListItems.updateWithCurrencies(tradeCurrencyList, null);
} }
}
@Override @Override
protected void activate() { protected void activate() {

View file

@ -350,6 +350,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void applyOfferState(Offer.State state) { private void applyOfferState(Offer.State state) {
UserThread.execute(() -> {
offerWarning.set(null); offerWarning.set(null);
// We have 2 situations handled here: // We have 2 situations handled here:
@ -394,6 +395,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
updateSpinnerInfo(); updateSpinnerInfo();
updateButtonDisableState(); updateButtonDisableState();
});
} }
private void applyTradeErrorMessage(@Nullable String errorMessage) { private void applyTradeErrorMessage(@Nullable String errorMessage) {