From 981e83012f1de254f3ea2ee9b8285d0235ad9bdc Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:47:18 +0100 Subject: [PATCH 1/2] Add default chain cosmoshub if empty --- context/ChainsContext/index.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/context/ChainsContext/index.tsx b/context/ChainsContext/index.tsx index eb8cd75a..3a88409a 100644 --- a/context/ChainsContext/index.tsx +++ b/context/ChainsContext/index.tsx @@ -1,7 +1,12 @@ 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, + getRecentChainNamesFromStorage, + setChainInUrl, +} from "./storage"; import { Action, ChainsContextType, State } from "./types"; const ChainsContext = createContext(undefined); @@ -61,7 +66,13 @@ export const ChainsProvider = ({ children }: ChainsProviderProps) => { setChainsError(dispatch, chainItemsError); const loadedChain = getChain(chainItems); - setChain(dispatch, loadedChain); + const recentChains = getRecentChainNamesFromStorage(); + + if (chainItems.mainnets.size && loadedChain === emptyChain && !recentChains.length) { + setChain(dispatch, chainItems.mainnets.get("cosmoshub") ?? emptyChain); + } else { + setChain(dispatch, loadedChain); + } }, [chainItems, chainItemsError]); useEffect(() => { From 6c997f5acc4044dec383e11808d0bcf713eb0f39 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:30:12 +0100 Subject: [PATCH 2/2] Remove unneeded extra check --- context/ChainsContext/index.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/context/ChainsContext/index.tsx b/context/ChainsContext/index.tsx index 3a88409a..bbfef9bc 100644 --- a/context/ChainsContext/index.tsx +++ b/context/ChainsContext/index.tsx @@ -1,12 +1,7 @@ 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, - getRecentChainNamesFromStorage, - setChainInUrl, -} from "./storage"; +import { addLocalChainInStorage, addRecentChainNameInStorage, setChainInUrl } from "./storage"; import { Action, ChainsContextType, State } from "./types"; const ChainsContext = createContext(undefined); @@ -66,9 +61,8 @@ export const ChainsProvider = ({ children }: ChainsProviderProps) => { setChainsError(dispatch, chainItemsError); const loadedChain = getChain(chainItems); - const recentChains = getRecentChainNamesFromStorage(); - if (chainItems.mainnets.size && loadedChain === emptyChain && !recentChains.length) { + if (chainItems.mainnets.size && loadedChain === emptyChain) { setChain(dispatch, chainItems.mainnets.get("cosmoshub") ?? emptyChain); } else { setChain(dispatch, loadedChain);