File tree 3 files changed +21
-11
lines changed
3 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ function AppRouter(props: Props) {
49
49
const routeContext = useContext ( RouteContext ) ;
50
50
51
51
const hasSetSsgConfig = useRef ( false ) ;
52
+ const isInitialLoad = useRef ( true ) ;
52
53
53
54
// We update the global config once when WormholeConnect is first mounted, if a custom
54
55
// config was provided.
@@ -60,8 +61,9 @@ function AppRouter(props: Props) {
60
61
setConfig ( customConfig ) ;
61
62
}
62
63
64
+ hasSetSsgConfig . current = true ;
63
65
config . triggerEvent ( {
64
- type : 'load ' ,
66
+ type : 'config ' ,
65
67
config : customConfig ,
66
68
} ) ;
67
69
} , [ ] ) ;
@@ -71,12 +73,20 @@ function AppRouter(props: Props) {
71
73
if ( props . config ) {
72
74
loadConfig ( props . config ) ;
73
75
}
74
- hasSetSsgConfig . current = true ;
75
76
}
76
77
77
78
useEffect ( ( ) => {
78
- if ( props . config ) {
79
- loadConfig ( props . config ) ;
79
+ if ( isInitialLoad . current ) {
80
+ isInitialLoad . current = false ;
81
+
82
+ config . triggerEvent ( {
83
+ type : 'load' ,
84
+ config : props . config ,
85
+ } ) ;
86
+ } else {
87
+ if ( props . config ) {
88
+ loadConfig ( props . config ) ;
89
+ }
80
90
}
81
91
} , [ props . config ] ) ;
82
92
// END config loading code
Original file line number Diff line number Diff line change @@ -146,7 +146,6 @@ function DemoApp() {
146
146
const [ customConfigInput , setCustomConfigInput ] = useState (
147
147
loadInitialConfig ( ) ,
148
148
) ;
149
- const [ customConfigNonce , setCustomConfigNonce ] = useState ( 1 ) ;
150
149
const [ isLoadingCustomConfig , setIsLoadingCustomConfig ] = useState ( true ) ;
151
150
152
151
const [ customTheme , setCustomTheme ] = useState <
@@ -168,7 +167,6 @@ function DemoApp() {
168
167
try {
169
168
const parsed = parseConfig ( customConfigInput ) ;
170
169
setCustomConfig ( parsed ) ;
171
- setCustomConfigNonce ( customConfigNonce + 1 ) ;
172
170
} catch ( e ) {
173
171
console . error ( e ) ;
174
172
}
@@ -206,11 +204,7 @@ function DemoApp() {
206
204
< article >
207
205
< div id = "demo-contents" >
208
206
{ ! isLoadingCustomConfig && (
209
- < WormholeConnect
210
- key = { customConfigNonce }
211
- config = { customConfig }
212
- theme = { customTheme }
213
- />
207
+ < WormholeConnect config = { customConfig } theme = { customTheme } />
214
208
) }
215
209
</ div >
216
210
Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ export interface LoadEvent {
7
7
config ?: WormholeConnectConfig ;
8
8
}
9
9
10
+ export interface UpdateConfigEvent {
11
+ type : 'config' ;
12
+ config ?: WormholeConnectConfig ;
13
+ }
14
+
10
15
export interface TransferDetails {
11
16
route : string ;
12
17
fromToken : TokenDetails ;
@@ -91,6 +96,7 @@ export interface ConnectWalletEvent {
91
96
92
97
export type WormholeConnectEventCore =
93
98
| LoadEvent
99
+ | UpdateConfigEvent
94
100
| TransferEvent
95
101
| TransferErrorEvent
96
102
| ConnectWalletEvent ;
You can’t perform that action at this time.
0 commit comments