1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add withMethodData HOC, add higher-order-component folder

This commit is contained in:
Alexander Tseung 2018-07-30 12:02:55 -07:00
parent 40d4ac9ae1
commit 4e0693eaff
10 changed files with 75 additions and 25 deletions

View File

@ -2,8 +2,8 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { DEFAULT_ROUTE, ADD_TOKEN_ROUTE } from '../../../routes'
import Button from '../../button'
import Identicon from '../../../components/identicon'
import TokenBalance from './token-balance'
import Identicon from '../../identicon'
import TokenBalance from '../../token-balance'
export default class ConfirmAddToken extends Component {
static contextTypes = {

View File

@ -1,2 +0,0 @@
import TokenBalance from './token-balance.container'
module.exports = TokenBalance

View File

@ -1,16 +0,0 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
export default class TokenBalance extends Component {
static propTypes = {
string: PropTypes.string,
symbol: PropTypes.string,
error: PropTypes.string,
}
render () {
return (
<div className="hide-text-overflow">{ this.props.string }</div>
)
}
}

View File

@ -0,0 +1 @@
export { default } from './token-balance.container'

View File

@ -0,0 +1,23 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
export default class TokenBalance extends PureComponent {
static propTypes = {
string: PropTypes.string,
symbol: PropTypes.string,
error: PropTypes.string,
className: PropTypes.string,
withSymbol: PropTypes.bool,
}
render () {
const { className, string, withSymbol, symbol } = this.props
return (
<div className={classnames('hide-text-overflow', className)}>
{ string + (withSymbol ? ` ${symbol}` : '') }
</div>
)
}
}

View File

@ -1,8 +1,8 @@
import { connect } from 'react-redux'
import { compose } from 'recompose'
import withTokenTracker from '../../../../helpers/with-token-tracker'
import withTokenTracker from '../../higher-order-components/with-token-tracker'
import TokenBalance from './token-balance.component'
import selectors from '../../../../selectors'
import selectors from '../../selectors'
const mapStateToProps = state => {
return {

View File

@ -0,0 +1 @@
export { default } from './with-method-data.component'

View File

@ -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}
/>
)
}
}
}

View File

@ -0,0 +1 @@
export { default } from './with-token-tracker.component'

View File

@ -2,7 +2,7 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import TokenTracker from 'eth-token-tracker'
const withTokenTracker = WrappedComponent => {
export default function withTokenTracker (WrappedComponent) {
return class TokenTrackerWrappedComponent extends Component {
static propTypes = {
userAddress: PropTypes.string.isRequired,
@ -104,5 +104,3 @@ const withTokenTracker = WrappedComponent => {
}
}
}
module.exports = withTokenTracker