attempt empty pass without replacing input value

This commit is contained in:
james-prado 2018-02-05 10:59:28 -05:00
parent 174dea8a29
commit 6a72d3ada9
No known key found for this signature in database
GPG Key ID: 313ACB2286229FD0
3 changed files with 49 additions and 32 deletions

View File

@ -203,7 +203,12 @@ export class WalletDecrypt extends Component<Props, State> {
public state: State = {
selectedWalletKey: null,
value: null,
value: {
key: '',
password: '',
valid: false,
attemptEmptyPass: false
},
hasAcknowledgedInsecure: false
};
@ -424,7 +429,11 @@ export class WalletDecrypt extends Component<Props, State> {
// some components (TrezorDecrypt) don't take an onChange prop, and thus
// this.state.value will remain unpopulated. in this case, we can expect
// the payload to contain the unlocked wallet info.
const unlockValue = value && !isEmpty(value) ? value : payload;
const unlockValue =
value && !isEmpty(value)
? (value as PrivateKeyValue).attemptEmptyPass ? { ...value, password: '' } : value
: payload;
console.log(unlockValue);
this.WALLETS[selectedWalletKey].unlock(unlockValue);
this.props.resetTransactionState();
};

View File

@ -8,6 +8,7 @@ export interface KeystoreValue {
file: string;
password: string;
valid: boolean;
attemptEmptyPass: boolean;
}
function isPassRequired(file: string): boolean {
@ -29,48 +30,49 @@ export class KeystoreDecrypt extends PureComponent {
public props: {
value: KeystoreValue;
isWalletPending: boolean;
isPasswordPending: boolean;
onChange(value: KeystoreValue): void;
onUnlock(): void;
showNotification(level: string, message: string): TShowNotification;
};
public render() {
const { isWalletPending, isPasswordPending, value: { file, password } } = this.props;
const { isWalletPending, value: { file, password } } = this.props;
const passReq = isPassRequired(file);
const unlockDisabled = !file || (passReq && !password);
return (
<form id="selectedUploadKey" onSubmit={this.unlock}>
<div className="form-group">
<input
className={'hidden'}
type="file"
id="fselector"
onChange={this.handleFileSelection}
/>
<label htmlFor="fselector" style={{ width: '100%' }}>
<a className="btn btn-default btn-block" id="aria1" tabIndex={0} role="button">
{translate('ADD_Radio_2_short')}
</a>
</label>
{isWalletPending ? <Spinner /> : ''}
<div className={file.length && isPasswordPending ? '' : 'hidden'}>
<p>{translate('ADD_Label_3')}</p>
{isWalletPending ? (
<Spinner size="x2" />
) : (
<div className="form-group">
<input
className={`form-control ${password.length > 0 ? 'is-valid' : 'is-invalid'}`}
value={password}
onChange={this.onPasswordChange}
onKeyDown={this.onKeyDown}
placeholder={translateRaw('x_Password')}
type="password"
className={'hidden'}
type="file"
id="fselector"
onChange={this.handleFileSelection}
/>
<label htmlFor="fselector" style={{ width: '100%', marginBottom: '0.5rem' }}>
<a className="btn btn-default btn-block" id="aria1" tabIndex={0} role="button">
{translate('ADD_Radio_2_short')}
</a>
</label>
<div className={file.length ? '' : 'hidden'}>
<p>{translate('ADD_Label_3')}</p>
<input
className={`form-control ${password.length > 0 ? 'is-valid' : 'is-invalid'}`}
value={password}
onChange={this.onPasswordChange}
onKeyDown={this.onKeyDown}
placeholder={translateRaw('x_Password')}
type="password"
/>
</div>
<button className="btn btn-primary btn-block" disabled={unlockDisabled}>
{translate('ADD_Label_6_short')}
</button>
</div>
</div>
<button className="btn btn-primary btn-block" disabled={unlockDisabled}>
{translate('ADD_Label_6_short')}
</button>
)}
</form>
);
}
@ -84,6 +86,10 @@ export class KeystoreDecrypt extends PureComponent {
private unlock = (e: React.SyntheticEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
this.props.onChange({
...this.props.value,
attemptEmptyPass: false
});
this.props.onUnlock();
};
@ -92,7 +98,8 @@ export class KeystoreDecrypt extends PureComponent {
this.props.onChange({
...this.props.value,
password: e.target.value,
valid
valid,
attemptEmptyPass: false
});
};
@ -109,7 +116,7 @@ export class KeystoreDecrypt extends PureComponent {
...this.props.value,
file: keystore,
valid: keystore.length && !passReq,
password: ''
attemptEmptyPass: true
});
this.props.onUnlock();
};

View File

@ -8,6 +8,7 @@ export interface PrivateKeyValue {
key: string;
password: string;
valid: boolean;
attemptEmptyPass: boolean;
}
interface Validated {