|
1 | 1 | "use client" |
2 | 2 |
|
| 3 | +import { getDefaultConfig, RainbowKitProvider } from '@rainbow-me/rainbowkit' |
| 4 | +import { WagmiProvider } from 'wagmi' |
| 5 | +import { base } from 'wagmi/chains' |
| 6 | +import { QueryClientProvider, QueryClient } from '@tanstack/react-query' |
| 7 | +import '@rainbow-me/rainbowkit/styles.css' |
| 8 | +import { useEffect, useState } from 'react' |
3 | 9 | import type { ReactNode } from "react" |
4 | 10 |
|
| 11 | +// Create a fallback config for SSR |
| 12 | +const createConfig = () => { |
| 13 | + if (typeof window === 'undefined') { |
| 14 | + // Return a minimal config for SSR |
| 15 | + return null |
| 16 | + } |
| 17 | + |
| 18 | + return getDefaultConfig({ |
| 19 | + appName: 'Pyth Entropy NFT Demo', |
| 20 | + projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID || 'demo-project-id', |
| 21 | + chains: [base], |
| 22 | + ssr: false, |
| 23 | + }) |
| 24 | +} |
| 25 | + |
| 26 | +const createQueryClient = () => { |
| 27 | + return new QueryClient({ |
| 28 | + defaultOptions: { |
| 29 | + queries: { |
| 30 | + refetchOnWindowFocus: false, |
| 31 | + retry: false, |
| 32 | + staleTime: 1000 * 60 * 5, // 5 minutes |
| 33 | + }, |
| 34 | + }, |
| 35 | + }) |
| 36 | +} |
| 37 | + |
5 | 38 | export function Providers({ children }: { children: ReactNode }) { |
6 | | - return <>{children}</> |
| 39 | + const [mounted, setMounted] = useState(false) |
| 40 | + const [config, setConfig] = useState<ReturnType<typeof getDefaultConfig> | null>(null) |
| 41 | + const [queryClient] = useState(() => createQueryClient()) |
| 42 | + |
| 43 | + useEffect(() => { |
| 44 | + // Only initialize on client side |
| 45 | + if (typeof window !== 'undefined') { |
| 46 | + setConfig(createConfig()) |
| 47 | + setMounted(true) |
| 48 | + } |
| 49 | + }, []) |
| 50 | + |
| 51 | + // Show loading state during hydration |
| 52 | + if (!mounted || !config) { |
| 53 | + return ( |
| 54 | + <div className="min-h-screen flex items-center justify-center"> |
| 55 | + <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"></div> |
| 56 | + </div> |
| 57 | + ) |
| 58 | + } |
| 59 | + |
| 60 | + return ( |
| 61 | + <WagmiProvider config={config}> |
| 62 | + <QueryClientProvider client={queryClient}> |
| 63 | + <RainbowKitProvider |
| 64 | + initialChain={base} |
| 65 | + showRecentTransactions={true} |
| 66 | + > |
| 67 | + {children} |
| 68 | + </RainbowKitProvider> |
| 69 | + </QueryClientProvider> |
| 70 | + </WagmiProvider> |
| 71 | + ) |
7 | 72 | } |
0 commit comments