Skip to content

Commit

Permalink
Fix errors in TransfersDetailsModal when metadata is missing
Browse files Browse the repository at this point in the history
Remove dead code in consts/values
Avoid cosmoshub inclusion in chain picker
  • Loading branch information
jmrossy committed Nov 20, 2024
1 parent 7fdd824 commit e685bad
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
7 changes: 0 additions & 7 deletions src/consts/values.ts

This file was deleted.

7 changes: 1 addition & 6 deletions src/features/chains/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
IRegistry,
cosmoshub,
chainMetadata as publishedChainMetadata,
} from '@hyperlane-xyz/registry';
import { IRegistry, chainMetadata as publishedChainMetadata } from '@hyperlane-xyz/registry';
import {
ChainMap,
ChainMetadata,
Expand All @@ -23,7 +19,6 @@ export async function assembleChainMetadata(
) {
// Chains must include a cosmos chain or CosmosKit throws errors
const result = z.record(ChainMetadataSchema).safeParse({
cosmoshub,
...ChainsYaml,
...ChainsTS,
});
Expand Down
2 changes: 1 addition & 1 deletion src/features/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function initWarpContext(
) {
try {
const coreConfig = await assembleWarpCoreConfig();
const chainsInTokens = coreConfig.tokens.map((t) => t.chainName);
const chainsInTokens = Array.from(new Set(coreConfig.tokens.map((t) => t.chainName)));
// Pre-load registry content to avoid repeated requests
await registry.listRegistryContent();
const { chainMetadata, chainMetadataWithOverrides } = await assembleChainMetadata(
Expand Down
11 changes: 6 additions & 5 deletions src/features/transfer/TransfersDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '../../utils/transfer';
import { useMultiProvider } from '../chains/hooks';
import { getChainDisplayName, hasPermissionlessChain } from '../chains/utils';
import { useWarpCore } from '../tokens/hooks';
import { tryFindToken, useWarpCore } from '../tokens/hooks';
import { TransferContext, TransferStatus } from './types';

export function TransfersDetailsModal({
Expand Down Expand Up @@ -58,7 +58,10 @@ export function TransfersDetailsModal({
} = transfer || {};

const multiProvider = useMultiProvider();
const account = useAccountForChain(multiProvider, origin);
const warpCore = useWarpCore();

const isChainKnown = multiProvider.hasChain(origin);
const account = useAccountForChain(multiProvider, isChainKnown ? origin : undefined);
const walletDetails = useWalletDetails()[account?.protocol || ProtocolType.Ethereum];

const getMessageUrls = useCallback(async () => {
Expand Down Expand Up @@ -87,10 +90,8 @@ export function TransfersDetailsModal({

const isAccountReady = !!account?.isReady;
const connectorName = walletDetails.name || 'wallet';
const token = useWarpCore().findToken(origin, originTokenAddressOrDenom);

const token = tryFindToken(warpCore, origin, originTokenAddressOrDenom);
const isPermissionlessRoute = hasPermissionlessChain(multiProvider, [destination, origin]);

const isSent = isTransferSent(status);
const isFailed = isTransferFailed(status);
const isFinal = isSent || isFailed;
Expand Down
12 changes: 7 additions & 5 deletions src/features/wallet/context/CosmosWalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { wallets as cosmostationWallets } from '@cosmos-kit/cosmostation';
import { wallets as keplrWallets } from '@cosmos-kit/keplr';
import { wallets as leapWallets } from '@cosmos-kit/leap';
import { ChainProvider } from '@cosmos-kit/react';
import { cosmoshub } from '@hyperlane-xyz/registry';
import { MultiProtocolProvider } from '@hyperlane-xyz/sdk';
import { getCosmosKitChainConfigs } from '@hyperlane-xyz/widgets';
import '@interchain-ui/react/styles';
import { PropsWithChildren, useMemo } from 'react';
Expand All @@ -19,11 +21,11 @@ const theme = extendTheme({
});

export function CosmosWalletContext({ children }: PropsWithChildren<unknown>) {
const multiProvider = useMultiProvider();
const { chains, assets } = useMemo(
() => getCosmosKitChainConfigs(multiProvider),
[multiProvider],
);
const chainMetadata = useMultiProvider().metadata;
const { chains, assets } = useMemo(() => {
const multiProvider = new MultiProtocolProvider({ ...chainMetadata, cosmoshub });
return getCosmosKitChainConfigs(multiProvider);
}, [chainMetadata]);
const leapWithoutSnap = leapWallets.filter((wallet) => !wallet.walletName.includes('snap'));
// TODO replace Chakra here with a custom modal for ChainProvider
// Using Chakra + @cosmos-kit/react instead of @cosmos-kit/react-lite adds about 600Kb to the bundle
Expand Down

0 comments on commit e685bad

Please sign in to comment.