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:
parent
40d4ac9ae1
commit
4e0693eaff
@ -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 = {
|
||||
|
@ -1,2 +0,0 @@
|
||||
import TokenBalance from './token-balance.container'
|
||||
module.exports = TokenBalance
|
@ -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>
|
||||
)
|
||||
}
|
||||
}
|
1
ui/app/components/token-balance/index.js
Normal file
1
ui/app/components/token-balance/index.js
Normal file
@ -0,0 +1 @@
|
||||
export { default } from './token-balance.container'
|
23
ui/app/components/token-balance/token-balance.component.js
Normal file
23
ui/app/components/token-balance/token-balance.component.js
Normal 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>
|
||||
)
|
||||
}
|
||||
}
|
@ -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 {
|
1
ui/app/higher-order-components/with-method-data/index.js
Normal file
1
ui/app/higher-order-components/with-method-data/index.js
Normal file
@ -0,0 +1 @@
|
||||
export { default } from './with-method-data.component'
|
@ -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}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
export { default } from './with-token-tracker.component'
|
@ -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
|
Loading…
Reference in New Issue
Block a user