From 77bce713ebb67f8ac606618e1e4bbbe51405ac47 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 18 Jun 2024 15:43:38 +0700 Subject: [PATCH] Persist selected market --- .../java/bisq/bisq_easy/BisqEasyService.java | 21 +++++++++++++++++-- .../main/java/bisq/settings/CookieKey.java | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bisq-easy/src/main/java/bisq/bisq_easy/BisqEasyService.java b/bisq-easy/src/main/java/bisq/bisq_easy/BisqEasyService.java index 38fca50c9f..f40a34d438 100644 --- a/bisq-easy/src/main/java/bisq/bisq_easy/BisqEasyService.java +++ b/bisq-easy/src/main/java/bisq/bisq_easy/BisqEasyService.java @@ -19,8 +19,10 @@ import bisq.account.AccountService; import bisq.bonded_roles.BondedRolesService; +import bisq.bonded_roles.market_price.MarketPriceService; import bisq.chat.ChatService; import bisq.common.application.Service; +import bisq.common.currency.MarketRepository; import bisq.common.observable.Observable; import bisq.common.observable.Pin; import bisq.contract.ContractService; @@ -31,6 +33,7 @@ import bisq.persistence.PersistenceService; import bisq.presentation.notifications.SendNotificationService; import bisq.security.SecurityService; +import bisq.settings.CookieKey; import bisq.settings.SettingsService; import bisq.support.SupportService; import bisq.trade.TradeService; @@ -65,9 +68,11 @@ public class BisqEasyService implements Service { private final UserIdentityService userIdentityService; private final BisqEasyNotificationsService bisqEasyNotificationsService; private final Observable minRequiredReputationScore = new Observable<>(); + private final MarketPriceService marketPriceService; private Pin difficultyAdjustmentFactorPin, ignoreDiffAdjustmentFromSecManagerPin, mostRecentDiffAdjustmentValueOrDefaultPin, minRequiredReputationScorePin, - ignoreMinRequiredReputationScoreFromSecManagerPin, mostRecentMinRequiredReputationScoreOrDefaultPin; + ignoreMinRequiredReputationScoreFromSecManagerPin, mostRecentMinRequiredReputationScoreOrDefaultPin, + selectedMarketPin; public BisqEasyService(PersistenceService persistenceService, SecurityService securityService, @@ -90,6 +95,7 @@ public BisqEasyService(PersistenceService persistenceService, this.networkService = networkService; this.identityService = identityService; this.bondedRolesService = bondedRolesService; + marketPriceService = bondedRolesService.getMarketPriceService(); this.accountService = accountService; this.offerService = offerService; this.contractService = contractService; @@ -120,10 +126,20 @@ public CompletableFuture initialize() { ignoreMinRequiredReputationScoreFromSecManagerPin = settingsService.getIgnoreMinRequiredReputationScoreFromSecManager().addObserver(e -> applyMinRequiredReputationScore()); mostRecentMinRequiredReputationScoreOrDefaultPin = bondedRolesService.getMinRequiredReputationScoreService().getMostRecentValueOrDefault().addObserver(e -> applyMinRequiredReputationScore()); + settingsService.getCookie().asString(CookieKey.SELECTED_MARKET_CODES) + .flatMap(MarketRepository::findAnyFiatMarketByMarketCodes) + .ifPresentOrElse(marketPriceService::setSelectedMarket, + () -> marketPriceService.setSelectedMarket(MarketRepository.getDefault())); + + selectedMarketPin = marketPriceService.getSelectedMarket().addObserver(market -> { + if (market != null) { + settingsService.setCookie(CookieKey.SELECTED_MARKET_CODES, market.getMarketCodes()); + } + }); + return bisqEasyNotificationsService.initialize(); } - public CompletableFuture shutdown() { if (difficultyAdjustmentFactorPin != null) { difficultyAdjustmentFactorPin.unbind(); @@ -132,6 +148,7 @@ public CompletableFuture shutdown() { minRequiredReputationScorePin.unbind(); ignoreMinRequiredReputationScoreFromSecManagerPin.unbind(); mostRecentMinRequiredReputationScoreOrDefaultPin.unbind(); + selectedMarketPin.unbind(); } return bisqEasyNotificationsService.shutdown(); } diff --git a/settings/src/main/java/bisq/settings/CookieKey.java b/settings/src/main/java/bisq/settings/CookieKey.java index 72316b345b..5f2b6eb1f0 100644 --- a/settings/src/main/java/bisq/settings/CookieKey.java +++ b/settings/src/main/java/bisq/settings/CookieKey.java @@ -47,7 +47,8 @@ public enum CookieKey { PERMIT_OPENING_BROWSER, USE_TRANSIENT_NOTIFICATIONS, MARKETS_FILTER, - MARKET_SORT_TYPE; + MARKET_SORT_TYPE, + SELECTED_MARKET_CODES; @Setter @Getter