@@ -20,24 +20,30 @@ export function SafeSdkProvider({ children }: { children: ReactNode }) {
2020 const { address } = useAccount ( ) ;
2121 const { data : walletClient } = useWalletClient ( ) ;
2222 const chainId = useChainId ( ) ;
23+ const [ mounted , setMounted ] = useState ( false ) ;
2324
24- const isConnected = ! ! address ;
25+ useEffect ( ( ) => {
26+ setMounted ( true ) ;
27+ } , [ ] ) ;
28+
29+ const isConnected = mounted && ! ! address ;
2530
2631 const safeApiService = useMemo ( ( ) => {
27- if ( isConnected && chainId ) {
32+ if ( mounted && isConnected && chainId ) {
2833 return new SafeApiService ( {
2934 chainId : chainId as number ,
3035 apiKey : process . env . NEXT_PUBLIC_SAFE_GLOBAL_API_KEY || '' ,
3136 } ) ;
3237 }
3338 return null ;
34- } , [ isConnected , chainId ] ) ;
39+ } , [ mounted , isConnected , chainId ] ) ;
3540
3641 const [ safeClient , setSafeClient ] = useState < SafeClient | null > ( null ) ;
3742 const [ safeAccountAddresses , setSafeAccountAddresses ] = useState < string [ ] > ( [ ] ) ;
3843 const [ selectedSafeAccountAddress , setSelectedSafeAccountAddress ] = useState < string | null > ( null ) ;
3944
4045 useEffect ( ( ) => {
46+ if ( ! mounted ) return ;
4147 if ( safeApiService && address ) {
4248 safeApiService . getSafesByOwner ( address ) . then ( ( response ) => {
4349 const safes = response . safes || [ ] ;
@@ -51,15 +57,16 @@ export function SafeSdkProvider({ children }: { children: ReactNode }) {
5157 } else {
5258 cleanSafeContext ( ) ;
5359 }
54- } , [ safeApiService , address ] ) ;
60+ } , [ mounted , safeApiService , address ] ) ;
5561
5662 useEffect ( ( ) => {
63+ if ( ! mounted ) return ;
5764 if ( selectedSafeAccountAddress ) {
5865 createSafeClientByExistSafeAccount ( ) ;
5966 } else {
6067 setSafeClient ( null ) ;
6168 }
62- } , [ selectedSafeAccountAddress ] ) ;
69+ } , [ mounted , selectedSafeAccountAddress ] ) ;
6370
6471 const createSafeClientByExistSafeAccount = async ( ) => {
6572 try {
0 commit comments