Skip to content

Commit

Permalink
Merge pull request #2575 from bigint/ens
Browse files Browse the repository at this point in the history
feat: add ens name and avatar support
  • Loading branch information
aminlatifi authored Mar 16, 2022
2 parents fdec34b + 0d1b0da commit 78f50ee
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"private": true,
"dependencies": {
"@ant-design/icons": "^4.5.0",
"@davatar/react": "^1.8.1",
"@ethersproject/providers": "^5.5.2",
"@feathersjs/authentication-client": "^4.5.11",
"@feathersjs/feathers": "^4.5.11",
"@feathersjs/rest-client": "^4.5.11",
Expand Down
21 changes: 19 additions & 2 deletions src/components/layout/MainMenu/RightMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import Avatar from 'react-avatar';
import { Link, useLocation } from 'react-router-dom';
import { withRouter } from 'react-router';
import { Menu, Grid } from 'antd';
import Davatar from '@davatar/react';

import { useENS } from 'hooks/useENS';
import { Context as UserContext } from '../../../contextProviders/UserProvider';
import { Context as Web3Context } from '../../../contextProviders/Web3Provider';
import { Context as WhiteListContext } from '../../../contextProviders/WhiteListProvider';
Expand Down Expand Up @@ -46,6 +48,8 @@ const RightMenu = () => {
state: { reviewerWhitelistEnabled, delegateWhitelistEnabled, projectOwnersWhitelistEnabled },
} = useContext(WhiteListContext);

const { ensName } = useENS(currentUser.address);

const userIsDelegator = currentUser.isDelegator || !delegateWhitelistEnabled;
const userIsCampaignManager = currentUser.isProjectOwner || !projectOwnersWhitelistEnabled;
const userIsReviewer = currentUser.isReviewer || !reviewerWhitelistEnabled;
Expand Down Expand Up @@ -189,12 +193,25 @@ const RightMenu = () => {

{validProvider && (
<Menu.Item key="userAddress">
<button type="button" className="btn btn-outline-success btn-sm" onClick={switchWallet}>
<button
type="button"
className="d-flex btn btn-outline-success btn-sm"
onClick={switchWallet}
>
{walletIcon && currentUser.address && (
<Avatar className="mr-2" size={25} src={walletIcon} />
)}
<span>
{currentUser.address ? shortenAddress(currentUser.address) : 'Switch Wallet'}
{currentUser.address ? (
<span className="d-flex align-items-center">
<span className="mr-1">
<Davatar size={20} address={currentUser.address} />
</span>
<div>{ensName || shortenAddress(currentUser.address)}</div>
</span>
) : (
'Switch Wallet'
)}
</span>
</button>
</Menu.Item>
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useENS.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getDefaultProvider } from '@ethersproject/providers';
import { useEffect, useState } from 'react';

export function useENS(address) {
const [ensName, setENSName] = useState();

useEffect(() => {
async function resolveENS() {
if (address) {
const provider = await getDefaultProvider();
const name = await provider.lookupAddress(address);
if (name) setENSName(name);
}
}
resolveENS();
}, [address]);

return { ensName };
}
Loading

0 comments on commit 78f50ee

Please sign in to comment.