Skip to content

Commit

Permalink
chore: Migrate various wallet hooks from the Warp UI to the Widgets l…
Browse files Browse the repository at this point in the history
…ib (#4865)

### Description

More ground-work for the upcoming Warp Deploy app
No new code, just migrating things from the Warp UI
Corresponds with
hyperlane-xyz/hyperlane-warp-ui-template#326
Fixes
hyperlane-xyz/hyperlane-warp-ui-template#321

### Drive-by changes

Update the hyp registry versions to 6.1.0

### Backward compatibility

Yes

### Testing

Tested in Warp UI and storybook


<img width="1000" alt="Screenshot 2024-11-16 at 7 08 00 PM"
src="https://github.com/user-attachments/assets/f8f9c616-01c4-46e1-8b3b-98415741d4e0">
  • Loading branch information
jmrossy authored Nov 18, 2024
1 parent 33b6f58 commit 0cd65c5
Show file tree
Hide file tree
Showing 37 changed files with 7,345 additions and 160 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-mayflies-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/widgets': minor
---

Add multi-protocol wallet integration hooks and types
5 changes: 5 additions & 0 deletions .changeset/tough-foxes-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Add chainMetadataToCosmosChain function
2 changes: 1 addition & 1 deletion typescript/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@aws-sdk/client-kms": "^3.577.0",
"@aws-sdk/client-s3": "^3.577.0",
"@hyperlane-xyz/registry": "4.7.0",
"@hyperlane-xyz/registry": "6.1.0",
"@hyperlane-xyz/sdk": "7.0.0",
"@hyperlane-xyz/utils": "7.0.0",
"@inquirer/core": "9.0.10",
Expand Down
2 changes: 1 addition & 1 deletion typescript/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "7.0.0",
"dependencies": {
"@hyperlane-xyz/core": "5.8.0",
"@hyperlane-xyz/registry": "4.7.0",
"@hyperlane-xyz/registry": "6.1.0",
"@hyperlane-xyz/sdk": "7.0.0",
"@openzeppelin/contracts-upgradeable": "^4.9.3",
"ethers": "^5.7.2"
Expand Down
2 changes: 1 addition & 1 deletion typescript/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@ethersproject/providers": "^5.7.2",
"@google-cloud/secret-manager": "^5.5.0",
"@hyperlane-xyz/helloworld": "7.0.0",
"@hyperlane-xyz/registry": "4.10.0",
"@hyperlane-xyz/registry": "6.1.0",
"@hyperlane-xyz/sdk": "7.0.0",
"@hyperlane-xyz/utils": "7.0.0",
"@inquirer/prompts": "^5.3.8",
Expand Down
3 changes: 2 additions & 1 deletion typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@arbitrum/sdk": "^4.0.0",
"@aws-sdk/client-s3": "^3.74.0",
"@chain-registry/types": "^0.50.14",
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@hyperlane-xyz/core": "5.8.0",
Expand All @@ -19,7 +20,7 @@
"cross-fetch": "^3.1.5",
"ethers": "^5.7.2",
"pino": "^8.19.0",
"viem": "^2.21.40",
"viem": "^2.21.45",
"zod": "^3.21.2"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ export { EV5TxTransformerInterface } from './providers/transactions/transformer/
export { EV5InterchainAccountTxTransformerPropsSchema } from './providers/transactions/transformer/ethersV5/schemas.js';
export { EV5InterchainAccountTxTransformerProps } from './providers/transactions/transformer/ethersV5/types.js';

export {
chainMetadataToCosmosChain,
chainMetadataToViemChain,
} from './metadata/chainMetadataConversion.js';
export {
EvmGasRouterAdapter,
EvmRouterAdapter,
Expand Down Expand Up @@ -503,7 +507,6 @@ export {
getSealevelAccountDataSchema,
} from './utils/sealevelSerialization.js';
export { getChainIdFromTxs } from './utils/transactions.js';
export { chainMetadataToViemChain } from './utils/viem.js';
export {
FeeConstantConfig,
RouteBlacklist,
Expand Down
98 changes: 98 additions & 0 deletions typescript/sdk/src/metadata/chainMetadataConversion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import type { AssetList, Chain as CosmosChain } from '@chain-registry/types';
import { Chain, defineChain } from 'viem';

import { test1 } from '../consts/testChains.js';
import {
ChainMetadata,
getChainIdNumber,
} from '../metadata/chainMetadataTypes.js';

export function chainMetadataToViemChain(metadata: ChainMetadata): Chain {
return defineChain({
id: getChainIdNumber(metadata),
name: metadata.displayName || metadata.name,
network: metadata.name,
nativeCurrency: metadata.nativeToken || test1.nativeToken!,
rpcUrls: {
public: { http: [metadata.rpcUrls[0].http] },
default: { http: [metadata.rpcUrls[0].http] },
},
blockExplorers: metadata.blockExplorers?.length
? {
default: {
name: metadata.blockExplorers[0].name,
url: metadata.blockExplorers[0].url,
},
}
: undefined,
testnet: !!metadata.isTestnet,
});
}

export function chainMetadataToCosmosChain(metadata: ChainMetadata): {
chain: CosmosChain;
assets: AssetList;
} {
const {
name,
displayName,
chainId,
rpcUrls,
restUrls,
isTestnet,
nativeToken,
bech32Prefix,
slip44,
} = metadata;

if (!nativeToken) throw new Error(`Missing native token for ${name}`);

const chain: CosmosChain = {
chain_name: name,
chain_type: 'cosmos',
status: 'live',
network_type: isTestnet ? 'testnet' : 'mainnet',
pretty_name: displayName || name,
chain_id: chainId as string,
bech32_prefix: bech32Prefix!,
slip44: slip44!,
apis: {
rpc: [{ address: rpcUrls[0].http, provider: displayName || name }],
rest: restUrls
? [{ address: restUrls[0].http, provider: displayName || name }]
: [],
},
fees: {
fee_tokens: [{ denom: 'token' }],
},
staking: {
staking_tokens: [{ denom: 'stake' }],
},
};

const assets: AssetList = {
chain_name: name,
assets: [
{
description: `The native token of ${displayName || name} chain.`,
denom_units: [{ denom: 'token', exponent: nativeToken.decimals }],
base: 'token',
name: 'token',
display: 'token',
symbol: 'token',
type_asset: 'sdk.coin',
},
{
description: `The native token of ${displayName || name} chain.`,
denom_units: [{ denom: 'token', exponent: nativeToken.decimals }],
base: 'stake',
name: 'stake',
display: 'stake',
symbol: 'stake',
type_asset: 'sdk.coin',
},
],
};

return { chain, assets };
}
29 changes: 0 additions & 29 deletions typescript/sdk/src/utils/viem.ts

This file was deleted.

8 changes: 6 additions & 2 deletions typescript/widgets/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
],
"plugins": ["react", "react-hooks"],
"rules": {
// TODO use utils rootLogger in widgets lib
"no-console": ["off"],
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
"settings": {
"react": {
"version": "18",
"defaultVersion": "18"
}
}
}
5 changes: 5 additions & 0 deletions typescript/widgets/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const config: StorybookConfig = {
'@storybook/addon-onboarding',
'@storybook/addon-interactions',
],
refs: {
'@chakra-ui/react': {
disable: true,
},
},
framework: {
name: '@storybook/react-vite',
options: {},
Expand Down
18 changes: 16 additions & 2 deletions typescript/widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@
"react-dom": "^18"
},
"dependencies": {
"@cosmos-kit/react": "^2.18.0",
"@headlessui/react": "^2.1.8",
"@hyperlane-xyz/sdk": "7.0.0",
"@hyperlane-xyz/utils": "7.0.0",
"@interchain-ui/react": "^1.23.28",
"@rainbow-me/rainbowkit": "^2.2.0",
"@solana/wallet-adapter-react": "^0.15.32",
"@solana/wallet-adapter-react-ui": "^0.9.31",
"@solana/web3.js": "^1.95.4",
"clsx": "^2.1.1",
"react-tooltip": "^5.28.0"
"react-tooltip": "^5.28.0",
"viem": "^2.21.41",
"wagmi": "^2.12.26"
},
"devDependencies": {
"@hyperlane-xyz/registry": "4.7.0",
"@chakra-ui/react": "^2.8.2",
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@hyperlane-xyz/registry": "6.1.0",
"@storybook/addon-essentials": "^7.6.14",
"@storybook/addon-interactions": "^7.6.14",
"@storybook/addon-links": "^7.6.14",
Expand All @@ -23,6 +35,7 @@
"@storybook/react": "^7.6.14",
"@storybook/react-vite": "^7.6.14",
"@storybook/test": "^7.6.14",
"@tanstack/react-query": "^5.59.20",
"@types/node": "^18.11.18",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
Expand All @@ -35,6 +48,7 @@
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-storybook": "^0.6.15",
"framer-motion": "^10.16.4",
"postcss": "^8.4.21",
"prettier": "^2.8.8",
"react": "^18.2.0",
Expand Down
66 changes: 65 additions & 1 deletion typescript/widgets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ export { WalletIcon } from './icons/Wallet.js';
export { WarningIcon } from './icons/Warning.js';
export { WebIcon } from './icons/Web.js';
export { WideChevronIcon } from './icons/WideChevron.js';
export { XCircleIcon } from './icons/XCircle.js';
export { XIcon } from './icons/X.js';
export { XCircleIcon } from './icons/XCircle.js';
export { DropdownMenu, type DropdownMenuProps } from './layout/DropdownMenu.js';
export { Modal, useModal, type ModalProps } from './layout/Modal.js';
export { Popover, type PopoverProps } from './layout/Popover.js';
export { CosmosLogo } from './logos/Cosmos.js';
export { EthereumLogo } from './logos/Ethereum.js';
export { HyperlaneLogo } from './logos/Hyperlane.js';
export { PROTOCOL_TO_LOGO } from './logos/protocols.js';
export { SolanaLogo } from './logos/Solana.js';
export { WalletConnectLogo } from './logos/WalletConnect.js';
export { MessageTimeline } from './messages/MessageTimeline.js';
export {
MessageStage,
Expand All @@ -81,3 +86,62 @@ export { useDebounce } from './utils/debounce.js';
export { useIsSsr } from './utils/ssr.js';
export { useInterval, useTimeout } from './utils/timeout.js';
export { useConnectionHealthTest } from './utils/useChainConnectionTest.js';
export {
AccountList,
AccountSummary,
} from './walletIntegrations/AccountList.js';
export { ConnectWalletButton } from './walletIntegrations/ConnectWalletButton.js';
export {
getCosmosKitChainConfigs,
useCosmosAccount,
useCosmosActiveChain,
useCosmosConnectFn,
useCosmosDisconnectFn,
useCosmosTransactionFns,
useCosmosWalletDetails,
} from './walletIntegrations/cosmos.js';
export {
getWagmiChainConfigs,
useEthereumAccount,
useEthereumActiveChain,
useEthereumConnectFn,
useEthereumDisconnectFn,
useEthereumTransactionFns,
useEthereumWalletDetails,
} from './walletIntegrations/ethereum.js';
export {
getAccountAddressAndPubKey,
getAccountAddressForChain,
useAccountAddressForChain,
useAccountForChain,
useAccounts,
useActiveChains,
useConnectFns,
useDisconnectFns,
useTransactionFns,
useWalletDetails,
} from './walletIntegrations/multiProtocol.js';
export { MultiProtocolWalletModal } from './walletIntegrations/MultiProtocolWalletModal.js';
export {
useSolanaAccount,
useSolanaActiveChain,
useSolanaConnectFn,
useSolanaDisconnectFn,
useSolanaTransactionFns,
useSolanaWalletDetails,
} from './walletIntegrations/solana.js';
export type {
AccountInfo,
ActiveChainInfo,
ChainAddress,
ChainTransactionFns,
SendTransactionFn,
SwitchNetworkFn,
WalletDetails,
} from './walletIntegrations/types.js';
export {
ethers5TxToWagmiTx,
findChainByRpcUrl,
getChainsForProtocol,
} from './walletIntegrations/utils.js';
export { WalletLogo } from './walletIntegrations/WalletLogo.js';
3 changes: 3 additions & 0 deletions typescript/widgets/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { rootLogger } from '@hyperlane-xyz/utils';

export const widgetLogger = rootLogger.child({ module: 'widgets' });
Loading

0 comments on commit 0cd65c5

Please sign in to comment.