-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7392b37
commit 8e96a48
Showing
6 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const api = { | ||
baseUrl: 'http://127.0.0.1:8080', | ||
endpoints: { | ||
chain: '/chain_registry', | ||
assets: '/chain_registry_assets', | ||
}, | ||
}; | ||
|
||
export const SPAWN_API_BASE_URL = api.baseUrl; | ||
export const SPAWN_CHAIN_URL = `${api.baseUrl}${api.endpoints.chain}`; | ||
export const SPAWN_ASSETS_URL = `${api.baseUrl}${api.endpoints.assets}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
examples/chain-template-spawn/hooks/common/useSpawnChains.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { AssetList, Chain } from '@chain-registry/types'; | ||
|
||
import { SPAWN_CHAIN_URL, SPAWN_ASSETS_URL } from '@/config'; | ||
|
||
export const useSpawnChains = () => { | ||
return useQuery({ | ||
queryKey: ['spawn-chains'], | ||
queryFn: async () => { | ||
try { | ||
const [spawnChain, spawnAssets] = await Promise.all([ | ||
fetcher<Chain>(SPAWN_CHAIN_URL), | ||
fetcher<AssetList>(SPAWN_ASSETS_URL), | ||
]); | ||
|
||
return { | ||
chains: spawnChain ? [spawnChain] : [], | ||
assets: spawnAssets ? [spawnAssets] : [], | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
return undefined; | ||
} | ||
}, | ||
staleTime: Infinity, | ||
cacheTime: Infinity, | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
}); | ||
}; | ||
|
||
const fetcher = async <T>(url: string): Promise<T | null> => { | ||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
return data; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters