Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"proxy": "https://api.thegraph.com",
"dependencies": {
"@ant-design/icons": "^4.6.2",
"@davatar/react": "^1.8.1",
"@indexed-finance/indexed.js": "^1.0.45",
"@indexed-finance/narwhal-sdk": "^1.0.1",
"@indexed-finance/subgraph-clients": "^0.0.18",
"@metamask/jazzicon": "^2.0.0",
"@octokit/core": "^3.5.1",
"@reduxjs/toolkit": "^1.5.0",
"@uiw/react-md-editor": "^3.4.9",
Expand Down
43 changes: 7 additions & 36 deletions src/components/atomic/molecules/JazzIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { Dropdown, Menu, notification } from "antd";
import { ExternalLink } from "components/atomic/atoms";
import { actions } from "features";
import { useBreakpoints, useTranslator } from "hooks";
import { useCallback, useEffect, useRef } from "react";
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { useWeb3React } from "@web3-react/core";
import ReactDOM from "react-dom";
import jazzicon from "@metamask/jazzicon";

import Davatar from "@davatar/react";
interface Props {
address: string;
isWalletIcon?: boolean;
Expand All @@ -17,7 +15,6 @@ export function JazzIcon({ address, isWalletIcon = false }: Props) {
const tx = useTranslator();
const { deactivate } = useWeb3React();
const dispatch = useDispatch();
const blockie = useRef<null | HTMLSpanElement>(null);
const handleDisconnect = useCallback(() => {
deactivate();
dispatch(actions.userDisconnected());
Expand All @@ -28,36 +25,10 @@ export function JazzIcon({ address, isWalletIcon = false }: Props) {
});
}, [dispatch, deactivate, tx]);
const breakpoints = useBreakpoints();
const inner = <span ref={blockie} />;

// Effect:
// Use refs to integrate the third party library for displaying a wallet identicon.
useEffect(() => {
const _blockie = blockie.current;
let element: any;

if (_blockie) {
const parsedAddress = parseInt(address.slice(2, 10), 16);

element = jazzicon(28, parsedAddress);
element.style.display = "block";
element.style.border = "2px solid #ccccff";
element.style.top = "-4px";

_blockie.appendChild(element);
}

return () => {
if (element) {
element.remove();
}

if (_blockie) {
ReactDOM.unmountComponentAtNode(_blockie);
}
};
}, [address, breakpoints]);

const getDavatar = () => (
<Davatar size={30} address={address} generatedAvatarType="jazzicon" />
);
return isWalletIcon ? (
<Dropdown
arrow={true}
Expand All @@ -75,11 +46,11 @@ export function JazzIcon({ address, isWalletIcon = false }: Props) {
</Menu>
}
>
{inner}
<span>{getDavatar()}</span>
</Dropdown>
) : (
<ExternalLink to={`https://etherscan.io/tx/${address}`} withIcon={false}>
{inner}
{getDavatar()}
</ExternalLink>
);
}
4 changes: 3 additions & 1 deletion src/components/atomic/molecules/ServerConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { selectors } from "features";
import { useMemo } from "react";
import { useSelector } from "react-redux";
import { useTranslator } from "hooks";
import useENS from "../../../hooks/useENS";

interface Props {
showText?: boolean;
}

export function ServerConnection({ showText = false }: Props) {
const tx = useTranslator();
const { ensName } = useENS();
const userAddress = useSelector(selectors.selectUserAddress);
const isUserConnected = useSelector(selectors.selectUserConnected);
const isServerConnected = useSelector(selectors.selectConnected);
Expand Down Expand Up @@ -55,7 +57,7 @@ export function ServerConnection({ showText = false }: Props) {
>
<Space>
<ConnectionIcon style={{ position: "relative", top: 2 }} />
{showText && connectionText}
{showText && (ensName || connectionText)}
</Space>
</Typography.Title>
);
Expand Down
2 changes: 0 additions & 2 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ declare module "colorthief";
declare module "coingecko-api";
declare module "fortmatic";
declare module "md-2-json";
declare module "react-identicons";
declare module "@metamask/jazzicon";
declare module "ssl-root-cas/latest";
declare module "*.md";
24 changes: 24 additions & 0 deletions src/hooks/useENS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ethers } from "ethers";
import { useEffect, useState } from "react";
import { useWeb3React } from "@web3-react/core";

const useENS = () => {
const [ensName, setENSName] = useState<string | null>(null);
const { connector, account } = useWeb3React();

useEffect(() => {
const resolveENS = async () => {
if (connector && account && ethers.utils.isAddress(account)) {
const _provider = await connector.getProvider();
const provider = new ethers.providers.Web3Provider(_provider, 1);
const ensName = await provider.lookupAddress(account);
if (ensName) setENSName(ensName);
}
};
resolveENS();
}, [account, connector]);

return { ensName };
};

export default useENS;
Loading