Merge pull request #229 from LukasKorba/202_createNewWallet

Onboarding -> Create Wallet -> Backup Phrase flows connected
This commit is contained in:
Francisco Gindre 2022-04-01 13:01:58 -03:00 committed by GitHub
commit 18cff600d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 5 deletions

View File

@ -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),

View File

@ -105,7 +105,7 @@ struct AppView_Previews: PreviewProvider {
store: AppStore( store: AppStore(
initialState: .placeholder, initialState: .placeholder,
reducer: .default, reducer: .default,
environment: .init() environment: .mock
) )
) )
} }

View File

@ -23,7 +23,7 @@ extension AppStore {
AppStore( AppStore(
initialState: .placeholder, initialState: .placeholder,
reducer: .default, reducer: .default,
environment: .init() environment: .mock
) )
} }
} }