Skip to content

Commit 01ff89f

Browse files
committed
interchain-kit addChain async
1 parent ad0fc7b commit 01ff89f

File tree

2 files changed

+21
-53
lines changed

2 files changed

+21
-53
lines changed

templates/chain-admin/hooks/common/useAddHyperwebChain.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ export const useAddHyperwebChain = () => {
1717
}
1818
}, [starshipData, isHyperwebAdded]);
1919

20-
const refetchAndAddChain = () => {
21-
refetch().then(({ data }) => {
22-
addHyperwebChain(data?.v2);
23-
});
20+
const refetchAndAddChain = async () => {
21+
const { data } = await refetch();
22+
await addHyperwebChain(data?.v2);
2423
};
2524

26-
const addHyperwebChain = (data: StarshipChains['v2'] | null | undefined) => {
25+
const addHyperwebChain = async (
26+
data: StarshipChains['v2'] | null | undefined
27+
) => {
2728
if (!data) return;
28-
addChains(data.chains, data.assets);
29+
await addChains(data.chains, data.assets);
2930
chainStore.setSelectedChain(data.chains[0].chainName);
3031
chainStore.setIsHyperwebAdded(true);
3132
};

templates/chain-admin/pages/_app.tsx

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import { ChainProvider, InterchainWalletModal } from '@interchain-kit/react';
66
import { chains, assetLists } from 'chain-registry';
77
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
88
import { Box, Toaster, useTheme } from '@interchain-ui/react';
9-
import { useMemo } from 'react';
109
// import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
1110

1211
import { CustomThemeProvider, Layout } from '@/components';
1312
import { wallets } from '@/config';
14-
import { useStarshipChains } from '@/hooks';
1513

1614
const queryClient = new QueryClient({
1715
defaultOptions: {
@@ -23,55 +21,24 @@ const queryClient = new QueryClient({
2321
},
2422
});
2523

26-
// Create a separate component for the app content
27-
function AppContent({ Component, pageProps }: AppProps) {
24+
function CreateCosmosApp({ Component, pageProps }: AppProps) {
2825
const { themeClass } = useTheme();
29-
const { data: starshipData, isLoading } = useStarshipChains();
30-
console.log('starshipData', starshipData);
3126

32-
// Merge chain-registry and starship chains
33-
const combinedChains = useMemo(() => {
34-
if (starshipData?.v2.chains) {
35-
return [...chains, ...starshipData.v2.chains];
36-
}
37-
return chains;
38-
}, [starshipData]);
39-
console.log('combinedChains', combinedChains);
40-
41-
// Merge chain-registry and starship assetLists
42-
const combinedAssetLists = useMemo(() => {
43-
if (starshipData?.v2.assets) {
44-
return [...assetLists, ...starshipData.v2.assets];
45-
}
46-
return assetLists;
47-
}, [starshipData]);
48-
49-
// Don't render ChainProvider until starship data is loaded
50-
if (isLoading) {
51-
return <div>Loading chains...</div>; // or your preferred loading component
52-
}
53-
54-
return (
55-
<ChainProvider chains={combinedChains} assetLists={combinedAssetLists} wallets={wallets}
56-
walletModal={() => <InterchainWalletModal />}
57-
>
58-
<Box className={themeClass}>
59-
<Layout>
60-
<Component {...pageProps} />
61-
<Toaster position="top-right" closeButton={true} />
62-
</Layout>
63-
</Box>
64-
</ChainProvider>
65-
);
66-
}
67-
68-
function CreateCosmosApp(props: AppProps) {
6927
return (
7028
<CustomThemeProvider>
71-
<QueryClientProvider client={queryClient}>
72-
<AppContent {...props} />
73-
{/* <ReactQueryDevtools /> */}
74-
</QueryClientProvider>
29+
<ChainProvider chains={chains} assetLists={assetLists} wallets={wallets}
30+
walletModal={() => <InterchainWalletModal />}
31+
>
32+
<QueryClientProvider client={queryClient}>
33+
<Box className={themeClass}>
34+
<Layout>
35+
<Component {...pageProps} />
36+
<Toaster position="top-right" closeButton={true} />
37+
</Layout>
38+
</Box>
39+
{/* <ReactQueryDevtools /> */}
40+
</QueryClientProvider>
41+
</ChainProvider>
7542
</CustomThemeProvider>
7643
);
7744
}

0 commit comments

Comments
 (0)