-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added token list functional component * Added list - img not showing up * Changed render list * Removed unused code * Clean up * Lint * Linted * Add newline * Filter out isERC721 * Added token list * Cleaned up style * Fixed typography * Fixed lint * Fixed spacing measure * Lint cleanup
- Loading branch information
Showing
5 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './token-list-display'; |
61 changes: 61 additions & 0 deletions
61
ui/components/app/token-list-display/token-list-display.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useSelector } from 'react-redux'; | ||
import { isEqual } from 'lodash'; | ||
|
||
import { getShouldHideZeroBalanceTokens } from '../../../selectors'; | ||
import { useTokenTracker } from '../../../hooks/useTokenTracker'; | ||
import Identicon from '../../ui/identicon'; | ||
import TokenBalance from '../../ui/token-balance'; | ||
import { useI18nContext } from '../../../hooks/useI18nContext'; | ||
import { getTokens } from '../../../ducks/metamask/metamask'; | ||
|
||
export default function TokenListDisplay({ clickHandler }) { | ||
const t = useI18nContext(); | ||
const shouldHideZeroBalanceTokens = useSelector( | ||
getShouldHideZeroBalanceTokens, | ||
); | ||
|
||
const tokens = useSelector(getTokens, isEqual); | ||
const { loading, tokensWithBalances } = useTokenTracker( | ||
tokens, | ||
true, | ||
shouldHideZeroBalanceTokens, | ||
); | ||
if (loading) { | ||
return <div className="loading-span">{t('loadingTokens')}</div>; | ||
} | ||
|
||
const sendableTokens = tokensWithBalances.filter((token) => !token.isERC721); | ||
|
||
return ( | ||
<> | ||
{sendableTokens.map((tokenData) => { | ||
const { address, symbol, image } = tokenData; | ||
|
||
return ( | ||
<div | ||
key={address} | ||
className="token-list-item" | ||
onClick={() => clickHandler(tokenData)} | ||
> | ||
<Identicon address={address} diameter={36} image={image} /> | ||
<div className="token-list-item__data"> | ||
<div className="token-list-item__symbol">{symbol}</div> | ||
<div className="token-list-item__balance"> | ||
<span className="token-list-item__balance__label"> | ||
{`${t('balance')}:`} | ||
</span> | ||
<TokenBalance token={tokenData} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
} | ||
|
||
TokenListDisplay.propTypes = { | ||
clickHandler: PropTypes.func, | ||
}; |
45 changes: 45 additions & 0 deletions
45
ui/components/app/token-list-display/token-list-display.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.loading-span { | ||
display: flex; | ||
height: 250px; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 32px; | ||
} | ||
|
||
.token-list-item { | ||
padding: 8px; | ||
display: flex; | ||
flex-flow: row nowrap; | ||
align-items: center; | ||
cursor: pointer; | ||
padding: 8px; | ||
|
||
&:hover { | ||
background-color: rgba($alto, 0.2); | ||
} | ||
|
||
&__data { | ||
margin-left: 8px; | ||
} | ||
|
||
&__symbol { | ||
@include Paragraph; | ||
|
||
line-height: 140%; | ||
margin-bottom: 2px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
|
||
&__balance { | ||
@include H7; | ||
|
||
display: flex; | ||
flex-flow: row nowrap; | ||
} | ||
|
||
&__balance__label { | ||
margin-right: 4px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters