diff options
Diffstat (limited to 'ui/app/store/actions.js')
-rw-r--r-- | ui/app/store/actions.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 7f6cbea1f..aff2636ba 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -8,6 +8,7 @@ const { } = require('../pages/send/send.utils') const ethUtil = require('ethereumjs-util') const { fetchLocale } = require('../helpers/utils/i18n-helper') +const { getMethodDataAsync } = require('../helpers/utils/transactions.util') const log = require('loglevel') const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../../app/scripts/lib/enums') const { hasUnconfirmedTransactions } = require('../helpers/utils/confirm-tx.util') @@ -360,6 +361,12 @@ var actions = { // AppStateController-related actions SET_LAST_ACTIVE_TIME: 'SET_LAST_ACTIVE_TIME', setLastActiveTime, + + getContractMethodData, + loadingMethoDataStarted, + loadingMethoDataFinished, + LOADING_METHOD_DATA_STARTED: 'LOADING_METHOD_DATA_STARTED', + LOADING_METHOD_DATA_FINISHED: 'LOADING_METHOD_DATA_FINISHED', } module.exports = actions @@ -2774,3 +2781,38 @@ function setLastActiveTime () { }) } } + +function loadingMethoDataStarted () { + return { + type: actions.LOADING_METHOD_DATA_STARTED, + } +} + +function loadingMethoDataFinished () { + return { + type: actions.LOADING_METHOD_DATA_FINISHED, + } +} + +function getContractMethodData (data = '') { + return (dispatch, getState) => { + const prefixedData = ethUtil.addHexPrefix(data) + const fourBytePrefix = prefixedData.slice(0, 10) + const { knownMethodData } = getState().metamask + if (knownMethodData && knownMethodData[fourBytePrefix]) { + return Promise.resolve(knownMethodData[fourBytePrefix]) + } + + dispatch(actions.loadingMethoDataStarted()) + log.debug(`loadingMethodData`) + + return getMethodDataAsync(fourBytePrefix) + .then(({ name, params }) => { + dispatch(actions.loadingMethoDataFinished()) + + background.addKnownMethodData(fourBytePrefix, { name, params }) + + return { name, params } + }) + } +} |