diff --git a/ui/app/components/app/asset-list/asset-list.component.js b/ui/app/components/app/asset-list/asset-list.component.js deleted file mode 100644 index 35dc8429d..000000000 --- a/ui/app/components/app/asset-list/asset-list.component.js +++ /dev/null @@ -1,106 +0,0 @@ -import PropTypes from 'prop-types' -import React, { Component } from 'react' -import AddTokenButton from '../add-token-button' -import TokenList from '../token-list' -import { ADD_TOKEN_ROUTE } from '../../../helpers/constants/routes' -import AssetListItem from '../asset-list-item' -import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display' -import { PRIMARY, SECONDARY } from '../../../helpers/constants/common' - -export default class AssetList extends Component { - static contextTypes = { - t: PropTypes.func, - metricsEvent: PropTypes.func, - } - - static defaultProps = { - selectedTokenAddress: undefined, - } - - static propTypes = { - history: PropTypes.object.isRequired, - selectedAccountBalance: PropTypes.string, - selectedTokenAddress: PropTypes.string, - setSelectedToken: PropTypes.func.isRequired, - showFiat: PropTypes.bool.isRequired, - unsetSelectedToken: PropTypes.func.isRequired, - } - - renderWalletBalance () { - const { - selectedAccountBalance, - selectedTokenAddress, - showFiat, - unsetSelectedToken, - } = this.props - - return ( - - - { - showFiat && ( - - ) - } - - ) - } - - renderAddToken () { - const { - history, - } = this.props - const { metricsEvent } = this.context - - return ( - { - history.push(ADD_TOKEN_ROUTE) - metricsEvent({ - eventOpts: { - category: 'Navigation', - action: 'Token Menu', - name: 'Clicked "Add Token"', - }, - }) - }} - /> - ) - } - - render () { - const { setSelectedToken } = this.props - return ( - <> - {this.renderWalletBalance()} - { - setSelectedToken(tokenAddress) - this.context.metricsEvent({ - eventOpts: { - category: 'Navigation', - action: 'Token Menu', - name: 'Clicked Token', - }, - }) - }} - /> - {this.renderAddToken()} - - ) - } -} diff --git a/ui/app/components/app/asset-list/asset-list.container.js b/ui/app/components/app/asset-list/asset-list.container.js deleted file mode 100644 index 65ea1ce73..000000000 --- a/ui/app/components/app/asset-list/asset-list.container.js +++ /dev/null @@ -1,26 +0,0 @@ -import { connect } from 'react-redux' -import { withRouter } from 'react-router-dom' -import { compose } from 'redux' -import AssetList from './asset-list.component' -import { setSelectedToken } from '../../../store/actions' -import { getCurrentAccountWithSendEtherInfo, getShouldShowFiat } from '../../../selectors/selectors' - -function mapStateToProps (state) { - return { - selectedAccountBalance: getCurrentAccountWithSendEtherInfo(state).balance, - selectedTokenAddress: state.metamask.selectedTokenAddress, - showFiat: getShouldShowFiat(state), - } -} - -function mapDispatchToProps (dispatch) { - return { - setSelectedToken: (tokenAddress) => dispatch(setSelectedToken(tokenAddress)), - unsetSelectedToken: () => dispatch(setSelectedToken()), - } -} - -export default compose( - withRouter, - connect(mapStateToProps, mapDispatchToProps) -)(AssetList) diff --git a/ui/app/components/app/asset-list/asset-list.js b/ui/app/components/app/asset-list/asset-list.js new file mode 100644 index 000000000..172704337 --- /dev/null +++ b/ui/app/components/app/asset-list/asset-list.js @@ -0,0 +1,84 @@ +import React from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { useHistory } from 'react-router-dom' +import AddTokenButton from '../add-token-button' +import TokenList from '../token-list' +import { ADD_TOKEN_ROUTE } from '../../../helpers/constants/routes' +import AssetListItem from '../asset-list-item' +import CurrencyDisplay from '../../ui/currency-display' +import { PRIMARY, SECONDARY } from '../../../helpers/constants/common' +import { useMetricEvent } from '../../../hooks/useMetricEvent' +import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency' +import { getCurrentAccountWithSendEtherInfo, getShouldShowFiat } from '../../../selectors/selectors' +import { setSelectedToken } from '../../../store/actions' + +const AssetList = () => { + const dispatch = useDispatch() + const history = useHistory() + const selectedAccountBalance = useSelector((state) => getCurrentAccountWithSendEtherInfo(state).balance) + const selectedTokenAddress = useSelector((state) => state.metamask.selectedTokenAddress) + const showFiat = useSelector(getShouldShowFiat) + const metricsEvent = useMetricEvent() + + const { + currency: primaryCurrency, + numberOfDecimals: primaryNumberOfDecimals, + } = useUserPreferencedCurrency(PRIMARY, { ethNumberOfDecimals: 4 }) + const { + currency: secondaryCurrency, + numberOfDecimals: secondaryNumberOfDecimals, + } = useUserPreferencedCurrency(SECONDARY, { ethNumberOfDecimals: 4 }) + + return ( + <> + dispatch(setSelectedToken())} + data-testid="wallet-balance" + > + + { + showFiat && ( + + ) + } + + { + dispatch(setSelectedToken(tokenAddress)) + metricsEvent({ + eventOpts: { + category: 'Navigation', + action: 'Token Menu', + name: 'Clicked Token', + }, + }) + }} + /> + { + history.push(ADD_TOKEN_ROUTE) + metricsEvent({ + eventOpts: { + category: 'Navigation', + action: 'Token Menu', + name: 'Clicked "Add Token"', + }, + }) + }} + /> + + ) +} + +export default AssetList diff --git a/ui/app/components/app/asset-list/index.js b/ui/app/components/app/asset-list/index.js index 777c5c187..49abc01fd 100644 --- a/ui/app/components/app/asset-list/index.js +++ b/ui/app/components/app/asset-list/index.js @@ -1 +1 @@ -export { default } from './asset-list.container.js' +export { default } from './asset-list.js'