diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-07-31 03:02:55 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-08-24 07:44:43 +0800 |
commit | 4e0693eaff0107d11bf93042db50cbb022cfeed8 (patch) | |
tree | 36d999929610b4f20646cb6265231105aa6c042f /ui/app/higher-order-components/with-method-data | |
parent | 40d4ac9ae1ed9557d066c184abd90e51a380cf06 (diff) | |
download | tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.tar tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.tar.gz tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.tar.bz2 tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.tar.lz tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.tar.xz tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.tar.zst tangerine-wallet-browser-4e0693eaff0107d11bf93042db50cbb022cfeed8.zip |
Add withMethodData HOC, add higher-order-component folder
Diffstat (limited to 'ui/app/higher-order-components/with-method-data')
-rw-r--r-- | ui/app/higher-order-components/with-method-data/index.js | 1 | ||||
-rw-r--r-- | ui/app/higher-order-components/with-method-data/with-method-data.component.js | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/ui/app/higher-order-components/with-method-data/index.js b/ui/app/higher-order-components/with-method-data/index.js new file mode 100644 index 000000000..f511e1ae7 --- /dev/null +++ b/ui/app/higher-order-components/with-method-data/index.js @@ -0,0 +1 @@ +export { default } from './with-method-data.component' 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 new file mode 100644 index 000000000..aa38afd8a --- /dev/null +++ b/ui/app/higher-order-components/with-method-data/with-method-data.component.js @@ -0,0 +1,44 @@ +import React, { PureComponent } from 'react' +import PropTypes from 'prop-types' +import { getMethodData } from '../../helpers/confirm-transaction/util' + +export default function withMethodData (WrappedComponent) { + return class MethodDataWrappedComponent extends PureComponent { + static propTypes = { + transaction: PropTypes.object, + } + + static defaultProps = { + transaction: {}, + } + + state = { + methodData: {}, + } + + componentDidMount () { + this.fetchMethodData() + } + + async fetchMethodData () { + const { transaction } = this.props + const { txParams: { data = '' } = {} } = transaction + + if (data) { + const methodData = await getMethodData(data) + this.setState({ methodData }) + } + } + + render () { + const { methodData } = this.state + + return ( + <WrappedComponent + { ...this.props } + methodData={methodData} + /> + ) + } + } +} |