diff --git a/apps/shell/src/app/authz/page.tsx b/apps/shell/src/app/authz/page.tsx index 81379affe..35f1fc98f 100644 --- a/apps/shell/src/app/authz/page.tsx +++ b/apps/shell/src/app/authz/page.tsx @@ -4,7 +4,6 @@ import { QueryClient, } from '@tanstack/react-query'; import { headers } from 'next/headers'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { AuthzPage } from '@haqq/shell-authz'; import { @@ -12,11 +11,15 @@ import { indexerBalancesFetcher, parseWagmiCookies, } from '@haqq/shell-shared'; +import { supportedChainsIds } from '../../config/wagmi-config'; export default async function Authz() { const cookies = headers().get('cookie'); const { chainId, walletAddress } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const queryClient = new QueryClient(); const { getAuthzGranteeGrants, getAuthzGranterGrants } = diff --git a/apps/shell/src/app/dao/page.tsx b/apps/shell/src/app/dao/page.tsx index 47d0b1486..146e6f49c 100644 --- a/apps/shell/src/app/dao/page.tsx +++ b/apps/shell/src/app/dao/page.tsx @@ -4,7 +4,6 @@ import { QueryClient, } from '@tanstack/react-query'; import { headers } from 'next/headers'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { DaoPage } from '@haqq/shell-dao'; import { @@ -12,11 +11,15 @@ import { indexerBalancesFetcher, parseWagmiCookies, } from '@haqq/shell-shared'; +import { supportedChainsIds } from '../../config/wagmi-config'; export default async function Authz() { const cookies = headers().get('cookie'); const { chainId, walletAddress } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; const queryClient = new QueryClient(); const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const { getErc20TokenPairs } = createCosmosService(cosmosRestEndpoint); diff --git a/apps/shell/src/app/faucet/page.tsx b/apps/shell/src/app/faucet/page.tsx index 18b4975f5..5d25bfd24 100644 --- a/apps/shell/src/app/faucet/page.tsx +++ b/apps/shell/src/app/faucet/page.tsx @@ -6,12 +6,13 @@ import { import dynamic from 'next/dynamic'; import { headers } from 'next/headers'; import { notFound } from 'next/navigation'; -import { haqqMainnet, haqqTestedge2 } from 'wagmi/chains'; +import { haqqTestedge2 } from 'wagmi/chains'; import { ethToHaqq, indexerBalancesFetcher, parseWagmiCookies, } from '@haqq/shell-shared'; +import { supportedChainsIds } from '../../config/wagmi-config'; import { env } from '../../env/client'; const AuthProvider = dynamic(async () => { @@ -26,8 +27,11 @@ const FaucetPage = dynamic(async () => { export default async function Faucet() { const cookies = headers().get('cookie'); - const { chainId: parsedChainId, walletAddress } = parseWagmiCookies(cookies); - const chainIdToUse = parsedChainId ?? haqqMainnet.id; + const { chainId, walletAddress } = parseWagmiCookies(cookies); + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; if (chainIdToUse !== haqqTestedge2.id) { return notFound(); diff --git a/apps/shell/src/app/governance/page.tsx b/apps/shell/src/app/governance/page.tsx index 1ad2eeca4..83d2445cb 100644 --- a/apps/shell/src/app/governance/page.tsx +++ b/apps/shell/src/app/governance/page.tsx @@ -5,10 +5,10 @@ import { dehydrate, } from '@tanstack/react-query'; import { headers } from 'next/headers'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { ProposalListPage } from '@haqq/shell-governance'; import { parseWagmiCookies } from '@haqq/shell-shared'; +import { supportedChainsIds } from '../../config/wagmi-config'; export const dynamic = 'force-dynamic'; export const fetchCache = 'force-no-store'; @@ -16,7 +16,10 @@ export const fetchCache = 'force-no-store'; export default async function ProposalList() { const cookies = headers().get('cookie'); const { chainId } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const { getProposals, getGovernanceParams, getProposalTally } = createCosmosService(cosmosRestEndpoint); diff --git a/apps/shell/src/app/governance/proposal/[id]/page.tsx b/apps/shell/src/app/governance/proposal/[id]/page.tsx index 83f8dc905..5aeeffc2b 100644 --- a/apps/shell/src/app/governance/proposal/[id]/page.tsx +++ b/apps/shell/src/app/governance/proposal/[id]/page.tsx @@ -5,10 +5,10 @@ import { } from '@tanstack/react-query'; import { headers } from 'next/headers'; import { notFound } from 'next/navigation'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { ProposalDetailsPage } from '@haqq/shell-governance'; import { parseWagmiCookies } from '@haqq/shell-shared'; +import { supportedChainsIds } from '../../../../config/wagmi-config'; export const dynamic = 'force-dynamic'; export const fetchCache = 'force-no-store'; @@ -26,7 +26,10 @@ export default async function ProposalDetails({ const cookies = headers().get('cookie'); const { chainId } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const { getProposalDetails, diff --git a/apps/shell/src/app/page.tsx b/apps/shell/src/app/page.tsx index 055735a90..aea7806a4 100644 --- a/apps/shell/src/app/page.tsx +++ b/apps/shell/src/app/page.tsx @@ -4,7 +4,6 @@ import { QueryClient, } from '@tanstack/react-query'; import { headers } from 'next/headers'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { MainPage } from '@haqq/shell-main'; import { @@ -13,12 +12,17 @@ import { indexerBalancesFetcher, parseWagmiCookies, } from '@haqq/shell-shared'; +import { supportedChainsIds } from '../config/wagmi-config'; export default async function IndexPage() { const headersList = headers(); const cookies = headersList.get('cookie'); const { chainId, walletAddress } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; + const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const { getProposals, diff --git a/apps/shell/src/app/staking/page.tsx b/apps/shell/src/app/staking/page.tsx index 33a3f09ea..0376df74c 100644 --- a/apps/shell/src/app/staking/page.tsx +++ b/apps/shell/src/app/staking/page.tsx @@ -4,7 +4,6 @@ import { dehydrate, } from '@tanstack/react-query'; import { headers } from 'next/headers'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { ethToHaqq, @@ -12,6 +11,7 @@ import { parseWagmiCookies, } from '@haqq/shell-shared'; import { ValidatorListPage } from '@haqq/shell-staking'; +import { supportedChainsIds } from '../../config/wagmi-config'; export const dynamic = 'force-dynamic'; export const fetchCache = 'force-no-store'; @@ -20,7 +20,10 @@ export default async function ValidatorList() { const headersList = headers(); const cookies = headersList.get('cookie'); const { chainId, walletAddress } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const { getStakingParams, diff --git a/apps/shell/src/app/staking/validator/[address]/page.tsx b/apps/shell/src/app/staking/validator/[address]/page.tsx index f3df417e5..488c0057b 100644 --- a/apps/shell/src/app/staking/validator/[address]/page.tsx +++ b/apps/shell/src/app/staking/validator/[address]/page.tsx @@ -5,7 +5,6 @@ import { } from '@tanstack/react-query'; import { headers } from 'next/headers'; import { notFound } from 'next/navigation'; -import { haqqMainnet } from 'wagmi/chains'; import { createCosmosService, getChainParams } from '@haqq/data-access-cosmos'; import { ethToHaqq, @@ -13,6 +12,7 @@ import { parseWagmiCookies, } from '@haqq/shell-shared'; import { ValidatorDetailsPage } from '@haqq/shell-staking'; +import { supportedChainsIds } from '../../../../config/wagmi-config'; export default async function ValidatorDetails({ params: { address }, @@ -25,7 +25,11 @@ export default async function ValidatorDetails({ const cookies = headers().get('cookie'); const { chainId, walletAddress } = parseWagmiCookies(cookies); - const chainIdToUse = chainId ?? haqqMainnet.id; + const chainIdToUse = + chainId && supportedChainsIds.includes(chainId) + ? chainId + : supportedChainsIds[0]; + const { cosmosRestEndpoint } = getChainParams(chainIdToUse); const { getValidators, diff --git a/apps/shell/src/config/wagmi-config.ts b/apps/shell/src/config/wagmi-config.ts index 699c621e9..70b0a6148 100644 --- a/apps/shell/src/config/wagmi-config.ts +++ b/apps/shell/src/config/wagmi-config.ts @@ -1,3 +1,4 @@ +import { Transport } from 'viem'; import { createConfig, http, @@ -8,6 +9,18 @@ import { import { haqqMainnet, haqqTestedge2 } from 'wagmi/chains'; import { walletConnect } from 'wagmi/connectors'; +export const supportedChains = [haqqMainnet, haqqTestedge2] as const; +export const supportedChainsIds = supportedChains.map((chain): number => { + return chain.id; +}); +const supportedChainsTransports = supportedChains.reduce( + (acc, chain) => { + acc[chain.id] = http(); + return acc; + }, + {} as Record, +); + export function createWagmiConfig(walletConnectProjectId?: string) { const connectors: CreateConnectorFn[] = []; @@ -24,11 +37,8 @@ export function createWagmiConfig(walletConnectProjectId?: string) { } return createConfig({ - chains: [haqqMainnet, haqqTestedge2], - transports: { - [haqqMainnet.id]: http(), - [haqqTestedge2.id]: http(), - }, + chains: supportedChains, + transports: supportedChainsTransports, connectors, ssr: true, multiInjectedProviderDiscovery: true, diff --git a/libs/data-access/cosmos/package.json b/libs/data-access/cosmos/package.json index e4cacb3df..c86ffb504 100644 --- a/libs/data-access/cosmos/package.json +++ b/libs/data-access/cosmos/package.json @@ -3,8 +3,6 @@ "version": "0.0.1", "dependencies": { "@swc/helpers": "~0.5.11", - "@evmos/proto": "0.1.27", - "@evmos/provider": "0.2.8", "@evmos/transactions": "0.2.13", "@haqq/data-access-falconer": "0.0.1" }, diff --git a/libs/data-access/cosmos/src/lib/get-chain-params.ts b/libs/data-access/cosmos/src/lib/get-chain-params.ts index 15e9abddc..40cad35a0 100644 --- a/libs/data-access/cosmos/src/lib/get-chain-params.ts +++ b/libs/data-access/cosmos/src/lib/get-chain-params.ts @@ -1,14 +1,13 @@ import type { Fee } from '@evmos/transactions'; import { chains } from './chains'; -export function getChainParams(chainId: number) { - const currentChain = chains[chainId]; - - if (!currentChain) { - throw new Error(`No configuration for chain with id ${chainId}`); - } +// Add a default chain ID (HAQQ mainnet) +const DEFAULT_CHAIN_ID = 11235; - return currentChain; +export function getChainParams(chainId: number) { + // Check if the chainId is supported, otherwise use the default + const supportedChainId = chainId in chains ? chainId : DEFAULT_CHAIN_ID; + return chains[supportedChainId]; } export const DEFAULT_FEE: Fee = { diff --git a/libs/ui-kit/src/lib/modal.tsx b/libs/ui-kit/src/lib/modal.tsx index 1e41b9914..9a3d35b2c 100644 --- a/libs/ui-kit/src/lib/modal.tsx +++ b/libs/ui-kit/src/lib/modal.tsx @@ -1,5 +1,5 @@ 'use client'; -import { Fragment, PropsWithChildren, SyntheticEvent } from 'react'; +import { PropsWithChildren, SyntheticEvent } from 'react'; import { Dialog } from '@headlessui/react'; import clsx from 'clsx'; diff --git a/libs/ui-kit/src/lib/sort-select.tsx b/libs/ui-kit/src/lib/sort-select.tsx index 5952a0182..ad8d950e3 100644 --- a/libs/ui-kit/src/lib/sort-select.tsx +++ b/libs/ui-kit/src/lib/sort-select.tsx @@ -1,5 +1,5 @@ 'use client'; -import { Fragment, useMemo } from 'react'; +import { useMemo } from 'react'; import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'; import clsx from 'clsx';