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 = { public state: State = {
selectedWalletKey: null, selectedWalletKey: null,
value: null, value: {
key: '',
password: '',
valid: false,
attemptEmptyPass: false
},
hasAcknowledgedInsecure: 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 // some components (TrezorDecrypt) don't take an onChange prop, and thus
// this.state.value will remain unpopulated. in this case, we can expect // this.state.value will remain unpopulated. in this case, we can expect
// the payload to contain the unlocked wallet info. // 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.WALLETS[selectedWalletKey].unlock(unlockValue);
this.props.resetTransactionState(); this.props.resetTransactionState();
}; };

View File

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

View File

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