Merge pull request #229 from LukasKorba/202_createNewWallet
Onboarding -> Create Wallet -> Backup Phrase flows connected
This commit is contained in:
commit
18cff600d0
|
@ -18,6 +18,7 @@ struct AppState: Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AppAction: Equatable {
|
enum AppAction: Equatable {
|
||||||
|
case createNewWallet
|
||||||
case updateRoute(AppState.Route)
|
case updateRoute(AppState.Route)
|
||||||
case home(HomeAction)
|
case home(HomeAction)
|
||||||
case onboarding(OnboardingAction)
|
case onboarding(OnboardingAction)
|
||||||
|
@ -25,7 +26,22 @@ enum AppAction: Equatable {
|
||||||
case phraseValidation(RecoveryPhraseValidationAction)
|
case phraseValidation(RecoveryPhraseValidationAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AppEnvironment: Equatable {}
|
struct AppEnvironment {
|
||||||
|
let mnemonicSeedPhraseProvider: MnemonicSeedPhraseProvider
|
||||||
|
let walletStorage: RecoveryPhraseStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppEnvironment {
|
||||||
|
static let live = AppEnvironment(
|
||||||
|
mnemonicSeedPhraseProvider: .live,
|
||||||
|
walletStorage: RecoveryPhraseStorage()
|
||||||
|
)
|
||||||
|
|
||||||
|
static let mock = AppEnvironment(
|
||||||
|
mnemonicSeedPhraseProvider: .mock,
|
||||||
|
walletStorage: RecoveryPhraseStorage()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - AppReducer
|
// MARK: - AppReducer
|
||||||
|
|
||||||
|
@ -34,6 +50,7 @@ typealias AppReducer = Reducer<AppState, AppAction, AppEnvironment>
|
||||||
extension AppReducer {
|
extension AppReducer {
|
||||||
static let `default` = AppReducer.combine(
|
static let `default` = AppReducer.combine(
|
||||||
[
|
[
|
||||||
|
appReducer,
|
||||||
routeReducer,
|
routeReducer,
|
||||||
homeReducer,
|
homeReducer,
|
||||||
onboardingReducer,
|
onboardingReducer,
|
||||||
|
@ -43,6 +60,33 @@ extension AppReducer {
|
||||||
)
|
)
|
||||||
.debug()
|
.debug()
|
||||||
|
|
||||||
|
private static let appReducer = AppReducer { state, action, environment in
|
||||||
|
switch action {
|
||||||
|
case .createNewWallet:
|
||||||
|
let randomPhraseWords: [String]
|
||||||
|
do {
|
||||||
|
let randomPhrase = try environment.mnemonicSeedPhraseProvider.randomMnemonic()
|
||||||
|
randomPhraseWords = try environment.mnemonicSeedPhraseProvider.asWords(randomPhrase)
|
||||||
|
// TODO: - Get birthday from the integrated SDK, issue 228 (https://github.com/zcash/secant-ios-wallet/issues/228)
|
||||||
|
let birthday = BlockHeight(12345678)
|
||||||
|
|
||||||
|
try environment.walletStorage.importRecoveryPhrase(bip39: randomPhrase, birthday: birthday)
|
||||||
|
} catch {
|
||||||
|
// TODO: - merge with issue 201 (https://github.com/zcash/secant-ios-wallet/issues/201) and its Error States
|
||||||
|
return .none
|
||||||
|
}
|
||||||
|
|
||||||
|
let recoveryPhrase = RecoveryPhrase(words: randomPhraseWords)
|
||||||
|
state.phraseDisplayState.phrase = recoveryPhrase
|
||||||
|
state.phraseValidationState = RecoveryPhraseValidationState.random(phrase: recoveryPhrase)
|
||||||
|
|
||||||
|
return Effect(value: .phraseValidation(.displayBackedUpPhrase))
|
||||||
|
|
||||||
|
default:
|
||||||
|
return .none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static let routeReducer = AppReducer { state, action, _ in
|
private static let routeReducer = AppReducer { state, action, _ in
|
||||||
switch action {
|
switch action {
|
||||||
case let .updateRoute(route):
|
case let .updateRoute(route):
|
||||||
|
@ -51,8 +95,10 @@ extension AppReducer {
|
||||||
case .home(.reset):
|
case .home(.reset):
|
||||||
state.route = .startup
|
state.route = .startup
|
||||||
|
|
||||||
case .onboarding(.createNewWallet),
|
case .onboarding(.createNewWallet):
|
||||||
.phraseValidation(.proceedToHome):
|
return Effect(value: .createNewWallet)
|
||||||
|
|
||||||
|
case .phraseValidation(.proceedToHome):
|
||||||
state.route = .home
|
state.route = .home
|
||||||
|
|
||||||
case .phraseValidation(.displayBackedUpPhrase),
|
case .phraseValidation(.displayBackedUpPhrase),
|
||||||
|
|
|
@ -105,7 +105,7 @@ struct AppView_Previews: PreviewProvider {
|
||||||
store: AppStore(
|
store: AppStore(
|
||||||
initialState: .placeholder,
|
initialState: .placeholder,
|
||||||
reducer: .default,
|
reducer: .default,
|
||||||
environment: .init()
|
environment: .mock
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ extension AppStore {
|
||||||
AppStore(
|
AppStore(
|
||||||
initialState: .placeholder,
|
initialState: .placeholder,
|
||||||
reducer: .default,
|
reducer: .default,
|
||||||
environment: .init()
|
environment: .mock
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue