2021-12-13 16:51:31 -08:00
|
|
|
import ComposableArchitecture
|
|
|
|
|
|
|
|
struct AppState: Equatable {
|
2021-12-13 12:50:04 -08:00
|
|
|
enum Route: Equatable {
|
2022-02-18 06:06:17 -08:00
|
|
|
case welcome
|
2021-12-13 16:51:31 -08:00
|
|
|
case startup
|
|
|
|
case onboarding
|
|
|
|
case home
|
2021-12-13 12:50:04 -08:00
|
|
|
case phraseValidation
|
|
|
|
case phraseDisplay
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
2021-12-13 12:50:04 -08:00
|
|
|
|
2021-12-13 16:51:31 -08:00
|
|
|
var homeState: HomeState
|
|
|
|
var onboardingState: OnboardingState
|
2021-12-13 12:50:04 -08:00
|
|
|
var phraseValidationState: RecoveryPhraseValidationState
|
|
|
|
var phraseDisplayState: RecoveryPhraseDisplayState
|
2022-02-18 06:06:17 -08:00
|
|
|
var route: Route = .welcome
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum AppAction: Equatable {
|
|
|
|
case updateRoute(AppState.Route)
|
|
|
|
case home(HomeAction)
|
|
|
|
case onboarding(OnboardingAction)
|
2021-12-13 12:50:04 -08:00
|
|
|
case phraseDisplay(RecoveryPhraseDisplayAction)
|
|
|
|
case phraseValidation(RecoveryPhraseValidationAction)
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
2021-12-13 12:50:04 -08:00
|
|
|
struct AppEnvironment: Equatable {}
|
2021-12-13 16:51:31 -08:00
|
|
|
|
|
|
|
// MARK: - AppReducer
|
|
|
|
|
|
|
|
typealias AppReducer = Reducer<AppState, AppAction, AppEnvironment>
|
|
|
|
|
|
|
|
extension AppReducer {
|
|
|
|
static let `default` = AppReducer.combine(
|
|
|
|
[
|
|
|
|
routeReducer,
|
|
|
|
homeReducer,
|
2021-12-13 12:50:04 -08:00
|
|
|
onboardingReducer,
|
2022-03-02 08:33:58 -08:00
|
|
|
phraseValidationReducer,
|
|
|
|
phraseDisplayReducer
|
2021-12-13 16:51:31 -08:00
|
|
|
]
|
|
|
|
)
|
2022-03-02 08:33:58 -08:00
|
|
|
.debug()
|
2021-12-13 16:51:31 -08:00
|
|
|
|
2021-12-13 18:16:03 -08:00
|
|
|
private static let routeReducer = AppReducer { state, action, _ in
|
2021-12-13 16:51:31 -08:00
|
|
|
switch action {
|
|
|
|
case let .updateRoute(route):
|
|
|
|
state.route = route
|
2021-12-13 12:50:04 -08:00
|
|
|
|
2021-12-13 16:20:56 -08:00
|
|
|
case .home(.reset):
|
|
|
|
state.route = .startup
|
2021-12-13 12:50:04 -08:00
|
|
|
|
|
|
|
case .onboarding(.createNewWallet),
|
|
|
|
.phraseValidation(.proceedToHome):
|
2021-12-13 16:51:31 -08:00
|
|
|
state.route = .home
|
2021-12-13 12:50:04 -08:00
|
|
|
|
|
|
|
case .phraseValidation(.displayBackedUpPhrase),
|
|
|
|
.phraseDisplay(.createPhrase):
|
|
|
|
state.route = .phraseDisplay
|
|
|
|
|
|
|
|
case .phraseDisplay(.finishedPressed):
|
|
|
|
state.route = .phraseValidation
|
|
|
|
|
2021-12-13 16:51:31 -08:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2021-12-13 12:50:04 -08:00
|
|
|
|
2021-12-13 16:51:31 -08:00
|
|
|
return .none
|
|
|
|
}
|
|
|
|
|
|
|
|
private static let homeReducer: AppReducer = HomeReducer.default.pullback(
|
|
|
|
state: \AppState.homeState,
|
|
|
|
action: /AppAction.home,
|
|
|
|
environment: { _ in }
|
|
|
|
)
|
|
|
|
|
|
|
|
private static let onboardingReducer: AppReducer = OnboardingReducer.default.pullback(
|
|
|
|
state: \AppState.onboardingState,
|
|
|
|
action: /AppAction.onboarding,
|
2021-12-13 18:16:03 -08:00
|
|
|
environment: { _ in }
|
2021-12-13 16:51:31 -08:00
|
|
|
)
|
2021-12-13 12:50:04 -08:00
|
|
|
|
|
|
|
private static let phraseValidationReducer: AppReducer = RecoveryPhraseValidationReducer.default.pullback(
|
|
|
|
state: \AppState.phraseValidationState,
|
|
|
|
action: /AppAction.phraseValidation,
|
|
|
|
environment: { _ in BackupPhraseEnvironment.demo }
|
|
|
|
)
|
|
|
|
|
|
|
|
private static let phraseDisplayReducer: AppReducer = RecoveryPhraseDisplayReducer.default.pullback(
|
|
|
|
state: \AppState.phraseDisplayState,
|
|
|
|
action: /AppAction.phraseDisplay,
|
|
|
|
environment: { _ in BackupPhraseEnvironment.demo }
|
|
|
|
)
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - AppStore
|
|
|
|
|
|
|
|
typealias AppStore = Store<AppState, AppAction>
|
|
|
|
|
|
|
|
extension AppStore {
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - AppViewStore
|
|
|
|
|
|
|
|
typealias AppViewStore = ViewStore<AppState, AppAction>
|
|
|
|
|
|
|
|
extension AppViewStore {
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: PlaceHolders
|
|
|
|
|
|
|
|
extension AppState {
|
|
|
|
static var placeholder: Self {
|
|
|
|
.init(
|
|
|
|
homeState: .placeholder,
|
2022-03-01 00:12:50 -08:00
|
|
|
onboardingState: .init(
|
|
|
|
importWalletState: .placeholder
|
|
|
|
),
|
2021-12-13 12:50:04 -08:00
|
|
|
phraseValidationState: RecoveryPhraseValidationState.placeholder,
|
|
|
|
phraseDisplayState: RecoveryPhraseDisplayState(
|
|
|
|
phrase: .placeholder
|
|
|
|
)
|
2021-12-13 16:51:31 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|