1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Prevent users from submitting password multiple times on the unlock screen

This commit is contained in:
Alexander Tseung 2018-07-10 14:56:12 -07:00
parent f6de948e42
commit 2175d03cca
3 changed files with 39 additions and 37 deletions

View File

@ -22,7 +22,6 @@ const Home = require('./components/pages/home')
const Authenticated = require('./components/pages/authenticated') const Authenticated = require('./components/pages/authenticated')
const Initialized = require('./components/pages/initialized') const Initialized = require('./components/pages/initialized')
const Settings = require('./components/pages/settings') const Settings = require('./components/pages/settings')
const UnlockPage = require('./components/pages/unlock-page')
const RestoreVaultPage = require('./components/pages/keychains/restore-vault').default const RestoreVaultPage = require('./components/pages/keychains/restore-vault').default
const RevealSeedConfirmation = require('./components/pages/keychains/reveal-seed') const RevealSeedConfirmation = require('./components/pages/keychains/reveal-seed')
const AddTokenPage = require('./components/pages/add-token') const AddTokenPage = require('./components/pages/add-token')
@ -40,6 +39,8 @@ const Modal = require('./components/modals/index').Modal
const AppHeader = require('./components/app-header') const AppHeader = require('./components/app-header')
import UnlockPage from './components/pages/unlock-page'
// Routes // Routes
const { const {
DEFAULT_ROUTE, DEFAULT_ROUTE,

View File

@ -2,19 +2,27 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
import TextField from '../../text-field' import TextField from '../../text-field'
import { ENVIRONMENT_TYPE_POPUP } from '../../../../../app/scripts/lib/enums'
import { getEnvironmentType } from '../../../../../app/scripts/lib/util'
import getCaretCoordinates from 'textarea-caret'
import { EventEmitter } from 'events'
import Mascot from '../../mascot'
import { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } from '../../../routes'
const { ENVIRONMENT_TYPE_POPUP } = require('../../../../../app/scripts/lib/enums') export default class UnlockPage extends Component {
const { getEnvironmentType } = require('../../../../../app/scripts/lib/util')
const getCaretCoordinates = require('textarea-caret')
const EventEmitter = require('events').EventEmitter
const Mascot = require('../../mascot')
const { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } = require('../../../routes')
class UnlockPage extends Component {
static contextTypes = { static contextTypes = {
t: PropTypes.func, t: PropTypes.func,
} }
static propTypes = {
forgotPassword: PropTypes.func,
tryUnlockMetamask: PropTypes.func,
markPasswordForgotten: PropTypes.func,
history: PropTypes.object,
isUnlocked: PropTypes.bool,
useOldInterface: PropTypes.func,
}
constructor (props) { constructor (props) {
super(props) super(props)
@ -23,6 +31,7 @@ class UnlockPage extends Component {
error: null, error: null,
} }
this.submitting = false
this.animationEventEmitter = new EventEmitter() this.animationEventEmitter = new EventEmitter()
} }
@ -41,20 +50,21 @@ class UnlockPage extends Component {
const { password } = this.state const { password } = this.state
const { tryUnlockMetamask, history } = this.props const { tryUnlockMetamask, history } = this.props
if (password === '') { if (password === '' || this.submitting) {
return return
} }
this.setState({ error: null }) this.setState({ error: null })
this.submitting = true
try { try {
await tryUnlockMetamask(password) await tryUnlockMetamask(password)
this.submitting = false
history.push(DEFAULT_ROUTE)
} catch ({ message }) { } catch ({ message }) {
this.setState({ error: message }) this.setState({ error: message })
return this.submitting = false
} }
history.push(DEFAULT_ROUTE)
} }
handleInputChange ({ target }) { handleInputChange ({ target }) {
@ -98,7 +108,9 @@ class UnlockPage extends Component {
} }
render () { render () {
const { error } = this.state const { password, error } = this.state
const { t } = this.context
const { markPasswordForgotten, history } = this.props
return ( return (
<div className="unlock-page__container"> <div className="unlock-page__container">
@ -111,18 +123,18 @@ class UnlockPage extends Component {
/> />
</div> </div>
<h1 className="unlock-page__title"> <h1 className="unlock-page__title">
{ this.context.t('welcomeBack') } { t('welcomeBack') }
</h1> </h1>
<div>{ this.context.t('unlockMessage') }</div> <div>{ t('unlockMessage') }</div>
<form <form
className="unlock-page__form" className="unlock-page__form"
onSubmit={event => this.handleSubmit(event)} onSubmit={event => this.handleSubmit(event)}
> >
<TextField <TextField
id="password" id="password"
label={this.context.t('password')} label={t('password')}
type="password" type="password"
value={this.state.password} value={password}
onChange={event => this.handleInputChange(event)} onChange={event => this.handleInputChange(event)}
error={error} error={error}
autoFocus autoFocus
@ -136,28 +148,28 @@ class UnlockPage extends Component {
<div <div
className="unlock-page__link" className="unlock-page__link"
onClick={() => { onClick={() => {
this.props.markPasswordForgotten() markPasswordForgotten()
this.props.history.push(RESTORE_VAULT_ROUTE) history.push(RESTORE_VAULT_ROUTE)
if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) {
global.platform.openExtensionInBrowser() global.platform.openExtensionInBrowser()
} }
}} }}
> >
{ this.context.t('restoreFromSeed') } { t('restoreFromSeed') }
</div> </div>
<div <div
className="unlock-page__link unlock-page__link--import" className="unlock-page__link unlock-page__link--import"
onClick={() => { onClick={() => {
this.props.markPasswordForgotten() markPasswordForgotten()
this.props.history.push(RESTORE_VAULT_ROUTE) history.push(RESTORE_VAULT_ROUTE)
if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) { if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP) {
global.platform.openExtensionInBrowser() global.platform.openExtensionInBrowser()
} }
}} }}
> >
{ this.context.t('importUsingSeed') } { t('importUsingSeed') }
</div> </div>
</div> </div>
</div> </div>
@ -165,15 +177,3 @@ class UnlockPage extends Component {
) )
} }
} }
UnlockPage.propTypes = {
forgotPassword: PropTypes.func,
tryUnlockMetamask: PropTypes.func,
markPasswordForgotten: PropTypes.func,
history: PropTypes.object,
isUnlocked: PropTypes.bool,
t: PropTypes.func,
useOldInterface: PropTypes.func,
}
export default UnlockPage

View File

@ -3,9 +3,10 @@ const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const AccountAndTransactionDetails = require('./account-and-transaction-details') const AccountAndTransactionDetails = require('./account-and-transaction-details')
const Settings = require('./components/pages/settings') const Settings = require('./components/pages/settings')
const UnlockScreen = require('./components/pages/unlock-page')
const log = require('loglevel') const log = require('loglevel')
import UnlockScreen from './components/pages/unlock-page'
module.exports = MainContainer module.exports = MainContainer
inherits(MainContainer, Component) inherits(MainContainer, Component)