Skip to content

Commit

Permalink
Merge branch 'paid-until-stuck-in-loading-droid-404'
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Nov 15, 2023
2 parents 2baf3f0 + 365b1b9 commit 898ecce
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ class AccountCache(private val endpoint: ServiceEndpoint) {

registerHandler(Request.FetchAccountExpiry::class) { _ ->
jobTracker.newBackgroundJob("fetchAccountExpiry") {
accountExpiry =
cachedAccountToken?.let { fetchAccountExpiry(it) } ?: AccountExpiry.Missing
val token = cachedAccountToken ?: return@newBackgroundJob
val newAccountExpiry = fetchAccountExpiry(token) ?: return@newBackgroundJob
accountExpiry = newAccountExpiry
}
}

Expand Down Expand Up @@ -141,6 +142,7 @@ class AccountCache(private val endpoint: ServiceEndpoint) {

private suspend fun doLogout() {
daemon.await().logoutAccount()
accountExpiry = AccountExpiry.Missing
accountHistory = fetchAccountHistory()
}

Expand All @@ -154,15 +156,15 @@ class AccountCache(private val endpoint: ServiceEndpoint) {
}
}

private suspend fun fetchAccountExpiry(accountToken: String): AccountExpiry {
private suspend fun fetchAccountExpiry(accountToken: String): AccountExpiry? {
return fetchAccountData(accountToken).let { result ->
if (result is GetAccountDataResult.Ok) {
result.accountData.expiry.parseAsDateTime()?.let { parsedDateTime ->
AccountExpiry.Available(parsedDateTime)
when (result) {
is GetAccountDataResult.Ok -> {
result.accountData.expiry.parseAsDateTime()?.let { AccountExpiry.Available(it) }
}
?: AccountExpiry.Missing
} else {
AccountExpiry.Missing
GetAccountDataResult.InvalidAccount -> AccountExpiry.Missing
GetAccountDataResult.OtherError -> null
GetAccountDataResult.RpcError -> null
}
}
}
Expand Down

0 comments on commit 898ecce

Please sign in to comment.