From fdda1d9a960b57fe442a68fab5721c5dec8751ea Mon Sep 17 00:00:00 2001 From: Nabarun Date: Thu, 10 Jul 2025 12:42:30 +0530 Subject: [PATCH 1/4] Add NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS to filter from public chains --- README.md | 2 +- context/ChainsContext/index.tsx | 10 +++++++-- context/ChainsContext/service.tsx | 22 +++++++++++++++---- context/ChainsContext/storage.tsx | 2 +- lib/chainRegistry.ts | 13 +++++++++++ .../docker-compose-cosmos-multisig-ui.yml | 1 + .../config/cosmos-multisig-ui/run.sh | 2 ++ .../stacks/cosmos-multisig-ui/README.md | 3 +++ 8 files changed, 47 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index de313b7..46c3263 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Copy the `.env.sample` file and rename it to `.env.local` ### 2. Run a local cosmos-sdk Simapp instance -It's recommended that you make your simapp instance mimic the denomination of cosmoshub-4 (`uatom`). Put the local address of your node as the value for `NEXT_PUBLIC_NODE_ADDRESS` in your `.env.local` file. +It's recommended that you make your simapp instance mimic the denomination of cosmoshub-4 (`uatom`). Put the local address of your node as the value for `NEXT_PUBLIC_NODE_ADDRESSES` in your `.env.local` file. A more in depth tutorial on this is coming soon :) diff --git a/context/ChainsContext/index.tsx b/context/ChainsContext/index.tsx index 9b83ca6..f70c6a2 100644 --- a/context/ChainsContext/index.tsx +++ b/context/ChainsContext/index.tsx @@ -3,7 +3,7 @@ import { toastError } from "@/lib/utils"; import { ReactNode, createContext, useContext, useEffect, useReducer } from "react"; import { emptyChain, isChainInfoFilled, setChain, setChains, setChainsError } from "./helpers"; import { getChain, getNodeFromArray, useChainsFromRegistry } from "./service"; -import { addLocalChainInStorage, addRecentChainNameInStorage, setChainInUrl } from "./storage"; +import { addLocalChainInStorage, addRecentChainNameInStorage, getChainFromEnvfile, setChainInUrl } from "./storage"; import { Action, ChainsContextType, Dispatch, State } from "./types"; const ChainsContext = createContext(undefined); @@ -61,6 +61,8 @@ interface ChainsProviderProps { readonly children: ReactNode; } +const envfileChain = getChainFromEnvfile(''); + export const ChainsProvider = ({ children }: ChainsProviderProps) => { const [state, dispatch] = useReducer(chainsReducer, { chain: emptyChain, @@ -69,7 +71,11 @@ export const ChainsProvider = ({ children }: ChainsProviderProps) => { validatorState: { validators: emptyAllValidatorsEmpty(), status: "initial" }, }); - const { chainItems, chainItemsError } = useChainsFromRegistry(); + let { chainItems, chainItemsError } = useChainsFromRegistry(); + + if (isChainInfoFilled(envfileChain)) { + chainItems.localnets.set(envfileChain.registryName, envfileChain); + } useEffect(() => { setChains(dispatch, chainItems); diff --git a/context/ChainsContext/service.tsx b/context/ChainsContext/service.tsx index b327c07..964bbaf 100644 --- a/context/ChainsContext/service.tsx +++ b/context/ChainsContext/service.tsx @@ -104,19 +104,33 @@ export const getChain = (chains: ChainItems) => { // Avoid app from thinking the /api route is a registryName const chainNameFromUrl = rootRoute === "api" ? "" : rootRoute; + // Get chain only after public chains have been fetched from registry + if (!(chains.mainnets.size || chains.testnets.size)) { + return emptyChain; + } + const recentChain = getRecentChainFromStorage(chains); if (!chainNameFromUrl && isChainInfoFilled(recentChain)) { return recentChain; } + // Set chain if no reccent chain and chain name set in URL + + // Check if info set in URL const urlChain = getChainFromUrl(chainNameFromUrl); + let storedChain = getChainFromStorage(chainNameFromUrl, chains); + let chain = { ...storedChain, ...urlChain }; + if (isChainInfoFilled(chain)) { + return chain; + } + + // Check if info set in env const envfileChain = getChainFromEnvfile(chainNameFromUrl); - const storedChain = getChainFromStorage( - chainNameFromUrl || envfileChain.registryName || "cosmoshub", + storedChain = getChainFromStorage( + envfileChain.registryName || "cosmoshub", chains, ); - - const chain = { ...storedChain, ...envfileChain, ...urlChain }; + chain = { ...storedChain, ...envfileChain }; return isChainInfoFilled(chain) ? chain : emptyChain; }; diff --git a/context/ChainsContext/storage.tsx b/context/ChainsContext/storage.tsx index f5e80da..d2d8ab8 100644 --- a/context/ChainsContext/storage.tsx +++ b/context/ChainsContext/storage.tsx @@ -165,7 +165,7 @@ export const getChainFromEnvfile = (chainName: string) => { const explorerLinksValue: Partial = JSON.parse(explorerLinks || "{}"); const envfileChain: Partial = { - registryName: chainName, + registryName, ...(logo && { logo }), ...(chainId && { chainId }), ...(chainDisplayName && { chainDisplayName }), diff --git a/lib/chainRegistry.ts b/lib/chainRegistry.ts index 77bfe86..0afc15b 100644 --- a/lib/chainRegistry.ts +++ b/lib/chainRegistry.ts @@ -11,6 +11,9 @@ const mainnetsUrl = `https://api.github.com/repos/${chainRegistryRepo}/contents` const testnetsUrl = `https://api.github.com/repos/${chainRegistryRepo}/contents/testnets`; const registryCdnUrl = `https://cdn.jsdelivr.net/gh/${chainRegistryRepo}@${repoBranch}`; +const registryEnabledChains = process.env.NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS; +const registryEnabledChainsValue: readonly string[] = JSON.parse(registryEnabledChains || "[]"); + const getShaFromRegistry = async () => { const { sha }: { sha: string } = await requestGhJson(shaUrl); return sha; @@ -36,6 +39,11 @@ const getChainsFromRegistry = async () => { continue; } + // Skip if chain is not included in NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS (unset env to fetch all chains) + if (registryEnabledChainsValue.length && !registryEnabledChainsValue.includes(path)) { + continue; + } + mainnetPromisesMap.set(path, { chainInfo: requestGhJson(`${registryCdnUrl}/${path}/chain.json`), assetList: requestGhJson(`${registryCdnUrl}/${path}/assetlist.json`), @@ -69,6 +77,11 @@ const getChainsFromRegistry = async () => { continue; } + // Skip if chain is not included in NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS (unset env to fetch all chains) + if (registryEnabledChainsValue.length && !registryEnabledChainsValue.includes(path)) { + continue; + } + testnetPromisesMap.set(path, { chainInfo: requestGhJson(`${registryCdnUrl}/${path}/chain.json`), assetList: requestGhJson(`${registryCdnUrl}/${path}/assetlist.json`), diff --git a/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml b/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml index 6a45ccb..48e5376 100644 --- a/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml +++ b/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml @@ -7,6 +7,7 @@ services: environment: DGRAPH_DOMAIN: ${DGRAPH_DOMAIN:-http://alpha:8080} NEXT_PUBLIC_MULTICHAIN: ${NEXT_PUBLIC_MULTICHAIN} + NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS=${NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS} NEXT_PUBLIC_REGISTRY_NAME: ${NEXT_PUBLIC_REGISTRY_NAME} NEXT_PUBLIC_LOGO: ${NEXT_PUBLIC_LOGO} NEXT_PUBLIC_CHAIN_ID: ${NEXT_PUBLIC_CHAIN_ID} diff --git a/stack-orchestrator/config/cosmos-multisig-ui/run.sh b/stack-orchestrator/config/cosmos-multisig-ui/run.sh index 5a1305c..46ffc49 100644 --- a/stack-orchestrator/config/cosmos-multisig-ui/run.sh +++ b/stack-orchestrator/config/cosmos-multisig-ui/run.sh @@ -8,6 +8,7 @@ fi # Export environment variables export DGRAPH_URL="${DGRAPH_DOMAIN}/graphql" export NEXT_PUBLIC_MULTICHAIN="${NEXT_PUBLIC_MULTICHAIN}" +export NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS="${NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS}" export NEXT_PUBLIC_REGISTRY_NAME="${NEXT_PUBLIC_REGISTRY_NAME}" export NEXT_PUBLIC_LOGO="${NEXT_PUBLIC_LOGO}" export NEXT_PUBLIC_CHAIN_ID="${NEXT_PUBLIC_CHAIN_ID}" @@ -25,6 +26,7 @@ echo "Using the following env variables:" echo "DGRAPH_DOMAIN: ${DGRAPH_DOMAIN}" echo "DGRAPH_URL: ${DGRAPH_URL}" echo "NEXT_PUBLIC_MULTICHAIN: ${NEXT_PUBLIC_MULTICHAIN}" +echo "NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS: ${NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS}" echo "NEXT_PUBLIC_REGISTRY_NAME: ${NEXT_PUBLIC_REGISTRY_NAME}" echo "NEXT_PUBLIC_LOGO: ${NEXT_PUBLIC_LOGO}" echo "NEXT_PUBLIC_CHAIN_ID: ${NEXT_PUBLIC_CHAIN_ID}" diff --git a/stack-orchestrator/stacks/cosmos-multisig-ui/README.md b/stack-orchestrator/stacks/cosmos-multisig-ui/README.md index 8816dfb..40243e7 100644 --- a/stack-orchestrator/stacks/cosmos-multisig-ui/README.md +++ b/stack-orchestrator/stacks/cosmos-multisig-ui/README.md @@ -52,6 +52,9 @@ Instructions for running the `cosmos-multisig-ui` using [laconic-so](https://git # Allow multiple networks/chains in app NEXT_PUBLIC_MULTICHAIN= + # List of public chains to show in app / or leave empty to show all chains + NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS= + # Name of the chain registry NEXT_PUBLIC_REGISTRY_NAME= -- 2.45.2 From db84751df6f9ebbf39672c8c46b4f3d3cb5adeb1 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Thu, 10 Jul 2025 15:42:41 +0530 Subject: [PATCH 2/4] Fix compose file syntax error --- .../compose/docker-compose-cosmos-multisig-ui.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml b/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml index 48e5376..30820b9 100644 --- a/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml +++ b/stack-orchestrator/compose/docker-compose-cosmos-multisig-ui.yml @@ -7,7 +7,7 @@ services: environment: DGRAPH_DOMAIN: ${DGRAPH_DOMAIN:-http://alpha:8080} NEXT_PUBLIC_MULTICHAIN: ${NEXT_PUBLIC_MULTICHAIN} - NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS=${NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS} + NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS: ${NEXT_PUBLIC_REGISTRY_ENABLED_CHAINS} NEXT_PUBLIC_REGISTRY_NAME: ${NEXT_PUBLIC_REGISTRY_NAME} NEXT_PUBLIC_LOGO: ${NEXT_PUBLIC_LOGO} NEXT_PUBLIC_CHAIN_ID: ${NEXT_PUBLIC_CHAIN_ID} -- 2.45.2 From 07ce57f87e44d5cab843c9a0248f888c8a51ecb2 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Thu, 10 Jul 2025 16:06:37 +0530 Subject: [PATCH 3/4] Upgrade package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2d49d8..538515f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cosmos-multisig-ui", "private": true, - "version": "0.1.2", + "version": "0.1.3", "scripts": { "dev": "next dev", "test": "jest --watch", -- 2.45.2 From bb432e4012c108884e9050ca42b1f70e36bdeee3 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Thu, 10 Jul 2025 16:11:10 +0530 Subject: [PATCH 4/4] Lint fix --- context/ChainsContext/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/ChainsContext/index.tsx b/context/ChainsContext/index.tsx index f70c6a2..be1f068 100644 --- a/context/ChainsContext/index.tsx +++ b/context/ChainsContext/index.tsx @@ -71,7 +71,7 @@ export const ChainsProvider = ({ children }: ChainsProviderProps) => { validatorState: { validators: emptyAllValidatorsEmpty(), status: "initial" }, }); - let { chainItems, chainItemsError } = useChainsFromRegistry(); + const { chainItems, chainItemsError } = useChainsFromRegistry(); if (isChainInfoFilled(envfileChain)) { chainItems.localnets.set(envfileChain.registryName, envfileChain); -- 2.45.2