Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate various utils from the Warp UI to the Widgets lib #322

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/buttons/ConnectAwareSubmitButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ProtocolType } from '@hyperlane-xyz/utils';
import { useTimeout } from '@hyperlane-xyz/widgets';
import { useFormikContext } from 'formik';
import { useCallback } from 'react';
import { useChainProtocol } from '../../features/chains/hooks';
import { useAccountForChain, useConnectFns } from '../../features/wallet/hooks/multiProtocol';
import { useTimeout } from '../../utils/timeout';
import { SolidButton } from './SolidButton';

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { tryClipboardSet } from '@hyperlane-xyz/widgets';
import Image from 'next/image';
import { useState } from 'react';
import CheckmarkIcon from '../../images/icons/checkmark.svg';
import CopyIcon from '../../images/icons/copy-stack.svg';
import { tryClipboardSet } from '../../utils/clipboard';

interface Props {
width: number;
Expand Down
6 changes: 3 additions & 3 deletions src/components/icons/TokenIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IRegistry } from '@hyperlane-xyz/registry';
import { IToken } from '@hyperlane-xyz/sdk';
import { isHttpsUrl, isRelativeUrl } from '@hyperlane-xyz/utils';
import { Circle } from '@hyperlane-xyz/widgets';
import { useStore } from '../../features/store';
import { isValidHttpsUrl, isValidRelativeUrl } from '../../utils/url';
import { ErrorBoundary } from '../errors/ErrorBoundary';

