Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ens name and avatar support #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -14,6 +14,7 @@
]
},
"dependencies": {
"@davatar/react": "^1.8.1",
"@ethersproject/providers": "^5.0.12",
"@material-ui/core": "^4.11.4",
"@material-ui/icons": "^4.11.2",
@@ -14,7 +14,9 @@

.wallet-link {
margin: 10px;

display: flex;
align-items: center;

p{
font-family: Montserrat SemiBold;
font-size: 14px;
@@ -14,11 +14,14 @@ import "./drawer-content.scss";
import DocsIcon from "../../../assets/icons/stake.svg";
import GlobeIcon from "../../../assets/icons/wonderglobe.svg";
import classnames from "classnames";
import useENS from "src/hooks/useENS";
import Davatar from "@davatar/react";

function NavContent() {
const [isActive] = useState();
const address = useAddress();
const { bonds } = useBonds();
const { ensName } = useENS(address);

const checkPage = useCallback((location: any, page: string): boolean => {
const currentPath = location.pathname.replace("/", "");
@@ -46,8 +49,9 @@ function NavContent() {

{address && (
<div className="wallet-link">
<Davatar size={20} address={address} style={{ marginRight: 8 }} generatedAvatarType="jazzicon" />
<Link href={`https://cchain.explorer.avax.network/address/${address}`} target="_blank">
<p>{shorten(address)}</p>
<p>{ensName || shorten(address)}</p>
</Link>
</div>
)}
@@ -0,0 +1,21 @@
import { ethers } from "ethers";
import { useEffect, useState } from "react";

const useENS = (address: string) => {
const [ensName, setENSName] = useState<string | null>(null);

useEffect(() => {
const resolveENS = async () => {
if (ethers.utils.isAddress(address)) {
const provider = new ethers.providers.JsonRpcProvider("https://cloudflare-eth.com");
const ensName = await provider.lookupAddress(address);
setENSName(ensName);
}
};
resolveENS();
}, [address]);

return { ensName };
};

export default useENS;