From 748801f4179d353959f40049cf6ca27851eebd0e Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Tue, 18 Jun 2019 09:47:14 -0230 Subject: 4byte fallback (#6551) * Adds 4byte registry fallback to getMethodData() (#6435) * Adds fetchWithCache to guard against unnecessary API calls * Add custom fetch wrapper with abort on timeout * Use opts and cacheRefreshTime in fetch-with-cache util * Use custom fetch wrapper with timeout for fetch-with-cache * Improve contract method data fetching (#6623) * Remove async call from getTransactionActionKey() * Stop blocking confirm screen rendering on method data loading, and base screen route on transactionCategory * Remove use of withMethodData, fix use of knownMethodData, in relation to transaction-list-item.component * Load data contract method data progressively, making it non-blocking; requires simplifying conf-tx-base lifecycle logic. * Allow editing of gas price while loading on the confirm screen. * Fix transactionAction component and its unit tests. * Fix confirm transaction components for cases of route transitions within metamask. * Only call toString on id if truthy in getNavigateTxData() * Fix knownMethodData retrieval and data fetching from fourbyte --- ui/app/store/actions.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'ui/app/store/actions.js') 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 } + }) + } +} -- cgit