Skip to content

Commit

Permalink
Provide pro auth token to all pro endpoints in MarketKit
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Jun 21, 2023
1 parent 9d58ba4 commit 385704f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10001,7 +10001,7 @@
repositoryURL = "https://github.com/horizontalsystems/MarketKit.Swift";
requirement = {
kind = exactVersion;
version = 2.0.8;
version = 2.0.9;
};
};
D3604E7128F03B0A0066C366 /* XCRemoteSwiftPackageReference "ScanQrKit.Swift" */ = {
Expand Down
2 changes: 1 addition & 1 deletion UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class App {

contactManager = ContactBookManager(localStorage: localStorage, ubiquityContainerIdentifier: appConfigProvider.privateCloudContainer, helper: ContactBookHelper(), logger: logger)

subscriptionManager = SubscriptionManager(localStorage: StorageKit.LocalStorage.default)
subscriptionManager = SubscriptionManager(localStorage: StorageKit.LocalStorage.default, marketKit: marketKit)

appManager = AppManager(
accountManager: accountManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import Foundation
import HsExtensions
import StorageKit
import MarketKit

class SubscriptionManager {
private let keyAuthToken = "subscription-auth-token"

private let localStorage: StorageKit.ILocalStorage
private let marketKit: MarketKit.Kit

@PostPublished private(set) var authToken: String?

init(localStorage: StorageKit.ILocalStorage) {
init(localStorage: StorageKit.ILocalStorage, marketKit: MarketKit.Kit) {
self.localStorage = localStorage
self.marketKit = marketKit

authToken = localStorage.value(for: keyAuthToken)
marketKit.set(proAuthToken: authToken)
}

}

extension SubscriptionManager {

func set(authToken: String) {
marketKit.set(proAuthToken: authToken)
self.authToken = authToken
localStorage.set(value: authToken, for: keyAuthToken)
}

func invalidateAuthToken() {
marketKit.set(proAuthToken: nil)
authToken = nil
localStorage.set(value: authToken, for: keyAuthToken)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ extension CoinAnalyticsService {

state = .loading

if let authToken = subscriptionManager.authToken {
if subscriptionManager.authToken != nil {
Task { [weak self, marketKit, fullCoin, currency] in
do {
let analytics = try await marketKit.analytics(coinUid: fullCoin.coin.uid, currencyCode: currency.code, authToken: authToken)
let analytics = try await marketKit.analytics(coinUid: fullCoin.coin.uid, currencyCode: currency.code)
self?.state = .success(analytics: analytics)
} catch {
if let responseError = error as? NetworkManager.ResponseError, (responseError.statusCode == 401 || responseError.statusCode == 403) {
Expand Down

0 comments on commit 385704f

Please sign in to comment.