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-7867 Remove Published from services #369

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
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
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()))
}
}
4 changes: 2 additions & 2 deletions TangemSdk/TangemSdk/Operations/Backup/BackupService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ 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
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
Loading