Skip to content

Commit

Permalink
Merge branch 'develop' into IOS-7148_handle_finalized_card
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y committed Sep 6, 2024
2 parents 892edec + 1bcdef8 commit b1d6cf6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Example/TangemSdkExample/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -816,18 +816,18 @@ extension AppModel {
@ViewBuilder
func makeBackupDestination() -> some View {
if let service = self.backupService {
BackupView().environmentObject(service)
BackupView(backupService: service)
} else {
BackupView()
EmptyView()
}
}

@ViewBuilder
func makePinResetDestination() -> some View {
if let service = self.resetPinService {
ResetPinView().environmentObject(service)
ResetPinView(resetPinService: service)
} else {
ResetPinView()
EmptyView()
}
}
}
7 changes: 2 additions & 5 deletions Example/TangemSdkExample/Developer/BackupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
import TangemSdk

struct BackupView: View {
@EnvironmentObject var backupService: BackupService
var backupService: BackupService

@State private var count: Int = 2
@State private var accessCode: String = ""
Expand Down Expand Up @@ -158,10 +158,7 @@ struct BackupView: View {
}

struct BackupView_Previews: PreviewProvider {
static let sdk = TangemSdk()

static var previews: some View {
BackupView()
.environmentObject(BackupService(sdk: sdk))
BackupView(backupService: BackupService(sdk: TangemSdk()))
}
}
7 changes: 2 additions & 5 deletions Example/TangemSdkExample/Developer/ResetPinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
import TangemSdk

struct ResetPinView: View {
@EnvironmentObject var resetPinService: ResetPinService
var resetPinService: ResetPinService

private var stateTitle: String { "Current state is: \(resetPinService.currentState)" }
@State private var accessCode: String = ""
Expand Down Expand Up @@ -80,10 +80,7 @@ struct ResetPinView: View {
}

struct ResetPinView_Previews: PreviewProvider {
static let sdk = TangemSdk()

static var previews: some View {
ResetPinView()
.environmentObject(ResetPinService(config: Config()))
ResetPinView(resetPinService: ResetPinService(config: Config()))
}
}
8 changes: 4 additions & 4 deletions TangemSdk/TangemSdk/Operations/Backup/BackupService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Foundation
import Combine

@available(iOS 13.0, *)
public class BackupService: ObservableObject {
public class BackupService {
public static let maxBackupCardsCount = 2

@Published public private(set) var currentState: State = .preparing

public private(set) var currentState: State = .preparing
public var canAddBackupCards: Bool {
addedBackupCardsCount < BackupService.maxBackupCardsCount
&& repo.data.primaryCard?.linkingKey != nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ResetCodesController {

private func bind() {
self.resetService
.$currentState
.currentStatePublisher
.dropFirst()
.sink {[weak self] newState in
guard let self else { return }
Expand Down
16 changes: 10 additions & 6 deletions TangemSdk/TangemSdk/Operations/ResetCode/ResetPinService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
//

import Foundation
import Combine

@available(iOS 13.0, *)
public class ResetPinService: ObservableObject {
@Published public private(set) var currentState: State = .needCode
@Published public private(set) var error: TangemSdkError? = nil
public class ResetPinService {
public var currentState: State { _currentState.value }
public var currentStatePublisher: AnyPublisher<State, Never> { _currentState.eraseToAnyPublisher() }

public private(set) var error: TangemSdkError? = nil

private var session: CardSession?
private let config: Config
private var repo: ResetPinRepo = .init()
private var currentCommand: AnyObject? = nil
private var _currentState: CurrentValueSubject<State, Never> = .init(.needCode)

public init(config: Config) {
self.config = config
Expand Down Expand Up @@ -47,7 +51,7 @@ public class ResetPinService: ObservableObject {
repo.accessCode = code.sha256()

if currentState == .needCode {
currentState = currentState.next()
_currentState.value = currentState.next()
}
}

Expand All @@ -72,7 +76,7 @@ public class ResetPinService: ObservableObject {
repo.passcode = code.sha256()

if currentState == .needCode {
currentState = currentState.next()
_currentState.value = currentState.next()
}
}

Expand All @@ -92,7 +96,7 @@ public class ResetPinService: ObservableObject {
private func handleCompletion(_ result: Result<Void, TangemSdkError>) -> Void {
switch result {
case .success:
currentState = currentState.next()
_currentState.value = currentState.next()
case .failure(let error):
self.error = error
}
Expand Down

0 comments on commit b1d6cf6

Please sign in to comment.