aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/higher-order-components/with-method-data/with-method-data.component.js
diff options
context:
space:
mode:
authorEsteban MiƱo <efmino@uc.cl>2019-01-23 02:22:56 +0800
committerDan Finlay <542863+danfinlay@users.noreply.github.com>2019-01-23 02:22:56 +0800
commite21dfd18622dd7f70dac51855a0052a56fb74e57 (patch)
tree03fe6571c87474c15af266fa0e3bc9c1a755c450 /ui/app/higher-order-components/with-method-data/with-method-data.component.js
parentfe780fb3d457dd22be84cf7ef386327ba9a2ec93 (diff)
downloadtangerine-wallet-browser-e21dfd18622dd7f70dac51855a0052a56fb74e57.tar.gz
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/with-method-data/with-method-data.component.js')
-rw-r--r--ui/app/higher-order-components/with-method-data/with-method-data.component.js19
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 })