Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable import button on Import Account screen for empty string/file #7912

Merged
merged 4 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Current Develop Branch
- [#7912](https://github.com/MetaMask/metamask-extension/pull/7912): Disable import button for empty string/file

## 7.7.0 Thu Nov 28 2019
- [#7004](https://github.com/MetaMask/metamask-extension/pull/7004): Connect distinct accounts per site
Expand Down
19 changes: 17 additions & 2 deletions ui/app/pages/create-account/import-account/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ const HELP_LINK = 'https://metamask.zendesk.com/hc/en-us/articles/360015489351-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">
Expand All @@ -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
Expand All @@ -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>
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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 = {
Expand Down
18 changes: 16 additions & 2 deletions ui/app/pages/create-account/import-account/private-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class PrivateKeyImportView extends Component {
error: PropTypes.node,
}

inputRef = React.createRef()

state = { isEmpty: true }

createNewKeychain () {
const input = document.getElementById('private-key-box')
const privateKey = input.value
const privateKey = this.inputRef.current.value
const { importNewAccount, history, displayWarning, setSelectedAddress, firstAddress } = this.props

importNewAccount('Private Key', [ privateKey ])
Expand Down Expand Up @@ -63,6 +65,15 @@ class PrivateKeyImportView extends Component {
}
}

checkInputEmpty () {
const privateKey = this.inputRef.current.value
let isEmpty = true
if (privateKey !== '') {
isEmpty = false
}
this.setState({ isEmpty })
}

render () {
const { error, displayWarning } = this.props

Expand All @@ -77,6 +88,8 @@ class PrivateKeyImportView extends Component {
type="password"
id="private-key-box"
onKeyPress={e => this.createKeyringOnEnter(e)}
onChange={() => this.checkInputEmpty()}
ref={this.inputRef}
/>
</div>
<div className="new-account-import-form__buttons">
Expand All @@ -96,6 +109,7 @@ class PrivateKeyImportView extends Component {
large
className="new-account-create-form__button"
onClick={() => this.createNewKeychain()}
disabled={this.state.isEmpty}
>
{this.context.t('import')}
</Button>
Expand Down