-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: restructure wallet arragement
- Loading branch information
1 parent
73bb045
commit 316319f
Showing
2 changed files
with
72 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@everipedia/iq-login": minor | ||
--- | ||
|
||
Removes default wallets and retained only metamask and web3auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,93 @@ | ||
import { getDefaultConfig, RainbowKitProvider } from '@rainbow-me/rainbowkit'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import type React from 'react'; | ||
import { cookieToInitialState, WagmiProvider } from 'wagmi'; | ||
import { polygon } from 'wagmi/chains'; | ||
import { iqTestnet } from '../lib/data/iq-testnet'; | ||
import { iqWikiTheme } from '../lib/data/rainbow-kit-theme'; | ||
import { | ||
getDefaultConfig, | ||
getDefaultWallets, | ||
RainbowKitProvider, | ||
} from "@rainbow-me/rainbowkit"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import type React from "react"; | ||
import { cookieToInitialState, WagmiProvider } from "wagmi"; | ||
import { polygon } from "wagmi/chains"; | ||
import { iqTestnet } from "../lib/data/iq-testnet"; | ||
import { iqWikiTheme } from "../lib/data/rainbow-kit-theme"; | ||
import { | ||
rainbowWeb3AuthConnector, | ||
createWeb3AuthInstance, | ||
} from "../lib/integrations/web3-auth-connector"; | ||
import { structuralSharing } from "@wagmi/core/query"; | ||
import { Web3AuthProvider } from "./web3-auth-provider"; | ||
rainbowWeb3AuthConnector, | ||
createWeb3AuthInstance | ||
} from '../lib/integrations/web3-auth-connector'; | ||
import { structuralSharing } from '@wagmi/core/query'; | ||
import { Web3AuthProvider } from './web3-auth-provider'; | ||
import { metaMaskWallet } from '@rainbow-me/rainbowkit/wallets'; | ||
|
||
if (!process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID) { | ||
throw new Error("NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID is not set"); | ||
throw new Error('NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID is not set'); | ||
} | ||
if (!process.env.NEXT_PUBLIC_IS_PRODUCTION) { | ||
console.log("NEXT_PUBLIC_IS_PRODUCTION is not set"); | ||
console.log('NEXT_PUBLIC_IS_PRODUCTION is not set'); | ||
} | ||
|
||
const chain = | ||
process.env.NEXT_PUBLIC_IS_PRODUCTION === "true" ? polygon : iqTestnet; | ||
process.env.NEXT_PUBLIC_IS_PRODUCTION === 'true' ? polygon : iqTestnet; | ||
const web3AuthInstance = createWeb3AuthInstance(chain); | ||
|
||
export const defaultConfig = getDefaultConfig({ | ||
appName: "IQ.wiki", | ||
projectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID, | ||
chains: [chain], | ||
wallets: [ | ||
...getDefaultWallets({ | ||
appName: "IQ.wiki", | ||
projectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID, | ||
}).wallets, | ||
{ | ||
groupName: "More", | ||
wallets: [() => rainbowWeb3AuthConnector({ web3AuthInstance })], | ||
}, | ||
], | ||
multiInjectedProviderDiscovery: false, | ||
ssr: true, | ||
appName: 'IQ.wiki', | ||
projectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID, | ||
chains: [chain], | ||
wallets: [ | ||
{ | ||
groupName: 'Recommended', | ||
wallets: [ | ||
() => rainbowWeb3AuthConnector({ web3AuthInstance }), | ||
metaMaskWallet | ||
] | ||
} | ||
], | ||
multiInjectedProviderDiscovery: false, | ||
ssr: true | ||
}); | ||
|
||
function makeQueryClient() { | ||
return new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
structuralSharing, | ||
}, | ||
}, | ||
}); | ||
return new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
structuralSharing | ||
} | ||
} | ||
}); | ||
} | ||
|
||
let browserQueryClient: QueryClient | undefined = undefined; | ||
|
||
function getQueryClient() { | ||
if (typeof window === "undefined") { | ||
// Server: always make a new query client | ||
return makeQueryClient(); | ||
} | ||
// Browser: make a new query client if we don't already have one | ||
// This is very important so we don't re-make a new client if React | ||
// suspends during the initial render. This may not be needed if we | ||
// have a suspense boundary BELOW the creation of the query client | ||
if (!browserQueryClient) browserQueryClient = makeQueryClient(); | ||
return browserQueryClient; | ||
if (typeof window === 'undefined') { | ||
// Server: always make a new query client | ||
return makeQueryClient(); | ||
} | ||
// Browser: make a new query client if we don't already have one | ||
// This is very important so we don't re-make a new client if React | ||
// suspends during the initial render. This may not be needed if we | ||
// have a suspense boundary BELOW the creation of the query client | ||
if (!browserQueryClient) browserQueryClient = makeQueryClient(); | ||
return browserQueryClient; | ||
} | ||
|
||
export function IqLoginProvider({ | ||
children, | ||
cookie, | ||
children, | ||
cookie | ||
}: { | ||
children: React.ReactNode; | ||
cookie?: string; | ||
children: React.ReactNode; | ||
cookie?: string; | ||
}) { | ||
const queryClient = getQueryClient(); | ||
const initialStates = cookieToInitialState(defaultConfig, cookie); | ||
const queryClient = getQueryClient(); | ||
const initialStates = cookieToInitialState(defaultConfig, cookie); | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<WagmiProvider config={defaultConfig} initialState={initialStates}> | ||
<RainbowKitProvider theme={iqWikiTheme}> | ||
<Web3AuthProvider web3AuthInstance={web3AuthInstance}> | ||
{children} | ||
</Web3AuthProvider> | ||
</RainbowKitProvider> | ||
</WagmiProvider> | ||
</QueryClientProvider> | ||
); | ||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<WagmiProvider config={defaultConfig} initialState={initialStates}> | ||
<RainbowKitProvider theme={iqWikiTheme}> | ||
<Web3AuthProvider web3AuthInstance={web3AuthInstance}> | ||
{children} | ||
</Web3AuthProvider> | ||
</RainbowKitProvider> | ||
</WagmiProvider> | ||
</QueryClientProvider> | ||
); | ||
} |