Skip to content

Commit

Permalink
IOS-2592 Merge remote-tracking branch 'origin/develop' into IOS-2592-…
Browse files Browse the repository at this point in the history
…wording-conflicts-card
  • Loading branch information
megakoko committed Nov 24, 2022
2 parents 3cb2c84 + 7652e19 commit 92abcf4
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions TangemSdk/TangemSdk/Operations/ResetCode/ResetPinService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class ResetPinService: ObservableObject {
private var session: CardSession?
private let config: Config
private var repo: ResetPinRepo = .init()

private var currentCommand: AnyObject? = nil

public init(config: Config) {
self.config = config
}
Expand Down Expand Up @@ -103,15 +104,22 @@ public class ResetPinService: ObservableObject {
self.session = TangemSdk().makeSession(with: config,
cardId: resetCardId,
initialMessage: Message(header: "reset_codes_scan_first_card".localized([userCodeType.name.lowercased()])))

let command = GetResetPinTokenCommand()
currentCommand = command

session!.start(with: GetResetPinTokenCommand()) { result in
session!.start(with: command) { [weak self] result in
guard let self = self else { return }

switch result {
case .success(let response):
self.repo.resetPinCard = response
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}

self.currentCommand = nil
}
}

Expand All @@ -124,15 +132,22 @@ public class ResetPinService: ObservableObject {
self.session = TangemSdk().makeSession(with: config,
cardId: nil,
initialMessage: Message(header: "reset_codes_scan_confirmation_card".localized))

session!.start(with: SignResetPinTokenCommand(resetPinCard: resetPinCard)) { result in

let command = SignResetPinTokenCommand(resetPinCard: resetPinCard)
currentCommand = command

session!.start(with: command) { [weak self] result in
guard let self = self else { return }

switch result {
case .success(let response):
self.repo.confirmationCard = response
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}

self.currentCommand = nil
}
}

Expand Down Expand Up @@ -173,16 +188,21 @@ public class ResetPinService: ObservableObject {
self.session = TangemSdk().makeSession(with: config,
cardId: resetPinCard.cardId,
initialMessage: Message(header: "reset_codes_scan_to_reset".localized))


let task = ResetPinTask(confirmationCard: confirmationCard, accessCode: accessCodeUnwrapped, passcode: passcodeUnwrapped)
session!.start(with: task) { result in

let command = ResetPinTask(confirmationCard: confirmationCard, accessCode: accessCodeUnwrapped, passcode: passcodeUnwrapped)
currentCommand = command

session!.start(with: command) { [weak self] result in
guard let self = self else { return }

switch result {
case .success:
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}

self.currentCommand = nil
}
}
}
Expand Down

0 comments on commit 92abcf4

Please sign in to comment.