@@ -16,6 +16,7 @@ import { createContext, useEffect, useState } from 'react';
16
16
import { base } from 'wagmi/chains' ;
17
17
18
18
type State = {
19
+ isInitialized : boolean ;
19
20
activeComponent ?: OnchainKitComponent ;
20
21
setActiveComponent ?: ( component : OnchainKitComponent ) => void ;
21
22
chainId ?: number ;
@@ -40,7 +41,8 @@ type State = {
40
41
isSponsored ?: boolean ;
41
42
} ;
42
43
43
- const defaultState : State = {
44
+ export const defaultState : State = {
45
+ isInitialized : false ,
44
46
activeComponent : OnchainKitComponent . Transaction ,
45
47
chainId : base . id ,
46
48
componentTheme : 'default' ,
@@ -54,6 +56,8 @@ const defaultState: State = {
54
56
export const AppContext = createContext ( defaultState ) ;
55
57
56
58
export const AppProvider = ( { children } : { children : React . ReactNode } ) => {
59
+ const [ isInitialized , setIsInitialized ] = useState ( false ) ;
60
+
57
61
const [ activeComponent , setActiveComponent ] =
58
62
useStateWithStorage < OnchainKitComponent > ( {
59
63
key : 'activeComponent' ,
@@ -63,7 +67,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
63
67
const [ componentTheme , setComponentTheme ] =
64
68
useStateWithStorage < ComponentTheme > ( {
65
69
key : 'componentTheme' ,
66
- defaultValue : 'none' ,
70
+ defaultValue : defaultState . componentTheme ,
67
71
} ) ;
68
72
69
73
const [ componentMode , setComponentMode ] = useStateWithStorage < ComponentMode > ( {
@@ -123,6 +127,9 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
123
127
if ( storedPaymasters ) {
124
128
setPaymastersState ( JSON . parse ( storedPaymasters ) ) ;
125
129
}
130
+
131
+ // Wait for all useStateWithStorage hooks to initialize
132
+ setIsInitialized ( true ) ;
126
133
} , [ ] ) ;
127
134
128
135
const setPaymaster = ( chainId : number , url : string , enabled : boolean ) => {
@@ -137,6 +144,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
137
144
return (
138
145
< AppContext . Provider
139
146
value = { {
147
+ isInitialized,
140
148
activeComponent,
141
149
setActiveComponent,
142
150
chainId,
0 commit comments