Skip to content

Commit d5377d9

Browse files
authored
dont trigger load event twice (#3356)
1 parent 734e3e2 commit d5377d9

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

wormhole-connect/src/AppRouter.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function AppRouter(props: Props) {
4949
const routeContext = useContext(RouteContext);
5050

5151
const hasSetSsgConfig = useRef(false);
52+
const isInitialLoad = useRef(true);
5253

5354
// We update the global config once when WormholeConnect is first mounted, if a custom
5455
// config was provided.
@@ -60,8 +61,9 @@ function AppRouter(props: Props) {
6061
setConfig(customConfig);
6162
}
6263

64+
hasSetSsgConfig.current = true;
6365
config.triggerEvent({
64-
type: 'load',
66+
type: 'config',
6567
config: customConfig,
6668
});
6769
}, []);
@@ -71,12 +73,20 @@ function AppRouter(props: Props) {
7173
if (props.config) {
7274
loadConfig(props.config);
7375
}
74-
hasSetSsgConfig.current = true;
7576
}
7677

7778
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+
}
8090
}
8191
}, [props.config]);
8292
// END config loading code

wormhole-connect/src/components/DemoApp/index.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ function DemoApp() {
146146
const [customConfigInput, setCustomConfigInput] = useState(
147147
loadInitialConfig(),
148148
);
149-
const [customConfigNonce, setCustomConfigNonce] = useState(1);
150149
const [isLoadingCustomConfig, setIsLoadingCustomConfig] = useState(true);
151150

152151
const [customTheme, setCustomTheme] = useState<
@@ -168,7 +167,6 @@ function DemoApp() {
168167
try {
169168
const parsed = parseConfig(customConfigInput);
170169
setCustomConfig(parsed);
171-
setCustomConfigNonce(customConfigNonce + 1);
172170
} catch (e) {
173171
console.error(e);
174172
}
@@ -206,11 +204,7 @@ function DemoApp() {
206204
<article>
207205
<div id="demo-contents">
208206
{!isLoadingCustomConfig && (
209-
<WormholeConnect
210-
key={customConfigNonce}
211-
config={customConfig}
212-
theme={customTheme}
213-
/>
207+
<WormholeConnect config={customConfig} theme={customTheme} />
214208
)}
215209
</div>
216210

wormhole-connect/src/telemetry/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export interface LoadEvent {
77
config?: WormholeConnectConfig;
88
}
99

10+
export interface UpdateConfigEvent {
11+
type: 'config';
12+
config?: WormholeConnectConfig;
13+
}
14+
1015
export interface TransferDetails {
1116
route: string;
1217
fromToken: TokenDetails;
@@ -91,6 +96,7 @@ export interface ConnectWalletEvent {
9196

9297
export type WormholeConnectEventCore =
9398
| LoadEvent
99+
| UpdateConfigEvent
94100
| TransferEvent
95101
| TransferErrorEvent
96102
| ConnectWalletEvent;

0 commit comments

Comments
 (0)