1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-25 12:52:33 +02:00
metamask-extension/ui/app/higher-order-components/with-method-data/with-method-data.component.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { getMethodData } from '../../helpers/transactions.util'
export default function withMethodData (WrappedComponent) {
return class MethodDataWrappedComponent extends PureComponent {
static propTypes = {
transaction: PropTypes.object,
}
static defaultProps = {
transaction: {},
}
state = {
2018-08-07 10:57:46 +02:00
methodData: {},
done: false,
error: null,
}
componentDidMount () {
this.fetchMethodData()
}
async fetchMethodData () {
const { transaction } = this.props
const { txParams: { data = '' } = {} } = transaction
if (data) {
try {
const methodData = await getMethodData(data)
2018-08-07 10:57:46 +02:00
this.setState({ methodData, done: true })
} catch (error) {
2018-08-07 10:57:46 +02:00
this.setState({ done: true, error })
}
2018-08-07 10:57:46 +02:00
} else {
this.setState({ done: true })
}
}
render () {
2018-08-07 10:57:46 +02:00
const { methodData, done, error } = this.state
return (
<WrappedComponent
{ ...this.props }
2018-08-07 10:57:46 +02:00
methodData={{ data: methodData, done, error }}
/>
)
}
}
}