mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Use Parity on-chain registry only when is needed (#6052)
* add and use knownMethodData to avoid infura requests * dataMethod to methodData and check empty response
This commit is contained in:
parent
fe780fb3d4
commit
e21dfd1862
@ -19,6 +19,7 @@ class PreferencesController {
|
|||||||
* @property {boolean} store.useBlockie The users preference for blockie identicons within the UI
|
* @property {boolean} store.useBlockie The users preference for blockie identicons within the UI
|
||||||
* @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the
|
* @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the
|
||||||
* user wishes to see that feature
|
* user wishes to see that feature
|
||||||
|
* @property {object} store.knownMethodData Contains all data methods known by the user
|
||||||
* @property {string} store.currentLocale The preferred language locale key
|
* @property {string} store.currentLocale The preferred language locale key
|
||||||
* @property {string} store.selectedAddress A hex string that matches the currently selected address in the app
|
* @property {string} store.selectedAddress A hex string that matches the currently selected address in the app
|
||||||
*
|
*
|
||||||
@ -36,6 +37,7 @@ class PreferencesController {
|
|||||||
betaUI: true,
|
betaUI: true,
|
||||||
skipAnnounceBetaUI: true,
|
skipAnnounceBetaUI: true,
|
||||||
},
|
},
|
||||||
|
knownMethodData: {},
|
||||||
currentLocale: opts.initLangCode,
|
currentLocale: opts.initLangCode,
|
||||||
identities: {},
|
identities: {},
|
||||||
lostIdentities: {},
|
lostIdentities: {},
|
||||||
@ -98,6 +100,18 @@ class PreferencesController {
|
|||||||
this.store.updateState({ suggestedTokens: suggested })
|
this.store.updateState({ suggestedTokens: suggested })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new methodData to state, to avoid requesting this information again through Infura
|
||||||
|
*
|
||||||
|
* @param {string} fourBytePrefix Four-byte method signature
|
||||||
|
* @param {string} methodData Corresponding data method
|
||||||
|
*/
|
||||||
|
addKnownMethodData (fourBytePrefix, methodData) {
|
||||||
|
const knownMethodData = this.store.getState().knownMethodData
|
||||||
|
knownMethodData[fourBytePrefix] = methodData
|
||||||
|
this.store.updateState({ knownMethodData })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RPC engine middleware for requesting new asset added
|
* RPC engine middleware for requesting new asset added
|
||||||
*
|
*
|
||||||
|
@ -425,6 +425,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
|
setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
|
||||||
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),
|
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),
|
||||||
setPreference: nodeify(preferencesController.setPreference, preferencesController),
|
setPreference: nodeify(preferencesController.setPreference, preferencesController),
|
||||||
|
addKnownMethodData: nodeify(preferencesController.addKnownMethodData, preferencesController),
|
||||||
|
|
||||||
// BlacklistController
|
// BlacklistController
|
||||||
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
|
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
|
||||||
|
@ -236,6 +236,7 @@ var actions = {
|
|||||||
removeToken,
|
removeToken,
|
||||||
updateTokens,
|
updateTokens,
|
||||||
removeSuggestedTokens,
|
removeSuggestedTokens,
|
||||||
|
addKnownMethodData,
|
||||||
UPDATE_TOKENS: 'UPDATE_TOKENS',
|
UPDATE_TOKENS: 'UPDATE_TOKENS',
|
||||||
setRpcTarget: setRpcTarget,
|
setRpcTarget: setRpcTarget,
|
||||||
delRpcTarget: delRpcTarget,
|
delRpcTarget: delRpcTarget,
|
||||||
@ -1490,7 +1491,6 @@ const backgroundSetLocked = () => {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return reject(error)
|
return reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -1721,6 +1721,12 @@ function removeSuggestedTokens () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addKnownMethodData (fourBytePrefix, methodData) {
|
||||||
|
return (dispatch) => {
|
||||||
|
background.addKnownMethodData(fourBytePrefix, methodData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateTokens (newTokens) {
|
function updateTokens (newTokens) {
|
||||||
return {
|
return {
|
||||||
type: actions.UPDATE_TOKENS,
|
type: actions.UPDATE_TOKENS,
|
||||||
|
@ -3,7 +3,7 @@ import { withRouter } from 'react-router-dom'
|
|||||||
import { compose } from 'recompose'
|
import { compose } from 'recompose'
|
||||||
import withMethodData from '../../higher-order-components/with-method-data'
|
import withMethodData from '../../higher-order-components/with-method-data'
|
||||||
import TransactionListItem from './transaction-list-item.component'
|
import TransactionListItem from './transaction-list-item.component'
|
||||||
import { setSelectedToken, showModal, showSidebar } from '../../actions'
|
import { setSelectedToken, showModal, showSidebar, addKnownMethodData } from '../../actions'
|
||||||
import { hexToDecimal } from '../../helpers/conversions.util'
|
import { hexToDecimal } from '../../helpers/conversions.util'
|
||||||
import { getTokenData } from '../../helpers/transactions.util'
|
import { getTokenData } from '../../helpers/transactions.util'
|
||||||
import { increaseLastGasPrice } from '../../helpers/confirm-transaction/util'
|
import { increaseLastGasPrice } from '../../helpers/confirm-transaction/util'
|
||||||
@ -15,11 +15,19 @@ import {
|
|||||||
setCustomGasLimit,
|
setCustomGasLimit,
|
||||||
} from '../../ducks/gas.duck'
|
} from '../../ducks/gas.duck'
|
||||||
|
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
const { metamask: { knownMethodData } } = state
|
||||||
|
return {
|
||||||
|
knownMethodData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
|
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
|
||||||
fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)),
|
fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)),
|
||||||
setSelectedToken: tokenAddress => dispatch(setSelectedToken(tokenAddress)),
|
setSelectedToken: tokenAddress => dispatch(setSelectedToken(tokenAddress)),
|
||||||
|
addKnownMethodData: (fourBytePrefix, methodData) => dispatch(addKnownMethodData(fourBytePrefix, methodData)),
|
||||||
retryTransaction: (transaction, gasPrice) => {
|
retryTransaction: (transaction, gasPrice) => {
|
||||||
dispatch(setCustomGasPriceForRetry(gasPrice || transaction.txParams.gasPrice))
|
dispatch(setCustomGasPriceForRetry(gasPrice || transaction.txParams.gasPrice))
|
||||||
dispatch(setCustomGasLimit(transaction.txParams.gas))
|
dispatch(setCustomGasLimit(transaction.txParams.gas))
|
||||||
@ -64,6 +72,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withRouter,
|
withRouter,
|
||||||
connect(null, mapDispatchToProps, mergeProps),
|
connect(mapStateToProps, mapDispatchToProps, mergeProps),
|
||||||
withMethodData,
|
withMethodData,
|
||||||
)(TransactionListItem)
|
)(TransactionListItem)
|
||||||
|
@ -59,6 +59,18 @@ export function isConfirmDeployContract (txData = {}) {
|
|||||||
return !txParams.to
|
return !txParams.to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns four-byte method signature from data
|
||||||
|
*
|
||||||
|
* @param {string} data - The hex data (@code txParams.data) of a transaction
|
||||||
|
* @returns {string} - The four-byte method signature
|
||||||
|
*/
|
||||||
|
export function getFourBytePrefix (data = '') {
|
||||||
|
const prefixedData = ethUtil.addHexPrefix(data)
|
||||||
|
const fourBytePrefix = prefixedData.slice(0, 10)
|
||||||
|
return fourBytePrefix
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the action of a transaction as a key to be passed into the translator.
|
* Returns the action of a transaction as a key to be passed into the translator.
|
||||||
* @param {Object} transaction - txData object
|
* @param {Object} transaction - txData object
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { getMethodData } from '../../helpers/transactions.util'
|
import { getMethodData, getFourBytePrefix } from '../../helpers/transactions.util'
|
||||||
|
|
||||||
export default function withMethodData (WrappedComponent) {
|
export default function withMethodData (WrappedComponent) {
|
||||||
return class MethodDataWrappedComponent extends PureComponent {
|
return class MethodDataWrappedComponent extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
transaction: PropTypes.object,
|
transaction: PropTypes.object,
|
||||||
|
knownMethodData: PropTypes.object,
|
||||||
|
addKnownMethodData: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
transaction: {},
|
transaction: {},
|
||||||
|
knownMethodData: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -23,12 +26,22 @@ export default function withMethodData (WrappedComponent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchMethodData () {
|
async fetchMethodData () {
|
||||||
const { transaction } = this.props
|
const { transaction, knownMethodData, addKnownMethodData } = this.props
|
||||||
const { txParams: { data = '' } = {} } = transaction
|
const { txParams: { data = '' } = {} } = transaction
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
try {
|
try {
|
||||||
const methodData = await getMethodData(data)
|
let methodData
|
||||||
|
const fourBytePrefix = getFourBytePrefix(data)
|
||||||
|
if (fourBytePrefix in knownMethodData) {
|
||||||
|
methodData = knownMethodData[fourBytePrefix]
|
||||||
|
} else {
|
||||||
|
methodData = await getMethodData(data)
|
||||||
|
if (!Object.entries(methodData).length === 0) {
|
||||||
|
addKnownMethodData(fourBytePrefix, methodData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({ methodData, done: true })
|
this.setState({ methodData, done: true })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({ done: true, error })
|
this.setState({ done: true, error })
|
||||||
|
@ -54,6 +54,7 @@ function reduceMetamask (state, action) {
|
|||||||
preferences: {
|
preferences: {
|
||||||
useNativeCurrencyAsPrimaryCurrency: true,
|
useNativeCurrencyAsPrimaryCurrency: true,
|
||||||
},
|
},
|
||||||
|
knownMethodData: {},
|
||||||
}, state.metamask)
|
}, state.metamask)
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user