From e1b3e6f2e06b4cc6e499319264c84a6e67dda9e9 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Wed, 21 Feb 2024 10:20:56 +0100 Subject: [PATCH] Fix refreshing of subscription preference pane when switching between panes --- .../PreferencesSubscriptionModel.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionModel.swift b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionModel.swift index 15b6c3ba93..22ab992e79 100644 --- a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionModel.swift +++ b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionModel.swift @@ -173,14 +173,18 @@ public final class PreferencesSubscriptionModel: ObservableObject { func fetchAndUpdateSubscriptionDetails() { guard fetchSubscriptionDetailsTask == nil else { return } - fetchSubscriptionDetailsTask = Task { - guard let token = accountManager.accessToken else { return } + fetchSubscriptionDetailsTask = Task { [weak self] in + defer { + self?.fetchSubscriptionDetailsTask = nil + } + + guard let token = self?.accountManager.accessToken else { return } if let cachedDate = SubscriptionService.cachedSubscriptionDetailsResponse?.expiresOrRenewsAt { - updateDescription(for: cachedDate) + self?.updateDescription(for: cachedDate) - if cachedDate.timeIntervalSinceNow > 0 { - self.cachedEntitlements = [] + if cachedDate.timeIntervalSinceNow < 0 { + self?.cachedEntitlements = [] } } @@ -190,13 +194,13 @@ public final class PreferencesSubscriptionModel: ObservableObject { return } - updateDescription(for: response.expiresOrRenewsAt) + self?.updateDescription(for: response.expiresOrRenewsAt) - subscriptionPlatform = response.platform + self?.subscriptionPlatform = response.platform } if case let .success(entitlements) = await AccountManager().fetchEntitlements() { - self.cachedEntitlements = entitlements + self?.cachedEntitlements = entitlements } } }