Skip to content

Commit

Permalink
feat: Add configuration for Optimism-Sepolia and Optimism-Mainnet. (#184
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brunomenezes authored May 23, 2024
1 parent 42ed081 commit 6cc6005
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/web/.env.optimism-mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_CHAIN_ID=10
NEXT_PUBLIC_EXPLORER_API_URL="https://optimism.api.cartesiscan.io/graphql"
2 changes: 2 additions & 0 deletions apps/web/.env.optimism-sepolia
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_CHAIN_ID=11155420
NEXT_PUBLIC_EXPLORER_API_URL="https://optimism-sepolia.api.cartesiscan.io/graphql"
26 changes: 24 additions & 2 deletions apps/web/src/providers/walletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ import Image from "next/image";
import { ReactNode } from "react";
import Jazzicon, { jsNumberForAddress } from "react-jazzicon";
import { createConfig, fallback, http, WagmiProvider } from "wagmi";
import { foundry, mainnet, sepolia } from "wagmi/chains";
import {
foundry,
mainnet,
optimism,
optimismSepolia,
sepolia,
} from "wagmi/chains";

// select chain based on env var
const chainId = parseInt(process.env.NEXT_PUBLIC_CHAIN_ID || "31337");
const alchemyApiKey = process.env.NEXT_PUBLIC_ALCHEMY_API_KEY;
const chain =
[foundry, mainnet, sepolia].find((c) => c.id == chainId) || foundry;
[foundry, mainnet, sepolia, optimism, optimismSepolia].find(
(c) => c.id == chainId,
) || foundry;

const projectId = "a6265c875f8a7513ac7c52362abf434b";

Expand Down Expand Up @@ -66,6 +74,8 @@ const CustomAvatar: AvatarComponent = ({ address, ensImage, size }) => {
const [defaultMainnetRpcUrl] = mainnet.rpcUrls.default.http;
const [defaultSepoliaRpcUrl] = sepolia.rpcUrls.default.http;
const [defaultFoundryRpcUrl] = foundry.rpcUrls.default.http;
const [defaultOptimismRpcUrl] = optimism.rpcUrls.default.http;
const [defaultOptimismSepoliaRpcUrl] = optimismSepolia.rpcUrls.default.http;

const wagmiConfig = createConfig({
ssr: true,
Expand All @@ -85,6 +95,18 @@ const wagmiConfig = createConfig({
])
: http(defaultSepoliaRpcUrl),
[foundry.id]: http(defaultFoundryRpcUrl),
[optimism.id]: alchemyApiKey
? fallback([
http(`https://opt-mainnet.g.alchemy.com/v2/${alchemyApiKey}`),
http(defaultOptimismRpcUrl),
])
: http(defaultOptimismRpcUrl),
[optimismSepolia.id]: alchemyApiKey
? fallback([
http(`https://opt-sepolia.g.alchemy.com/v2/${alchemyApiKey}`),
http(defaultOptimismSepoliaRpcUrl),
])
: http(defaultOptimismSepoliaRpcUrl),
},
});

Expand Down

0 comments on commit 6cc6005

Please sign in to comment.