Skip to content

Commit

Permalink
feat: config service as param
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
zach88 committed Oct 31, 2024
1 parent 0b71bcf commit 44d5aca
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/hooks/useChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkInfo[]> => {
const result = await fetch(CONFIG_SERVICE_URL).then((resp) => {
const result = await fetch(configUrl).then((resp) => {
if (resp.ok) {
return resp.json() as Promise<ChainEndpointResponse>;
}
Expand Down

0 comments on commit 44d5aca

Please sign in to comment.