diff --git a/web/package.json b/web/package.json index 05283dabd..462a91c44 100644 --- a/web/package.json +++ b/web/package.json @@ -69,7 +69,7 @@ "chart.js": "^3.9.1", "chartjs-adapter-moment": "^1.0.0", "core-js": "^3.21.1", - "ethers": "^5.7.0", + "ethers": "5.7.0", "graphql": "^16.4.0", "graphql-request": "^5.0.0", "moment": "^2.29.4", @@ -88,7 +88,8 @@ "react-toastify": "^9.1.1", "react-use": "^17.4.0", "styled-components": "^5.3.6", - "swr": "^1.3.0" + "swr": "^1.3.0", + "wagmi": "^0.12.10" }, "volta": { "node": "16.18.1", diff --git a/web/src/components/ConnectButton.tsx b/web/src/components/ConnectButton.tsx index 86c9a765b..0b8b9d2be 100644 --- a/web/src/components/ConnectButton.tsx +++ b/web/src/components/ConnectButton.tsx @@ -2,18 +2,23 @@ import React from "react"; import styled from "styled-components"; import { shortenAddress } from "utils/shortenAddress"; import { Button } from "@kleros/ui-components-library"; -import { useWeb3 } from "hooks/useWeb3"; -import { useConnect } from "hooks/useConnect"; -import { SUPPORTED_CHAINS } from "consts/chains"; + +import { useAccount, useConnect, useNetwork, useEnsAvatar } from "wagmi"; +import { arbitrumGoerli } from "wagmi/chains"; +import { useErrorHandler } from "react-error-boundary"; const AccountDisplay: React.FC = () => { - const { account, chainId } = useWeb3(); - const chainName = chainId ? SUPPORTED_CHAINS[chainId].chainName : undefined; - const shortAddress = account ? shortenAddress(account) : undefined; + const { chain } = useNetwork(); + const { address } = useAccount(); + const { data } = useEnsAvatar({ address }); + + const shortAddress = address ? shortenAddress(address) : undefined; + const addressOrAvatar = data ? data : shortAddress; + return ( - {chainName} - + {chain?.name} + ); }; @@ -40,12 +45,38 @@ const StyledContainer = styled.div` `; const ConnectButton: React.FC = () => { - const { active } = useWeb3(); - const { activate, connecting } = useConnect(); - return active ? ( + const { isConnected } = useAccount(); + + const { chain } = useNetwork(); + + const handleError = useErrorHandler(); + + const { connect, connectors } = useConnect(); + + try { + if (isConnected) { + if (chain?.id !== arbitrumGoerli.id) { + throw new Error("chain not configure"); + } + } + } catch (e) { + handleError(e); + } + + return isConnected ? ( ) : ( -