networkcontext.tsx
1 "use client" 2 import { createContext, useContext, ReactNode } from 'react' 3 import { getCurrentNetwork } from '@/services/api/main' 4 interface NetCtx { 5 currentNetwork: 'mainnet' 6 networkInfo: { 7 name: string 8 apiBaseUrl: string 9 apiVersion: string 10 wsBaseUrl: string 11 scanBaseUrl: string 12 webWorkerUrl: string 13 } 14 } 15 16 const NetContext = createContext<NetCtx | undefined>(undefined) 17 18 interface NetProviderProps { 19 children: ReactNode 20 } 21 22 export function NetworkProvider({ children }: NetProviderProps) { 23 const currentNetwork = 'mainnet' 24 const networkInfo = getCurrentNetwork() 25 26 return ( 27 <NetContext.Provider value={{ 28 currentNetwork, 29 networkInfo 30 }}> 31 {children} 32 </NetContext.Provider> 33 ) 34 } 35 36 export function useNetwork() { 37 const context = useContext(NetContext) 38 if (context === undefined) { 39 throw new Error('useNetwork must be used within a NetworkProvider') 40 } 41 return context 42 }