refactor(@desktop/onboarding): `state_factory` splitted in three more files
Old `state_factory` logic is splitted in three more files. Now it represents only an interface, but implementation logic is placed in the following three files: - `state_factory_general_implementation.nim` - `state_factory_state_onboarding_implementation.nim` - `state_factory_state_login_implementation.nim`
This commit is contained in:
parent
7f2563edf4
commit
d3fffac4be
|
@ -13,7 +13,9 @@ logScope:
|
|||
topics = "startup-module-state-factory"
|
||||
|
||||
# Forward declaration
|
||||
# General section
|
||||
proc createState*(stateToBeCreated: StateType, flowType: FlowType, backState: State): State
|
||||
# Resolve state section
|
||||
proc ensureReaderAndCardPresenceOnboarding*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State
|
||||
proc ensureReaderAndCardPresenceLogin*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State
|
||||
proc ensureReaderAndCardPresenceAndResolveNextOnboardingState*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State
|
||||
|
@ -76,290 +78,6 @@ include profile_fetching_timeout_state
|
|||
include profile_fetching_announcement_state
|
||||
include recover_old_user_state
|
||||
|
||||
proc createState*(stateToBeCreated: StateType, flowType: FlowType, backState: State): State =
|
||||
if stateToBeCreated == StateType.AllowNotifications:
|
||||
return newNotificationState(flowType, backState)
|
||||
if stateToBeCreated == StateType.Welcome:
|
||||
return newWelcomeState(flowType, backState)
|
||||
if stateToBeCreated == StateType.WelcomeNewStatusUser:
|
||||
return newWelcomeStateNewUser(flowType, backState)
|
||||
if stateToBeCreated == StateType.WelcomeOldStatusUser:
|
||||
return newWelcomeStateOldUser(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileCreate:
|
||||
return newUserProfileCreateState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileCreateSameChatKey:
|
||||
return newUserProfileCreateSameChatKeyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileChatKey:
|
||||
return newUserProfileChatKeyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileCreatePassword:
|
||||
return newUserProfileCreatePasswordState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileConfirmPassword:
|
||||
return newUserProfileConfirmPasswordState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileImportSeedPhrase:
|
||||
return newUserProfileImportSeedPhraseState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileEnterSeedPhrase:
|
||||
return newUserProfileEnterSeedPhraseState(flowType, backState)
|
||||
if stateToBeCreated == StateType.Biometrics:
|
||||
return newBiometricsState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardPluginReader:
|
||||
return newKeycardPluginReaderState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardInsertKeycard:
|
||||
return newKeycardInsertKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardInsertedKeycard:
|
||||
return newKeycardInsertedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardReadingKeycard:
|
||||
return newKeycardReadingKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardRecognizedKeycard:
|
||||
return newKeycardRecognizedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardCreatePin:
|
||||
return newKeycardCreatePinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardRepeatPin:
|
||||
return newKeycardRepeatPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardPinSet:
|
||||
return newKeycardPinSetState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEnterPin:
|
||||
return newKeycardEnterPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardWrongPin:
|
||||
return newKeycardWrongPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEnterPuk:
|
||||
return newKeycardEnterPukState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardWrongKeycard:
|
||||
return newKeycardWrongKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardWrongPuk:
|
||||
return newKeycardWrongPukState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardDisplaySeedPhrase:
|
||||
return newKeycardDisplaySeedPhraseState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEnterSeedPhraseWords:
|
||||
return newKeycardEnterSeedPhraseWordsState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardNotEmpty:
|
||||
return newKeycardNotEmptyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardNotKeycard:
|
||||
return newKeycardNotKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEmpty:
|
||||
return newKeycardEmptyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardLocked:
|
||||
return newKeycardLockedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardRecover:
|
||||
return newKeycardRecoverState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardMaxPairingSlotsReached:
|
||||
return newKeycardMaxPairingSlotsReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardMaxPinRetriesReached:
|
||||
return newKeycardMaxPinRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardMaxPukRetriesReached:
|
||||
return newKeycardMaxPukRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.Login:
|
||||
return newLoginState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginPlugin:
|
||||
return newLoginPluginState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardInsertKeycard:
|
||||
return newLoginKeycardInsertKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardInsertedKeycard:
|
||||
return newLoginKeycardInsertedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardReadingKeycard:
|
||||
return newLoginKeycardReadingKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardRecognizedKeycard:
|
||||
return newLoginKeycardRecognizedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardEnterPin:
|
||||
return newLoginKeycardEnterPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardEnterPassword:
|
||||
return newLoginKeycardEnterPasswordState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardPinVerified:
|
||||
return newLoginKeycardPinVerifiedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardWrongKeycard:
|
||||
return newLoginKeycardWrongKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardWrongPin:
|
||||
return newLoginKeycardWrongPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardMaxPinRetriesReached:
|
||||
return newLoginKeycardMaxPinRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardMaxPukRetriesReached:
|
||||
return newLoginKeycardMaxPukRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardMaxPairingSlotsReached:
|
||||
return newLoginKeycardMaxPairingSlotsReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardEmpty:
|
||||
return newLoginKeycardEmptyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginNotKeycard:
|
||||
return newLoginNotKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetching:
|
||||
return newProfileFetchingState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetchingSuccess:
|
||||
return newProfileFetchingSuccessState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetchingTimeout:
|
||||
return newProfileFetchingTimeoutState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetchingAnnouncement:
|
||||
return newProfileFetchingAnnouncementState(flowType, backState)
|
||||
if stateToBeCreated == StateType.RecoverOldUser:
|
||||
return newRecoverOldUserState(flowType, backState)
|
||||
|
||||
|
||||
error "No implementation available for state ", state=stateToBeCreated
|
||||
|
||||
proc ensureReaderAndCardPresenceOnboarding*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
controller.resumeCurrentFlowLater()
|
||||
if state.stateType == StateType.KeycardPluginReader:
|
||||
return nil
|
||||
return createState(StateType.KeycardPluginReader, state.flowType, state)
|
||||
if keycardFlowType == ResponseTypeValueInsertCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
if state.stateType == StateType.KeycardInsertKeycard:
|
||||
return nil
|
||||
return createState(StateType.KeycardInsertKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueCardInserted:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.WronglyInsertedCard, add = false))
|
||||
return createState(StateType.KeycardInsertedKeycard, state.flowType, state.getBackState)
|
||||
|
||||
proc ensureReaderAndCardPresenceLogin*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
controller.resumeCurrentFlowLater()
|
||||
if state.stateType == StateType.LoginPlugin:
|
||||
return nil
|
||||
return createState(StateType.LoginPlugin, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueInsertCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
if state.stateType == StateType.LoginKeycardInsertKeycard:
|
||||
return nil
|
||||
return createState(StateType.LoginKeycardInsertKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueCardInserted:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.WronglyInsertedCard, add = false))
|
||||
return createState(StateType.LoginKeycardInsertedKeycard, state.flowType, state.getBackState)
|
||||
|
||||
proc ensureReaderAndCardPresenceAndResolveNextOnboardingState*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
let ensureState = ensureReaderAndCardPresenceOnboarding(state, keycardFlowType, keycardEvent, controller)
|
||||
if not ensureState.isNil:
|
||||
return ensureState
|
||||
|
||||
if state.flowType == FlowType.FirstRunNewUserNewKeycardKeys:
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
return createState(StateType.KeycardRecognizedKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN and
|
||||
keycardEvent.error.len == 0:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPUK and
|
||||
keycardEvent.error.len == 0:
|
||||
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == ErrorNotAKeycard:
|
||||
return createState(StateType.KeycardNotKeycard, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == ErrorHasKeys:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterMnemonic and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorLoadingKeys:
|
||||
controller.buildSeedPhrasesFromIndexes(keycardEvent.seedPhraseIndexes)
|
||||
return createState(StateType.KeycardPinSet, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.keyUid.len > 0:
|
||||
controller.setKeyUid(keycardEvent.keyUid)
|
||||
return createState(StateType.UserProfileCreate, state.flowType, state)
|
||||
|
||||
if state.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard:
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
if state.stateType == StateType.UserProfileEnterSeedPhrase:
|
||||
return createState(StateType.KeycardCreatePin, state.flowType, state.getBackState)
|
||||
return createState(StateType.KeycardRecognizedKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN and
|
||||
keycardEvent.error.len == 0:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == ErrorNotAKeycard:
|
||||
return createState(StateType.KeycardNotKeycard, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == ErrorHasKeys:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.keyUid.len > 0:
|
||||
controller.setKeyUid(keycardEvent.keyUid)
|
||||
return createState(StateType.KeycardPinSet, state.flowType, state.getBackState)
|
||||
|
||||
if state.flowType == FlowType.FirstRunOldUserKeycardImport:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.MaxPUKReached, add = false))
|
||||
controller.setKeyUid(keycardEvent.keyUid)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN and
|
||||
keycardEvent.error.len == 0:
|
||||
return createState(StateType.KeycardRecognizedKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPUK and
|
||||
keycardEvent.error.len == 0:
|
||||
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.KeycardMaxPinRetriesReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorNoKeys:
|
||||
return createState(StateType.KeycardEmpty, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == RequestParamPUKRetries:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.MaxPUKReached, add = true))
|
||||
return createState(StateType.KeycardMaxPukRetriesReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.KeycardMaxPairingSlotsReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
return createState(StateType.KeycardCreatePin, state.flowType, nil)
|
||||
|
||||
if state.flowType == FlowType.AppLogin:
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.KeycardMaxPukRetriesReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
return createState(StateType.KeycardCreatePin, state.flowType, state.getBackState)
|
||||
|
||||
proc ensureReaderAndCardPresenceAndResolveNextLoginState*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
let ensureState = ensureReaderAndCardPresenceLogin(state, keycardFlowType, keycardEvent, controller)
|
||||
if not ensureState.isNil:
|
||||
return ensureState
|
||||
if state.flowType == FlowType.AppLogin:
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.error.len == 0:
|
||||
controller.setKeycardEvent(keycardEvent)
|
||||
return createState(StateType.LoginKeycardPinVerified, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN:
|
||||
if keycardEvent.error.len == 0:
|
||||
if not controller.keyUidMatch(keycardEvent.keyUid):
|
||||
return createState(StateType.LoginKeycardWrongKeycard, state.flowType, nil)
|
||||
return createState(StateType.LoginKeycardRecognizedKeycard, state.flowType, nil)
|
||||
if keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == RequestParamPIN:
|
||||
controller.setRemainingAttempts(keycardEvent.pinRetries)
|
||||
if keycardEvent.pinRetries > 0:
|
||||
return createState(StateType.LoginKeycardWrongPin, state.flowType, nil)
|
||||
return createState(StateType.LoginKeycardMaxPinRetriesReached, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueEnterPUK and
|
||||
keycardEvent.error.len == 0:
|
||||
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.LoginKeycardMaxPinRetriesReached, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == ErrorNoKeys:
|
||||
return createState(StateType.LoginKeycardEmpty, state.flowType, nil)
|
||||
if keycardEvent.error == ErrorNotAKeycard:
|
||||
return createState(StateType.LoginNotKeycard, state.flowType, nil)
|
||||
if keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.LoginKeycardMaxPukRetriesReached, state.flowType, nil)
|
||||
if keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.LoginKeycardMaxPairingSlotsReached, state.flowType, nil)
|
||||
include state_factory_general_implementation
|
||||
include state_factory_state_onboarding_implementation
|
||||
include state_factory_state_login_implementation
|
|
@ -0,0 +1,115 @@
|
|||
proc createState*(stateToBeCreated: StateType, flowType: FlowType, backState: State): State =
|
||||
if stateToBeCreated == StateType.AllowNotifications:
|
||||
return newNotificationState(flowType, backState)
|
||||
if stateToBeCreated == StateType.Welcome:
|
||||
return newWelcomeState(flowType, backState)
|
||||
if stateToBeCreated == StateType.WelcomeNewStatusUser:
|
||||
return newWelcomeStateNewUser(flowType, backState)
|
||||
if stateToBeCreated == StateType.WelcomeOldStatusUser:
|
||||
return newWelcomeStateOldUser(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileCreate:
|
||||
return newUserProfileCreateState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileCreateSameChatKey:
|
||||
return newUserProfileCreateSameChatKeyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileChatKey:
|
||||
return newUserProfileChatKeyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileCreatePassword:
|
||||
return newUserProfileCreatePasswordState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileConfirmPassword:
|
||||
return newUserProfileConfirmPasswordState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileImportSeedPhrase:
|
||||
return newUserProfileImportSeedPhraseState(flowType, backState)
|
||||
if stateToBeCreated == StateType.UserProfileEnterSeedPhrase:
|
||||
return newUserProfileEnterSeedPhraseState(flowType, backState)
|
||||
if stateToBeCreated == StateType.Biometrics:
|
||||
return newBiometricsState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardPluginReader:
|
||||
return newKeycardPluginReaderState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardInsertKeycard:
|
||||
return newKeycardInsertKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardInsertedKeycard:
|
||||
return newKeycardInsertedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardReadingKeycard:
|
||||
return newKeycardReadingKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardRecognizedKeycard:
|
||||
return newKeycardRecognizedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardCreatePin:
|
||||
return newKeycardCreatePinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardRepeatPin:
|
||||
return newKeycardRepeatPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardPinSet:
|
||||
return newKeycardPinSetState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEnterPin:
|
||||
return newKeycardEnterPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardWrongPin:
|
||||
return newKeycardWrongPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEnterPuk:
|
||||
return newKeycardEnterPukState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardWrongKeycard:
|
||||
return newKeycardWrongKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardWrongPuk:
|
||||
return newKeycardWrongPukState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardDisplaySeedPhrase:
|
||||
return newKeycardDisplaySeedPhraseState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEnterSeedPhraseWords:
|
||||
return newKeycardEnterSeedPhraseWordsState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardNotEmpty:
|
||||
return newKeycardNotEmptyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardNotKeycard:
|
||||
return newKeycardNotKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardEmpty:
|
||||
return newKeycardEmptyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardLocked:
|
||||
return newKeycardLockedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardRecover:
|
||||
return newKeycardRecoverState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardMaxPairingSlotsReached:
|
||||
return newKeycardMaxPairingSlotsReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardMaxPinRetriesReached:
|
||||
return newKeycardMaxPinRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.KeycardMaxPukRetriesReached:
|
||||
return newKeycardMaxPukRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.Login:
|
||||
return newLoginState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginPlugin:
|
||||
return newLoginPluginState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardInsertKeycard:
|
||||
return newLoginKeycardInsertKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardInsertedKeycard:
|
||||
return newLoginKeycardInsertedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardReadingKeycard:
|
||||
return newLoginKeycardReadingKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardRecognizedKeycard:
|
||||
return newLoginKeycardRecognizedKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardEnterPin:
|
||||
return newLoginKeycardEnterPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardEnterPassword:
|
||||
return newLoginKeycardEnterPasswordState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardPinVerified:
|
||||
return newLoginKeycardPinVerifiedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardWrongKeycard:
|
||||
return newLoginKeycardWrongKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardWrongPin:
|
||||
return newLoginKeycardWrongPinState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardMaxPinRetriesReached:
|
||||
return newLoginKeycardMaxPinRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardMaxPukRetriesReached:
|
||||
return newLoginKeycardMaxPukRetriesReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardMaxPairingSlotsReached:
|
||||
return newLoginKeycardMaxPairingSlotsReachedState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginKeycardEmpty:
|
||||
return newLoginKeycardEmptyState(flowType, backState)
|
||||
if stateToBeCreated == StateType.LoginNotKeycard:
|
||||
return newLoginNotKeycardState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetching:
|
||||
return newProfileFetchingState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetchingSuccess:
|
||||
return newProfileFetchingSuccessState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetchingTimeout:
|
||||
return newProfileFetchingTimeoutState(flowType, backState)
|
||||
if stateToBeCreated == StateType.ProfileFetchingAnnouncement:
|
||||
return newProfileFetchingAnnouncementState(flowType, backState)
|
||||
if stateToBeCreated == StateType.RecoverOldUser:
|
||||
return newRecoverOldUserState(flowType, backState)
|
||||
|
||||
error "No implementation available for state ", state=stateToBeCreated
|
|
@ -0,0 +1,52 @@
|
|||
proc ensureReaderAndCardPresenceLogin*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
controller.resumeCurrentFlowLater()
|
||||
if state.stateType == StateType.LoginPlugin:
|
||||
return nil
|
||||
return createState(StateType.LoginPlugin, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueInsertCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
if state.stateType == StateType.LoginKeycardInsertKeycard:
|
||||
return nil
|
||||
return createState(StateType.LoginKeycardInsertKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueCardInserted:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.WronglyInsertedCard, add = false))
|
||||
return createState(StateType.LoginKeycardInsertedKeycard, state.flowType, state.getBackState)
|
||||
|
||||
proc ensureReaderAndCardPresenceAndResolveNextLoginState*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
let ensureState = ensureReaderAndCardPresenceLogin(state, keycardFlowType, keycardEvent, controller)
|
||||
if not ensureState.isNil:
|
||||
return ensureState
|
||||
if state.flowType == FlowType.AppLogin:
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.error.len == 0:
|
||||
controller.setKeycardEvent(keycardEvent)
|
||||
return createState(StateType.LoginKeycardPinVerified, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN:
|
||||
if keycardEvent.error.len == 0:
|
||||
if not controller.keyUidMatch(keycardEvent.keyUid):
|
||||
return createState(StateType.LoginKeycardWrongKeycard, state.flowType, nil)
|
||||
return createState(StateType.LoginKeycardRecognizedKeycard, state.flowType, nil)
|
||||
if keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == RequestParamPIN:
|
||||
controller.setRemainingAttempts(keycardEvent.pinRetries)
|
||||
if keycardEvent.pinRetries > 0:
|
||||
return createState(StateType.LoginKeycardWrongPin, state.flowType, nil)
|
||||
return createState(StateType.LoginKeycardMaxPinRetriesReached, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueEnterPUK and
|
||||
keycardEvent.error.len == 0:
|
||||
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.LoginKeycardMaxPinRetriesReached, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == ErrorNoKeys:
|
||||
return createState(StateType.LoginKeycardEmpty, state.flowType, nil)
|
||||
if keycardEvent.error == ErrorNotAKeycard:
|
||||
return createState(StateType.LoginNotKeycard, state.flowType, nil)
|
||||
if keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.LoginKeycardMaxPukRetriesReached, state.flowType, nil)
|
||||
if keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.LoginKeycardMaxPairingSlotsReached, state.flowType, nil)
|
|
@ -0,0 +1,117 @@
|
|||
proc ensureReaderAndCardPresenceOnboarding*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
controller.resumeCurrentFlowLater()
|
||||
if state.stateType == StateType.KeycardPluginReader:
|
||||
return nil
|
||||
return createState(StateType.KeycardPluginReader, state.flowType, state)
|
||||
if keycardFlowType == ResponseTypeValueInsertCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorConnection:
|
||||
if state.stateType == StateType.KeycardInsertKeycard:
|
||||
return nil
|
||||
return createState(StateType.KeycardInsertKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueCardInserted:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.WronglyInsertedCard, add = false))
|
||||
return createState(StateType.KeycardInsertedKeycard, state.flowType, state.getBackState)
|
||||
|
||||
proc ensureReaderAndCardPresenceAndResolveNextOnboardingState*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
|
||||
let ensureState = ensureReaderAndCardPresenceOnboarding(state, keycardFlowType, keycardEvent, controller)
|
||||
if not ensureState.isNil:
|
||||
return ensureState
|
||||
|
||||
if state.flowType == FlowType.FirstRunNewUserNewKeycardKeys:
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
return createState(StateType.KeycardRecognizedKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN and
|
||||
keycardEvent.error.len == 0:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPUK and
|
||||
keycardEvent.error.len == 0:
|
||||
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == ErrorNotAKeycard:
|
||||
return createState(StateType.KeycardNotKeycard, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == ErrorHasKeys:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterMnemonic and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorLoadingKeys:
|
||||
controller.buildSeedPhrasesFromIndexes(keycardEvent.seedPhraseIndexes)
|
||||
return createState(StateType.KeycardPinSet, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.keyUid.len > 0:
|
||||
controller.setKeyUid(keycardEvent.keyUid)
|
||||
return createState(StateType.UserProfileCreate, state.flowType, state)
|
||||
|
||||
if state.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard:
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
if state.stateType == StateType.UserProfileEnterSeedPhrase:
|
||||
return createState(StateType.KeycardCreatePin, state.flowType, state.getBackState)
|
||||
return createState(StateType.KeycardRecognizedKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN and
|
||||
keycardEvent.error.len == 0:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0:
|
||||
if keycardEvent.error == ErrorNotAKeycard:
|
||||
return createState(StateType.KeycardNotKeycard, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.KeycardLocked, state.flowType, state.getBackState)
|
||||
if keycardEvent.error == ErrorHasKeys:
|
||||
return createState(StateType.KeycardNotEmpty, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult and
|
||||
keycardEvent.keyUid.len > 0:
|
||||
controller.setKeyUid(keycardEvent.keyUid)
|
||||
return createState(StateType.KeycardPinSet, state.flowType, state.getBackState)
|
||||
|
||||
if state.flowType == FlowType.FirstRunOldUserKeycardImport:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.MaxPUKReached, add = false))
|
||||
controller.setKeyUid(keycardEvent.keyUid)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN and
|
||||
keycardEvent.error.len == 0:
|
||||
return createState(StateType.KeycardRecognizedKeycard, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterPUK and
|
||||
keycardEvent.error.len == 0:
|
||||
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.KeycardMaxPinRetriesReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorNoKeys:
|
||||
return createState(StateType.KeycardEmpty, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == RequestParamPUKRetries:
|
||||
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.MaxPUKReached, add = true))
|
||||
return createState(StateType.KeycardMaxPukRetriesReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == RequestParamFreeSlots:
|
||||
return createState(StateType.KeycardMaxPairingSlotsReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
return createState(StateType.KeycardCreatePin, state.flowType, nil)
|
||||
|
||||
if state.flowType == FlowType.AppLogin:
|
||||
if keycardFlowType == ResponseTypeValueSwapCard and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == RequestParamPUKRetries:
|
||||
return createState(StateType.KeycardMaxPukRetriesReached, state.flowType, state.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorRequireInit:
|
||||
return createState(StateType.KeycardCreatePin, state.flowType, state.getBackState)
|
Loading…
Reference in New Issue