Skip to content

Commit

Permalink
remove ConfigurationCallbackStorage; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxdesmarais committed Aug 7, 2024
1 parent 8f8b5ab commit 3b68a60
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 74 deletions.
4 changes: 0 additions & 4 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
80581A8C25531D0A00006F53 /* BTConfiguration+ThreeDSecure_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80581A8B25531D0A00006F53 /* BTConfiguration+ThreeDSecure_Tests.swift */; };
80581B1D2553319C00006F53 /* BTGraphQLHTTP_SSLPinning_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80581B1C2553319C00006F53 /* BTGraphQLHTTP_SSLPinning_IntegrationTests.swift */; };
806C85632B90EBED00A2754C /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 806C85622B90EBED00A2754C /* PrivacyInfo.xcprivacy */; };
807296042C41B63F0093F2AB /* ConfigurationCallbackStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807296032C41B63F0093F2AB /* ConfigurationCallbackStorage.swift */; };
8075CBEE2B1B735200CA6265 /* BTAPIRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8075CBED2B1B735200CA6265 /* BTAPIRequest.swift */; };
80842DA72B8E49EF00A5CD92 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 80842DA62B8E49EF00A5CD92 /* PrivacyInfo.xcprivacy */; };
8087C10F2BFBACCA0020FC2E /* TokenizationKey_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8087C10E2BFBACCA0020FC2E /* TokenizationKey_Tests.swift */; };
Expand Down Expand Up @@ -857,7 +856,6 @@
8064F3942B1E4FEB0059C4CB /* BTShopperInsightsClient_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsClient_Tests.swift; sourceTree = "<group>"; };
8064F3962B1E63800059C4CB /* BTShopperInsightsRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsRequest.swift; sourceTree = "<group>"; };
806C85622B90EBED00A2754C /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
807296032C41B63F0093F2AB /* ConfigurationCallbackStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationCallbackStorage.swift; sourceTree = "<group>"; };
8075CBED2B1B735200CA6265 /* BTAPIRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTAPIRequest.swift; sourceTree = "<group>"; };
80842DA62B8E49EF00A5CD92 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
8087C10E2BFBACCA0020FC2E /* TokenizationKey_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenizationKey_Tests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1509,7 +1507,6 @@
BE5C8C0228A2C183004F9130 /* BTConfiguration+Core.swift */,
804DC45C2B2D08FF00F17A15 /* BTConfigurationRequest.swift */,
BE698EA128AA8EEA001D9B10 /* ConfigurationCache.swift */,
807296032C41B63F0093F2AB /* ConfigurationCallbackStorage.swift */,
45EFC3962C2DBF32005E7F5B /* ConfigurationLoader.swift */,
);
path = Configuration;
Expand Down Expand Up @@ -3280,7 +3277,6 @@
800E78C429E0DD5300D1B0FC /* FPTIBatchData.swift in Sources */,
BED00CB028A579D700D74AEC /* BTClientToken.swift in Sources */,
5708E0A628809AD9007946B9 /* BTJSON.swift in Sources */,
807296042C41B63F0093F2AB /* ConfigurationCallbackStorage.swift in Sources */,
574891ED286F7ECA0020DA36 /* BTClientMetadata.swift in Sources */,
BE24C66E28E49A730067B11A /* BTAPIClientError.swift in Sources */,
BC17F9BC28D24C9E004B18CC /* BTGraphQLErrorTree.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Demo/Application/Features/ApplePayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ApplePayViewController: PaymentButtonBaseViewController {
paymentAuthorizationViewController.delegate = self

self.progressBlock("Presenting Apple Pay Sheet")
// TODO: why does this need dispatch queue main
self.present(paymentAuthorizationViewController, animated: true)
}
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/BraintreeCore/BTHTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ class BTHTTP: NSObject, URLSessionTaskDelegate {
}
}

func get(_ path: String, configuration: BTConfiguration? = nil, parameters: Encodable? = nil) async throws -> (BTJSON, HTTPURLResponse) {
func get(
_ path: String,
configuration: BTConfiguration? = nil,
parameters: Encodable? = nil
) async throws -> (BTJSON, HTTPURLResponse) {
try await withCheckedThrowingContinuation { continuation in
get(path, configuration: configuration, parameters: parameters) { body, response, error in
if let error {
Expand Down

This file was deleted.

44 changes: 1 addition & 43 deletions Sources/BraintreeCore/Configuration/ConfigurationLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ class ConfigurationLoader {
private let configPath = "v1/configuration"
private let configurationCache = ConfigurationCache.shared
private let http: BTHTTP
private let pendingCompletions = ConfigurationCallbackStorage()
private var isConfigCached = false // TODO: - Rename; should this bool live here?

// MARK: - Intitializer
// MARK: - Initializer

init(http: BTHTTP) {
self.http = http
Expand All @@ -36,41 +35,6 @@ class ConfigurationLoader {
/// - `BTConfiguration?`: The configuration object if it is successfully fetched or retrieved from the cache.
/// - `Error?`: An error object if fetching the configuration fails or if the instance is deallocated.
@_documentation(visibility: private)
func getConfig(completion: @escaping (BTConfiguration?, Error?) -> Void) {
if let cachedConfig = try? configurationCache.getFromCache(authorization: http.authorization.bearer) {
completion(cachedConfig, nil)
return
}

pendingCompletions.add(completion)

// If this is the 1st `v1/config` GET attempt, proceed with firing the network request.
// Otherwise, there is already a pending network request.
if pendingCompletions.count == 1 {
http.get(configPath, parameters: BTConfigurationRequest()) { [weak self] body, response, error in
guard let self else {
self?.notifyCompletions(nil, BTAPIClientError.deallocated)
return
}

if let error {
notifyCompletions(nil, error)
return
} else if response?.statusCode != 200 || body == nil {
notifyCompletions(nil, BTAPIClientError.configurationUnavailable)
return
} else {
let configuration = BTConfiguration(json: body)

try? configurationCache.putInCache(authorization: http.authorization.bearer, configuration: configuration)

notifyCompletions(configuration, nil)
return
}
}
}
}

func getConfig() async throws -> BTConfiguration {
if let cachedConfig = try? configurationCache.getFromCache(authorization: http.authorization.bearer) {
isConfigCached = true
Expand Down Expand Up @@ -103,10 +67,4 @@ class ConfigurationLoader {
print("Exited while loop")
throw BTAPIClientError.configurationUnavailable
}

// MARK: - Private Methods

func notifyCompletions(_ configuration: BTConfiguration?, _ error: Error?) {
pendingCompletions.invoke(configuration, error)
}
}

0 comments on commit 3b68a60

Please sign in to comment.