Skip to content

Commit

Permalink
Merge pull request #2309 from HenrikJannsen/Persist-selected-market-p…
Browse files Browse the repository at this point in the history
…rice-at-price-display

Persist selected market
  • Loading branch information
djing-chan authored Jun 19, 2024
2 parents 3417c14 + 77bce71 commit 8ba00e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions bisq-easy/src/main/java/bisq/bisq_easy/BisqEasyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,9 +68,11 @@ public class BisqEasyService implements Service {
private final UserIdentityService userIdentityService;
private final BisqEasyNotificationsService bisqEasyNotificationsService;
private final Observable<Long> minRequiredReputationScore = new Observable<>();
private final MarketPriceService marketPriceService;
private Pin difficultyAdjustmentFactorPin, ignoreDiffAdjustmentFromSecManagerPin,
mostRecentDiffAdjustmentValueOrDefaultPin, minRequiredReputationScorePin,
ignoreMinRequiredReputationScoreFromSecManagerPin, mostRecentMinRequiredReputationScoreOrDefaultPin;
ignoreMinRequiredReputationScoreFromSecManagerPin, mostRecentMinRequiredReputationScoreOrDefaultPin,
selectedMarketPin;

public BisqEasyService(PersistenceService persistenceService,
SecurityService securityService,
Expand All @@ -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;
Expand Down Expand Up @@ -120,10 +126,20 @@ public CompletableFuture<Boolean> 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<Boolean> shutdown() {
if (difficultyAdjustmentFactorPin != null) {
difficultyAdjustmentFactorPin.unbind();
Expand All @@ -132,6 +148,7 @@ public CompletableFuture<Boolean> shutdown() {
minRequiredReputationScorePin.unbind();
ignoreMinRequiredReputationScoreFromSecManagerPin.unbind();
mostRecentMinRequiredReputationScoreOrDefaultPin.unbind();
selectedMarketPin.unbind();
}
return bisqEasyNotificationsService.shutdown();
}
Expand Down
3 changes: 2 additions & 1 deletion settings/src/main/java/bisq/settings/CookieKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ba00e0

Please sign in to comment.