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

chore(explorer): Update wagmi to v2 in the Explorer #832

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
10 changes: 5 additions & 5 deletions explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"dependencies": {
"@floating-ui/react": "^0.26.25",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@tanstack/react-query": "^5.61.4",
"@tanstack/react-table": "^8.10.7",
"@verax-attestation-registry/verax-sdk": "2.1.1",
"@wagmi/core": "^1.4.7",
"@verax-attestation-registry/verax-sdk": "2.1.3",
"abitype": "^0.10.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"connectkit": "1.5.3",
"connectkit": "^1.8.2",
"framer-motion": "^10.16.12",
"i18next": "^23.7.8",
"lucide-react": "^0.292.0",
Expand All @@ -47,9 +47,9 @@
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7",
"usehooks-ts": "^2.9.1",
"viem": "1.18.9",
"viem": "2.21.51",
"vite-tsconfig-paths": "^4.2.1",
"wagmi": "1.4.6"
"wagmi": "^2.13.0"
},
"devDependencies": {
"@types/node": "^20.9.2",
Expand Down
3 changes: 2 additions & 1 deletion explorer/src/components/EnsNameDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Address } from "viem";
import { mainnet, useEnsName } from "wagmi";
import { useEnsName } from "wagmi";
import { mainnet } from "wagmi/chains";

import { cropString } from "@/utils/stringUtils";

Expand Down
63 changes: 27 additions & 36 deletions explorer/src/config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { getDefaultConfig } from "connectkit";
import { Chain, createConfig, mainnet } from "wagmi";
import { arbitrum, arbitrumSepolia, base, baseSepolia, bsc, bscTestnet, linea } from "wagmi/chains";
import { createConfig, http } from "wagmi";
import {
arbitrum,
arbitrumSepolia,
base,
baseSepolia,
bsc,
bscTestnet,
linea,
lineaSepolia,
mainnet,
} from "wagmi/chains";

import veraxColoredIcon from "@/assets/logo/verax-colored-icon.svg";
import ArbitrumIconDark from "@/assets/networks/arbitrum-dark.svg?react";
Expand All @@ -18,36 +28,6 @@ import LineaSepoliaIcon from "@/assets/networks/linea-sepolia.svg?react";
import LineaMainnetIcon from "@/assets/networks/linea.svg?react";
import { INetwork } from "@/interfaces/config";

const lineaSepolia = {
id: 59_141,
name: "Linea Sepolia Testnet",
network: "linea-sepolia",
nativeCurrency: { name: "Linea Ether", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: {
http: ["https://rpc.sepolia.linea.build"],
webSocket: ["wss://rpc.sepolia.linea.build"],
},
public: {
http: ["https://rpc.sepolia.linea.build"],
webSocket: ["wss://rpc.sepolia.linea.build"],
},
},
blockExplorers: {
default: {
name: "Etherscan",
url: "https://sepolia.lineascan.build",
},
},
contracts: {
multicall3: {
address: "0xca11bde05977b3631167028862be2a173976ca11",
blockCreated: 227427,
},
},
testnet: true,
} as const satisfies Chain;

const chains: INetwork[] = [
{
name: "Linea Mainnet",
Expand Down Expand Up @@ -151,14 +131,25 @@ const chains: INetwork[] = [
},
];

const infuraApiKey: string = import.meta.env.VITE_INFURA_API_KEY;

const config = createConfig(
getDefaultConfig({
autoConnect: true,
infuraId: import.meta.env.VITE_INFURA_API_KEY,
walletConnectProjectId: import.meta.env.VITE_WALLETCONNECT_PROJECT_ID || "",
chains: [...chains.map((el) => el.chain), mainnet],
appName: "Verax | Explorer",
appIcon: veraxColoredIcon,
walletConnectProjectId: import.meta.env.VITE_WALLETCONNECT_PROJECT_ID || "",
chains: [mainnet, ...chains.map((el) => el.chain)],
transports: {
[mainnet.id]: http(`https://mainnet.infura.io/v3/${infuraApiKey}`),
[arbitrum.id]: http(`https://arbitrum-mainnet.infura.io/v3/${infuraApiKey}`),
[arbitrumSepolia.id]: http(`https://arbitrum-sepolia.infura.io/v3/${infuraApiKey}`),
[base.id]: http(`https://base-mainnet.infura.io/v3/${infuraApiKey}`),
[baseSepolia.id]: http(`https://base-sepolia.infura.io/v3/${infuraApiKey}`),
[bsc.id]: http(`https://bsc-mainnet.infura.io/v3/${infuraApiKey}`),
[bscTestnet.id]: http(`https://bsc-testnet.infura.io/v3/${infuraApiKey}`),
[linea.id]: http(`https://linea-mainnet.infura.io/v3/${infuraApiKey}`),
[lineaSepolia.id]: http(`https://linea-sepolia.infura.io/v3/${infuraApiKey}`),
},
}),
);

Expand Down
3 changes: 1 addition & 2 deletions explorer/src/interfaces/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Conf } from "@verax-attestation-registry/verax-sdk";
import { Hex } from "viem";
import { Chain } from "wagmi";
import { Chain, Hex } from "viem";

