2021-12-13 16:51:31 -08:00
|
|
|
import ComposableArchitecture
|
2022-04-12 01:02:36 -07:00
|
|
|
import ZcashLightClientKit
|
2021-12-13 16:51:31 -08:00
|
|
|
|
|
|
|
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
|
2022-04-14 02:25:05 -07:00
|
|
|
case sandbox
|
2021-12-13 16:51:31 -08:00
|
|
|
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
|
|
|
|
2022-04-14 02:25:05 -07:00
|
|
|
var appInitializationState: InitializationState = .uninitialized
|
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
|
2022-04-14 02:25:05 -07:00
|
|
|
var sandboxState: SandboxState
|
2022-04-04 05:04:01 -07:00
|
|
|
var storedWallet: StoredWallet?
|
2022-04-14 02:25:05 -07:00
|
|
|
var welcomeState: WelcomeState
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum AppAction: Equatable {
|
2022-04-04 05:04:01 -07:00
|
|
|
case appDelegate(AppDelegateAction)
|
2022-04-13 06:52:31 -07:00
|
|
|
case checkBackupPhraseValidation
|
2022-04-04 05:04:01 -07:00
|
|
|
case checkWalletInitialization
|
2022-04-01 04:27:37 -07:00
|
|
|
case createNewWallet
|
2021-12-13 16:51:31 -08:00
|
|
|
case home(HomeAction)
|
2022-04-13 06:52:31 -07:00
|
|
|
case initializeSDK
|
2022-04-07 06:52:34 -07:00
|
|
|
case nukeWallet
|
2021-12-13 16:51:31 -08:00
|
|
|
case onboarding(OnboardingAction)
|
2021-12-13 12:50:04 -08:00
|
|
|
case phraseDisplay(RecoveryPhraseDisplayAction)
|
|
|
|
case phraseValidation(RecoveryPhraseValidationAction)
|
2022-04-12 04:12:07 -07:00
|
|
|
case respondToWalletInitializationState(InitializationState)
|
2022-04-14 02:25:05 -07:00
|
|
|
case sandbox(SandboxAction)
|
2022-04-04 05:04:01 -07:00
|
|
|
case updateRoute(AppState.Route)
|
2022-04-04 04:23:57 -07:00
|
|
|
case welcome(WelcomeAction)
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
2022-04-01 04:27:37 -07:00
|
|
|
struct AppEnvironment {
|
2022-04-13 06:52:31 -07:00
|
|
|
let combineSynchronizer: CombineSynchronizer
|
2022-04-07 07:13:40 -07:00
|
|
|
let databaseFiles: DatabaseFilesInteractor
|
2022-04-01 04:27:37 -07:00
|
|
|
let mnemonicSeedPhraseProvider: MnemonicSeedPhraseProvider
|
2022-04-13 06:52:31 -07:00
|
|
|
let scheduler: AnySchedulerOf<DispatchQueue>
|
2022-03-28 04:02:17 -07:00
|
|
|
let walletStorage: WalletStorageInteractor
|
2022-04-12 01:02:36 -07:00
|
|
|
let wrappedDerivationTool: WrappedDerivationTool
|
2022-04-13 06:52:31 -07:00
|
|
|
let zcashSDKEnvironment: ZCashSDKEnvironment
|
2022-04-01 04:27:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
extension AppEnvironment {
|
|
|
|
static let live = AppEnvironment(
|
2022-04-13 06:52:31 -07:00
|
|
|
combineSynchronizer: LiveCombineSynchronizer(),
|
2022-04-07 07:13:40 -07:00
|
|
|
databaseFiles: .live(),
|
2022-04-01 04:27:37 -07:00
|
|
|
mnemonicSeedPhraseProvider: .live,
|
2022-04-13 06:52:31 -07:00
|
|
|
scheduler: DispatchQueue.main.eraseToAnyScheduler(),
|
2022-04-12 01:02:36 -07:00
|
|
|
walletStorage: .live(),
|
2022-04-13 06:52:31 -07:00
|
|
|
wrappedDerivationTool: .live(),
|
|
|
|
zcashSDKEnvironment: .mainnet
|
2022-04-01 04:27:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
static let mock = AppEnvironment(
|
2022-04-13 06:52:31 -07:00
|
|
|
combineSynchronizer: LiveCombineSynchronizer(),
|
2022-04-07 07:13:40 -07:00
|
|
|
databaseFiles: .live(),
|
2022-04-01 04:27:37 -07:00
|
|
|
mnemonicSeedPhraseProvider: .mock,
|
2022-04-13 06:52:31 -07:00
|
|
|
scheduler: DispatchQueue.main.eraseToAnyScheduler(),
|
2022-04-12 01:02:36 -07:00
|
|
|
walletStorage: .live(),
|
2022-04-13 06:52:31 -07:00
|
|
|
wrappedDerivationTool: .live(derivationTool: DerivationTool(networkType: .mainnet)),
|
|
|
|
zcashSDKEnvironment: .mainnet
|
2022-04-01 04:27:37 -07:00
|
|
|
)
|
|
|
|
}
|
2021-12-13 16:51:31 -08:00
|
|
|
|
|
|
|
// MARK: - AppReducer
|
|
|
|
|
2022-04-04 04:23:57 -07:00
|
|
|
private struct ListenerId: Hashable {}
|
|
|
|
|
2021-12-13 16:51:31 -08:00
|
|
|
typealias AppReducer = Reducer<AppState, AppAction, AppEnvironment>
|
|
|
|
|
|
|
|
extension AppReducer {
|
|
|
|
static let `default` = AppReducer.combine(
|
|
|
|
[
|
2022-04-01 04:27:37 -07:00
|
|
|
appReducer,
|
2021-12-13 16:51:31 -08:00
|
|
|
homeReducer,
|
2021-12-13 12:50:04 -08:00
|
|
|
onboardingReducer,
|
2022-03-02 08:33:58 -08:00
|
|
|
phraseValidationReducer,
|
2022-04-14 02:25:05 -07:00
|
|
|
phraseDisplayReducer,
|
|
|
|
routeReducer,
|
|
|
|
sandboxReducer
|
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
|
|
|
|
2022-04-01 04:27:37 -07:00
|
|
|
private static let appReducer = AppReducer { state, action, environment in
|
|
|
|
switch action {
|
2022-04-12 04:12:07 -07:00
|
|
|
case .appDelegate(.didFinishLaunching):
|
|
|
|
/// We need to fetch data from keychain, in order to be 100% sure the kecyhain can be read we delay the check a bit
|
|
|
|
return Effect(value: .checkWalletInitialization)
|
|
|
|
.delay(for: 0.02, scheduler: environment.scheduler)
|
|
|
|
.eraseToEffect()
|
2022-04-01 04:27:37 -07:00
|
|
|
|
2022-04-12 04:12:07 -07:00
|
|
|
/// Evaluate the wallet's state based on keychain keys and database files presence
|
2022-04-04 05:04:01 -07:00
|
|
|
case .checkWalletInitialization:
|
2022-04-12 04:12:07 -07:00
|
|
|
let walletState = walletInitializationState(environment)
|
|
|
|
return Effect(value: .respondToWalletInitializationState(walletState))
|
|
|
|
|
|
|
|
/// Respond to all possible states of the wallet and initiate appropriate side effects including errors handling
|
|
|
|
case .respondToWalletInitializationState(let walletState):
|
|
|
|
switch walletState {
|
|
|
|
case .failed:
|
|
|
|
// TODO: error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
2022-04-04 05:04:01 -07:00
|
|
|
state.appInitializationState = .failed
|
2022-04-12 04:12:07 -07:00
|
|
|
case .keysMissing:
|
2022-04-04 05:04:01 -07:00
|
|
|
// TODO: error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
2022-04-12 04:12:07 -07:00
|
|
|
state.appInitializationState = .keysMissing
|
2022-04-13 06:52:31 -07:00
|
|
|
case .initialized, .filesMissing:
|
|
|
|
if walletState == .filesMissing {
|
|
|
|
state.appInitializationState = .filesMissing
|
|
|
|
}
|
|
|
|
return .concatenate(
|
|
|
|
Effect(value: .initializeSDK),
|
|
|
|
Effect(value: .checkBackupPhraseValidation)
|
|
|
|
)
|
2022-04-12 04:12:07 -07:00
|
|
|
case .uninitialized:
|
|
|
|
state.appInitializationState = .uninitialized
|
2022-03-28 04:02:17 -07:00
|
|
|
return Effect(value: .updateRoute(.onboarding))
|
|
|
|
.delay(for: 3, scheduler: environment.scheduler)
|
|
|
|
.eraseToEffect()
|
2022-04-04 04:23:57 -07:00
|
|
|
.cancellable(id: ListenerId(), cancelInFlight: true)
|
2022-03-28 04:02:17 -07:00
|
|
|
}
|
|
|
|
|
2022-04-04 05:04:01 -07:00
|
|
|
return .none
|
|
|
|
|
|
|
|
/// Stored wallet is present, database files may or may not be present, trying to initialize app state variables and environments.
|
|
|
|
/// When initialization succeeds user is taken to the home screen.
|
2022-04-13 06:52:31 -07:00
|
|
|
case .initializeSDK:
|
2022-04-04 05:04:01 -07:00
|
|
|
do {
|
|
|
|
state.storedWallet = try environment.walletStorage.exportWallet()
|
2022-04-13 06:52:31 -07:00
|
|
|
|
|
|
|
guard let storedWallet = state.storedWallet else {
|
|
|
|
state.appInitializationState = .failed
|
|
|
|
// TODO: fatal error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
|
|
|
|
try environment.mnemonicSeedPhraseProvider.isValid(storedWallet.seedPhrase)
|
|
|
|
|
|
|
|
let birthday = state.storedWallet?.birthday ?? environment.zcashSDKEnvironment.defaultBirthday
|
|
|
|
|
|
|
|
let initializer = try prepareInitializer(
|
|
|
|
for: storedWallet.seedPhrase,
|
|
|
|
birthday: birthday,
|
|
|
|
with: environment
|
|
|
|
)
|
|
|
|
try environment.combineSynchronizer.prepareWith(initializer: initializer)
|
|
|
|
try environment.combineSynchronizer.start()
|
2022-04-04 05:04:01 -07:00
|
|
|
} catch {
|
|
|
|
state.appInitializationState = .failed
|
|
|
|
// TODO: error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
|
|
|
}
|
2022-04-13 06:52:31 -07:00
|
|
|
return .none
|
|
|
|
|
|
|
|
case .checkBackupPhraseValidation:
|
2022-04-07 06:52:34 -07:00
|
|
|
guard let storedWallet = state.storedWallet else {
|
2022-04-13 06:52:31 -07:00
|
|
|
state.appInitializationState = .failed
|
|
|
|
// TODO: fatal error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
|
|
|
return .none
|
2022-04-07 06:52:34 -07:00
|
|
|
}
|
|
|
|
|
2022-04-14 02:25:05 -07:00
|
|
|
var landingRoute: AppState.Route = .home
|
2022-04-07 06:52:34 -07:00
|
|
|
|
|
|
|
if !storedWallet.hasUserPassedPhraseBackupTest {
|
|
|
|
do {
|
2022-04-13 06:52:31 -07:00
|
|
|
let phraseWords = try environment.mnemonicSeedPhraseProvider.asWords(storedWallet.seedPhrase)
|
|
|
|
|
|
|
|
let recoveryPhrase = RecoveryPhrase(words: phraseWords)
|
|
|
|
state.phraseDisplayState.phrase = recoveryPhrase
|
|
|
|
state.phraseValidationState = RecoveryPhraseValidationState.random(phrase: recoveryPhrase)
|
|
|
|
landingRoute = .phraseDisplay
|
2022-04-07 06:52:34 -07:00
|
|
|
} catch {
|
|
|
|
// TODO: - merge with issue 201 (https://github.com/zcash/secant-ios-wallet/issues/201) and its Error States
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 05:04:01 -07:00
|
|
|
state.appInitializationState = .initialized
|
2022-04-07 06:52:34 -07:00
|
|
|
return Effect(value: .updateRoute(landingRoute))
|
2022-04-04 05:04:01 -07:00
|
|
|
.delay(for: 3, scheduler: environment.scheduler)
|
|
|
|
.eraseToEffect()
|
2022-04-07 06:52:34 -07:00
|
|
|
.cancellable(id: ListenerId(), cancelInFlight: true)
|
2022-04-13 06:52:31 -07:00
|
|
|
|
2022-04-12 04:12:07 -07:00
|
|
|
case .createNewWallet:
|
|
|
|
do {
|
|
|
|
// get the random english mnemonic
|
|
|
|
let randomPhrase = try environment.mnemonicSeedPhraseProvider.randomMnemonic()
|
2022-04-13 06:52:31 -07:00
|
|
|
let birthday = try environment.zcashSDKEnvironment.lightWalletService.latestBlockHeight()
|
2022-04-12 04:12:07 -07:00
|
|
|
|
|
|
|
// store the wallet to the keychain
|
|
|
|
try environment.walletStorage.importWallet(randomPhrase, birthday, .english, false)
|
|
|
|
|
|
|
|
// start the backup phrase validation test
|
2022-04-13 06:52:31 -07:00
|
|
|
let randomPhraseWords = try environment.mnemonicSeedPhraseProvider.asWords(randomPhrase)
|
2022-04-12 04:12:07 -07:00
|
|
|
let recoveryPhrase = RecoveryPhrase(words: randomPhraseWords)
|
|
|
|
state.phraseDisplayState.phrase = recoveryPhrase
|
|
|
|
state.phraseValidationState = RecoveryPhraseValidationState.random(phrase: recoveryPhrase)
|
|
|
|
|
2022-04-13 06:52:31 -07:00
|
|
|
return .concatenate(
|
|
|
|
Effect(value: .initializeSDK),
|
|
|
|
Effect(value: .phraseValidation(.displayBackedUpPhrase))
|
|
|
|
)
|
2022-04-12 04:12:07 -07:00
|
|
|
} catch {
|
|
|
|
// TODO: - merge with issue 201 (https://github.com/zcash/secant-ios-wallet/issues/201) and its Error States
|
|
|
|
}
|
|
|
|
|
|
|
|
return .none
|
|
|
|
|
2022-04-07 06:52:34 -07:00
|
|
|
case .phraseValidation(.succeed):
|
|
|
|
do {
|
|
|
|
try environment.walletStorage.markUserPassedPhraseBackupTest()
|
|
|
|
} catch {
|
|
|
|
// TODO: error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
|
|
|
}
|
|
|
|
return .none
|
2022-04-13 06:52:31 -07:00
|
|
|
|
2022-04-07 06:52:34 -07:00
|
|
|
case .nukeWallet:
|
|
|
|
environment.walletStorage.nukeWallet()
|
2022-04-13 06:52:31 -07:00
|
|
|
do {
|
|
|
|
try environment.databaseFiles.nukeDbFilesFor(environment.zcashSDKEnvironment.network)
|
|
|
|
} catch {
|
|
|
|
// TODO: error we need to handle, issue #221 (https://github.com/zcash/secant-ios-wallet/issues/221)
|
|
|
|
}
|
2022-04-07 06:52:34 -07:00
|
|
|
return .none
|
2022-04-13 06:52:31 -07:00
|
|
|
|
|
|
|
case .welcome(.debugMenuStartup), .home(.debugMenuStartup):
|
2022-04-04 04:23:57 -07:00
|
|
|
return .concatenate(
|
|
|
|
Effect.cancel(id: ListenerId()),
|
|
|
|
Effect(value: .updateRoute(.startup))
|
|
|
|
)
|
2022-04-13 06:52:31 -07:00
|
|
|
|
2022-04-11 05:31:55 -07:00
|
|
|
case .onboarding(.importWallet(.successfullyRecovered)):
|
2022-04-13 06:52:31 -07:00
|
|
|
return Effect(value: .updateRoute(.home))
|
|
|
|
|
|
|
|
case .onboarding(.importWallet(.initializeSDK)):
|
|
|
|
return Effect(value: .initializeSDK)
|
|
|
|
|
2022-04-04 05:04:01 -07:00
|
|
|
/// Default is meaningful here because there's `routeReducer` handling routes and this reducer is handling only actions. We don't here plenty of unused cases.
|
2022-04-01 04:27:37 -07:00
|
|
|
default:
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
}
|
2022-04-04 05:04:01 -07: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
|
|
|
|
2022-04-14 02:25:05 -07:00
|
|
|
case .sandbox(.reset):
|
2021-12-13 16:20:56 -08:00
|
|
|
state.route = .startup
|
2021-12-13 12:50:04 -08:00
|
|
|
|
2022-04-01 04:27:37 -07:00
|
|
|
case .onboarding(.createNewWallet):
|
|
|
|
return Effect(value: .createNewWallet)
|
|
|
|
|
|
|
|
case .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
|
|
|
|
|
2022-04-04 05:04:01 -07:00
|
|
|
/// Default is meaningful here because there's `appReducer` handling actions and this reducer is handling only routes. We don't here plenty of unused cases.
|
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,
|
2022-04-13 06:52:31 -07:00
|
|
|
environment: { environment in
|
|
|
|
HomeEnvironment(
|
|
|
|
combineSynchronizer: environment.combineSynchronizer
|
|
|
|
)
|
|
|
|
}
|
2021-12-13 16:51:31 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
private static let onboardingReducer: AppReducer = OnboardingReducer.default.pullback(
|
|
|
|
state: \AppState.onboardingState,
|
|
|
|
action: /AppAction.onboarding,
|
2022-04-11 05:31:55 -07:00
|
|
|
environment: { environment in
|
|
|
|
OnboardingEnvironment(
|
|
|
|
mnemonicSeedPhraseProvider: environment.mnemonicSeedPhraseProvider,
|
2022-04-13 06:52:31 -07:00
|
|
|
walletStorage: environment.walletStorage,
|
|
|
|
zcashSDKEnvironment: environment.zcashSDKEnvironment
|
2022-04-11 05:31:55 -07:00
|
|
|
)
|
|
|
|
}
|
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 }
|
|
|
|
)
|
2022-04-04 04:23:57 -07:00
|
|
|
|
2022-04-14 02:25:05 -07:00
|
|
|
private static let sandboxReducer: AppReducer = SandboxReducer.default.pullback(
|
|
|
|
state: \AppState.sandboxState,
|
|
|
|
action: /AppAction.sandbox,
|
|
|
|
environment: { _ in }
|
|
|
|
)
|
|
|
|
|
2022-04-04 04:23:57 -07:00
|
|
|
private static let welcomeReducer: AppReducer = WelcomeReducer.default.pullback(
|
|
|
|
state: \AppState.welcomeState,
|
|
|
|
action: /AppAction.welcome,
|
|
|
|
environment: { _ in }
|
|
|
|
)
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
2022-04-12 04:12:07 -07:00
|
|
|
// MARK: - AppReducer Helper Functions
|
|
|
|
|
|
|
|
extension AppReducer {
|
|
|
|
static func walletInitializationState(_ environment: AppEnvironment) -> InitializationState {
|
|
|
|
var keysPresent = false
|
|
|
|
do {
|
|
|
|
keysPresent = try environment.walletStorage.areKeysPresent()
|
2022-04-13 06:52:31 -07:00
|
|
|
let databaseFilesPresent = try environment.databaseFiles.areDbFilesPresentFor(
|
|
|
|
environment.zcashSDKEnvironment.network
|
|
|
|
)
|
2022-04-12 04:12:07 -07:00
|
|
|
|
|
|
|
switch (keysPresent, databaseFilesPresent) {
|
|
|
|
case (false, false):
|
|
|
|
return .uninitialized
|
|
|
|
case (false, true):
|
|
|
|
return .keysMissing
|
|
|
|
case (true, false):
|
|
|
|
return .filesMissing
|
|
|
|
case (true, true):
|
|
|
|
return .initialized
|
|
|
|
}
|
|
|
|
} catch DatabaseFiles.DatabaseFilesError.filesPresentCheck {
|
|
|
|
if keysPresent {
|
|
|
|
return .filesMissing
|
|
|
|
}
|
|
|
|
} catch WalletStorage.WalletStorageError.uninitializedWallet {
|
|
|
|
do {
|
2022-04-13 06:52:31 -07:00
|
|
|
if try environment.databaseFiles.areDbFilesPresentFor(
|
|
|
|
environment.zcashSDKEnvironment.network
|
|
|
|
) {
|
2022-04-14 04:12:09 -07:00
|
|
|
return .keysMissing
|
|
|
|
}
|
2022-04-12 04:12:07 -07:00
|
|
|
} catch {
|
|
|
|
return .uninitialized
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
return .failed
|
|
|
|
}
|
|
|
|
|
|
|
|
return .uninitialized
|
|
|
|
}
|
2022-04-13 06:52:31 -07:00
|
|
|
|
|
|
|
static func prepareInitializer(
|
|
|
|
for seedPhrase: String,
|
|
|
|
birthday: BlockHeight,
|
|
|
|
with environment: AppEnvironment
|
|
|
|
) throws -> Initializer {
|
|
|
|
do {
|
|
|
|
let seedBytes = try environment.mnemonicSeedPhraseProvider.toSeed(seedPhrase)
|
|
|
|
let viewingKeys = try environment.wrappedDerivationTool.deriveUnifiedViewingKeysFromSeed(seedBytes, 1)
|
|
|
|
|
|
|
|
let network = environment.zcashSDKEnvironment.network
|
|
|
|
|
|
|
|
let initializer = Initializer(
|
|
|
|
cacheDbURL: try environment.databaseFiles.cacheDbURLFor(network),
|
|
|
|
dataDbURL: try environment.databaseFiles.dataDbURLFor(network),
|
|
|
|
pendingDbURL: try environment.databaseFiles.pendingDbURLFor(network),
|
|
|
|
endpoint: environment.zcashSDKEnvironment.endpoint,
|
|
|
|
network: environment.zcashSDKEnvironment.network,
|
|
|
|
spendParamsURL: try environment.databaseFiles.spendParamsURLFor(network),
|
|
|
|
outputParamsURL: try environment.databaseFiles.outputParamsURLFor(network),
|
|
|
|
viewingKeys: viewingKeys,
|
|
|
|
walletBirthday: birthday
|
|
|
|
)
|
|
|
|
|
|
|
|
return initializer
|
|
|
|
} catch {
|
|
|
|
throw SDKInitializationError.failed
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 04:12:07 -07:00
|
|
|
}
|
|
|
|
|
2021-12-13 16:51:31 -08:00
|
|
|
// MARK: - AppStore
|
|
|
|
|
|
|
|
typealias AppStore = Store<AppState, AppAction>
|
|
|
|
|
|
|
|
extension AppStore {
|
2022-04-04 05:04:01 -07:00
|
|
|
static var placeholder: AppStore {
|
|
|
|
AppStore(
|
|
|
|
initialState: .placeholder,
|
|
|
|
reducer: .default,
|
2022-04-13 06:52:31 -07:00
|
|
|
environment: .live
|
2022-04-04 05:04:01 -07:00
|
|
|
)
|
|
|
|
}
|
2021-12-13 16:51:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2022-04-04 04:23:57 -07:00
|
|
|
),
|
2022-04-14 02:25:05 -07:00
|
|
|
sandboxState: .placeholder,
|
2022-04-04 04:23:57 -07:00
|
|
|
welcomeState: .placeholder
|
2021-12-13 16:51:31 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|