Skip to content

Commit

Permalink
fix: Fix async function name in config.ts and remove unnecessary catc…
Browse files Browse the repository at this point in the history
…h block
  • Loading branch information
samcm committed Jan 9, 2025
1 parent e29cde7 commit 3e17417
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/common/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const NETWORK_METADATA = {
} as const

export const NetworkSelector = ({ selectedNetwork, onNetworkChange }: Props) => {
const [config, setConfig] = useState<Config | null>(null)
const [config, setConfig] = useState<Config>()
const [isOpen, setIsOpen] = useState(false)

useEffect(() => {
getConfig().then(setConfig).catch(console.error)
getConfig().then(setConfig)
}, [])

const networks = config?.notebooks['xatu-public-contributors'].networks || ['mainnet']
Expand Down
26 changes: 18 additions & 8 deletions frontend/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ import yaml from 'js-yaml'
// Cache the config once loaded
let loadedConfig: Config | undefined

export async function loadConfig() {
export const getConfig = async (): Promise<Config> => {
// Return cached config if available
if (loadedConfig) {
return loadedConfig
}

// Fetch config from the appropriate location
try {
const response = await fetch('/config.yaml')

// In production, we get the raw YAML
if (import.meta.env.PROD) {
const yamlText = await response.text()
return yaml.load(yamlText)
if (!response.ok) {
throw new Error(`Failed to load config: ${response.statusText}`)
}

// In production, we get raw YAML
// In dev, we get JSON from our middleware
return await response.json()
const text = await response.text()
const data = import.meta.env.PROD
? yaml.load(text) as Config
: JSON.parse(text) as Config

loadedConfig = data
return loadedConfig
} catch (error) {
console.error('Failed to load config:', error)
console.error('Failed to load config:', error)
throw error
}
}
Expand Down

0 comments on commit 3e17417

Please sign in to comment.