Skip to content

Commit

Permalink
Merge pull request #16 from dynamic-labs/chore/networks
Browse files Browse the repository at this point in the history
chore: cleanup network config
  • Loading branch information
matthew1809 authored Jul 9, 2024
2 parents 2bbb10b + ce7360a commit 8d0d692
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
22 changes: 1 addition & 21 deletions packages/nextjs/components/ScaffoldEthAppWithProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,14 @@ export const queryClient = new QueryClient({
export const ScaffoldEthAppWithProviders = ({ children }: { children: React.ReactNode }) => {
const { resolvedTheme } = useTheme();

/**
* For more information on the `evmNetworks` object, see:
* https://docs.dynamic.xyz/chains/evmNetwork#custom-evm-networks-evmnetwork
*/

const evmNetworks = [
...scaffoldConfig.targetNetworks.map(chain => ({
blockExplorerUrls: chain.blockExplorers
? Object.values(chain.blockExplorers as any).map(({ url }: any) => url)
: [],
chainId: chain.id,
name: chain.name,
rpcUrls: Object.values(chain.rpcUrls).map(({ http }) => http[0]),
iconUrls: [],
nativeCurrency: chain.nativeCurrency,
networkId: chain.id,
})),
...customEvmNetworks,
];

return (
<DynamicContextProvider
theme={resolvedTheme === "dark" ? "dark" : "light"}
settings={{
environmentId: scaffoldConfig.dynamicEnvId,
walletConnectors: [EthereumWalletConnectors],
overrides: {
evmNetworks: networks => mergeNetworks(evmNetworks, networks),
evmNetworks: networks => mergeNetworks(customEvmNetworks, networks),
},
}}
>
Expand Down
13 changes: 4 additions & 9 deletions packages/nextjs/services/web3/wagmiConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { getOrMapViemChain } from "@dynamic-labs/viem-utils";
import { Chain, createClient, http } from "viem";
import { hardhat, mainnet } from "viem/chains";
import { baseSepolia, hardhat, mainnet } from "viem/chains";
import { createConfig } from "wagmi";
import { customEvmNetworks } from "~~/lib/networks";
import scaffoldConfig from "~~/scaffold.config";
import { getAlchemyHttpUrl } from "~~/utils/scaffold-eth";

const { targetNetworks } = scaffoldConfig;

// We always want to have mainnet enabled (ENS resolution, ETH price, etc). But only once.
export const enabledChains = targetNetworks.find((network: Chain) => network.id === 1)
? targetNetworks
: ([...targetNetworks, mainnet] as const);

export const wagmiConfig = createConfig({
chains: enabledChains,
chains: [baseSepolia, mainnet, ...customEvmNetworks.map(getOrMapViemChain)],
ssr: true,
client({ chain }) {
return createClient({
Expand Down

0 comments on commit 8d0d692

Please sign in to comment.