From 2db85824f02ee2e39c910e83d411f2905b4f4c01 Mon Sep 17 00:00:00 2001 From: MananTank Date: Fri, 13 Dec 2024 16:59:01 +0000 Subject: [PATCH] [DASH-610] Fix useActiveWalletChain missing chain overrides added in dashboard (#5731) Fixes: DASH-610 --- .../react/components/connect-wallet/index.tsx | 9 ++----- apps/dashboard/src/app/providers.tsx | 27 +++++++++++++++++-- apps/dashboard/src/hooks/chains/allChains.ts | 9 ++++++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx b/apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx index 846d15f23a8..684abf256b1 100644 --- a/apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx +++ b/apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx @@ -48,12 +48,7 @@ export const CustomConnectWallet = (props: { // chains const favChainIdsQuery = useFavoriteChainIds(); const recentChainIds = useStore(recentlyUsedChainIdsStore); - const { idToChain, allChains } = useAllChainsData(); - - const allChainsWithMetadata = useMemo( - () => allChains.map(mapV4ChainToV5Chain), - [allChains], - ); + const { idToChain, allChainsV5 } = useAllChainsData(); const recentlyUsedChainsWithMetadata = useMemo( () => @@ -170,7 +165,7 @@ export const CustomConnectWallet = (props: { detailsButton={{ className: props.detailsButtonClassName, }} - chains={allChainsWithMetadata} + chains={allChainsV5} detailsModal={{ networkSelector: { sections: chainSections, diff --git a/apps/dashboard/src/app/providers.tsx b/apps/dashboard/src/app/providers.tsx index 39680b3d838..8a5e1cf908a 100644 --- a/apps/dashboard/src/app/providers.tsx +++ b/apps/dashboard/src/app/providers.tsx @@ -2,11 +2,16 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ThemeProvider } from "next-themes"; -import { useMemo } from "react"; -import { ThirdwebProvider, useActiveAccount } from "thirdweb/react"; +import { useEffect, useMemo } from "react"; +import { + ThirdwebProvider, + useActiveAccount, + useConnectionManager, +} from "thirdweb/react"; import { CustomConnectWallet } from "../@3rdweb-sdk/react/components/connect-wallet"; import { PosthogIdentifier } from "../components/wallets/PosthogIdentifier"; import { isSanctionedAddress } from "../data/eth-sanctioned-addresses"; +import { useAllChainsData } from "../hooks/chains/allChains"; import { SyncChainStores } from "../stores/chainStores"; import { TWAutoConnect } from "./components/autoconnect"; @@ -17,6 +22,7 @@ export function AppRouterProviders(props: { children: React.ReactNode }) { + { + if (allChainsV5.length > 0) { + connectionManager.defineChains(allChainsV5); + } + }, [allChainsV5, connectionManager]); + + return null; +} + const SanctionedAddressesChecker = ({ children, }: { diff --git a/apps/dashboard/src/hooks/chains/allChains.ts b/apps/dashboard/src/hooks/chains/allChains.ts index 2f2def68005..b68db380936 100644 --- a/apps/dashboard/src/hooks/chains/allChains.ts +++ b/apps/dashboard/src/hooks/chains/allChains.ts @@ -4,7 +4,8 @@ import { isProd } from "@/constants/env"; import { createStore, useStore } from "@/lib/reactive"; import { useQuery } from "@tanstack/react-query"; import { useEffect } from "react"; -import type { ChainMetadata } from "thirdweb/chains"; +import type { Chain, ChainMetadata } from "thirdweb/chains"; +import { mapV4ChainToV5Chain } from "../../contexts/map-chains"; import { type StoredChain, chainOverridesStore, @@ -12,6 +13,7 @@ import { type AllChainsStore = { allChains: StoredChain[]; + allChainsV5: Chain[]; idToChain: Map; nameToChain: Map; slugToChain: Map; @@ -20,6 +22,7 @@ type AllChainsStore = { function createAllChainsStore() { const store = createStore({ allChains: [], + allChainsV5: [], idToChain: new Map(), nameToChain: new Map(), slugToChain: new Map(), @@ -47,6 +50,7 @@ function createAllChainsStore() { // but don't ignore if chainOverrides is empty! const allChains: StoredChain[] = []; + const allChainsV5: Chain[] = []; const idToChain: Map = new Map(); const nameToChain: Map = new Map(); const slugToChain: Map = new Map(); @@ -71,6 +75,8 @@ function createAllChainsStore() { chainOverrides.find((x) => x.chainId === _chain.chainId) || _chain; allChains.push(chain); + // eslint-disable-next-line no-restricted-syntax + allChainsV5.push(mapV4ChainToV5Chain(chain)); idToChain.set(chain.chainId, chain); nameToChain.set(chain.name, chain); slugToChain.set(chain.slug, chain); @@ -88,6 +94,7 @@ function createAllChainsStore() { store.setValue({ allChains, + allChainsV5, idToChain: idToChain, nameToChain: nameToChain, slugToChain: slugToChain,