Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
wip. staging fails now, maybe unrelated
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub committed Nov 18, 2022
1 parent 145c673 commit 8497262
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions Client/BraveSkus/BraveSkusManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ public class BraveSkusManager {
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase
let credentialSummaryJson = try jsonDecoder.decode(CredentialSummary.self, from: data)

if credentialSummaryJson.expirationDate == nil {
assertionFailure("Failed to parse expiration date")
}

if credentialSummaryJson.isValid, let expirationDate = credentialSummaryJson.expirationDate {
Preferences.VPN.expirationDate.value = expirationDate
if credentialSummaryJson.isValid {
Preferences.VPN.expirationDate.value = credentialSummaryJson.expiresAt

// The credential has not expired yet, we can proceed with preparing it.
if expirationDate > Date() {
if credentialSummaryJson.expiresAt > Date() {
self?.prepareCredentialsPresentation(for: domain, path: "*", resultCredential: nil)
}
} else {
if !credentialSummaryJson.active {
Logger.module.debug("The credential summary is not active")
}

if credentialSummaryJson.remainingCredentialCount <= 0 {
Logger.module.debug("The credential summary does not have any remaining credentials")
}
}
} catch {
Logger.module.error("refrshOrder: Failed to decode json: \(error.localizedDescription)")
Expand All @@ -125,7 +129,7 @@ public class BraveSkusManager {
}

private struct CredentialSummary: Codable {
let expiresAt: String
let expiresAt: Date
let active: Bool
let remainingCredentialCount: Int
// The json for credential summary has additional fields. They are not used in the app at the moment.
Expand All @@ -134,9 +138,17 @@ public class BraveSkusManager {
active && remainingCredentialCount > 0
}

// FIXME: Convert right away at init-from-decoder
var expirationDate: Date? {
BraveSkusWebHelper.milisecondsOptionalDate(from: expiresAt)
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.active = try container.decode(Bool.self, forKey: .active)
self.remainingCredentialCount = try container.decode(Int.self, forKey: .remainingCredentialCount)
guard let expiresAt =
BraveSkusWebHelper.milisecondsOptionalDate(from: try container.decode(String.self, forKey: .expiresAt)) else {
throw DecodingError.typeMismatch(Data.self, .init(codingPath: [],
debugDescription: "Failed to decode Data from String"))
}

self.expiresAt = expiresAt
}
}
}

0 comments on commit 8497262

Please sign in to comment.