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:
parent
11e8e5c7b5
commit
8e445f8b09
|
@ -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" */ = {
|
||||
|
|
|
@ -338,7 +338,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/zcash/ZcashLightClientKit/",
|
||||
"state" : {
|
||||
"revision" : "9bfbdcb4c5ce315beb2e6bf94e982e7e10703707"
|
||||
"revision" : "763d3eaeee333b1c7a592d8c2810847d00a50ee1",
|
||||
"version" : "0.19.0-beta"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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? {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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,7 +40,7 @@ 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 }
|
||||
|
||||
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -97,6 +99,8 @@ class DebugTests: XCTestCase {
|
|||
reducer: RootReducer()
|
||||
)
|
||||
|
||||
store.dependencies.mainQueue = .immediate
|
||||
|
||||
await store.send(.debug(.fullRescan)) { state in
|
||||
state.destinationState.internalDestination = .home
|
||||
state.destinationState.previousDestination = .welcome
|
||||
|
|
Loading…
Reference in New Issue