Skip to content

Commit b8791fe

Browse files
authored
Bepro 2257 support to develop locally with a ganache network (#508)
* add localhost to supported chains * use polygon as default chain * get initial chain from config * fix: only allow ganache if is dev environment
1 parent d9eff39 commit b8791fe

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

contexts/wagmi-provider.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {getDefaultConfig} from "@rainbow-me/rainbowkit";
44
import getConfig from "next/config";
55
import {parseCookies} from "nookies";
66
import {defineChain} from "viem";
7-
import {aurora, auroraTestnet, mainnet, moonbeam, polygon, polygonAmoy, polygonMumbai} from "viem/chains";
7+
import {aurora, auroraTestnet, mainnet, moonbeam, polygon, polygonAmoy, polygonMumbai, localhost} from "viem/chains";
88
import {cookieStorage, cookieToInitialState, createStorage, WagmiProvider} from "wagmi";
99

1010
interface WagmiProps {
@@ -30,18 +30,31 @@ const coinEx = defineChain({
3030
}
3131
});
3232

33+
const ganache = defineChain({
34+
...localhost,
35+
blockExplorers: {
36+
default: {
37+
name: "Local",
38+
url: "http://127.0.0.1:8545",
39+
}
40+
}
41+
});
42+
3343
const config = getDefaultConfig({
3444
appName: "BEPRO",
3545
projectId: publicRuntimeConfig?.walletConnectProjectId || "bc2288336095f20ebf8653a1ab670566",
3646
chains: [
3747
polygon,
38-
polygonAmoy,
39-
polygonMumbai,
4048
aurora,
41-
auroraTestnet,
4249
moonbeam,
4350
coinEx,
4451
mainnet,
52+
polygonAmoy,
53+
polygonMumbai,
54+
auroraTestnet,
55+
... (publicRuntimeConfig?.isProduction ? [] : [
56+
ganache,
57+
])
4558
],
4659
ssr: true,
4760
storage: createStorage({

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const publicRuntimeConfig = {
3232
},
3333
walletConnectProjectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID,
3434
defaultChain: {
35-
id: process.env.NEXT_PUBLIC_NEEDS_CHAIN_ID,
35+
id: +process.env.NEXT_PUBLIC_NEEDS_CHAIN_ID || 137,
3636
name: process.env.NEXT_PUBLIC_NEEDS_CHAIN_NAME,
3737
nativeToken: process.env.NEXT_PUBLIC_NATIVE_TOKEN_NAME,
3838
blockscan: process.env.NEXT_PUBLIC_BLOCKSCAN_LINK,

pages/_app.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {appWithTranslation} from "next-i18next";
88
import getConfig from "next/config";
99
import {useRouter} from "next/router";
1010
import {GoogleAnalytics} from "nextjs-google-analytics";
11-
import {polygon} from "viem/chains";
1211

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

0 commit comments

Comments
 (0)