|
|
|
@ -14,10 +14,14 @@ const HELP_LINK = 'https://metamask.zendesk.com/hc/en-us/articles/360015489331-I |
|
|
|
|
class JsonImportSubview extends Component { |
|
|
|
|
state = { |
|
|
|
|
fileContents: '', |
|
|
|
|
isEmpty: true, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inputRef = React.createRef() |
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
|
const { error } = this.props |
|
|
|
|
const enabled = !this.state.isEmpty && this.state.fileContents !== '' |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div className="new-account-import-form__json"> |
|
|
|
@ -40,6 +44,8 @@ class JsonImportSubview extends Component { |
|
|
|
|
placeholder={this.context.t('enterPassword')} |
|
|
|
|
id="json-password-box" |
|
|
|
|
onKeyPress={this.createKeyringOnEnter.bind(this)} |
|
|
|
|
onChange={() => this.checkInputEmpty()} |
|
|
|
|
ref={this.inputRef} |
|
|
|
|
/> |
|
|
|
|
<div className="new-account-create-form__buttons"> |
|
|
|
|
<Button |
|
|
|
@ -55,6 +61,7 @@ class JsonImportSubview extends Component { |
|
|
|
|
large |
|
|
|
|
className="new-account-create-form__button" |
|
|
|
|
onClick={() => this.createNewKeychain()} |
|
|
|
|
disabled={!enabled} |
|
|
|
|
> |
|
|
|
|
{this.context.t('import')} |
|
|
|
|
</Button> |
|
|
|
@ -90,8 +97,7 @@ class JsonImportSubview extends Component { |
|
|
|
|
return displayWarning(message) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const passwordInput = document.getElementById('json-password-box') |
|
|
|
|
const password = passwordInput.value |
|
|
|
|
const password = this.inputRef.current.value |
|
|
|
|
|
|
|
|
|
importNewJsonAccount([ fileContents, password ]) |
|
|
|
|
.then(({ selectedAddress }) => { |
|
|
|
@ -119,6 +125,15 @@ class JsonImportSubview extends Component { |
|
|
|
|
}) |
|
|
|
|
.catch(err => err && displayWarning(err.message || err)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
checkInputEmpty () { |
|
|
|
|
const password = this.inputRef.current.value |
|
|
|
|
let isEmpty = true |
|
|
|
|
if (password !== '') { |
|
|
|
|
isEmpty = false |
|
|
|
|
} |
|
|
|
|
this.setState({ isEmpty }) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JsonImportSubview.propTypes = { |
|
|
|
|