Skip to content

Commit

Permalink
fix: Exclude unused cosmos chains from wallet connection (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy authored Sep 18, 2024
1 parent 295dc2a commit 25d33ea
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/features/chains/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { AssetList, Chain as CosmosChain } from '@chain-registry/types';
import type { Chain as WagmiChain } from '@wagmi/core';

import { ChainName, chainMetadataToWagmiChain } from '@hyperlane-xyz/sdk';
import { ChainMetadata, ChainName, chainMetadataToWagmiChain } from '@hyperlane-xyz/sdk';
import { ProtocolType } from '@hyperlane-xyz/utils';

import { getWarpContext } from '../../context/context';
import { getTokens, getWarpContext } from '../../context/context';

import { cosmosDefaultChain } from './cosmosDefault';

// Metadata formatted for use in Wagmi config
export function getWagmiChainConfig(): WagmiChain[] {
Expand All @@ -15,9 +17,7 @@ export function getWagmiChainConfig(): WagmiChain[] {
}

export function getCosmosKitConfig(): { chains: CosmosChain[]; assets: AssetList[] } {
const cosmosChains = Object.values(getWarpContext().chains).filter(
(c) => c.protocol === ProtocolType.Cosmos,
);
const cosmosChains = getCosmosChains();
const chains = cosmosChains.map((c) => ({
chain_name: c.name,
status: 'live',
Expand Down Expand Up @@ -96,7 +96,13 @@ export function getCosmosKitConfig(): { chains: CosmosChain[]; assets: AssetList
}

export function getCosmosChainNames(): ChainName[] {
return Object.values(getWarpContext().chains)
.filter((c) => c.protocol === ProtocolType.Cosmos)
.map((c) => c.name);
return getCosmosChains().map((c) => c.name);
}

export function getCosmosChains(): ChainMetadata[] {
const tokens = getTokens();
const chains = Object.values(getWarpContext().chains).filter(
(c) => c.protocol === ProtocolType.Cosmos && tokens.some((t) => t.chainName === c.name),
);
return [...chains, cosmosDefaultChain];
}

0 comments on commit 25d33ea

Please sign in to comment.