-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Finance, Tokens: update verified tokens * Finance: upgrade to MCD DAI and use tokenIconUrl() for token icons * Finance: only show token icons on test networks for known test tokens
- Loading branch information
Showing
10 changed files
with
643 additions
and
245 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
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
93 changes: 53 additions & 40 deletions
93
apps/finance/app/src/components/NewTransfer/TokenSelectorInstance.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 |
---|---|---|
@@ -1,52 +1,65 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { GU } from '@aragon/ui' | ||
import { useNetwork } from '@aragon/api-react' | ||
import LocalIdentityBadge from '../LocalIdentityBadge/LocalIdentityBadge' | ||
import { tokenIconUrl } from '../../lib/icon-utils' | ||
import { ETHER_TOKEN_FAKE_ADDRESS } from '../../lib/token-utils' | ||
import { addressesEqual } from '../../lib/web3-utils' | ||
|
||
class TokenSelectorInstance extends React.PureComponent { | ||
render() { | ||
const { address, name, symbol, showIcon = true } = this.props | ||
return ( | ||
<Main> | ||
{showIcon ? ( | ||
<Icon src={`https://chasing-coins.com/coin/logo/${symbol}`} /> | ||
) : ( | ||
<IconSpacer /> | ||
)} | ||
{symbol && <TokenSymbol>{symbol}</TokenSymbol>} | ||
{name && <TokenName>({name})</TokenName>} | ||
{!addressesEqual(address, ETHER_TOKEN_FAKE_ADDRESS) && ( | ||
<LocalIdentityBadge badgeOnly compact entity={address} /> | ||
)} | ||
</Main> | ||
) | ||
} | ||
} | ||
|
||
const Main = styled.div` | ||
display: flex; | ||
align-items: center; | ||
` | ||
const TokenSelectorInstance = React.memo(function TokenSelectorInstance({ | ||
address, | ||
name, | ||
symbol, | ||
showIcon = true, | ||
}) { | ||
const network = useNetwork() | ||
return ( | ||
<div | ||
css={` | ||
display: flex; | ||
align-items: center; | ||
`} | ||
> | ||
{showIcon ? ( | ||
<Icon src={tokenIconUrl(address, symbol, network && network.type)} /> | ||
) : ( | ||
<div | ||
css={` | ||
width: ${3 * GU}px; | ||
`} | ||
/> | ||
)} | ||
{symbol && ( | ||
<span | ||
css={` | ||
margin-right: ${1 * GU}px; | ||
`} | ||
> | ||
{symbol} | ||
</span> | ||
)} | ||
{name && ( | ||
<span | ||
css={` | ||
max-width: 110px; | ||
margin-right: ${1 * GU}px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
`} | ||
> | ||
({name}) | ||
</span> | ||
)} | ||
{!addressesEqual(address, ETHER_TOKEN_FAKE_ADDRESS) && ( | ||
<LocalIdentityBadge badgeOnly compact entity={address} /> | ||
)} | ||
</div> | ||
) | ||
}) | ||
|
||
const Icon = styled.img.attrs({ alt: '', width: '16', height: '16' })` | ||
margin-right: ${1 * GU}px; | ||
` | ||
|
||
const IconSpacer = styled.div` | ||
width: ${3 * GU}px; | ||
` | ||
|
||
const TokenName = styled.span` | ||
max-width: 110px; | ||
margin-right: ${1 * GU}px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
` | ||
|
||
const TokenSymbol = styled.span` | ||
margin-right: ${1 * GU}px; | ||
` | ||
|
||
export default TokenSelectorInstance | ||
export default React.memo(TokenSelectorInstance) |
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,19 @@ | ||
import { tokenIconUrl as _tokenIconUrl } from '@aragon/ui' | ||
import { getTestTokenAddresses } from '../testnet' | ||
import { ETHER_TOKEN_VERIFIED_BY_SYMBOL } from './verified-tokens' | ||
|
||
// Small shim on top of @aragon/ui's tokenIconUrl, to handle our testnet tokens | ||
export const tokenIconUrl = (tokenAddress, tokenSymbol, networkType) => { | ||
if (networkType === 'main') { | ||
return _tokenIconUrl(tokenAddress) | ||
} | ||
|
||
// On other networks, only pretend known test tokens are legit | ||
const testTokens = new Set(getTestTokenAddresses(networkType)) | ||
if (testTokens.has(tokenAddress.toLowerCase())) { | ||
const mainnetEquivalent = ETHER_TOKEN_VERIFIED_BY_SYMBOL.get(tokenSymbol) | ||
return mainnetEquivalent ? _tokenIconUrl(mainnetEquivalent) : '' | ||
} | ||
|
||
return '' | ||
} |
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
Oops, something went wrong.