From 818dfb2498ca1df1e71cf3efca066833068627b5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 26 Sep 2018 20:24:43 +0200 Subject: [PATCH] Account backup & restore functionality (#333) * Account JSON backup & restore * import isObject from correct package * Fix isLocked logic * Add "or" --- packages/app-accounts/package.json | 4 +- packages/app-accounts/src/Backup.tsx | 150 ++++++++++++++++++ packages/app-accounts/src/Editor.tsx | 32 +++- packages/app-accounts/src/Restore.tsx | 168 +++++++++++++++++++++ packages/app-accounts/src/index.tsx | 10 +- packages/ui-app/src/AddressSummary.tsx | 8 +- packages/ui-app/src/InputFile.tsx | 104 +++++++++++++ packages/ui-app/src/Params/Param/File.tsx | 96 ++---------- packages/ui-app/src/Params/Params.css | 25 --- packages/ui-app/src/styles/components.css | 30 +++- packages/ui-keyring/src/account/addPair.ts | 16 ++ packages/ui-keyring/src/index.ts | 5 + packages/ui-keyring/src/types.d.ts | 1 + yarn.lock | 8 + 14 files changed, 543 insertions(+), 114 deletions(-) create mode 100644 packages/app-accounts/src/Backup.tsx create mode 100644 packages/app-accounts/src/Restore.tsx create mode 100644 packages/ui-app/src/InputFile.tsx create mode 100644 packages/ui-keyring/src/account/addPair.ts diff --git a/packages/app-accounts/package.json b/packages/app-accounts/package.json index 662e5b4730..431d7b12bd 100644 --- a/packages/app-accounts/package.json +++ b/packages/app-accounts/package.json @@ -11,6 +11,8 @@ "license": "ISC", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/ui-app": "^0.20.19" + "@polkadot/ui-app": "^0.20.19", + "@types/file-saver": "^1.3.0", + "file-saver": "^1.3.8" } } diff --git a/packages/app-accounts/src/Backup.tsx b/packages/app-accounts/src/Backup.tsx new file mode 100644 index 0000000000..e9ed3bc281 --- /dev/null +++ b/packages/app-accounts/src/Backup.tsx @@ -0,0 +1,150 @@ +// Copyright 2017-2018 @polkadot/app-accounts authors & contributors +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. + +import { KeyringPair } from '@polkadot/util-keyring/types'; +import { I18nProps } from '@polkadot/ui-app/types'; + +import FileSaver from 'file-saver'; +import React from 'react'; +import Button from '@polkadot/ui-app/Button'; +import Modal from '@polkadot/ui-app/Modal'; +import Password from '@polkadot/ui-app/Password'; +import AddressSummary from '@polkadot/ui-app/AddressSummary'; + +import translate from './translate'; + +type Props = I18nProps & { + onClose: () => void, + pair: KeyringPair +}; + +type State = { + isPassValid: boolean, + password: string +}; + +class Backup extends React.PureComponent { + state: State; + + constructor (props: Props) { + super(props); + + this.state = { + isPassValid: false, + password: '' + }; + } + + render () { + return ( + + {this.renderContent()} + {this.renderButtons()} + + ); + } + + renderButtons () { + const { onClose, t } = this.props; + const { isPassValid } = this.state; + + return ( + + +