Skip to content

Commit 1d9e0f9

Browse files
committed
feat: restrict cosmos-specific features to cosmos chains only
- Add chain type validation in StakingSection, AssetListSection, and Contract pages - Display user-friendly messages when features are unavailable for non-cosmos chains - Improve UX by clearly indicating feature compatibility
1 parent e672ff5 commit 1d9e0f9

File tree

6 files changed

+186
-84
lines changed

6 files changed

+186
-84
lines changed

templates/chain-template/components/asset-list/AssetListSection.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,37 @@ interface AssetListSectionProps {
1111
}
1212

1313
export const AssetListSection = ({ chainName }: AssetListSectionProps) => {
14-
const { address } = useChain(chainName);
14+
const { address, chain } = useChain(chainName);
1515
const { data, isLoading, refetch } = useAssets(chainName);
1616

17+
if (chain && chain.chainType !== 'cosmos') {
18+
return (
19+
<Box maxWidth="768px" marginX="auto" marginBottom="60px">
20+
<Text
21+
fontSize="$xl"
22+
fontWeight="$semibold"
23+
attributes={{ marginBottom: '$10' }}
24+
>
25+
My assets
26+
</Text>
27+
28+
<Box
29+
height="160px"
30+
bg="$cardBg"
31+
borderRadius="$md"
32+
p="$6"
33+
display="flex"
34+
justifyContent="center"
35+
alignItems="center"
36+
>
37+
<Text fontSize="$md" color="$textSecondary" textAlign="center">
38+
Asset list functionality is not available for {chain.chainType} chains
39+
</Text>
40+
</Box>
41+
</Box>
42+
);
43+
}
44+
1745
if (!address) {
1846
return (
1947
<Box maxWidth="768px" marginX="auto" marginBottom="60px">

templates/chain-template/components/staking/StakingSection.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { AllValidators } from './AllValidators';
77
import { useStakingData, useValidatorLogos } from '@/hooks';
88

99
export const StakingSection = ({ chainName }: { chainName: string }) => {
10-
const { address } = useChain(chainName);
10+
const { address, chain } = useChain(chainName);
11+
console.log('chain', chain, chain.chainType);
1112
const { data, isLoading, refetch } = useStakingData(chainName);
1213
const { data: logos, isLoading: isFetchingLogos } = useValidatorLogos(
1314
chainName,
@@ -16,7 +17,18 @@ export const StakingSection = ({ chainName }: { chainName: string }) => {
1617

1718
return (
1819
<Box my="$16" maxWidth="$containerMd" mx="auto">
19-
{!address ? (
20+
{chain && chain.chainType !== 'cosmos' ? (
21+
<Box
22+
height="$28"
23+
display="flex"
24+
justifyContent="center"
25+
alignItems="center"
26+
>
27+
<Text fontWeight="$semibold" fontSize="$xl" textAlign="center">
28+
Staking functionality is not available for {chain.chainType} chains
29+
</Text>
30+
</Box>
31+
) : !address ? (
2032
<Box
2133
height="$28"
2234
display="flex"

templates/chain-template/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"@interchain-kit/react": "0.3.36",
3030
"@interchain-ui/react": "1.23.31",
3131
"@interchain-ui/react-no-ssr": "0.1.2",
32-
"@interchainjs/cosmos": "^1.11.2",
33-
"@interchainjs/react": "^1.11.2",
32+
"@interchainjs/cosmos": "1.11.2",
33+
"@interchainjs/react": "1.11.2",
3434
"@keplr-wallet/cosmos": "^0.12.44",
3535
"@tanstack/react-query": "4.32.0",
3636
"ace-builds": "1.35.0",

templates/chain-template/pages/contract.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useState, useCallback, useEffect, useRef } from 'react';
2-
import { Box, Tabs } from '@interchain-ui/react';
2+
import { Box, Tabs, Text } from '@interchain-ui/react';
33
import { useRouter } from 'next/router';
4+
import { useChain } from '@interchain-kit/react';
45

56
import { ExecuteTab, MyContractsTab, QueryTab } from '@/components';
67
import { splitCamelCase, toKebabCase, toPascalCase } from '@/utils';
8+
import { useChainStore } from '@/contexts';
79
import styles from '@/styles/comp.module.css';
810

911
export enum TabLabel {
@@ -14,6 +16,8 @@ export enum TabLabel {
1416

1517
export default function Contract() {
1618
const router = useRouter();
19+
const { selectedChain } = useChainStore();
20+
const { chain } = useChain(selectedChain);
1721
const [activeTab, setActiveTab] = useState<TabLabel>(TabLabel.MyContracts);
1822
const [queryAddress, setQueryAddress] = useState('');
1923
const [executeAddress, setExecuteAddress] = useState('');
@@ -64,8 +68,8 @@ export default function Contract() {
6468
tabId === TabLabel.Query
6569
? queryAddress
6670
: tabId === TabLabel.Execute
67-
? executeAddress
68-
: undefined
71+
? executeAddress
72+
: undefined
6973
);
7074
},
7175
[updateUrl, queryAddress, executeAddress]
@@ -90,6 +94,21 @@ export default function Contract() {
9094
[activeTab, updateUrl]
9195
);
9296

97+
if (chain && chain.chainType !== 'cosmos') {
98+
return (
99+
<Box
100+
display="flex"
101+
justifyContent="center"
102+
alignItems="center"
103+
minHeight="400px"
104+
>
105+
<Text fontWeight="$semibold" fontSize="$xl" textAlign="center">
106+
Contract functionality is not available for {chain.chainType} chains
107+
</Text>
108+
</Box>
109+
);
110+
}
111+
93112
return (
94113
<>
95114
<Tabs

templates/chain-template/pages/governance.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
import { ReactNoSSR } from '@interchain-ui/react-no-ssr';
22
import { Voting } from '@/components';
33
import { useChainStore } from '@/contexts';
4+
import { useChain } from '@interchain-kit/react';
5+
import { Box, Text } from '@interchain-ui/react';
46

57
export default function GovernancePage() {
68
const { selectedChain } = useChainStore();
9+
const { chain } = useChain(selectedChain);
10+
11+
if (chain && chain.chainType !== 'cosmos') {
12+
return (
13+
<Box
14+
display="flex"
15+
justifyContent="center"
16+
alignItems="center"
17+
minHeight="400px"
18+
>
19+
<Text fontWeight="$semibold" fontSize="$xl" textAlign="center">
20+
Governance functionality is not available for {chain.chainType} chains
21+
</Text>
22+
</Box>
23+
);
24+
}
725

826
return (
927
<ReactNoSSR>

0 commit comments

Comments
 (0)