Simplify use of promisified background connection (#8396)

The background connection used in `actions.js` was being promisified
in specific actions. Instead it's now promisified once. This was made
possible by changes in `pify` v5.0.0 that ensure the binding works
correctly when passing in an object to `pify` (e.g. the `this` value
is correctly set to the wrapped background connection).

This async background connection has been temporarily assigned to a
separate variable, until we can transition all of our actions to using
this. This was done to reduce the size of this PR. There are a lot of
actions.
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent e2bf779acd
commit 0d6dc380b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ui/app/store/actions.js

@ -17,8 +17,10 @@ import { getEnvironmentType } from '../../../app/scripts/lib/util'
import actionConstants from './actionConstants' import actionConstants from './actionConstants'
let background = null let background = null
let promisifiedBackground = null
export function _setBackgroundConnection (backgroundConnection) { export function _setBackgroundConnection (backgroundConnection) {
background = backgroundConnection background = backgroundConnection
promisifiedBackground = pify(background)
} }
export function goHome () { export function goHome () {
@ -301,9 +303,9 @@ export function importNewAccount (strategy, args) {
dispatch(showLoadingIndication('This may take a while, please be patient.')) dispatch(showLoadingIndication('This may take a while, please be patient.'))
try { try {
log.debug(`background.importAccountWithStrategy`) log.debug(`background.importAccountWithStrategy`)
await pify(background.importAccountWithStrategy).call(background, strategy, args) await promisifiedBackground.importAccountWithStrategy(strategy, args)
log.debug(`background.getState`) log.debug(`background.getState`)
newState = await pify(background.getState).call(background) newState = await promisifiedBackground.getState()
} catch (err) { } catch (err) {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
dispatch(displayWarning(err.message)) dispatch(displayWarning(err.message))
@ -1874,7 +1876,7 @@ export function setCompletedOnboarding () {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
try { try {
await pify(background.completeOnboarding).call(background) await promisifiedBackground.completeOnboarding()
} catch (err) { } catch (err) {
dispatch(displayWarning(err.message)) dispatch(displayWarning(err.message))
throw err throw err
@ -2426,7 +2428,7 @@ export function setRequestAccountTabIds (requestAccountTabIds) {
export function getRequestAccountTabIds () { export function getRequestAccountTabIds () {
return async (dispatch) => { return async (dispatch) => {
const requestAccountTabIds = await pify(background.getRequestAccountTabIds).call(background) const requestAccountTabIds = await promisifiedBackground.getRequestAccountTabIds()
dispatch(setRequestAccountTabIds(requestAccountTabIds)) dispatch(setRequestAccountTabIds(requestAccountTabIds))
} }
} }
@ -2440,7 +2442,7 @@ export function setOpenMetamaskTabsIDs (openMetaMaskTabIDs) {
export function getOpenMetamaskTabsIds () { export function getOpenMetamaskTabsIds () {
return async (dispatch) => { return async (dispatch) => {
const openMetaMaskTabIDs = await pify(background.getOpenMetamaskTabsIds).call(background) const openMetaMaskTabIDs = await promisifiedBackground.getOpenMetamaskTabsIds()
dispatch(setOpenMetamaskTabsIDs(openMetaMaskTabIDs)) dispatch(setOpenMetamaskTabsIDs(openMetaMaskTabIDs))
} }
} }

Loading…
Cancel
Save