From bb868f58348962d4a85415380d11f72892a2e28c Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Thu, 16 Aug 2018 20:19:19 -0300 Subject: [PATCH] correct behavior when notification is closed when popup --- app/scripts/controllers/preferences.js | 2 +- ui/app/actions.js | 23 +++++++++++-------- .../confirm-add-suggested-token.component.js | 12 ++++++---- .../confirm-add-suggested-token.container.js | 3 +-- ui/app/components/pages/home.js | 1 - 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 59c24f987..1438d6f7f 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -237,7 +237,7 @@ class PreferencesController { removeSuggestedTokens () { return new Promise((resolve, reject) => { this.store.updateState({ suggestedTokens: {} }) - resolve() + resolve({}) }) } diff --git a/ui/app/actions.js b/ui/app/actions.js index 4e3c87756..0760377c2 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -1626,16 +1626,21 @@ function addTokens (tokens) { function removeSuggestedTokens () { return (dispatch) => { dispatch(actions.showLoadingIndication()) - background.removeSuggestedTokens((err) => { - dispatch(actions.hideLoadingIndication()) - if (err) { - dispatch(actions.displayWarning(err.message)) - } - dispatch(actions.clearPendingTokens()) - if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION) { - return global.platform.closeCurrentWindow() - } + return new Promise((resolve, reject) => { + background.removeSuggestedTokens((err, suggestedTokens) => { + dispatch(actions.hideLoadingIndication()) + if (err) { + dispatch(actions.displayWarning(err.message)) + } + dispatch(actions.clearPendingTokens()) + if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION) { + return global.platform.closeCurrentWindow() + } + resolve(suggestedTokens) + }) }) + .then(() => updateMetamaskStateFromBackground()) + .then(suggestedTokens => dispatch(actions.updateMetamaskState({...suggestedTokens}))) } } diff --git a/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js b/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js index e8155b5f0..37d9aca02 100644 --- a/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js +++ b/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js @@ -33,7 +33,7 @@ export default class ConfirmAddSuggestedToken extends Component { } render () { - const { addToken, clearPendingTokens, pendingTokens, removeSuggestedTokens, history } = this.props + const { addToken, pendingTokens, removeSuggestedTokens, history } = this.props const pendingTokenKey = Object.keys(pendingTokens)[0] const pendingToken = pendingTokens[pendingTokenKey] @@ -96,8 +96,10 @@ export default class ConfirmAddSuggestedToken extends Component { className="page-container__footer-button" onClick={() => { removeSuggestedTokens() - history.push(DEFAULT_ROUTE) - }} + .then(() => { + history.push(DEFAULT_ROUTE) + }) + }} > { this.context.t('cancel') } @@ -109,7 +111,9 @@ export default class ConfirmAddSuggestedToken extends Component { addToken(pendingToken) .then(() => { removeSuggestedTokens() - history.push(DEFAULT_ROUTE) + .then(() => { + history.push(DEFAULT_ROUTE) + }) }) }} > diff --git a/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.container.js b/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.container.js index 97e07afda..89291ff4f 100644 --- a/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.container.js +++ b/ui/app/components/pages/confirm-add-suggested-token/confirm-add-suggested-token.container.js @@ -5,7 +5,7 @@ import { withRouter } from 'react-router-dom' const extend = require('xtend') -const { addToken, clearPendingTokens, removeSuggestedTokens } = require('../../../actions') +const { addToken, removeSuggestedTokens } = require('../../../actions') const mapStateToProps = ({ metamask }) => { const { pendingTokens, suggestedTokens } = metamask @@ -19,7 +19,6 @@ const mapStateToProps = ({ metamask }) => { const mapDispatchToProps = dispatch => { return { addToken: ({address, symbol, decimals, imageUrl}) => dispatch(addToken(address, symbol, decimals, imageUrl)), - clearPendingTokens: () => dispatch(clearPendingTokens()), removeSuggestedTokens: () => dispatch(removeSuggestedTokens()), } } diff --git a/ui/app/components/pages/home.js b/ui/app/components/pages/home.js index 629dc11fc..6ee083579 100644 --- a/ui/app/components/pages/home.js +++ b/ui/app/components/pages/home.js @@ -40,7 +40,6 @@ class Home extends Component { // suggested new tokens if (Object.keys(suggestedTokens).length > 0) { - console.log('CALLING CONFIRM ADD SUGGESTED') history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE) }