Skip to content

Commit

Permalink
Handle suggested token resolved elsewhere (#8910)
Browse files Browse the repository at this point in the history
When a suggested token was resolved in a different window, the popup
or notification UI could get stuck with an empty suggested token list,
where either action would throw an error.

This case is now handled by either redirecting or closing the window,
in the popup and notification cases respectively. This check is
performed on both component mount and update.
  • Loading branch information
Gudahtt authored Jul 3, 2020
1 parent a4e7cff commit b0014a9
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import PropTypes from 'prop-types'
import Button from '../../components/ui/button'
import Identicon from '../../components/ui/identicon'
import TokenBalance from '../../components/ui/token-balance'
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'

export default class ConfirmAddSuggestedToken extends Component {
static contextTypes = {
Expand All @@ -19,9 +21,23 @@ export default class ConfirmAddSuggestedToken extends Component {
}

componentDidMount () {
this._checkPendingTokens()
}

componentDidUpdate () {
this._checkPendingTokens()
}

_checkPendingTokens () {
const { mostRecentOverviewPage, pendingTokens = {}, history } = this.props

if (Object.keys(pendingTokens).length === 0) {
if (Object.keys(pendingTokens).length > 0) {
return
}

if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
global.platform.closeCurrentWindow()
} else {
history.push(mostRecentOverviewPage)
}
}
Expand Down

0 comments on commit b0014a9

Please sign in to comment.