Skip to content

Commit 314f79f

Browse files
committed
[DASH-610] Fix useActiveWalletChain missing chain overrides added in dashboard
1 parent 8761fe6 commit 314f79f

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ export const CustomConnectWallet = (props: {
4848
// chains
4949
const favChainIdsQuery = useFavoriteChainIds();
5050
const recentChainIds = useStore(recentlyUsedChainIdsStore);
51-
const { idToChain, allChains } = useAllChainsData();
52-
53-
const allChainsWithMetadata = useMemo(
54-
() => allChains.map(mapV4ChainToV5Chain),
55-
[allChains],
56-
);
51+
const { idToChain, allChainsV5 } = useAllChainsData();
5752

5853
const recentlyUsedChainsWithMetadata = useMemo(
5954
() =>
@@ -170,7 +165,7 @@ export const CustomConnectWallet = (props: {
170165
detailsButton={{
171166
className: props.detailsButtonClassName,
172167
}}
173-
chains={allChainsWithMetadata}
168+
chains={allChainsV5}
174169
detailsModal={{
175170
networkSelector: {
176171
sections: chainSections,

apps/dashboard/src/app/providers.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
44
import { ThemeProvider } from "next-themes";
5-
import { useMemo } from "react";
6-
import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
5+
import { useEffect, useMemo } from "react";
6+
import {
7+
ThirdwebProvider,
8+
useActiveAccount,
9+
useConnectionManager,
10+
} from "thirdweb/react";
711
import { CustomConnectWallet } from "../@3rdweb-sdk/react/components/connect-wallet";
812
import { PosthogIdentifier } from "../components/wallets/PosthogIdentifier";
913
import { isSanctionedAddress } from "../data/eth-sanctioned-addresses";
14+
import { useAllChainsData } from "../hooks/chains/allChains";
1015
import { SyncChainStores } from "../stores/chainStores";
1116
import { TWAutoConnect } from "./components/autoconnect";
1217

@@ -17,6 +22,7 @@ export function AppRouterProviders(props: { children: React.ReactNode }) {
1722
<QueryClientProvider client={queryClient}>
1823
<SyncChainStores />
1924
<ThirdwebProvider>
25+
<SyncChainDefinitionsToConnectionManager />
2026
<TWAutoConnect />
2127
<PosthogIdentifier />
2228
<ThemeProvider
@@ -34,6 +40,23 @@ export function AppRouterProviders(props: { children: React.ReactNode }) {
3440
);
3541
}
3642

43+
function SyncChainDefinitionsToConnectionManager() {
44+
const { allChainsV5 } = useAllChainsData();
45+
const connectionManager = useConnectionManager();
46+
47+
// whenever user updates chains, update connection manager store
48+
// This is the same pattern used in ConnectButton for updating the connection manager when props.chain or props.chains change
49+
// this is added to root layout because ConnectButton is not always rendered in the page
50+
// eslint-disable-next-line no-restricted-syntax
51+
useEffect(() => {
52+
if (allChainsV5.length > 0) {
53+
connectionManager.defineChains(allChainsV5);
54+
}
55+
}, [allChainsV5, connectionManager]);
56+
57+
return null;
58+
}
59+
3760
const SanctionedAddressesChecker = ({
3861
children,
3962
}: {

apps/dashboard/src/hooks/chains/allChains.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { isProd } from "@/constants/env";
44
import { createStore, useStore } from "@/lib/reactive";
55
import { useQuery } from "@tanstack/react-query";
66
import { useEffect } from "react";
7-
import type { ChainMetadata } from "thirdweb/chains";
7+
import type { Chain, ChainMetadata } from "thirdweb/chains";
8+
import { mapV4ChainToV5Chain } from "../../contexts/map-chains";
89
import {
910
type StoredChain,
1011
chainOverridesStore,
1112
} from "../../stores/chainStores";
1213

1314
type AllChainsStore = {
1415
allChains: StoredChain[];
16+
allChainsV5: Chain[];
1517
idToChain: Map<number, StoredChain | undefined>;
1618
nameToChain: Map<string, StoredChain | undefined>;
1719
slugToChain: Map<string, StoredChain | undefined>;
@@ -20,6 +22,7 @@ type AllChainsStore = {
2022
function createAllChainsStore() {
2123
const store = createStore<AllChainsStore>({
2224
allChains: [],
25+
allChainsV5: [],
2326
idToChain: new Map(),
2427
nameToChain: new Map(),
2528
slugToChain: new Map(),
@@ -47,6 +50,7 @@ function createAllChainsStore() {
4750
// but don't ignore if chainOverrides is empty!
4851

4952
const allChains: StoredChain[] = [];
53+
const allChainsV5: Chain[] = [];
5054
const idToChain: Map<number, StoredChain | undefined> = new Map();
5155
const nameToChain: Map<string, StoredChain | undefined> = new Map();
5256
const slugToChain: Map<string, StoredChain | undefined> = new Map();
@@ -71,6 +75,8 @@ function createAllChainsStore() {
7175
chainOverrides.find((x) => x.chainId === _chain.chainId) || _chain;
7276

7377
allChains.push(chain);
78+
// eslint-disable-next-line no-restricted-syntax
79+
allChainsV5.push(mapV4ChainToV5Chain(chain));
7480
idToChain.set(chain.chainId, chain);
7581
nameToChain.set(chain.name, chain);
7682
slugToChain.set(chain.slug, chain);
@@ -88,6 +94,7 @@ function createAllChainsStore() {
8894

8995
store.setValue({
9096
allChains,
97+
allChainsV5,
9198
idToChain: idToChain,
9299
nameToChain: nameToChain,
93100
slugToChain: slugToChain,

0 commit comments

Comments
 (0)