From a8d40ff01f022a6be237b16aab7902eee0e351a8 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 21 Apr 2023 22:25:29 +0200 Subject: [PATCH 1/3] Add testnets to selector --- components/chainSelect/ChainSelect.tsx | 28 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/components/chainSelect/ChainSelect.tsx b/components/chainSelect/ChainSelect.tsx index 9ef95b4..189f718 100644 --- a/components/chainSelect/ChainSelect.tsx +++ b/components/chainSelect/ChainSelect.tsx @@ -41,7 +41,7 @@ const ChainSelect = () => { const { state, dispatch } = useAppContext(); // UI State - const [chainArray, setChainArray] = useState([]); + const [chainArray, setChainArray] = useState([]); const [chainOptions, setChainOptions] = useState([]); const [chainError, setChainError] = useState(null); const [showSettings, setShowSettings] = useState(false); @@ -61,20 +61,28 @@ const ChainSelect = () => { const [tempRegistryName, setRegistryName] = useState(state.chain.registryName); const [tempExplorerLink, setExplorerLink] = useState(state.chain.explorerLink); - const url = "https://api.github.com/repos/cosmos/chain-registry/contents"; + const chainsUrl = "https://api.github.com/repos/cosmos/chain-registry/contents"; + const testnetsUrl = "https://api.github.com/repos/cosmos/chain-registry/contents/testnets"; const getGhJson = useCallback(async () => { // getting chain info from this repo: https://github.com/cosmos/chain-registry try { - const res = await axios.get(url); - const chains = res.data.filter((item: GithubChainRegistryItem) => { - return item.type == "dir" && !item.name.startsWith(".") && item.name != "testnets"; - }); - setChainArray(chains); - const options = chains.map(({ name }: GithubChainRegistryItem, index: number) => { - return { label: name, value: index }; - }); + const { data: chains } = await axios.get(chainsUrl); + const { data: testnets } = await axios.get(testnetsUrl); + + const allChains: GithubChainRegistryItem[] = [...chains, ...testnets].filter( + (item: GithubChainRegistryItem) => { + return item.type == "dir" && !item.name.startsWith(".") && !item.name.startsWith("_"); + }, + ); + setChainArray(allChains); + + const options = allChains.map(({ name }: GithubChainRegistryItem, index: number) => ({ + label: name, + value: index, + })); setChainOptions(options); + assert(state.chain.registryName, "registryName missing"); setSelectValue(findExistingOption(options, state.chain.registryName)); // eslint-disable-next-line @typescript-eslint/no-explicit-any From cbc1f7b293140fecf1a305c32e3606a474a3a0ec Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 24 Apr 2023 22:23:51 +0200 Subject: [PATCH 2/3] Use Promise.all --- components/chainSelect/ChainSelect.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/chainSelect/ChainSelect.tsx b/components/chainSelect/ChainSelect.tsx index 189f718..bfa7fbf 100644 --- a/components/chainSelect/ChainSelect.tsx +++ b/components/chainSelect/ChainSelect.tsx @@ -67,8 +67,10 @@ const ChainSelect = () => { const getGhJson = useCallback(async () => { // getting chain info from this repo: https://github.com/cosmos/chain-registry try { - const { data: chains } = await axios.get(chainsUrl); - const { data: testnets } = await axios.get(testnetsUrl); + const [{ data: chains }, { data: testnets }] = await Promise.all([ + axios.get(chainsUrl), + axios.get(testnetsUrl), + ]); const allChains: GithubChainRegistryItem[] = [...chains, ...testnets].filter( (item: GithubChainRegistryItem) => { From 14e7283bdc913636f00fb3ff358bd4e5d2958916 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 24 Apr 2023 22:24:06 +0200 Subject: [PATCH 3/3] Move constants out of component --- components/chainSelect/ChainSelect.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/chainSelect/ChainSelect.tsx b/components/chainSelect/ChainSelect.tsx index bfa7fbf..e9193bb 100644 --- a/components/chainSelect/ChainSelect.tsx +++ b/components/chainSelect/ChainSelect.tsx @@ -37,6 +37,9 @@ interface GithubChainRegistryItem { }; } +const chainsUrl = "https://api.github.com/repos/cosmos/chain-registry/contents"; +const testnetsUrl = "https://api.github.com/repos/cosmos/chain-registry/contents/testnets"; + const ChainSelect = () => { const { state, dispatch } = useAppContext(); @@ -61,9 +64,6 @@ const ChainSelect = () => { const [tempRegistryName, setRegistryName] = useState(state.chain.registryName); const [tempExplorerLink, setExplorerLink] = useState(state.chain.explorerLink); - const chainsUrl = "https://api.github.com/repos/cosmos/chain-registry/contents"; - const testnetsUrl = "https://api.github.com/repos/cosmos/chain-registry/contents/testnets"; - const getGhJson = useCallback(async () => { // getting chain info from this repo: https://github.com/cosmos/chain-registry try {