Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-2602 Retain current command explicitly #233

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Andoran90 marked this conversation as resolved.
Show resolved Hide resolved

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