Skip to content

Commit

Permalink
IOS-1943 Fixed the saving of cardIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
megakoko committed Oct 19, 2022
1 parent aef301d commit 3ac5bc8
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ public class AccessCodeRepository {
}

public func deleteAccessCode(for cardIds: [String]) -> Result<Void, TangemSdkError> {
if cardIds.isEmpty {
return .success(())
}

do {
let savedCardIds = getCards()
var savedCardIds = getCards()
for cardId in cardIds {
guard savedCardIds.contains(cardId) else { continue }

try biometricsStorage.delete(SecureStorageKey.accessCode(for: cardId))
savedCardIds.remove(cardId)
}
saveCards()
saveCards(cardIds: savedCardIds)
return .success(())
} catch {
Log.error(error)
Expand Down Expand Up @@ -173,7 +178,11 @@ public class AccessCodeRepository {
}

private func saveCards() {
if let data = try? JSONEncoder().encode(Set(accessCodes.keys)) {
saveCards(cardIds: Set(accessCodes.keys))
}

private func saveCards(cardIds: Set<String>) {
if let data = try? JSONEncoder().encode(cardIds) {
try? secureStorage.store(data, forKey: .cardsWithSavedCodes)
}
}
Expand Down

0 comments on commit 3ac5bc8

Please sign in to comment.