add send token button on fullscreen asset list (#8812)

feature/default_network_editable
Brad Decker 5 years ago committed by GitHub
parent 53e88b06b6
commit 61d9fcde35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 62
      ui/app/components/app/asset-list-item/asset-list-item.js
  2. 15
      ui/app/components/app/asset-list-item/asset-list-item.scss
  3. 13
      ui/app/components/app/token-cell/token-cell.js
  4. 3
      ui/app/components/app/token-cell/token-cell.test.js

@ -1,10 +1,17 @@
import React from 'react' import React, { useMemo } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import classnames from 'classnames' import classnames from 'classnames'
import Identicon from '../../ui/identicon' import Identicon from '../../ui/identicon'
import ListItem from '../../ui/list-item' import ListItem from '../../ui/list-item'
import Tooltip from '../../ui/tooltip-v2' import Tooltip from '../../ui/tooltip-v2'
import InfoIcon from '../../ui/icon/info-icon.component' import InfoIcon from '../../ui/icon/info-icon.component'
import Button from '../../ui/button'
import { useI18nContext } from '../../../hooks/useI18nContext'
import { useMetricEvent } from '../../../hooks/useMetricEvent'
import { useDispatch } from 'react-redux'
import { updateSendToken } from '../../../store/actions'
import { useHistory } from 'react-router-dom'
import { SEND_ROUTE } from '../../../helpers/constants/routes'
const AssetListItem = ({ const AssetListItem = ({
@ -13,11 +20,23 @@ const AssetListItem = ({
iconClassName, iconClassName,
onClick, onClick,
tokenAddress, tokenAddress,
tokenSymbol,
tokenDecimals,
tokenImage, tokenImage,
warning, warning,
primary, primary,
secondary, secondary,
}) => { }) => {
const t = useI18nContext()
const dispatch = useDispatch()
const history = useHistory()
const sendTokenEvent = useMetricEvent({
eventOpts: {
category: 'Navigation',
action: 'Home',
name: 'Clicked Send: Token',
},
})
const titleIcon = warning const titleIcon = warning
? ( ? (
<Tooltip <Tooltip
@ -40,6 +59,38 @@ const AssetListItem = ({
) )
: null : null
const sendTokenButton = useMemo(() => {
if (tokenAddress == null) {
return null
}
return (
<Button
type="link"
className="asset-list-item__send-token-button"
onClick={(e) => {
e.stopPropagation()
sendTokenEvent()
dispatch(updateSendToken({
address: tokenAddress,
decimals: tokenDecimals,
symbol: tokenSymbol,
}))
history.push(SEND_ROUTE)
}}
>
{t('sendSpecifiedTokens', [tokenSymbol])}
</Button>
)
}, [
tokenSymbol,
sendTokenEvent,
tokenAddress,
tokenDecimals,
history,
t,
dispatch,
])
return ( return (
<ListItem <ListItem
className={classnames('asset-list-item', className)} className={classnames('asset-list-item', className)}
@ -57,7 +108,12 @@ const AssetListItem = ({
/> />
)} )}
midContent={midContent} midContent={midContent}
rightContent={<i className="fas fa-chevron-right asset-list-item__chevron-right" />} rightContent={(
<>
<i className="fas fa-chevron-right asset-list-item__chevron-right" />
{sendTokenButton}
</>
)}
/> />
) )
} }
@ -68,6 +124,8 @@ AssetListItem.propTypes = {
iconClassName: PropTypes.string, iconClassName: PropTypes.string,
onClick: PropTypes.func.isRequired, onClick: PropTypes.func.isRequired,
tokenAddress: PropTypes.string, tokenAddress: PropTypes.string,
tokenSymbol: PropTypes.string,
tokenDecimals: PropTypes.number,
tokenImage: PropTypes.string, tokenImage: PropTypes.string,
warning: PropTypes.node, warning: PropTypes.node,
primary: PropTypes.string, primary: PropTypes.string,

@ -17,6 +17,13 @@
margin-left: 8px; margin-left: 8px;
} }
&__send-token-button {
display: none;
text-transform: uppercase;
width: fit-content;
font-size: 14px;
}
@media (min-width: 576px) { @media (min-width: 576px) {
&__warning-tooltip { &__warning-tooltip {
display: none; display: none;
@ -25,5 +32,13 @@
.list-item__mid-content { .list-item__mid-content {
display: flex; display: flex;
} }
&__send-token-button {
display: inline-block;
}
&__chevron-right {
display: none;
}
} }
} }

@ -8,7 +8,15 @@ import { useI18nContext } from '../../../hooks/useI18nContext'
import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount' import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount'
export default function TokenCell ({ address, outdatedBalance, symbol, string, image, onClick }) { export default function TokenCell ({
address,
decimals,
outdatedBalance,
symbol,
string,
image,
onClick,
}) {
const userAddress = useSelector(getSelectedAddress) const userAddress = useSelector(getSelectedAddress)
const t = useI18nContext() const t = useI18nContext()
@ -37,6 +45,8 @@ export default function TokenCell ({ address, outdatedBalance, symbol, string, i
onClick={onClick.bind(null, address)} onClick={onClick.bind(null, address)}
tokenAddress={address} tokenAddress={address}
tokenImage={image} tokenImage={image}
tokenSymbol={symbol}
tokenDecimals={decimals}
warning={warning} warning={warning}
primary={`${string || 0} ${symbol}`} primary={`${string || 0} ${symbol}`}
secondary={formattedFiat} secondary={formattedFiat}
@ -49,6 +59,7 @@ TokenCell.propTypes = {
address: PropTypes.string, address: PropTypes.string,
outdatedBalance: PropTypes.bool, outdatedBalance: PropTypes.bool,
symbol: PropTypes.string, symbol: PropTypes.string,
decimals: PropTypes.number,
string: PropTypes.string, string: PropTypes.string,
image: PropTypes.string, image: PropTypes.string,
onClick: PropTypes.func.isRequired, onClick: PropTypes.func.isRequired,

@ -5,6 +5,7 @@ import { Provider } from 'react-redux'
import configureMockStore from 'redux-mock-store' import configureMockStore from 'redux-mock-store'
import { mount } from 'enzyme' import { mount } from 'enzyme'
import sinon from 'sinon' import sinon from 'sinon'
import { MemoryRouter } from 'react-router-dom'
import TokenCell from '.' import TokenCell from '.'
import Identicon from '../../ui/identicon' import Identicon from '../../ui/identicon'
@ -44,6 +45,7 @@ describe('Token Cell', function () {
onClick = sinon.stub() onClick = sinon.stub()
wrapper = mount( wrapper = mount(
<Provider store={store}> <Provider store={store}>
<MemoryRouter>
<TokenCell <TokenCell
address="0xAnotherToken" address="0xAnotherToken"
symbol="TEST" symbol="TEST"
@ -52,6 +54,7 @@ describe('Token Cell', function () {
image="./test-image" image="./test-image"
onClick={onClick} onClick={onClick}
/> />
</MemoryRouter>
</Provider> </Provider>
) )
}) })

Loading…
Cancel
Save