Skip to content

Commit 35bc91f

Browse files
committed
Add TokenLogo
If you give it a known token address it'll give you a nice token logo, e.g. Streamr's. If the address isn't known it'll generate an identicon.
1 parent 0fa7ec2 commit 35bc91f

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

src/components/TokenLogo.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Avatar from '$/components/Avatar'
2+
import useTokenInfo from '$/hooks/useTokenInfo'
3+
import { OptionalAddress } from '$/types'
4+
import tw from 'twin.macro'
5+
6+
export default function TokenLogo({ tokenAddress }: { tokenAddress: OptionalAddress }) {
7+
const info = useTokenInfo(tokenAddress)
8+
9+
return info && 'symbol' in info ? (
10+
<img
11+
src={`https://polygonscan.com/token/images/${info.logo}`}
12+
alt={info.symbol}
13+
width="32"
14+
height="32"
15+
/>
16+
) : (
17+
<Avatar
18+
seed={tokenAddress?.toLowerCase()}
19+
css={tw`
20+
w-8
21+
h-8
22+
mr-3
23+
`}
24+
/>
25+
)
26+
}

src/components/modals/AddTokenGatedRoomModal.tsx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import useTokenMetadata from '$/hooks/useTokenMetadata'
2929
import { parseUnits } from '@ethersproject/units'
3030
import i18n from '$/utils/i18n'
3131
import TokenStandardLabel from '$/components/TokenStandardLabel'
32+
import TokenLogo from '$/components/TokenLogo'
3233

3334
interface Gate {
3435
tokenAddress: Address
@@ -285,37 +286,22 @@ function Token({ info, onChangeClick }: TokenProps) {
285286
text-[14px]
286287
`}
287288
>
288-
{'symbol' in info ? (
289-
<>
290-
<img
291-
src={`https://polygonscan.com/token/images/${info.logo}`}
292-
alt={info.symbol}
293-
width="32"
294-
height="32"
295-
/>
296-
<div>
289+
<TokenLogo tokenAddress={info.address} />
290+
<div>
291+
{'symbol' in info ? (
292+
<>
297293
<div css={tw`font-semibold`}>
298294
<Text>{info.symbol}</Text>
299295
</div>
300296
<div css={tw`text-[#59799C]`}>
301297
<Text>{info.name}</Text>
302298
</div>
303-
</div>
304-
</>
305-
) : (
306-
<>
307-
<Avatar
308-
seed={info.address.toLowerCase()}
309-
css={tw`
310-
w-8
311-
h-8
312-
mr-3
313-
`}
314-
/>
315-
<div>{trunc(info.address)}</div>
316-
</>
317-
)}
318-
<TokenStandardLabel tokenAddress={info.address} />
299+
</>
300+
) : (
301+
trunc(info.address)
302+
)}
303+
</div>
304+
<TokenStandardLabel tokenAddress={info.address} css={tw`ml-6`} />
319305
<div css={tw`grow`} />
320306
{isFetchingTokenStandard ? (
321307
<div

0 commit comments

Comments
 (0)