From 0eaa471c42f52183101ce1012b9e6a191854137d Mon Sep 17 00:00:00 2001 From: William Prado Date: Wed, 20 Dec 2017 12:27:59 -0500 Subject: [PATCH 1/3] Check for appropriate keystore file type on upload. --- common/components/WalletDecrypt/Keystore.tsx | 13 ++++++++++++- common/components/WalletDecrypt/index.tsx | 12 ++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/common/components/WalletDecrypt/Keystore.tsx b/common/components/WalletDecrypt/Keystore.tsx index bb42ace5d0b..13abbf2e0c4 100644 --- a/common/components/WalletDecrypt/Keystore.tsx +++ b/common/components/WalletDecrypt/Keystore.tsx @@ -1,6 +1,7 @@ import { isKeystorePassRequired } from 'libs/wallet'; import React, { Component } from 'react'; import translate, { translateRaw } from 'translations'; +import { TShowNotification } from 'actions/notifications'; export interface KeystoreValue { file: string; @@ -18,11 +19,17 @@ function isPassRequired(file: string): boolean { return passReq; } +function isValidFile(rawFile: any): boolean { + const fileType = rawFile.type; + return fileType === '' || fileType === 'application/json'; +} + export default class KeystoreDecrypt extends Component { public props: { value: KeystoreValue; onChange(value: KeystoreValue): void; onUnlock(): void; + showNotification(level: string, message: string): TShowNotification; }; public render() { @@ -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')); + } }; } diff --git a/common/components/WalletDecrypt/index.tsx b/common/components/WalletDecrypt/index.tsx index 0918a3da2b3..392b9396399 100644 --- a/common/components/WalletDecrypt/index.tsx +++ b/common/components/WalletDecrypt/index.tsx @@ -30,6 +30,7 @@ import Help from 'components/ui/Help'; import { knowledgeBaseURL } from 'config/data'; import NavigationPrompt from './NavigationPrompt'; import { IWallet } from 'libs/wallet'; +import { showNotification, TShowNotification } from 'actions/notifications'; type UnlockParams = {} | PrivateKeyValue; @@ -41,6 +42,7 @@ interface Props { setWallet: TSetWallet; unlockWeb3: TUnlockWeb3; resetWallet: TResetWallet; + showNotification: TShowNotification; wallet: IWallet; hidden?: boolean; offline: boolean; @@ -124,7 +126,12 @@ export class WalletDecrypt extends Component { return null; } return ( - + ); } @@ -237,5 +244,6 @@ export default connect(mapStateToProps, { unlockWeb3, setWallet, resetWallet, - resetTransactionState: reset + resetTransactionState: reset, + showNotification })(WalletDecrypt); From 873bb55a08e7971a1642e709c80b426793fdfc61 Mon Sep 17 00:00:00 2001 From: William Prado Date: Wed, 20 Dec 2017 15:15:31 -0500 Subject: [PATCH 2/3] Pass props to component. --- common/components/WalletDecrypt/Keystore.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/components/WalletDecrypt/Keystore.tsx b/common/components/WalletDecrypt/Keystore.tsx index 13abbf2e0c4..ddb1a14b866 100644 --- a/common/components/WalletDecrypt/Keystore.tsx +++ b/common/components/WalletDecrypt/Keystore.tsx @@ -9,6 +9,13 @@ export interface KeystoreValue { valid: boolean; } +interface Props { + value: KeystoreValue; + onChange(value: KeystoreValue): void; + onUnlock(): void; + showNotification(level: string, message: string): TShowNotification; +} + function isPassRequired(file: string): boolean { let passReq = false; try { @@ -24,14 +31,7 @@ function isValidFile(rawFile: any): boolean { return fileType === '' || fileType === 'application/json'; } -export default class KeystoreDecrypt extends Component { - public props: { - value: KeystoreValue; - onChange(value: KeystoreValue): void; - onUnlock(): void; - showNotification(level: string, message: string): TShowNotification; - }; - +export default class KeystoreDecrypt extends Component { public render() { const { file, password } = this.props.value; const passReq = isPassRequired(file); From c7425d9154732967bb30c6639f7668a080a4f37e Mon Sep 17 00:00:00 2001 From: William Prado Date: Wed, 20 Dec 2017 18:59:28 -0500 Subject: [PATCH 3/3] Add typing for rawFile --- common/components/WalletDecrypt/Keystore.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/components/WalletDecrypt/Keystore.tsx b/common/components/WalletDecrypt/Keystore.tsx index ddb1a14b866..8b414dea674 100644 --- a/common/components/WalletDecrypt/Keystore.tsx +++ b/common/components/WalletDecrypt/Keystore.tsx @@ -26,7 +26,7 @@ function isPassRequired(file: string): boolean { return passReq; } -function isValidFile(rawFile: any): boolean { +function isValidFile(rawFile: File): boolean { const fileType = rawFile.type; return fileType === '' || fileType === 'application/json'; }