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;
|
isa = XCRemoteSwiftPackageReference;
|
||||||
repositoryURL = "https://github.com/zcash/ZcashLightClientKit/";
|
repositoryURL = "https://github.com/zcash/ZcashLightClientKit/";
|
||||||
requirement = {
|
requirement = {
|
||||||
kind = revision;
|
kind = exactVersion;
|
||||||
revision = 9bfbdcb4c5ce315beb2e6bf94e982e7e10703707;
|
version = "0.19.0-beta";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
|
6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
|
||||||
|
|
|
@ -338,7 +338,8 @@
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/zcash/ZcashLightClientKit/",
|
"location" : "https://github.com/zcash/ZcashLightClientKit/",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "9bfbdcb4c5ce315beb2e6bf94e982e7e10703707"
|
"revision" : "763d3eaeee333b1c7a592d8c2810847d00a50ee1",
|
||||||
|
"version" : "0.19.0-beta"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -44,7 +44,7 @@ protocol SDKSynchronizerClient {
|
||||||
func isSyncing() -> Bool
|
func isSyncing() -> Bool
|
||||||
func isInitialized() -> Bool
|
func isInitialized() -> Bool
|
||||||
|
|
||||||
func rewind(_ policy: RewindPolicy) async throws
|
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>?
|
||||||
|
|
||||||
func getShieldedBalance() -> WalletBalance?
|
func getShieldedBalance() -> WalletBalance?
|
||||||
func getTransparentBalance() -> WalletBalance?
|
func getTransparentBalance() -> WalletBalance?
|
||||||
|
|
|
@ -109,8 +109,8 @@ class LiveSDKSynchronizerClient: SDKSynchronizerClient {
|
||||||
return SyncStatusSnapshot.snapshotFor(state: synchronizer.status)
|
return SyncStatusSnapshot.snapshotFor(state: synchronizer.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rewind(_ policy: RewindPolicy) async throws {
|
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? {
|
||||||
try await synchronizer?.rewind(policy)
|
return synchronizer?.rewind(policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getShieldedBalance() -> WalletBalance? {
|
func getShieldedBalance() -> WalletBalance? {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class MockSDKSynchronizerClient: SDKSynchronizerClient {
|
||||||
|
|
||||||
func statusSnapshot() -> SyncStatusSnapshot { .default }
|
func statusSnapshot() -> SyncStatusSnapshot { .default }
|
||||||
|
|
||||||
func rewind(_ policy: RewindPolicy) throws { }
|
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? { Empty<Void, Error>().eraseToAnyPublisher() }
|
||||||
|
|
||||||
func getShieldedBalance() -> WalletBalance? {
|
func getShieldedBalance() -> WalletBalance? {
|
||||||
WalletBalance(verified: Zatoshi(12345000), total: Zatoshi(12345000))
|
WalletBalance(verified: Zatoshi(12345000), total: Zatoshi(12345000))
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
// Created by Lukáš Korba on 15.11.2022.
|
// Created by Lukáš Korba on 15.11.2022.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import Combine
|
import Combine
|
||||||
import ComposableArchitecture
|
import ComposableArchitecture
|
||||||
|
import Foundation
|
||||||
import ZcashLightClientKit
|
import ZcashLightClientKit
|
||||||
|
|
||||||
extension SDKSynchronizerDependency: TestDependencyKey {
|
extension SDKSynchronizerDependency: TestDependencyKey {
|
||||||
|
@ -40,7 +40,7 @@ class NoopSDKSynchronizer: SDKSynchronizerClient {
|
||||||
|
|
||||||
func statusSnapshot() -> SyncStatusSnapshot { .default }
|
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 getShieldedBalance() -> WalletBalance? { nil }
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class TestSDKSynchronizerClient: SDKSynchronizerClient {
|
||||||
|
|
||||||
func statusSnapshot() -> SyncStatusSnapshot { .default }
|
func statusSnapshot() -> SyncStatusSnapshot { .default }
|
||||||
|
|
||||||
func rewind(_ policy: RewindPolicy) throws { }
|
func rewind(_ policy: RewindPolicy) -> AnyPublisher<Void, Error>? { nil }
|
||||||
|
|
||||||
func getShieldedBalance() -> WalletBalance? { nil }
|
func getShieldedBalance() -> WalletBalance? { nil }
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
// Created by Lukáš Korba on 02.03.2023.
|
// Created by Lukáš Korba on 02.03.2023.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Combine
|
||||||
import ComposableArchitecture
|
import ComposableArchitecture
|
||||||
|
import Foundation
|
||||||
import ZcashLightClientKit
|
import ZcashLightClientKit
|
||||||
|
|
||||||
/// In this file is a collection of helpers that control all state and action related operations
|
/// 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):
|
case .debug(.quickRescan):
|
||||||
state.destinationState.destination = .home
|
state.destinationState.destination = .home
|
||||||
return .run { send in
|
return rewind(policy: .quick, sourceAction: .quickRescan)
|
||||||
do {
|
|
||||||
try await sdkSynchronizer.rewind(.quick)
|
|
||||||
await send(.debug(.rewindDone(nil, .debug(.quickRescan))))
|
|
||||||
} catch {
|
|
||||||
await send(.debug(.rewindDone(error.localizedDescription, .debug(.quickRescan))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case .debug(.fullRescan):
|
case .debug(.fullRescan):
|
||||||
state.destinationState.destination = .home
|
state.destinationState.destination = .home
|
||||||
return .run { send in
|
return rewind(policy: .birthday, sourceAction: .fullRescan)
|
||||||
do {
|
|
||||||
try await sdkSynchronizer.rewind(.birthday)
|
|
||||||
await send(.debug(.rewindDone(nil, .debug(.fullRescan))))
|
|
||||||
} catch {
|
|
||||||
await send(.debug(.rewindDone(error.localizedDescription, .debug(.fullRescan))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case let .debug(.rewindDone(errorDescription, _)):
|
case let .debug(.rewindDone(errorDescription, _)):
|
||||||
if let errorDescription {
|
if let errorDescription {
|
||||||
|
@ -82,7 +69,19 @@ extension RootReducer {
|
||||||
message: TextState("Error: \(errorDescription)"),
|
message: TextState("Error: \(errorDescription)"),
|
||||||
dismissButton: .default(TextState("Ok"), action: .send(.dismissAlert))
|
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
|
return .none
|
||||||
|
|
||||||
case let .debug(.updateFlag(flag, isEnabled)):
|
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
|
// MARK: Placeholders
|
||||||
|
|
|
@ -71,6 +71,8 @@ class DebugTests: XCTestCase {
|
||||||
reducer: RootReducer()
|
reducer: RootReducer()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
store.dependencies.mainQueue = .immediate
|
||||||
|
|
||||||
await store.send(.debug(.quickRescan)) { state in
|
await store.send(.debug(.quickRescan)) { state in
|
||||||
state.destinationState.internalDestination = .home
|
state.destinationState.internalDestination = .home
|
||||||
state.destinationState.previousDestination = .welcome
|
state.destinationState.previousDestination = .welcome
|
||||||
|
@ -97,6 +99,8 @@ class DebugTests: XCTestCase {
|
||||||
reducer: RootReducer()
|
reducer: RootReducer()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
store.dependencies.mainQueue = .immediate
|
||||||
|
|
||||||
await store.send(.debug(.fullRescan)) { state in
|
await store.send(.debug(.fullRescan)) { state in
|
||||||
state.destinationState.internalDestination = .home
|
state.destinationState.internalDestination = .home
|
||||||
state.destinationState.previousDestination = .welcome
|
state.destinationState.previousDestination = .welcome
|
||||||
|
|
Loading…
Reference in New Issue