|
|
|
@ -1,17 +1,22 @@
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
import { SettingsKey } from '../../../data/settings-key';
|
|
|
|
|
import { ToastUtils } from '../../../session/utils';
|
|
|
|
|
import { sanitizeSessionUsername } from '../../../session/utils/String';
|
|
|
|
|
import { trigger } from '../../../shims/events';
|
|
|
|
|
import { AccountCreation } from '../../../state/onboarding/ducks/registration';
|
|
|
|
|
import {
|
|
|
|
|
useOnboardAccountCreationStep,
|
|
|
|
|
useOnboardGeneratedRecoveryPhrase,
|
|
|
|
|
useOnboardHexGeneratedPubKey,
|
|
|
|
|
} from '../../../state/onboarding/selectors/registration';
|
|
|
|
|
import { registerSingleDevice } from '../../../util/accountManager';
|
|
|
|
|
import { Storage, setSignWithRecoveryPhrase } from '../../../util/storage';
|
|
|
|
|
import { Flex } from '../../basic/Flex';
|
|
|
|
|
import { SessionButton, SessionButtonColor } from '../../basic/SessionButton';
|
|
|
|
|
import { SpacerLG, SpacerSM } from '../../basic/Text';
|
|
|
|
|
import { SessionInput } from '../../inputs';
|
|
|
|
|
import { signUp } from '../RegistrationStages';
|
|
|
|
|
import { resetRegistration } from '../RegistrationStages';
|
|
|
|
|
import { BackButtonWithininContainer } from '../components/BackButton';
|
|
|
|
|
|
|
|
|
|
const StyledContainer = styled.div`
|
|
|
|
@ -45,6 +50,46 @@ function sanitizeDisplayNameOrToast(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns undefined if an error happened, or the trim userName.
|
|
|
|
|
*
|
|
|
|
|
* Be sure to use the trimmed userName for creating the account.
|
|
|
|
|
*/
|
|
|
|
|
export const displayNameIsValid = (displayName: string): undefined | string => {
|
|
|
|
|
const trimName = displayName.trim();
|
|
|
|
|
|
|
|
|
|
if (!trimName) {
|
|
|
|
|
window?.log?.warn('invalid trimmed name for registration');
|
|
|
|
|
ToastUtils.pushToastError('invalidDisplayName', window.i18n('displayNameEmpty'));
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
return trimName;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function signUp(signUpDetails: { displayName: string; generatedRecoveryPhrase: string }) {
|
|
|
|
|
const { displayName, generatedRecoveryPhrase } = signUpDetails;
|
|
|
|
|
window?.log?.info('SIGNING UP');
|
|
|
|
|
|
|
|
|
|
const trimName = displayNameIsValid(displayName);
|
|
|
|
|
// shows toast to user about the error
|
|
|
|
|
if (!trimName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await resetRegistration();
|
|
|
|
|
await registerSingleDevice(generatedRecoveryPhrase, 'english', trimName);
|
|
|
|
|
await Storage.put(SettingsKey.hasSyncedInitialConfigurationItem, Date.now());
|
|
|
|
|
await setSignWithRecoveryPhrase(false);
|
|
|
|
|
trigger('openInbox');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
await resetRegistration();
|
|
|
|
|
|
|
|
|
|
ToastUtils.pushToastError('registrationError', `Error: ${e.message || 'Something went wrong'}`);
|
|
|
|
|
window?.log?.warn('exception during registration:', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const CreateAccount = () => {
|
|
|
|
|
const step = useOnboardAccountCreationStep();
|
|
|
|
|
const generatedRecoveryPhrase = useOnboardGeneratedRecoveryPhrase();
|
|
|
|
|