interface Props {
Expand Down Expand Up @@ -36,8 +36,8 @@ export function TokenIcon({ token, size = 32 }: Props) {
function getImageSrc(registry: IRegistry, token?: IToken | null) {
if (!token?.logoURI) return null;
// If it's a valid, direct URL, return it
if (isValidHttpsUrl(token.logoURI)) return token.logoURI;
if (isHttpsUrl(token.logoURI)) return token.logoURI;
// Otherwise assume it's a relative URL to the registry base
if (isValidRelativeUrl(token.logoURI)) return registry.getUri(token.logoURI);
if (isRelativeUrl(token.logoURI)) return registry.getUri(token.logoURI);
return null;
}
2 changes: 1 addition & 1 deletion src/features/WarpContextInitGate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTimeout } from '@hyperlane-xyz/widgets';
import { PropsWithChildren, useState } from 'react';
import { Spinner } from '../components/animation/Spinner';
import { useTimeout } from '../utils/timeout';
import { useReadyMultiProvider } from './chains/hooks';

const INIT_TIMEOUT = 10_000; // 10 seconds
Expand Down
22 changes: 0 additions & 22 deletions src/features/chains/cosmosDefault.ts

This file was deleted.

11 changes: 7 additions & 4 deletions src/features/chains/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { AssetList, Chain as CosmosChain } from '@chain-registry/types';
import { IRegistry, chainMetadata as publishedChainMetadata } from '@hyperlane-xyz/registry';
import {
IRegistry,
cosmoshub,
chainMetadata as publishedChainMetadata,
} from '@hyperlane-xyz/registry';
import {
ChainMap,
ChainMetadata,
Expand All @@ -16,15 +20,14 @@ import { chains as ChainsTS } from '../../consts/chains.ts';
import ChainsYaml from '../../consts/chains.yaml';
import { config } from '../../consts/config.ts';
import { logger } from '../../utils/logger.ts';
import { cosmosDefaultChain } from './cosmosDefault';

export async function assembleChainMetadata(
registry: IRegistry,
storeMetadataOverrides?: ChainMap<Partial<ChainMetadata | undefined>>,
) {
// Chains must include a cosmos chain or CosmosKit throws errors
const result = z.record(ChainMetadataSchema).safeParse({
cosmoshub: cosmosDefaultChain,
cosmoshub,
...ChainsYaml,
...ChainsTS,
});
Expand Down Expand Up @@ -74,7 +77,7 @@ export function getCosmosChains(warpCore: WarpCore): ChainMetadata[] {
(c) =>
c.protocol === ProtocolType.Cosmos && warpCore.tokens.some((t) => t.chainName === c.name),
);
return [...chains, cosmosDefaultChain];
return [...chains, cosmoshub];
}

export function getCosmosKitConfig(warpCore: WarpCore): {
Expand Down
3 changes: 1 addition & 2 deletions src/features/tokens/warpCoreConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { warpRouteConfigs } from '@hyperlane-xyz/registry';
import { WarpCoreConfig, WarpCoreConfigSchema } from '@hyperlane-xyz/sdk';
import { WarpCoreConfig, WarpCoreConfigSchema, validateZodResult } from '@hyperlane-xyz/sdk';
import { objFilter, objMerge } from '@hyperlane-xyz/utils';
import { warpRouteWhitelist } from '../../consts/warpRouteWhitelist.ts';
import { warpRouteConfigs as WarpRoutesTs } from '../../consts/warpRoutes.ts';
import WarpRoutesYaml from '../../consts/warpRoutes.yaml';
import { validateZodResult } from '../../utils/zod.ts';

export function assembleWarpCoreConfig(): WarpCoreConfig {
const resultYaml = WarpCoreConfigSchema.safeParse(WarpRoutesYaml);
Expand Down
8 changes: 6 additions & 2 deletions src/features/transfer/TransfersDetailsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ProtocolType } from '@hyperlane-xyz/utils';
import { MessageStatus, MessageTimeline, useMessageTimeline } from '@hyperlane-xyz/widgets';
import {
MessageStatus,
MessageTimeline,
useMessageTimeline,
useTimeout,
} from '@hyperlane-xyz/widgets';
import Image from 'next/image';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Spinner } from '../../components/animation/Spinner';
Expand All @@ -12,7 +17,6 @@ import LinkIcon from '../../images/icons/external-link-icon.svg';
import { formatTimestamp } from '../../utils/date';
import { getHypExplorerLink } from '../../utils/links';
import { logger } from '../../utils/logger';
import { useTimeout } from '../../utils/timeout';
import {
getIconByTransferStatus,
getTransferStatusLabel,
Expand Down
2 changes: 1 addition & 1 deletion src/features/wallet/SideBarMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { tryClipboardSet } from '@hyperlane-xyz/widgets';
import Image from 'next/image';
import { useEffect, useMemo, useRef, useState } from 'react';
import { toast } from 'react-toastify';
Expand All @@ -9,7 +10,6 @@ import CollapseIcon from '../../images/icons/collapse-icon.svg';
import Logout from '../../images/icons/logout.svg';
import ResetIcon from '../../images/icons/reset-icon.svg';
import Wallet from '../../images/icons/wallet.svg';
import { tryClipboardSet } from '../../utils/clipboard';
import { STATUSES_WITH_ICON, getIconByTransferStatus } from '../../utils/transfer';
import { useMultiProvider } from '../chains/hooks';
import { getChainDisplayName } from '../chains/utils';
Expand Down
3 changes: 1 addition & 2 deletions src/features/wallet/WalletControlBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ProtocolType, shortenAddress } from '@hyperlane-xyz/utils';
import { ChevronIcon } from '@hyperlane-xyz/widgets';
import { ChevronIcon, useIsSsr } from '@hyperlane-xyz/widgets';
import Image from 'next/image';
import { SolidButton } from '../../components/buttons/SolidButton';
import { WalletLogo } from '../../components/icons/WalletLogo';
import Wallet from '../../images/icons/wallet.svg';
import { useIsSsr } from '../../utils/ssr';
import { useStore } from '../store';
import { useAccounts, useWalletDetails } from './hooks/multiProtocol';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useIsSsr } from '@hyperlane-xyz/widgets';
import '@hyperlane-xyz/widgets/styles.css';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Analytics } from '@vercel/analytics/react';
Expand All @@ -12,7 +13,6 @@ import { CosmosWalletContext } from '../features/wallet/context/CosmosWalletCont
import { EvmWalletContext } from '../features/wallet/context/EvmWalletContext';
import { SolanaWalletContext } from '../features/wallet/context/SolanaWalletContext';
import '../styles/globals.css';
import { useIsSsr } from '../utils/ssr';
import '../vendor/inpage-metamask';
import '../vendor/polyfill';

Expand Down
26 changes: 0 additions & 26 deletions src/utils/clipboard.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/utils/debounce.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/utils/ssr.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/utils/timeout.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/utils/url.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/utils/zod.ts

This file was deleted.

Loading