Skip to content

Commit

Permalink
Bepro 2257 support to develop locally with a ganache network (#508)
Browse files Browse the repository at this point in the history
* add localhost to supported chains

* use polygon as default chain

* get initial chain from config

* fix: only allow ganache if is dev environment
  • Loading branch information
vhcsilva authored Sep 6, 2024
1 parent d9eff39 commit b8791fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
21 changes: 17 additions & 4 deletions contexts/wagmi-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {getDefaultConfig} from "@rainbow-me/rainbowkit";
import getConfig from "next/config";
import {parseCookies} from "nookies";
import {defineChain} from "viem";
import {aurora, auroraTestnet, mainnet, moonbeam, polygon, polygonAmoy, polygonMumbai} from "viem/chains";
import {aurora, auroraTestnet, mainnet, moonbeam, polygon, polygonAmoy, polygonMumbai, localhost} from "viem/chains";
import {cookieStorage, cookieToInitialState, createStorage, WagmiProvider} from "wagmi";

interface WagmiProps {
Expand All @@ -30,18 +30,31 @@ const coinEx = defineChain({
}
});

const ganache = defineChain({
...localhost,
blockExplorers: {
default: {
name: "Local",
url: "http://127.0.0.1:8545",
}
}
});

const config = getDefaultConfig({
appName: "BEPRO",
projectId: publicRuntimeConfig?.walletConnectProjectId || "bc2288336095f20ebf8653a1ab670566",
chains: [
polygon,
polygonAmoy,
polygonMumbai,
aurora,
auroraTestnet,
moonbeam,
coinEx,
mainnet,
polygonAmoy,
polygonMumbai,
auroraTestnet,
... (publicRuntimeConfig?.isProduction ? [] : [
ganache,
])
],
ssr: true,
storage: createStorage({
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const publicRuntimeConfig = {
},
walletConnectProjectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID,
defaultChain: {
id: process.env.NEXT_PUBLIC_NEEDS_CHAIN_ID,
id: +process.env.NEXT_PUBLIC_NEEDS_CHAIN_ID || 137,
name: process.env.NEXT_PUBLIC_NEEDS_CHAIN_NAME,
nativeToken: process.env.NEXT_PUBLIC_NATIVE_TOKEN_NAME,
blockscan: process.env.NEXT_PUBLIC_BLOCKSCAN_LINK,
Expand Down
3 changes: 1 addition & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {appWithTranslation} from "next-i18next";
import getConfig from "next/config";
import {useRouter} from "next/router";
import {GoogleAnalytics} from "nextjs-google-analytics";
import {polygon} from "viem/chains";

import ConsentCookie from "components/consent-cokie";
import Loading from "components/loading";
Expand Down Expand Up @@ -43,7 +42,7 @@ function App({ Component, pageProps: { session, seoData, ...pageProps } }) {
<QueryClientProvider client={queryClient}>
<GoogleAnalytics gaMeasurementId={publicRuntimeConfig.gaMeasureID} trackPageViews />
<SessionProvider session={session}>
<RainbowKitProvider initialChain={polygon}>
<RainbowKitProvider initialChain={publicRuntimeConfig?.defaultChain?.id}>
<AuthenticationProvider>
<RootProviders>
<HydrationBoundary state={pageProps.dehydratedState}>
Expand Down

0 comments on commit b8791fe

Please sign in to comment.