Skip to content

Commit

Permalink
chore: restructure wallet arragement
Browse files Browse the repository at this point in the history
  • Loading branch information
Adebesin-Cell committed Nov 26, 2024
1 parent 73bb045 commit 316319f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-geese-grow.md
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
138 changes: 67 additions & 71 deletions src/components/iq-login-provider.tsx
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>
);
}

0 comments on commit 316319f

Please sign in to comment.