Check for appropriate keystore file type on upload (#646)
* Check for appropriate keystore file type on upload. * Pass props to component. * Add typing for rawFile
This commit is contained in:
parent
ff9e4d7706
commit
97c32800e5
|
@ -1,6 +1,7 @@
|
||||||
import { isKeystorePassRequired } from 'libs/wallet';
|
import { isKeystorePassRequired } from 'libs/wallet';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import translate, { translateRaw } from 'translations';
|
import translate, { translateRaw } from 'translations';
|
||||||
|
import { TShowNotification } from 'actions/notifications';
|
||||||
|
|
||||||
export interface KeystoreValue {
|
export interface KeystoreValue {
|
||||||
file: string;
|
file: string;
|
||||||
|
@ -8,6 +9,13 @@ export interface KeystoreValue {
|
||||||
valid: boolean;
|
valid: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
value: KeystoreValue;
|
||||||
|
onChange(value: KeystoreValue): void;
|
||||||
|
onUnlock(): void;
|
||||||
|
showNotification(level: string, message: string): TShowNotification;
|
||||||
|
}
|
||||||
|
|
||||||
function isPassRequired(file: string): boolean {
|
function isPassRequired(file: string): boolean {
|
||||||
let passReq = false;
|
let passReq = false;
|
||||||
try {
|
try {
|
||||||
|
@ -18,13 +26,12 @@ function isPassRequired(file: string): boolean {
|
||||||
return passReq;
|
return passReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class KeystoreDecrypt extends Component {
|
function isValidFile(rawFile: File): boolean {
|
||||||
public props: {
|
const fileType = rawFile.type;
|
||||||
value: KeystoreValue;
|
return fileType === '' || fileType === 'application/json';
|
||||||
onChange(value: KeystoreValue): void;
|
}
|
||||||
onUnlock(): void;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
export default class KeystoreDecrypt extends Component<Props> {
|
||||||
public render() {
|
public render() {
|
||||||
const { file, password } = this.props.value;
|
const { file, password } = this.props.value;
|
||||||
const passReq = isPassRequired(file);
|
const passReq = isPassRequired(file);
|
||||||
|
@ -96,6 +103,10 @@ export default class KeystoreDecrypt extends Component {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
fileReader.readAsText(inputFile, 'utf-8');
|
if (isValidFile(inputFile)) {
|
||||||
|
fileReader.readAsText(inputFile, 'utf-8');
|
||||||
|
} else {
|
||||||
|
this.props.showNotification('danger', translateRaw('ERROR_3'));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import Help from 'components/ui/Help';
|
||||||
import { knowledgeBaseURL } from 'config/data';
|
import { knowledgeBaseURL } from 'config/data';
|
||||||
import NavigationPrompt from './NavigationPrompt';
|
import NavigationPrompt from './NavigationPrompt';
|
||||||
import { IWallet } from 'libs/wallet';
|
import { IWallet } from 'libs/wallet';
|
||||||
|
import { showNotification, TShowNotification } from 'actions/notifications';
|
||||||
|
|
||||||
type UnlockParams = {} | PrivateKeyValue;
|
type UnlockParams = {} | PrivateKeyValue;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ interface Props {
|
||||||
setWallet: TSetWallet;
|
setWallet: TSetWallet;
|
||||||
unlockWeb3: TUnlockWeb3;
|
unlockWeb3: TUnlockWeb3;
|
||||||
resetWallet: TResetWallet;
|
resetWallet: TResetWallet;
|
||||||
|
showNotification: TShowNotification;
|
||||||
wallet: IWallet;
|
wallet: IWallet;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
offline: boolean;
|
offline: boolean;
|
||||||
|
@ -125,7 +127,12 @@ export class WalletDecrypt extends Component<Props, State> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<selectedWallet.component value={value} onChange={this.onChange} onUnlock={this.onUnlock} />
|
<selectedWallet.component
|
||||||
|
value={value}
|
||||||
|
onChange={this.onChange}
|
||||||
|
onUnlock={this.onUnlock}
|
||||||
|
showNotification={this.props.showNotification}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,5 +253,6 @@ export default connect(mapStateToProps, {
|
||||||
unlockWeb3,
|
unlockWeb3,
|
||||||
setWallet,
|
setWallet,
|
||||||
resetWallet,
|
resetWallet,
|
||||||
resetTransactionState: reset
|
resetTransactionState: reset,
|
||||||
|
showNotification
|
||||||
})(WalletDecrypt);
|
})(WalletDecrypt);
|
||||||
|
|
Loading…
Reference in New Issue