-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ens avatar resolution * chore: uninstall @davatar/react * fix: add avatar alt * feat: support data uris * feat: support arweave uris * feat: support erc721 avatars * feat: support erc1155 avatars * fix: jazzicon integration * fix: clean usage of status icon * fix: fix jazzicon svg offset * refactor: share status icon component * fix: pass memoized args to multicall
- Loading branch information
Showing
11 changed files
with
354 additions
and
141 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,49 @@ | ||
[ | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "_id", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "_id", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "uri", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
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,40 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "tokenId", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "ownerOf", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "tokenId", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "tokenURI", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
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,25 @@ | ||
import { AbstractConnector } from '@web3-react/abstract-connector' | ||
|
||
import CoinbaseWalletIcon from '../../assets/images/coinbaseWalletIcon.svg' | ||
import FortmaticIcon from '../../assets/images/fortmaticIcon.png' | ||
import PortisIcon from '../../assets/images/portisIcon.png' | ||
import WalletConnectIcon from '../../assets/images/walletConnectIcon.svg' | ||
import { fortmatic, injected, portis, walletconnect, walletlink } from '../../connectors' | ||
import Identicon from '../Identicon' | ||
|
||
export default function StatusIcon({ connector }: { connector: AbstractConnector }) { | ||
switch (connector) { | ||
case injected: | ||
return <Identicon /> | ||
case walletconnect: | ||
return <img src={WalletConnectIcon} alt={'WalletConnect'} /> | ||
case walletlink: | ||
return <img src={CoinbaseWalletIcon} alt={'Coinbase Wallet'} /> | ||
case fortmatic: | ||
return <img src={FortmaticIcon} alt={'Fortmatic'} /> | ||
case portis: | ||
return <img src={PortisIcon} alt={'Portis'} /> | ||
default: | ||
return null | ||
} | ||
} |
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,32 +1,47 @@ | ||
import Davatar, { Image } from '@davatar/react' | ||
import { useMemo } from 'react' | ||
import jazzicon from '@metamask/jazzicon' | ||
import useENSAvatar from 'hooks/useENSAvatar' | ||
import { useEffect, useRef, useState } from 'react' | ||
import styled from 'styled-components/macro' | ||
|
||
import { useActiveWeb3React } from '../../hooks/web3' | ||
|
||
const StyledIdenticonContainer = styled.div` | ||
const StyledIdenticon = styled.div` | ||
height: 1rem; | ||
width: 1rem; | ||
border-radius: 1.125rem; | ||
background-color: ${({ theme }) => theme.bg4}; | ||
font-size: initial; | ||
` | ||
|
||
const StyledAvatar = styled.img` | ||
height: inherit; | ||
width: inherit; | ||
border-radius: inherit; | ||
` | ||
|
||
export default function Identicon() { | ||
const { account, library } = useActiveWeb3React() | ||
const ref = useRef<HTMLDivElement>(null) | ||
const { account } = useActiveWeb3React() | ||
const { avatar } = useENSAvatar(account ?? undefined) | ||
const [fetchable, setFetchable] = useState(true) | ||
|
||
// restrict usage of Davatar until it stops sending 3p requests | ||
// see https://github.com/metaphor-xyz/davatar-helpers/issues/18 | ||
const supportsENS = useMemo(() => { | ||
return ([1, 3, 4, 5] as Array<number | undefined>).includes(library?.network?.chainId) | ||
}, [library]) | ||
useEffect(() => { | ||
if ((!avatar || !fetchable) && account) { | ||
const icon = jazzicon(16, parseInt(account?.slice(2, 10), 16)) | ||
const current = ref.current | ||
current?.appendChild(icon) | ||
return () => { | ||
current?.removeChild(icon) | ||
} | ||
} | ||
return | ||
}, [account, avatar, fetchable]) | ||
|
||
return ( | ||
<StyledIdenticonContainer> | ||
{account && supportsENS ? ( | ||
<Davatar address={account} size={16} provider={library} /> | ||
) : ( | ||
<Image address={account} size={16} /> | ||
<StyledIdenticon ref={ref}> | ||
{avatar && fetchable && ( | ||
<StyledAvatar alt="avatar" src={avatar} onError={() => setFetchable(false)}></StyledAvatar> | ||
)} | ||
</StyledIdenticonContainer> | ||
</StyledIdenticon> | ||
) | ||
} |
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.