diff --git a/ts/components/registration/RegistrationStages.tsx b/ts/components/registration/RegistrationStages.tsx index fb19987bf..a81dd94cf 100644 --- a/ts/components/registration/RegistrationStages.tsx +++ b/ts/components/registration/RegistrationStages.tsx @@ -1,9 +1,6 @@ import { shell } from 'electron'; import { AnimatePresence } from 'framer-motion'; -import { useMount } from 'react-use'; import styled from 'styled-components'; -import { Data } from '../../data/data'; -import { getConversationController } from '../../session/conversations'; import { AccountCreation, AccountRestoration, @@ -14,21 +11,12 @@ import { useOnboardAccountRestorationStep, useOnboardStep, } from '../../state/onboarding/selectors/registration'; -import { Storage } from '../../util/storage'; import { Flex } from '../basic/Flex'; import { SpacerLG, SpacerSM } from '../basic/Text'; import { SessionIcon, SessionIconButton } from '../icon'; import { OnboardContainer } from './components'; import { CreateAccount, RestoreAccount, Start } from './stages'; -export async function resetRegistration() { - await Data.removeAll(); - Storage.reset(); - await Storage.fetch(); - getConversationController().reset(); - await getConversationController().load(); -} - export type RecoverDetails = { recoveryPassword: string; errorCallback: (error: Error) => void; @@ -37,7 +25,6 @@ export type RecoverDetails = { const StyledRegistrationContainer = styled(Flex)` width: 348px; - .session-button { width: 100%; margin: 0; @@ -49,10 +36,6 @@ export const RegistrationStages = () => { const creationStep = useOnboardAccountCreationStep(); const restorationStep = useOnboardAccountRestorationStep(); - useMount(() => { - void resetRegistration(); - }); - return ( diff --git a/ts/components/registration/stages/CreateAccount.tsx b/ts/components/registration/stages/CreateAccount.tsx index 80c7402dc..b6af01bf0 100644 --- a/ts/components/registration/stages/CreateAccount.tsx +++ b/ts/components/registration/stages/CreateAccount.tsx @@ -28,27 +28,24 @@ import { Flex } from '../../basic/Flex'; import { SessionButton, SessionButtonColor } from '../../basic/SessionButton'; import { SpacerLG, SpacerSM } from '../../basic/Text'; import { SessionInput } from '../../inputs'; -import { RecoverDetails, resetRegistration } from '../RegistrationStages'; +import { RecoverDetails } from '../RegistrationStages'; import { OnboardDescription, OnboardHeading } from '../components'; import { BackButtonWithininContainer } from '../components/BackButton'; -import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils'; +import { displayNameIsValid, resetRegistration, sanitizeDisplayNameOrToast } from '../utils'; async function signUp(signUpDetails: RecoverDetails) { const { displayName, recoveryPassword, errorCallback } = signUpDetails; - window.log.debug(`WIP: [signUp] starting sign up....`); try { - const trimName = displayNameIsValid(displayName); - + const validDisplayName = displayNameIsValid(displayName); await resetRegistration(); - await registerSingleDevice(recoveryPassword, 'english', trimName); + await registerSingleDevice(recoveryPassword, 'english', validDisplayName); await Storage.put(SettingsKey.hasSyncedInitialConfigurationItem, Date.now()); await setSignWithRecoveryPhrase(false); trigger('openInbox'); } catch (e) { await resetRegistration(); void errorCallback(e); - window.log.debug(`WIP: [signUp] exception during registration: ${e.message || e}`); } } @@ -89,6 +86,9 @@ export const CreateAccount = () => { } try { + window.log.debug( + `WIP: [onboarding] create account: signUp() is starting display name: ${displayName} recoveryPassword: ${recoveryPassword}` + ); await signUp({ displayName, recoveryPassword, @@ -101,7 +101,7 @@ export const CreateAccount = () => { dispatch(setAccountCreationStep(AccountCreation.Done)); } catch (e) { window.log.debug( - `WIP: [recoverAndFetchDisplayName] AccountRestoration.RecoveryPassword failed to fetch display name so we need to enter it manually. Error: ${e}` + `WIP: [onboarding] create account: creation failed! Error: ${e.message || e}` ); dispatch(setAccountCreationStep(AccountCreation.DisplayName)); } diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx index d1a28c16e..374211f6e 100644 --- a/ts/components/registration/stages/RestoreAccount.tsx +++ b/ts/components/registration/stages/RestoreAccount.tsx @@ -33,11 +33,11 @@ import { SpacerLG, SpacerSM } from '../../basic/Text'; import { SessionIcon } from '../../icon'; import { SessionInput } from '../../inputs'; import { SessionProgressBar } from '../../loading'; -import { RecoverDetails, resetRegistration } from '../RegistrationStages'; +import { RecoverDetails } from '../RegistrationStages'; import { OnboardDescription, OnboardHeading } from '../components'; import { BackButtonWithininContainer } from '../components/BackButton'; import { useRecoveryProgressEffect } from '../hooks'; -import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils'; +import { displayNameIsValid, resetRegistration, sanitizeDisplayNameOrToast } from '../utils'; /** * Sign in/restore from seed. diff --git a/ts/components/registration/stages/Start.tsx b/ts/components/registration/stages/Start.tsx index 7d46731f8..761cd5b51 100644 --- a/ts/components/registration/stages/Start.tsx +++ b/ts/components/registration/stages/Start.tsx @@ -1,8 +1,10 @@ import { useDispatch } from 'react-redux'; +import { useMount } from 'react-use'; import { AccountCreation, AccountRestoration, Onboarding, + resetOnboardingState, setAccountCreationStep, setAccountRestorationStep, setDirection, @@ -11,10 +13,16 @@ import { import { SessionButton, SessionButtonColor } from '../../basic/SessionButton'; import { SpacerLG } from '../../basic/Text'; import { TermsAndConditions } from '../TermsAndConditions'; +import { resetRegistration } from '../utils'; export const Start = () => { const dispatch = useDispatch(); + useMount(() => { + dispatch(resetOnboardingState()); + void resetRegistration(); + }); + return ( <> { - window.log.info('handling registration event'); + window.log.info('WIP: [onboarding] handling registration event'); void connect(); }); diff --git a/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts b/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts index aaae284d1..65e933461 100644 --- a/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts +++ b/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts @@ -4,11 +4,14 @@ import { v4 } from 'uuid'; import { UserUtils } from '../..'; import { ConfigDumpData } from '../../../../data/configDump/configDump'; import { ConfigurationSyncJobDone } from '../../../../shims/events'; +import { ReleasedFeatures } from '../../../../util/releaseFeature'; +import { isSignInByLinking } from '../../../../util/storage'; import { GenericWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface'; import { NotEmptyArrayOfBatchResults } from '../../../apis/snode_api/SnodeRequestTypes'; import { getConversationController } from '../../../conversations'; import { SharedConfigMessage } from '../../../messages/outgoing/controlMessage/SharedConfigMessage'; import { MessageSender } from '../../../sending/MessageSender'; +import { allowOnlyOneAtATime } from '../../Promise'; import { LibSessionUtil, OutgoingConfResult } from '../../libsession/libsession_utils'; import { runners } from '../JobRunner'; import { @@ -17,9 +20,6 @@ import { PersistedJob, RunJobResult, } from '../PersistedJob'; -import { ReleasedFeatures } from '../../../../util/releaseFeature'; -import { allowOnlyOneAtATime } from '../../Promise'; -import { isSignInByLinking } from '../../../../util/storage'; const defaultMsBetweenRetries = 15000; // a long time between retries, to avoid running multiple jobs at the same time, when one was postponed at the same time as one already planned (5s) const defaultMaxAttempts = 2; diff --git a/ts/session/utils/libsession/libsession_utils.ts b/ts/session/utils/libsession/libsession_utils.ts index 0e6208df4..37855f438 100644 --- a/ts/session/utils/libsession/libsession_utils.ts +++ b/ts/session/utils/libsession/libsession_utils.ts @@ -36,6 +36,9 @@ export type OutgoingConfResult = { oldMessageHashes: Array; }; +/** + * Initializes the libsession wrappers for the required user variants if the dumps are not already in the database. It will use an empty dump if the dump is not found. + */ async function initializeLibSessionUtilWrappers() { const keypair = await UserUtils.getUserED25519KeyPairBytes(); if (!keypair || !keypair.privKeyBytes) { diff --git a/ts/state/onboarding/ducks/registration.ts b/ts/state/onboarding/ducks/registration.ts index 8ae2427a0..9c9fcc466 100644 --- a/ts/state/onboarding/ducks/registration.ts +++ b/ts/state/onboarding/ducks/registration.ts @@ -64,6 +64,7 @@ export const registrationSlice = createSlice({ initialState, reducers: { resetOnboardingState() { + window.log.debug(`WIP: [onboarding] resetOnboardingState() called`); return { ...initialState }; }, setRecoveryPassword(state, action: PayloadAction) {