diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2018-03-12 22:50:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-12 22:50:55 +0800 |
commit | b7c7083a112ea6908e8c5990886ab388200a51f4 (patch) | |
tree | bf7e0f880b5a3ce32cd0b0e680f62e0f5068df8d /ui/app/accounts | |
parent | 174f57b4646b3d320850c6286189a146cf0e23b0 (diff) | |
parent | ddc85354d3df508cbecc016fc0213a6560d885e1 (diff) | |
download | tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.gz tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.bz2 tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.lz tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.xz tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.tar.zst tangerine-wallet-browser-b7c7083a112ea6908e8c5990886ab388200a51f4.zip |
Merge branch 'master' into i18n
Diffstat (limited to 'ui/app/accounts')
-rw-r--r-- | ui/app/accounts/import/json.js | 180 |
1 files changed, 102 insertions, 78 deletions
diff --git a/ui/app/accounts/import/json.js b/ui/app/accounts/import/json.js index 791759666..93c7afdb9 100644 --- a/ui/app/accounts/import/json.js +++ b/ui/app/accounts/import/json.js @@ -1,5 +1,5 @@ -const inherits = require('util').inherits const Component = require('react').Component +const PropTypes = require('prop-types') const h = require('react-hyperscript') const connect = require('react-redux').connect const actions = require('../../actions') @@ -8,100 +8,124 @@ const t = require('../../../i18n') const HELP_LINK = 'https://support.metamask.io/kb/article/7-importing-accounts' -module.exports = connect(mapStateToProps)(JsonImportSubview) +class JsonImportSubview extends Component { + constructor (props) { + super(props) -function mapStateToProps (state) { - return { - error: state.appState.warning, + this.state = { + file: null, + fileContents: '', + } } -} -inherits(JsonImportSubview, Component) -function JsonImportSubview () { - Component.call(this) -} + render () { + const { error } = this.props + + return ( + h('div.new-account-import-form__json', [ + + h('p', 'Used by a variety of different clients'), + h('a.warning', { + href: HELP_LINK, + target: '_blank', + }, 'File import not working? Click here!'), + + h(FileInput, { + readAs: 'text', + onLoad: this.onLoad.bind(this), + style: { + margin: '20px 0px 12px 34%', + fontSize: '15px', + display: 'flex', + justifyContent: 'center', + }, + }), + + h('input.new-account-import-form__input-password', { + type: 'password', + placeholder: 'Enter password', + id: 'json-password-box', + onKeyPress: this.createKeyringOnEnter.bind(this), + }), + + h('div.new-account-create-form__buttons', {}, [ + + h('button.new-account-create-form__button-cancel', { + onClick: () => this.props.goHome(), + }, [ + 'CANCEL', + ]), + + h('button.new-account-create-form__button-create', { + onClick: () => this.createNewKeychain(), + }, [ + 'IMPORT', + ]), -JsonImportSubview.prototype.render = function () { - const { error } = this.props - - return ( - h('div.new-account-import-form__json', [ - - h('p', t('usedByClients')), - h('a.warning', { href: HELP_LINK, target: '_blank' }, t('fileImportFail')), - - h(FileInput, { - readAs: 'text', - onLoad: this.onLoad.bind(this), - style: { - margin: '20px 0px 12px 34%', - fontSize: '15px', - display: 'flex', - justifyContent: 'center', - }, - }), - - h('input.new-account-import-form__input-password', { - type: 'password', - placeholder: t('enterPassword'), - id: 'json-password-box', - onKeyPress: this.createKeyringOnEnter.bind(this), - }), - - h('div.new-account-create-form__buttons', {}, [ - - h('button.new-account-create-form__button-cancel.allcaps', { - onClick: () => this.props.goHome(), - }, [ - t('cancel'), ]), - h('button.new-account-create-form__button-create.allcaps', { - onClick: () => this.createNewKeychain.bind(this), - }, [ - t('import'), - ]), + error ? h('span.error', error) : null, + ]) + ) + } - ]), + onLoad (event, file) { + this.setState({file: file, fileContents: event.target.result}) + } - error ? h('span.error', error) : null, - ]) - ) -} + createKeyringOnEnter (event) { + if (event.key === 'Enter') { + event.preventDefault() + this.createNewKeychain() + } + } -JsonImportSubview.prototype.onLoad = function (event, file) { - this.setState({file: file, fileContents: event.target.result}) -} + createNewKeychain () { + const state = this.state -JsonImportSubview.prototype.createKeyringOnEnter = function (event) { - if (event.key === 'Enter') { - event.preventDefault() - this.createNewKeychain() - } -} + if (!state) { + const message = 'You must select a valid file to import.' + return this.props.displayWarning(message) + } -JsonImportSubview.prototype.createNewKeychain = function () { - const state = this.state + const { fileContents } = state - if (!state) { - const message = 'You must select a valid file to import.' - return this.props.dispatch(actions.displayWarning(message)) - } + if (!fileContents) { + const message = 'You must select a file to import.' + return this.props.displayWarning(message) + } - const { fileContents } = state + const passwordInput = document.getElementById('json-password-box') + const password = passwordInput.value - if (!fileContents) { - const message = t('needImportFile') - return this.props.dispatch(actions.displayWarning(message)) + if (!password) { + const message = 'You must enter a password for the selected file.' + return this.props.displayWarning(message) + } + + this.props.importNewJsonAccount([ fileContents, password ]) } +} - const passwordInput = document.getElementById('json-password-box') - const password = passwordInput.value +JsonImportSubview.propTypes = { + error: PropTypes.string, + goHome: PropTypes.func, + displayWarning: PropTypes.func, + importNewJsonAccount: PropTypes.func, +} - if (!password) { - const message = t('needImportPassword') - return this.props.dispatch(actions.displayWarning(message)) +const mapStateToProps = state => { + return { + error: state.appState.warning, } +} - this.props.dispatch(actions.importNewAccount('JSON File', [ fileContents, password ])) +const mapDispatchToProps = dispatch => { + return { + goHome: () => dispatch(actions.goHome()), + displayWarning: warning => dispatch(actions.displayWarning(warning)), + importNewJsonAccount: options => dispatch(actions.importNewAccount('JSON File', options)), + } } + +module.exports = connect(mapStateToProps, mapDispatchToProps)(JsonImportSubview) |