export interface INetwork {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ export const AttestationInfo: React.FC<Attestation> = ({ ...attestation }) => {
const { data: attesterEnsAddress } = useEnsName({
address: attestation.attester as Address,
chainId: mainnet.id,
enabled: true,
});

const { data: subjectEnsAddress } = useEnsName({
address: attestation.subject as Address,
chainId: mainnet.id,
enabled: isAddress(attestation.subject),
query: { enabled: isAddress(attestation.subject) },
});

const displayAttesterEnsNameOrAddress = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/pages/Portal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Portal = () => {
const { data: portalOwnerEnsAddress } = useEnsName({
address: portal?.ownerAddress as Address,
chainId: mainnet.id,
enabled: !isLoading,
query: { enabled: !isLoading },
});

const displayPortalOwnerEnsAddress = useCallback(() => {
Expand Down
25 changes: 15 additions & 10 deletions explorer/src/providers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConnectKitProvider } from "connectkit";
import { Outlet } from "react-router-dom";
import { WagmiConfig } from "wagmi";
import { WagmiProvider } from "wagmi";

import { config } from "@/config";
import { Layout } from "@/pages/Layout";

import { NetworkContextProvider } from "./network-provider";

export const Providers = () => {
const queryClient = new QueryClient();

return (
<WagmiConfig config={config}>
<ConnectKitProvider>
<NetworkContextProvider>
<Layout>
<Outlet />
</Layout>
</NetworkContextProvider>
</ConnectKitProvider>
</WagmiConfig>
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<ConnectKitProvider>
<NetworkContextProvider>
<Layout>
<Outlet />
</Layout>
</NetworkContextProvider>
</ConnectKitProvider>
</QueryClientProvider>
</WagmiProvider>
);
};
12 changes: 6 additions & 6 deletions explorer/src/providers/network-provider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { Chain } from "@wagmi/core";
import { FC, PropsWithChildren, useCallback, useState } from "react";
import { useLoaderData, useLocation, useNavigate } from "react-router-dom";
import { useAccount, useNetwork, useSwitchNetwork } from "wagmi";
import { useAccount, useSwitchChain } from "wagmi";
import { Chain } from "wagmi/chains";

import { INetwork } from "@/interfaces/config";

Expand All @@ -13,8 +13,8 @@ export const NetworkContextProvider: FC<PropsWithChildren> = ({ children }): JSX
const location = useLocation();

const { isConnected } = useAccount();
const { chain: currentChain } = useNetwork();
const { switchNetworkAsync } = useSwitchNetwork();
const { chain: currentChain } = useAccount();
const { switchChainAsync } = useSwitchChain();
const retrievedNetwork = useLoaderData() as INetwork;

const [network, setNetwork] = useState<INetwork>(retrievedNetwork);
Expand All @@ -27,14 +27,14 @@ export const NetworkContextProvider: FC<PropsWithChildren> = ({ children }): JSX
}

try {
await switchNetworkAsync?.(pendingChain.id);
await switchChainAsync?.({ chainId: pendingChain.id });
return true;
} catch (error) {
console.error(`Error: while switching network: ${pendingChain.name} \n\n`, error);
return false;
}
},
[isConnected, switchNetworkAsync],
[isConnected, switchChainAsync],
);

const setNetworkHandler = async (params: INetwork) => {
Expand Down
Loading
Loading