[#613] Adopt ZcashLightClientKit version 0.19.0-beta (#616)

Closes #613

- Only change was in usage of rewind function. So it's changed.
- And when rewind is done then start of the sync process is called. So
  rewind now really works without app restart.
This commit is contained in:
Michal Fousek 2023-03-03 18:58:53 +01:00 committed by GitHub
parent 11e8e5c7b5
commit 8e445f8b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 28 deletions

View File

@ -3567,8 +3567,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/zcash/ZcashLightClientKit/";
requirement = {
kind = revision;
revision = 9bfbdcb4c5ce315beb2e6bf94e982e7e10703707;
kind = exactVersion;
version = "0.19.0-beta";
};
};
6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {

View File

@ -338,7 +338,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/zcash/ZcashLightClientKit/",
"state" : {
"revision" : "9bfbdcb4c5ce315beb2e6bf94e982e7e10703707"
"revision" : "763d3eaeee333b1c7a592d8c2810847d00a50ee1",
"version" : "0.19.0-beta"
}
}
],

View File

@ -44,7 +44,7 @@ protocol SDKSynchronizerClient {
func isSyncing() -> Bool
func isInitialized() -> Bool
func rewind(_ policy: RewindPolicy) async throws
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>?
func getShieldedBalance() -> WalletBalance?
func getTransparentBalance() -> WalletBalance?

View File

@ -109,8 +109,8 @@ class LiveSDKSynchronizerClient: SDKSynchronizerClient {
return SyncStatusSnapshot.snapshotFor(state: synchronizer.status)
}
func rewind(_ policy: RewindPolicy) async throws {
try await synchronizer?.rewind(policy)
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? {
return synchronizer?.rewind(policy)
}
func getShieldedBalance() -> WalletBalance? {

View File

@ -41,7 +41,7 @@ class MockSDKSynchronizerClient: SDKSynchronizerClient {
func statusSnapshot() -> SyncStatusSnapshot { .default }
func rewind(_ policy: RewindPolicy) throws { }
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? { Empty<Void, Error>().eraseToAnyPublisher() }
func getShieldedBalance() -> WalletBalance? {
WalletBalance(verified: Zatoshi(12345000), total: Zatoshi(12345000))

View File

@ -5,9 +5,9 @@
// Created by Lukáš Korba on 15.11.2022.
//
import Foundation
import Combine
import ComposableArchitecture
import Foundation
import ZcashLightClientKit
extension SDKSynchronizerDependency: TestDependencyKey {
@ -40,8 +40,8 @@ class NoopSDKSynchronizer: SDKSynchronizerClient {
func statusSnapshot() -> SyncStatusSnapshot { .default }
func rewind(_ policy: RewindPolicy) async throws { }
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? { Empty<Void, Error>().eraseToAnyPublisher() }
func getShieldedBalance() -> WalletBalance? { nil }
func getTransparentBalance() -> WalletBalance? { nil }
@ -104,7 +104,7 @@ class TestSDKSynchronizerClient: SDKSynchronizerClient {
func statusSnapshot() -> SyncStatusSnapshot { .default }
func rewind(_ policy: RewindPolicy) throws { }
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? { nil }
func getShieldedBalance() -> WalletBalance? { nil }

View File

@ -5,8 +5,9 @@
// Created by Lukáš Korba on 02.03.2023.
//
import Foundation
import Combine
import ComposableArchitecture
import Foundation
import ZcashLightClientKit
/// In this file is a collection of helpers that control all state and action related operations
@ -54,25 +55,11 @@ extension RootReducer {
case .debug(.quickRescan):
state.destinationState.destination = .home
return .run { send in
do {
try await sdkSynchronizer.rewind(.quick)
await send(.debug(.rewindDone(nil, .debug(.quickRescan))))
} catch {
await send(.debug(.rewindDone(error.localizedDescription, .debug(.quickRescan))))
}
}
return rewind(policy: .quick, sourceAction: .quickRescan)
case .debug(.fullRescan):
state.destinationState.destination = .home
return .run { send in
do {
try await sdkSynchronizer.rewind(.birthday)
await send(.debug(.rewindDone(nil, .debug(.fullRescan))))
} catch {
await send(.debug(.rewindDone(error.localizedDescription, .debug(.fullRescan))))
}
}
return rewind(policy: .birthday, sourceAction: .fullRescan)
case let .debug(.rewindDone(errorDescription, _)):
if let errorDescription {
@ -82,7 +69,19 @@ extension RootReducer {
message: TextState("Error: \(errorDescription)"),
dismissButton: .default(TextState("Ok"), action: .send(.dismissAlert))
)
} else {
do {
try sdkSynchronizer.start()
} catch {
// TODO: [#221] Handle error more properly (https://github.com/zcash/secant-ios-wallet/issues/221)
state.alert = AlertState(
title: TextState("Can't start sync process after rewind"),
message: TextState("Error: \(error.localizedDescription)"),
dismissButton: .default(TextState("Ok"), action: .send(.dismissAlert))
)
}
}
return .none
case let .debug(.updateFlag(flag, isEnabled)):
@ -106,6 +105,21 @@ extension RootReducer {
}
}
}
private func rewind(policy: RewindPolicy, sourceAction: DebugAction) -> EffectPublisher<RootReducer.Action, Never> {
guard let rewindPublisher = sdkSynchronizer.rewind(policy) else {
return EffectTask(value: .debug(.rewindDone("SDKSynchronizer not initilized. rewindPublisher is nil", .debug(sourceAction))))
}
return rewindPublisher
.replaceEmpty(with: Void())
.map { _ in return RootReducer.Action.debug(.rewindDone(nil, .debug(sourceAction))) }
.catch { error in
return Just(RootReducer.Action.debug(.rewindDone(error.localizedDescription, .debug(sourceAction)))).eraseToAnyPublisher()
}
.receive(on: mainQueue)
.eraseToEffect()
.cancellable(id: SynchronizerCancelId.self, cancelInFlight: true)
}
}
// MARK: Placeholders

View File

@ -71,6 +71,8 @@ class DebugTests: XCTestCase {
reducer: RootReducer()
)
store.dependencies.mainQueue = .immediate
await store.send(.debug(.quickRescan)) { state in
state.destinationState.internalDestination = .home
state.destinationState.previousDestination = .welcome
@ -96,6 +98,8 @@ class DebugTests: XCTestCase {
initialState: mockState,
reducer: RootReducer()
)
store.dependencies.mainQueue = .immediate
await store.send(.debug(.fullRescan)) { state in
state.destinationState.internalDestination = .home