From 9ad89704e5c999046a44589c6f18e0ee7650d66b Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 30 Apr 2019 18:18:36 +0200 Subject: [PATCH] Old json checksum & imports (#1055) * Old json checksum & imports * Set address null on chage of file * Organise imports --- packages/app-accounts/src/Restore.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/app-accounts/src/Restore.tsx b/packages/app-accounts/src/Restore.tsx index 3b967de2da..b920b25891 100644 --- a/packages/app-accounts/src/Restore.tsx +++ b/packages/app-accounts/src/Restore.tsx @@ -4,6 +4,7 @@ import { KeyringPair$Json } from '@polkadot/keyring/types'; import { I18nProps } from '@polkadot/ui-app/types'; +import { ActionStatus } from '@polkadot/ui-app/Status/types'; import { ComponentProps } from './types'; import React from 'react'; @@ -13,11 +14,11 @@ import { isHex, isObject, u8aToString } from '@polkadot/util'; import keyring from '@polkadot/ui-keyring'; import translate from './translate'; -import { ActionStatus } from '@polkadot/ui-app/Status/types'; type Props = ComponentProps & I18nProps; type State = { + address: string | null, isFileValid: boolean, isPassValid: boolean, json: KeyringPair$Json | null, @@ -26,6 +27,7 @@ type State = { class Restore extends React.PureComponent { state: State = { + address: null, isFileValid: false, isPassValid: false, json: null, @@ -34,7 +36,7 @@ class Restore extends React.PureComponent { render () { const { t } = this.props; - const { isFileValid, isPassValid, json } = this.state; + const { address, isFileValid, isPassValid } = this.state; return (
@@ -42,8 +44,8 @@ class Restore extends React.PureComponent { @@ -97,18 +99,22 @@ class Restore extends React.PureComponent { private onChangeFile = (file: Uint8Array): void => { try { const json = JSON.parse(u8aToString(file)); - const isFileValid = keyring.decodeAddress(json.address).length === 32 && isHex(json.encoded) && isObject(json.meta) && ( + const publicKey = keyring.decodeAddress(json.address, true); + const address = keyring.encodeAddress(publicKey); + const isFileValid = publicKey.length === 32 && isHex(json.encoded) && isObject(json.meta) && ( Array.isArray(json.encoding.content) ? json.encoding.content[0] === 'pkcs8' : json.encoding.content === 'pkcs8' ); this.setState({ + address, isFileValid, json }); } catch (error) { this.setState({ + address: null, isFileValid: false, json: null });