- Profile migrated to ReducerProtocol - unit and snapshot tests fixed - sandbox feature still works with all the TCA pullback/scope navigation
This commit is contained in:
parent
046681efff
commit
7f6c104d28
|
@ -6,6 +6,7 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import ComposableArchitecture
|
||||
|
||||
struct AppVersionHandler {
|
||||
let appVersion: () -> String
|
||||
|
@ -23,3 +24,15 @@ extension AppVersionHandler {
|
|||
appBuild: { "31" }
|
||||
)
|
||||
}
|
||||
|
||||
private enum AppVersionHandlerKey: DependencyKey {
|
||||
static let liveValue = AppVersionHandler.live
|
||||
static let testValue = AppVersionHandler.test
|
||||
}
|
||||
|
||||
extension DependencyValues {
|
||||
var appVersionHandler: AppVersionHandler {
|
||||
get { self[AppVersionHandlerKey.self] }
|
||||
set { self[AppVersionHandlerKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ typealias HomeViewStore = ViewStore<HomeState, HomeAction>
|
|||
typealias AnyBalanceBreakdownReducer = AnyReducer<BalanceBreakdownReducer.State, BalanceBreakdownReducer.Action, HomeEnvironment>
|
||||
typealias AnyScanReducer = AnyReducer<ScanReducer.State, ScanReducer.Action, HomeEnvironment>
|
||||
typealias AnyWalletEventsFlowReducer = AnyReducer<WalletEventsFlowReducer.State, WalletEventsFlowReducer.Action, HomeEnvironment>
|
||||
typealias AnyProfileReducer = AnyReducer<ProfileReducer.State, ProfileReducer.Action, HomeEnvironment>
|
||||
|
||||
// MARK: State
|
||||
|
||||
|
@ -29,7 +30,7 @@ struct HomeState: Equatable {
|
|||
|
||||
var balanceBreakdown: BalanceBreakdownReducer.State
|
||||
var drawerOverlay: DrawerOverlay
|
||||
var profileState: ProfileState
|
||||
var profileState: ProfileReducer.State
|
||||
var requestState: RequestReducer.State
|
||||
var requiredTransactionConfirmations = 0
|
||||
var scanState: ScanReducer.State
|
||||
|
@ -66,7 +67,7 @@ enum HomeAction: Equatable {
|
|||
case debugMenuStartup
|
||||
case onAppear
|
||||
case onDisappear
|
||||
case profile(ProfileAction)
|
||||
case profile(ProfileReducer.Action)
|
||||
case request(RequestReducer.Action)
|
||||
case send(SendFlowAction)
|
||||
case scan(ScanReducer.Action)
|
||||
|
@ -269,18 +270,13 @@ extension HomeReducer {
|
|||
environment: { $0 }
|
||||
)
|
||||
|
||||
private static let profileReducer: HomeReducer = ProfileReducer.default.pullback(
|
||||
private static let profileReducer: HomeReducer = AnyProfileReducer { _ in
|
||||
ProfileReducer()
|
||||
}
|
||||
.pullback(
|
||||
state: \HomeState.profileState,
|
||||
action: /HomeAction.profile,
|
||||
environment: { environment in
|
||||
ProfileEnvironment(
|
||||
appVersionHandler: .live,
|
||||
mnemonic: environment.mnemonic,
|
||||
SDKSynchronizer: environment.SDKSynchronizer,
|
||||
walletStorage: environment.walletStorage,
|
||||
zcashSDKEnvironment: environment.zcashSDKEnvironment
|
||||
)
|
||||
}
|
||||
environment: { $0 }
|
||||
)
|
||||
|
||||
private static let balanceBreakdownReducer: HomeReducer = AnyBalanceBreakdownReducer { _ in
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
import ComposableArchitecture
|
||||
import SwiftUI
|
||||
|
||||
typealias ProfileReducer = Reducer<ProfileState, ProfileAction, ProfileEnvironment>
|
||||
typealias ProfileStore = Store<ProfileState, ProfileAction>
|
||||
typealias ProfileViewStore = ViewStore<ProfileState, ProfileAction>
|
||||
typealias ProfileStore = Store<ProfileReducer.State, ProfileReducer.Action>
|
||||
typealias ProfileViewStore = ViewStore<ProfileReducer.State, ProfileReducer.Action>
|
||||
|
||||
typealias AnySettingsReducer = AnyReducer<SettingsReducer.State, SettingsReducer.Action, ProfileEnvironment>
|
||||
typealias AnyAddressDetailsReducer = AnyReducer<AddressDetailsReducer.State, AddressDetailsReducer.Action, ProfileEnvironment>
|
||||
|
||||
// MARK: - State
|
||||
|
||||
struct ProfileState: Equatable {
|
||||
struct ProfileReducer: ReducerProtocol {
|
||||
struct State: Equatable {
|
||||
enum Route {
|
||||
case addressDetails
|
||||
case settings
|
||||
|
@ -25,62 +20,34 @@ struct ProfileState: Equatable {
|
|||
var settingsState: SettingsReducer.State
|
||||
}
|
||||
|
||||
// MARK: - Action
|
||||
|
||||
enum ProfileAction: Equatable {
|
||||
enum Action: Equatable {
|
||||
case addressDetails(AddressDetailsReducer.Action)
|
||||
case back
|
||||
case onAppear
|
||||
case settings(SettingsReducer.Action)
|
||||
case updateRoute(ProfileState.Route?)
|
||||
case updateRoute(ProfileReducer.State.Route?)
|
||||
}
|
||||
|
||||
// MARK: - Environment
|
||||
@Dependency(\.sdkSynchronizer) var sdkSynchronizer
|
||||
@Dependency(\.zcashSDKEnvironment) var zcashSDKEnvironment
|
||||
@Dependency(\.appVersionHandler) var appVersionHandler
|
||||
|
||||
struct ProfileEnvironment {
|
||||
let appVersionHandler: AppVersionHandler
|
||||
let mnemonic: WrappedMnemonic
|
||||
let SDKSynchronizer: WrappedSDKSynchronizer
|
||||
let walletStorage: WrappedWalletStorage
|
||||
let zcashSDKEnvironment: ZCashSDKEnvironment
|
||||
var body: some ReducerProtocol<State, Action> {
|
||||
Scope(state: \.addressDetailsState, action: /Action.addressDetails) {
|
||||
AddressDetailsReducer()
|
||||
}
|
||||
|
||||
extension ProfileEnvironment {
|
||||
static let live = ProfileEnvironment(
|
||||
appVersionHandler: .live,
|
||||
mnemonic: .live,
|
||||
SDKSynchronizer: LiveWrappedSDKSynchronizer(),
|
||||
walletStorage: .live(),
|
||||
zcashSDKEnvironment: .mainnet
|
||||
)
|
||||
|
||||
static let mock = ProfileEnvironment(
|
||||
appVersionHandler: .test,
|
||||
mnemonic: .mock,
|
||||
SDKSynchronizer: MockWrappedSDKSynchronizer(),
|
||||
walletStorage: .live(),
|
||||
zcashSDKEnvironment: .testnet
|
||||
)
|
||||
Scope(state: \.settingsState, action: /Action.settings) {
|
||||
SettingsReducer()
|
||||
}
|
||||
|
||||
// MARK: - Reducer
|
||||
|
||||
extension ProfileReducer {
|
||||
static let `default` = ProfileReducer.combine(
|
||||
[
|
||||
profileReducer,
|
||||
addressDetailsReducer,
|
||||
settingsReducer
|
||||
]
|
||||
)
|
||||
|
||||
private static let profileReducer = ProfileReducer { state, action, environment in
|
||||
Reduce { state, action in
|
||||
switch action {
|
||||
case .onAppear:
|
||||
state.address = environment.SDKSynchronizer.getShieldedAddress() ?? ""
|
||||
state.appBuild = environment.appVersionHandler.appBuild()
|
||||
state.appVersion = environment.appVersionHandler.appVersion()
|
||||
state.sdkVersion = environment.zcashSDKEnvironment.sdkVersion
|
||||
state.address = sdkSynchronizer.getShieldedAddress() ?? ""
|
||||
state.appBuild = appVersionHandler.appBuild()
|
||||
state.appVersion = appVersionHandler.appVersion()
|
||||
state.sdkVersion = zcashSDKEnvironment.sdkVersion
|
||||
return .none
|
||||
|
||||
case .back:
|
||||
|
@ -97,24 +64,7 @@ extension ProfileReducer {
|
|||
return .none
|
||||
}
|
||||
}
|
||||
|
||||
private static let addressDetailsReducer: ProfileReducer = AnyAddressDetailsReducer { _ in
|
||||
AddressDetailsReducer()
|
||||
}
|
||||
.pullback(
|
||||
state: \ProfileState.addressDetailsState,
|
||||
action: /ProfileAction.addressDetails,
|
||||
environment: { $0 }
|
||||
)
|
||||
|
||||
private static let settingsReducer: ProfileReducer = AnySettingsReducer { _ in
|
||||
SettingsReducer()
|
||||
}
|
||||
.pullback(
|
||||
state: \ProfileState.settingsState,
|
||||
action: /ProfileAction.settings,
|
||||
environment: { $0 }
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Store
|
||||
|
@ -123,7 +73,7 @@ extension ProfileStore {
|
|||
func settingsStore() -> SettingsStore {
|
||||
self.scope(
|
||||
state: \.settingsState,
|
||||
action: ProfileAction.settings
|
||||
action: ProfileReducer.Action.settings
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -131,10 +81,10 @@ extension ProfileStore {
|
|||
// MARK: - ViewStore
|
||||
|
||||
extension ProfileViewStore {
|
||||
var routeBinding: Binding<ProfileState.Route?> {
|
||||
var routeBinding: Binding<ProfileReducer.State.Route?> {
|
||||
self.binding(
|
||||
get: \.route,
|
||||
send: ProfileAction.updateRoute
|
||||
send: ProfileReducer.Action.updateRoute
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -153,9 +103,9 @@ extension ProfileViewStore {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Placeholders
|
||||
// MARK: - Placeholders
|
||||
|
||||
extension ProfileState {
|
||||
extension ProfileReducer.State {
|
||||
static var placeholder: Self {
|
||||
.init(
|
||||
addressDetailsState: .placeholder,
|
||||
|
|
|
@ -116,8 +116,7 @@ struct ProfileView_Previews: PreviewProvider {
|
|||
addressDetailsState: .placeholder,
|
||||
settingsState: .placeholder
|
||||
),
|
||||
reducer: .default,
|
||||
environment: .live
|
||||
reducer: ProfileReducer()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,14 +15,14 @@ struct SandboxReducer: ReducerProtocol {
|
|||
case request
|
||||
}
|
||||
var walletEventsState: WalletEventsFlowReducer.State
|
||||
var profileState: ProfileState
|
||||
var profileState: ProfileReducer.State
|
||||
var route: Route?
|
||||
}
|
||||
|
||||
enum Action: Equatable {
|
||||
case updateRoute(SandboxReducer.State.Route?)
|
||||
case walletEvents(WalletEventsFlowReducer.Action)
|
||||
case profile(ProfileAction)
|
||||
case profile(ProfileReducer.Action)
|
||||
case reset
|
||||
}
|
||||
|
||||
|
@ -38,14 +38,10 @@ struct SandboxReducer: ReducerProtocol {
|
|||
.map(SandboxReducer.Action.walletEvents)
|
||||
|
||||
case .profile:
|
||||
return ProfileReducer
|
||||
.default
|
||||
.pullback(
|
||||
state: \.profileState,
|
||||
action: /SandboxReducer.Action.profile,
|
||||
environment: { _ in ProfileEnvironment.live }
|
||||
)
|
||||
.run(&state, action, ())
|
||||
return Scope(state: \SandboxReducer.State.profileState, action: /SandboxReducer.Action.profile) {
|
||||
ProfileReducer()
|
||||
}
|
||||
.reduce(into: &state, action: action)
|
||||
|
||||
case .reset:
|
||||
return .none
|
||||
|
|
|
@ -11,18 +11,10 @@ import ComposableArchitecture
|
|||
|
||||
class ProfileTests: XCTestCase {
|
||||
func testSynchronizerStateChanged_AnyButSynced() throws {
|
||||
let testEnvironment = ProfileEnvironment(
|
||||
appVersionHandler: .test,
|
||||
mnemonic: .mock,
|
||||
SDKSynchronizer: TestWrappedSDKSynchronizer(),
|
||||
walletStorage: .throwing,
|
||||
zcashSDKEnvironment: .testnet
|
||||
)
|
||||
|
||||
let store = TestStore(
|
||||
initialState: .placeholder,
|
||||
reducer: ProfileReducer.default,
|
||||
environment: testEnvironment
|
||||
reducer: ProfileReducer()
|
||||
.dependency(\.sdkSynchronizer, TestWrappedSDKSynchronizer())
|
||||
)
|
||||
|
||||
store.send(.onAppear) { state in
|
||||
|
|
|
@ -12,18 +12,10 @@ import SwiftUI
|
|||
|
||||
class ProfileSnapshotTests: XCTestCase {
|
||||
func testProfileSnapshot_sent() throws {
|
||||
let testEnvironment = ProfileEnvironment(
|
||||
appVersionHandler: .test,
|
||||
mnemonic: .mock,
|
||||
SDKSynchronizer: TestWrappedSDKSynchronizer(),
|
||||
walletStorage: .throwing,
|
||||
zcashSDKEnvironment: .testnet
|
||||
)
|
||||
|
||||
let store = Store(
|
||||
initialState: .placeholder,
|
||||
reducer: ProfileReducer.default,
|
||||
environment: testEnvironment
|
||||
reducer: ProfileReducer()
|
||||
.dependency(\.sdkSynchronizer, TestWrappedSDKSynchronizer())
|
||||
)
|
||||
|
||||
ViewStore(store).send(.onAppear)
|
||||
|
|
Loading…
Reference in New Issue