feature/default_network_editable
Chi Kei Chan 7 years ago
parent 25f4f69706
commit 63a5eca967
  1. 42
      mascara/src/app/first-time/import-account-screen.js

@ -1,5 +1,5 @@
import React, {Component, PropTypes} from 'react' import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'; import {connect} from 'react-redux'
import classnames from 'classnames' import classnames from 'classnames'
import LoadingScreen from './loading-screen' import LoadingScreen from './loading-screen'
import {importNewAccount, hideWarning} from '../../../../ui/app/actions' import {importNewAccount, hideWarning} from '../../../../ui/app/actions'
@ -11,7 +11,7 @@ const Input = ({ label, placeholder, onChange, errorMessage, type = 'text' }) =>
type={type} type={type}
placeholder={placeholder} placeholder={placeholder}
className={classnames('first-time-flow__input import-account__input', { className={classnames('first-time-flow__input import-account__input', {
'first-time-flow__input--error': errorMessage 'first-time-flow__input--error': errorMessage,
})} })}
onChange={onChange} onChange={onChange}
/> />
@ -19,6 +19,14 @@ const Input = ({ label, placeholder, onChange, errorMessage, type = 'text' }) =>
</div> </div>
) )
Input.prototype.propTypes = {
label: PropTypes.string.isRequired,
placeholder: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
errorMessage: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
}
class ImportAccountScreen extends Component { class ImportAccountScreen extends Component {
static OPTIONS = { static OPTIONS = {
PRIVATE_KEY: 'private_key', PRIVATE_KEY: 'private_key',
@ -31,6 +39,7 @@ class ImportAccountScreen extends Component {
next: PropTypes.func.isRequired, next: PropTypes.func.isRequired,
importNewAccount: PropTypes.func.isRequired, importNewAccount: PropTypes.func.isRequired,
hideWarning: PropTypes.func.isRequired, hideWarning: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
}; };
state = { state = {
@ -40,8 +49,8 @@ class ImportAccountScreen extends Component {
} }
isValid () { isValid () {
const { OPTIONS } = ImportAccountScreen; const { OPTIONS } = ImportAccountScreen
const { privateKey, jsonFile, password } = this.state; const { privateKey, jsonFile, password } = this.state
switch (this.state.selectedOption) { switch (this.state.selectedOption) {
case OPTIONS.JSON_FILE: case OPTIONS.JSON_FILE:
@ -53,9 +62,9 @@ class ImportAccountScreen extends Component {
} }
onClick = () => { onClick = () => {
const { OPTIONS } = ImportAccountScreen; const { OPTIONS } = ImportAccountScreen
const { importNewAccount, next } = this.props; const { importNewAccount, next } = this.props
const { privateKey, jsonFile, password } = this.state; const { privateKey, jsonFile, password } = this.state
switch (this.state.selectedOption) { switch (this.state.selectedOption) {
case OPTIONS.JSON_FILE: case OPTIONS.JSON_FILE:
@ -73,13 +82,13 @@ class ImportAccountScreen extends Component {
label: 'Add Private Key String', label: 'Add Private Key String',
placeholder: 'Enter private key', placeholder: 'Enter private key',
onChange: e => this.setState({ privateKey: e.target.value }), onChange: e => this.setState({ privateKey: e.target.value }),
errorMessage: this.props.warning && 'Something went wrong. Please make sure your private key is correct.' errorMessage: this.props.warning && 'Something went wrong. Please make sure your private key is correct.',
}) })
} }
renderJsonFile () { renderJsonFile () {
const { jsonFile: { name } } = this.state; const { jsonFile: { name } } = this.state
const { warning } = this.props; const { warning } = this.props
return ( return (
<div className=""> <div className="">
@ -95,7 +104,7 @@ class ImportAccountScreen extends Component {
<label <label
htmlFor="file" htmlFor="file"
className={classnames('import-account__file-input-label', { className={classnames('import-account__file-input-label', {
'import-account__file-input-label--error': warning 'import-account__file-input-label--error': warning,
})} })}
> >
Choose File Choose File
@ -111,14 +120,14 @@ class ImportAccountScreen extends Component {
placeholder: 'Enter Password', placeholder: 'Enter Password',
type: 'password', type: 'password',
onChange: e => this.setState({ password: e.target.value }), onChange: e => this.setState({ password: e.target.value }),
errorMessage: warning && 'Please make sure your password is correct.' errorMessage: warning && 'Please make sure your password is correct.',
})} })}
</div> </div>
) )
} }
renderContent () { renderContent () {
const { OPTIONS } = ImportAccountScreen; const { OPTIONS } = ImportAccountScreen
switch (this.state.selectedOption) { switch (this.state.selectedOption) {
case OPTIONS.JSON_FILE: case OPTIONS.JSON_FILE:
@ -130,10 +139,10 @@ class ImportAccountScreen extends Component {
} }
render () { render () {
const { OPTIONS } = ImportAccountScreen; const { OPTIONS } = ImportAccountScreen
const { selectedOption } = this.state; const { selectedOption } = this.state
return isLoading return this.props.isLoading
? <LoadingScreen loadingMessage="Creating your new account" /> ? <LoadingScreen loadingMessage="Creating your new account" />
: ( : (
<div className="import-account"> <div className="import-account">
@ -175,6 +184,7 @@ class ImportAccountScreen extends Component {
<a <a
href="https://github.com/MetaMask/faq/blob/master/README.md#q-i-cant-use-the-import-feature-for-uploading-a-json-file-the-window-keeps-closing-when-i-try-to-select-a-file" href="https://github.com/MetaMask/faq/blob/master/README.md#q-i-cant-use-the-import-feature-for-uploading-a-json-file-the-window-keeps-closing-when-i-try-to-select-a-file"
className="first-time-flow__link import-account__faq-link" className="first-time-flow__link import-account__faq-link"
rel="noopener noreferrer"
target="_blank" target="_blank"
> >
File import not working? File import not working?

Loading…
Cancel
Save