diff options
author | Esteban MiƱo <efmino@uc.cl> | 2019-01-23 02:22:56 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2019-01-23 02:22:56 +0800 |
commit | e21dfd18622dd7f70dac51855a0052a56fb74e57 (patch) | |
tree | 03fe6571c87474c15af266fa0e3bc9c1a755c450 /ui/app/higher-order-components | |
parent | fe780fb3d457dd22be84cf7ef386327ba9a2ec93 (diff) | |
download | tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar.gz tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar.bz2 tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar.lz tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar.xz tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar.zst tangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.zip |
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
Diffstat (limited to 'ui/app/higher-order-components')
-rw-r--r-- | ui/app/higher-order-components/with-method-data/with-method-data.component.js | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/ui/app/higher-order-components/with-method-data/with-method-data.component.js b/ui/app/higher-order-components/with-method-data/with-method-data.component.js index fed7d9865..08b9083e1 100644 --- a/ui/app/higher-order-components/with-method-data/with-method-data.component.js +++ b/ui/app/higher-order-components/with-method-data/with-method-data.component.js @@ -1,15 +1,18 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' -import { getMethodData } from '../../helpers/transactions.util' +import { getMethodData, getFourBytePrefix } from '../../helpers/transactions.util' export default function withMethodData (WrappedComponent) { return class MethodDataWrappedComponent extends PureComponent { static propTypes = { transaction: PropTypes.object, + knownMethodData: PropTypes.object, + addKnownMethodData: PropTypes.func, } static defaultProps = { transaction: {}, + knownMethodData: {}, } state = { @@ -23,12 +26,22 @@ export default function withMethodData (WrappedComponent) { } async fetchMethodData () { - const { transaction } = this.props + const { transaction, knownMethodData, addKnownMethodData } = this.props const { txParams: { data = '' } = {} } = transaction if (data) { 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 }) } catch (error) { this.setState({ done: true, error }) |