Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small improvements - submit on enter pressed #114

Merged
merged 2 commits into from Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/basicComponents/SmInput.js
Expand Up @@ -46,6 +46,7 @@ const ErrorMsg = styled.div`

type Props = {
onChange?: ({ value: string }) => void,
onEnterPress?: () => void,
defaultValue?: string,
isDisabled?: boolean,
placeholder?: string,
Expand Down Expand Up @@ -75,6 +76,7 @@ class SmInput extends PureComponent<Props> {
hasError={errorMsg}
readOnly={isDisabled}
placeholder={placeholder || INPUT_PLACEHOLDER}
onKeyPress={this.onEnterPress}
onChange={this.onChange}
style={style}
type={type}
Expand All @@ -89,6 +91,13 @@ class SmInput extends PureComponent<Props> {
hasDebounce && clearTimeout(this.debounce);
}

onEnterPress = ({ key }: { key: string }) => {
const { onEnterPress } = this.props;
if (key === 'Enter' && !!onEnterPress) {
onEnterPress();
}
};

onChange = ({ target }: { target: { value: string } }) => {
const { hasDebounce, debounceTime, onChange } = this.props;
if (hasDebounce) {
Expand Down
27 changes: 21 additions & 6 deletions app/components/auth/CreateWallet.js
Expand Up @@ -10,6 +10,9 @@ import { smColors } from '/vars';
import type { Action } from '/types';
import { shell } from 'electron';

// TODO: For testing purposes, set to 1 minimum length. Should be changed back to 8 when ready.
const passwordMinimumLentgth = 1;

const Wrapper = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -122,9 +125,16 @@ class CreateWallet extends Component<Props, State> {
<Wrapper>
<UpperPart>
<UpperPartHeader>Encrypt your Wallet</UpperPartHeader>
<GrayText>Must be at least 8 characters</GrayText>
<SmInput type="password" placeholder="Type passphrase" errorMsg={passphraseError} onChange={this.handlePasswordTyping} hasDebounce />
<SmInput type="password" placeholder="Verify passphrase" errorMsg={verifyPassphraseError} onChange={this.handlePasswordVerifyTyping} hasDebounce />
<GrayText>{`Must be at least ${passwordMinimumLentgth} character${passwordMinimumLentgth > 1 ? 's' : ''}`}</GrayText>
<SmInput type="password" placeholder="Type passphrase" errorMsg={passphraseError} onEnterPress={this.handleEnterPress} onChange={this.handlePasswordTyping} hasDebounce />
<SmInput
type="password"
placeholder="Verify passphrase"
errorMsg={verifyPassphraseError}
onEnterPress={this.handleEnterPress}
onChange={this.handlePasswordVerifyTyping}
hasDebounce
/>
<GrayText>
Your Wallet file is encrypted and saved on your computer. <Link onClick={this.openWalletBackupDirectory}>Show me the file</Link>
</GrayText>
Expand Down Expand Up @@ -155,6 +165,13 @@ class CreateWallet extends Component<Props, State> {
);
};

handleEnterPress = () => {
const { passphrase, verifiedPassphrase, passphraseError, verifyPassphraseError } = this.state;
if (!!passphrase || !!verifiedPassphrase || !passphraseError || !verifyPassphraseError) {
this.createWallet();
}
};

handlePasswordTyping = ({ value }: { value: string }) => {
this.setState({ passphrase: value, passphraseError: null });
};
Expand All @@ -165,11 +182,9 @@ class CreateWallet extends Component<Props, State> {

validate = () => {
const { passphrase, verifiedPassphrase } = this.state;
// TODO: For testing purposes, set to 1 minimum length. Should be changed back to 8 when ready.
const passwordMinimumLentgth = 1;
const hasPassphraseError = !passphrase || (!!passphrase && passphrase.length < passwordMinimumLentgth);
const hasVerifyPassphraseError = !verifiedPassphrase || passphrase !== verifiedPassphrase;
const passphraseError = hasPassphraseError ? 'Passphrase has to be 8 characters or more.' : null;
const passphraseError = hasPassphraseError ? `Passphrase has to be ${passwordMinimumLentgth} characters or more.` : null;
const verifyPassphraseError = hasVerifyPassphraseError ? 'Passphrase does not match.' : null;
this.setState({ passphraseError, verifyPassphraseError });
return !passphraseError && !verifyPassphraseError;
Expand Down
11 changes: 9 additions & 2 deletions app/components/auth/UnlockWallet.js
Expand Up @@ -97,7 +97,7 @@ class UnlockWallet extends Component<Props, State> {
<Image src={welcomeBack} />
</ImageWrapper>
<UpperPartHeader>Enter your wallet passphrase</UpperPartHeader>
<SmInput type="password" placeholder="Type passphrase" errorMsg={errorMsg} onChange={this.handlePasswordTyping} />
<SmInput type="password" placeholder="Type passphrase" errorMsg={errorMsg} onEnterPress={this.handleEnterPress} onChange={this.handlePasswordTyping} />
</UpperPart>
<BottomPart>
<SmButton text="Unlock" isDisabled={!passphrase || !!errorMsg} theme="orange" onPress={this.decryptWallet} />
Expand All @@ -110,6 +110,13 @@ class UnlockWallet extends Component<Props, State> {
);
}

handleEnterPress = () => {
const { passphrase, errorMsg } = this.state;
if (!!passphrase || !errorMsg) {
this.decryptWallet();
}
};

handlePasswordTyping = ({ value }: { value: string }) => {
this.setState({ passphrase: value, errorMsg: null });
};
Expand All @@ -128,7 +135,7 @@ class UnlockWallet extends Component<Props, State> {
this.setState({ errorMsg: 'Passphrase Incorrect.' });
}
} else {
this.setState({ errorMsg: 'Passphrase cannot be less than 8 characters.' });
this.setState({ errorMsg: `Passphrase cannot be less than ${passwordMinimumLentgth} character${passwordMinimumLentgth > 1 ? 's' : ''}.` });
}
};
}
Expand Down
34 changes: 29 additions & 5 deletions app/components/settings/ChangePassphrase.js
Expand Up @@ -8,6 +8,9 @@ import { fileSystemService } from '/infra/fileSystemService';
import { smColors } from '/vars';
import type { Action, Account } from '/types';

// TODO: For testing purposes, set to 1 minimum length. Should be changed back to 8 when ready.
const passwordMinimumLentgth = 1;

const Wrapper = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -104,9 +107,23 @@ class ChangePassphrase extends Component<Props, State> {
<Wrapper>
<UpperPart>
<UpperPartHeader>Encrypt your Wallet</UpperPartHeader>
<GrayText>Must be at least 8 characters</GrayText>
<SmInput type="password" placeholder="Type passphrase" errorMsg={passphraseError} onChange={this.handlePassphraseTyping} hasDebounce />
<SmInput type="password" placeholder="Verify passphrase" errorMsg={verifyPassphraseError} onChange={this.handlePassphraseVerifyTyping} hasDebounce />
<GrayText>{`Must be at least ${passwordMinimumLentgth} character${passwordMinimumLentgth > 1 ? 's' : ''}`}</GrayText>
<SmInput
type="password"
placeholder="Type passphrase"
errorMsg={passphraseError}
onEnterPress={this.handleEnterPress}
onChange={this.handlePassphraseTyping}
hasDebounce
/>
<SmInput
type="password"
placeholder="Verify passphrase"
errorMsg={verifyPassphraseError}
onEnterPress={this.handleEnterPress}
onChange={this.handlePassphraseVerifyTyping}
hasDebounce
/>
<GrayText>
Your Wallet file is encrypted and saved on your computer. <Link onClick={this.openWalletBackupDirectory}>Show me the file</Link>
</GrayText>
Expand All @@ -118,6 +135,13 @@ class ChangePassphrase extends Component<Props, State> {
);
};

handleEnterPress = () => {
const { passphrase, verifiedPassphrase, passphraseError, verifyPassphraseError } = this.state;
if (!!passphrase || !!verifiedPassphrase || !passphraseError || !verifyPassphraseError) {
this.updatePassphrase();
}
};

handlePassphraseTyping = ({ value }: { value: string }) => {
this.setState({ passphrase: value, passphraseError: null });
};
Expand All @@ -128,9 +152,9 @@ class ChangePassphrase extends Component<Props, State> {

validate = () => {
const { passphrase, verifiedPassphrase } = this.state;
const hasPassphraseError = !passphrase || (!!passphrase && passphrase.length < 8);
const hasPassphraseError = !passphrase || (!!passphrase && passphrase.length < passwordMinimumLentgth);
const hasVerifyPassphraseError = !verifiedPassphrase || passphrase !== verifiedPassphrase;
const passphraseError = hasPassphraseError ? 'Passphrase has to be 8 characters or more.' : null;
const passphraseError = hasPassphraseError ? `Passphrase has to be ${passwordMinimumLentgth} characters or more.` : null;
const verifyPassphraseError = hasVerifyPassphraseError ? 'Passphrase does not match.' : null;
this.setState({ passphraseError, verifyPassphraseError });
return !passphraseError && !verifyPassphraseError;
Expand Down