otterscan/src/useConfig.ts
2021-07-09 14:13:31 -03:00

29 lines
701 B
TypeScript

import { useState, useEffect } from "react";
export type OtterscanConfig = {
erigonURL?: string;
assetsURLPrefix?: string;
};
export const useConfig = (): [boolean?, OtterscanConfig?] => {
const [configOK, setConfigOK] = useState<boolean>();
const [config, setConfig] = useState<OtterscanConfig>();
useEffect(() => {
const readConfig = async () => {
const res = await fetch("/config.json");
if (res.ok) {
const _config: OtterscanConfig = await res.json();
console.info("Loaded app config");
console.info(_config);
setConfig(_config);
setConfigOK(res.ok);
}
};
readConfig();
}, []);
return [configOK, config];
};