Skip to content

Commit

Permalink
IOS-2410 Refactoring. Taking card ID format from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
megakoko committed Oct 27, 2022
1 parent 36c68e7 commit 4e5cf34
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion TangemSdk/TangemSdk/Common/Core/CardSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ public class CardSession {

if tag != currentTag { //handle wrong tag connection during any operation
let cardId = self.environment.card?.cardId
self.viewDelegate.wrongCard(message: TangemSdkError.wrongCardNumber(cardId: cardId).localizedDescription)
let formatter = CardIdFormatter(style: environment.config.cardIdDisplayFormat)
let cardIdFormatted = cardId.flatMap {
formatter.string(from: $0)
}
self.viewDelegate.wrongCard(message: TangemSdkError.wrongCardNumber(cardId: cardIdFormatted).localizedDescription)
DispatchQueue.global().asyncAfter(deadline: .now() + 2) { [weak self] in
self?.restartPolling()
}
Expand Down
5 changes: 2 additions & 3 deletions TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,8 @@ public enum TangemSdkError: Error, LocalizedError, Encodable {
case .userCancelled: return "error_user_cancelled".localized
case .cardVerificationFailed: return "error_card_verification_failed".localized
case .wrongCardNumber(let cardId):
if let cardId,
let cardIdFormatted = CardIdFormatter(style: .full).string(from: cardId) {
return "error_wrong_card_number_with_card_id".localized(cardIdFormatted)
if let cardId {
return "error_wrong_card_number_with_card_id".localized(cardId)
} else {
return "error_wrong_card_number_without_card_id".localized
}
Expand Down
4 changes: 3 additions & 1 deletion TangemSdk/TangemSdk/Operations/PreflightReadTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ final class PreflightReadTask: CardSessionRunnable {
if session.environment.config.handleErrors {
if let expectedCardId = self.cardId?.uppercased(),
expectedCardId != readResponse.cardId.uppercased() {
completion(.failure(.wrongCardNumber(cardId: expectedCardId)))
let formatter = CardIdFormatter(style: session.environment.config.cardIdDisplayFormat)
let expectedCardIdFormatted = formatter.string(from: expectedCardId)
completion(.failure(.wrongCardNumber(cardId: expectedCardIdFormatted)))
return
}
}
Expand Down

0 comments on commit 4e5cf34

Please sign in to comment.