feat: reset onboarding state when we return to the start stage

added better logging for create account flow
pull/3056/head
William Grant 1 year ago
parent 76b7c2192f
commit 8dceb93b09

@ -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 (
<AnimatePresence>
<StyledRegistrationContainer container={true} flexDirection="column">

@ -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));
}

@ -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.

@ -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 (
<>
<SessionButton

@ -1,5 +1,17 @@
import { AnyAction, Dispatch } from '@reduxjs/toolkit';
import { Data } from 'emoji-mart';
import { getConversationController } from '../../../session/conversations';
import { sanitizeSessionUsername } from '../../../session/utils/String';
import { Storage } from '../../../util/storage';
export async function resetRegistration() {
await Data.removeAll();
Storage.reset();
await Storage.fetch();
getConversationController().reset();
await getConversationController().load();
// TODO[epic=ses-899] onboarding reset here?
}
export function sanitizeDisplayNameOrToast(
displayName: string,

@ -285,7 +285,7 @@ async function start() {
window.log.info('listening for registration events');
WhisperEvents.on('registration_done', () => {
window.log.info('handling registration event');
window.log.info('WIP: [onboarding] handling registration event');
void connect();
});

@ -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;

@ -36,6 +36,9 @@ export type OutgoingConfResult = {
oldMessageHashes: Array<string>;
};
/**
* 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) {

@ -64,6 +64,7 @@ export const registrationSlice = createSlice({
initialState,
reducers: {
resetOnboardingState() {
window.log.debug(`WIP: [onboarding] resetOnboardingState() called`);
return { ...initialState };
},
setRecoveryPassword(state, action: PayloadAction<string>) {

Loading…
Cancel
Save