11"use client" ;
22
3- import { createContext , useContext , ReactNode } from "react" ;
3+ import { createContext , useContext , ReactNode , useCallback } from "react" ;
44import type { ClobClient } from "@polymarket/clob-client" ;
55import type { RelayClient } from "@polymarket/builder-relayer-client" ;
66import { useWallet } from "./WalletContext" ;
77import useClobClient from "@/hooks/useClobClient" ;
88import useTradingSession from "@/hooks/useTradingSession" ;
99import useSafeDeployment from "@/hooks/useSafeDeployment" ;
10+ import useGeoblock , { GeoblockStatus } from "@/hooks/useGeoblock" ;
1011import { TradingSession , SessionStep } from "@/utils/session" ;
1112
1213interface TradingContextType {
@@ -20,6 +21,9 @@ interface TradingContextType {
2021 relayClient : RelayClient | null ;
2122 eoaAddress : string | undefined ;
2223 safeAddress : string | undefined ;
24+ isGeoblocked : boolean ;
25+ isGeoblockLoading : boolean ;
26+ geoblockStatus : GeoblockStatus | null ;
2327}
2428
2529const TradingContext = createContext < TradingContextType | null > ( null ) ;
@@ -34,12 +38,18 @@ export default function TradingProvider({ children }: { children: ReactNode }) {
3438 const { eoaAddress } = useWallet ( ) ;
3539 const { derivedSafeAddressFromEoa } = useSafeDeployment ( eoaAddress ) ;
3640
41+ const {
42+ isBlocked : isGeoblocked ,
43+ isLoading : isGeoblockLoading ,
44+ geoblockStatus,
45+ } = useGeoblock ( ) ;
46+
3747 const {
3848 tradingSession,
3949 currentStep,
4050 sessionError,
4151 isTradingSessionComplete,
42- initializeTradingSession,
52+ initializeTradingSession : initSession ,
4353 endTradingSession,
4454 relayClient,
4555 } = useTradingSession ( ) ;
@@ -49,6 +59,15 @@ export default function TradingProvider({ children }: { children: ReactNode }) {
4959 isTradingSessionComplete
5060 ) ;
5161
62+ const initializeTradingSession = useCallback ( async ( ) => {
63+ if ( isGeoblocked ) {
64+ throw new Error (
65+ "Trading is not available in your region. Polymarket is geoblocked in your location."
66+ ) ;
67+ }
68+ return initSession ( ) ;
69+ } , [ isGeoblocked , initSession ] ) ;
70+
5271 return (
5372 < TradingContext . Provider
5473 value = { {
@@ -62,6 +81,9 @@ export default function TradingProvider({ children }: { children: ReactNode }) {
6281 relayClient,
6382 eoaAddress,
6483 safeAddress : derivedSafeAddressFromEoa ,
84+ isGeoblocked,
85+ isGeoblockLoading,
86+ geoblockStatus,
6587 } }
6688 >
6789 { children }
0 commit comments