From 44d5acabeac3565031ccf0a2244e0595fc133972 Mon Sep 17 00:00:00 2001 From: Diego Zacarias Date: Thu, 31 Oct 2024 07:29:37 -0600 Subject: [PATCH] feat: config service as param - Looks for the configUrl parameter in the query string to use it as a custom ConfigService URL. - Uses the hardcoded ConfigService URL as a fallback if the parameter is not present. --- src/hooks/useChains.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hooks/useChains.ts b/src/hooks/useChains.ts index adc3c64..6f5300f 100644 --- a/src/hooks/useChains.ts +++ b/src/hooks/useChains.ts @@ -37,9 +37,21 @@ export const useLoadChains = () => { }, [chains, dispatch]); }; +const useConfigService = () => { + const configUrl = useMemo(() => { + const urlParams = new URLSearchParams(window.location.search); + const configParam = urlParams.get("configUrl"); + return configParam || CONFIG_SERVICE_URL; + }, []); + + return configUrl; +}; + const useChains = () => { + const configUrl = useConfigService(); + const { data: chainConfigs, isLoading } = useSwr("chains", async (): Promise => { - const result = await fetch(CONFIG_SERVICE_URL).then((resp) => { + const result = await fetch(configUrl).then((resp) => { if (resp.ok) { return resp.json() as Promise; }