handle Enter Key on the signin tab

pull/1528/head
Audric Ackermann 4 years ago
parent c420bfcf74
commit e930348684

@ -136,6 +136,25 @@ export const SignInTab = () => {
const activateContinueButton = const activateContinueButton =
seedOK && displayNameOK && passwordsOK && !loading; seedOK && displayNameOK && passwordsOK && !loading;
const continueYourSession = async () => {
if (isRecovery) {
await signInWithRecovery({
displayName,
userRecoveryPhrase: recoveryPhrase,
password,
verifyPassword: passwordVerify,
});
} else if (isLinking) {
setIsLoading(true);
await signInWithLinking({
userRecoveryPhrase: recoveryPhrase,
password,
verifyPassword: passwordVerify,
});
setIsLoading(false);
}
};
return ( return (
<div className="session-registration__content"> <div className="session-registration__content">
{signInMode !== SignInMode.Default && ( {signInMode !== SignInMode.Default && (
@ -143,9 +162,7 @@ export const SignInTab = () => {
showDisplayNameField={showDisplayNameField} showDisplayNameField={showDisplayNameField}
showSeedField={true} showSeedField={true}
displayName={displayName} displayName={displayName}
handlePressEnter={() => { handlePressEnter={continueYourSession}
throw new Error('TODO');
}}
onDisplayNameChanged={(name: string) => { onDisplayNameChanged={(name: string) => {
const sanitizedName = name.replace(window.displayNameRegex, ''); const sanitizedName = name.replace(window.displayNameRegex, '');
const trimName = sanitizedName.trim(); const trimName = sanitizedName.trim();
@ -156,6 +173,13 @@ export const SignInTab = () => {
}} }}
onPasswordChanged={(val: string) => { onPasswordChanged={(val: string) => {
setPassword(val); setPassword(val);
// if user just removed the password, empty the verify too
if (!val) {
setPasswordVerify('');
setPasswordErrorString('');
setPasswordFieldsMatch(true);
return;
}
const errors = validatePassword(val, passwordVerify); const errors = validatePassword(val, passwordVerify);
setPasswordErrorString(errors.passwordErrorString); setPasswordErrorString(errors.passwordErrorString);
setPasswordFieldsMatch(errors.passwordFieldsMatch); setPasswordFieldsMatch(errors.passwordFieldsMatch);
@ -197,24 +221,7 @@ export const SignInTab = () => {
/> />
<SignInContinueButton <SignInContinueButton
signInMode={signInMode} signInMode={signInMode}
handleContinueYourSessionClick={async () => { handleContinueYourSessionClick={continueYourSession}
if (isRecovery) {
await signInWithRecovery({
displayName,
userRecoveryPhrase: recoveryPhrase,
password,
verifyPassword: passwordVerify,
});
} else if (isLinking) {
setIsLoading(true);
await signInWithLinking({
userRecoveryPhrase: recoveryPhrase,
password,
verifyPassword: passwordVerify,
});
setIsLoading(false);
}
}}
disabled={!activateContinueButton} disabled={!activateContinueButton}
/> />
<Flex container={true} justifyContent="center"> <Flex container={true} justifyContent="center">

@ -116,7 +116,14 @@ export const SignUpTab = (props: Props) => {
!password || (!passwordErrorString && passwordFieldsMatch); !password || (!passwordErrorString && passwordFieldsMatch);
const enableCompleteSignUp = displayNameOK && passwordsOK; const enableCompleteSignUp = displayNameOK && passwordsOK;
console.warn('handlePressEnter TODO'); const signUpWithDetails = async () => {
await signUp({
displayName,
generatedRecoveryPhrase: props.generatedRecoveryPhrase,
password,
verifyPassword: passwordVerify,
});
};
return ( return (
<div className="session-registration__content"> <div className="session-registration__content">
@ -128,9 +135,7 @@ export const SignUpTab = (props: Props) => {
showDisplayNameField={true} showDisplayNameField={true}
showSeedField={false} showSeedField={false}
displayName={displayName} displayName={displayName}
handlePressEnter={() => { handlePressEnter={signUpWithDetails}
throw new Error('TODO');
}}
onDisplayNameChanged={(name: string) => { onDisplayNameChanged={(name: string) => {
const sanitizedName = name.replace(window.displayNameRegex, ''); const sanitizedName = name.replace(window.displayNameRegex, '');
const trimName = sanitizedName.trim(); const trimName = sanitizedName.trim();
@ -142,9 +147,9 @@ export const SignUpTab = (props: Props) => {
onPasswordChanged={(val: string) => { onPasswordChanged={(val: string) => {
setPassword(val); setPassword(val);
if (!val) { if (!val) {
setPasswordVerify('');
setPasswordErrorString(''); setPasswordErrorString('');
setPasswordFieldsMatch(true); setPasswordFieldsMatch(true);
setPasswordVerify('');
return; return;
} }
const errors = validatePassword(val, passwordVerify); const errors = validatePassword(val, passwordVerify);
@ -163,14 +168,7 @@ export const SignUpTab = (props: Props) => {
stealAutoFocus={true} stealAutoFocus={true}
/> />
<SessionButton <SessionButton
onClick={async () => { onClick={signUpWithDetails}
await signUp({
displayName,
generatedRecoveryPhrase: props.generatedRecoveryPhrase,
password,
verifyPassword: passwordVerify,
});
}}
buttonType={SessionButtonType.Brand} buttonType={SessionButtonType.Brand}
buttonColor={SessionButtonColor.Green} buttonColor={SessionButtonColor.Green}
text={window.i18n('getStarted')} text={window.i18n('getStarted')}

Loading…
Cancel
Save