From 5769d468da1a3eba4d99786603874d3f1c4ba971 Mon Sep 17 00:00:00 2001 From: gin-lsl Date: Tue, 8 Oct 2024 19:22:14 +0800 Subject: [PATCH 1/2] fix: hooks missing return type --- .changeset/clean-lemons-sit.md | 5 +++++ packages/web3/src/hooks/useAccount.ts | 4 +++- packages/web3/src/hooks/useConnection.ts | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/clean-lemons-sit.md diff --git a/.changeset/clean-lemons-sit.md b/.changeset/clean-lemons-sit.md new file mode 100644 index 000000000..b50899976 --- /dev/null +++ b/.changeset/clean-lemons-sit.md @@ -0,0 +1,5 @@ +--- +'@ant-design/web3': patch +--- + +fix: hooks missing return type diff --git a/packages/web3/src/hooks/useAccount.ts b/packages/web3/src/hooks/useAccount.ts index 206a6aa6c..fb9b57a5b 100644 --- a/packages/web3/src/hooks/useAccount.ts +++ b/packages/web3/src/hooks/useAccount.ts @@ -1,7 +1,9 @@ +import type { UniversalWeb3ProviderInterface } from '@ant-design/web3-common'; + import useProvider from './useProvider'; export default function useAccount() { - const { account } = useProvider(); + const { account } = useProvider() as UniversalWeb3ProviderInterface; return { account, diff --git a/packages/web3/src/hooks/useConnection.ts b/packages/web3/src/hooks/useConnection.ts index 5fa2f2afb..fd39d78ca 100644 --- a/packages/web3/src/hooks/useConnection.ts +++ b/packages/web3/src/hooks/useConnection.ts @@ -1,7 +1,9 @@ +import type { UniversalWeb3ProviderInterface } from '@ant-design/web3-common'; + import useProvider from './useProvider'; export default function useConnection() { - const { connect, disconnect } = useProvider(); + const { connect, disconnect } = useProvider() as UniversalWeb3ProviderInterface; return { connect, From f20ab4d435569baed52a9c6882b0a4bb4e4a798a Mon Sep 17 00:00:00 2001 From: gin-lsl Date: Thu, 10 Oct 2024 19:16:36 +0800 Subject: [PATCH 2/2] refactor: move enums to new file --- packages/common/src/enums.ts | 51 ++++++++++++++++++++++ packages/common/src/index.ts | 1 + packages/common/src/types.ts | 54 +----------------------- packages/web3/src/hooks/useAccount.ts | 4 +- packages/web3/src/hooks/useConnection.ts | 4 +- 5 files changed, 56 insertions(+), 58 deletions(-) create mode 100644 packages/common/src/enums.ts diff --git a/packages/common/src/enums.ts b/packages/common/src/enums.ts new file mode 100644 index 000000000..fe8442dad --- /dev/null +++ b/packages/common/src/enums.ts @@ -0,0 +1,51 @@ +export enum ChainIds { + Mainnet = 1, + Polygon = 137, + BSC = 56, + Arbitrum = 42_161, + Optimism = 10, + Goerli = 5, + Avalanche = 43_114, + X1Testnet = 195, + Sepolia = 11_155_111, + Holesky = 17_000, + Scroll = 534_352, + ScrollSepolia = 534_351, + Hardhat = 31_337, + Localhost = 1_337, +} + +export enum SolanaChainIds { + MainnetBeta = 2, + Devnet = 3, + Testnet = 4, +} + +export enum SuiChainIds { + Mainnet = 1, + Testnet = 2, + Devnet = 3, + Localnet = 4, +} + +export enum ChainType { + /** + * Ethereum virtual machine and EVM compatible chains + */ + EVM = 'EVM', + + /** + * Solana virtual machine + */ + SVM = 'SVM', + + /** + * Bitcoin chain + */ + Bitcoin = 'Bitcoin', + + /** + * Sui chain + */ + Sui = 'Sui', +} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index e5e34ac20..9a1e6bb02 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,3 +1,4 @@ +export * from './enums'; export * from './types'; export * from './utils'; export * from './web3-config-provider'; diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index bfc1a74c4..9d258b5d7 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -1,3 +1,5 @@ +import { ChainIds, ChainType } from './enums'; + export interface Account { address: string; name?: string; @@ -5,36 +7,6 @@ export interface Account { addresses?: readonly [`0x${string}`, ...`0x${string}`[]]; } -export enum ChainIds { - Mainnet = 1, - Polygon = 137, - BSC = 56, - Arbitrum = 42_161, - Optimism = 10, - Goerli = 5, - Avalanche = 43_114, - X1Testnet = 195, - Sepolia = 11_155_111, - Holesky = 17_000, - Scroll = 534_352, - ScrollSepolia = 534_351, - Hardhat = 31_337, - Localhost = 1_337, -} - -export enum SolanaChainIds { - MainnetBeta = 2, - Devnet = 3, - Testnet = 4, -} - -export enum SuiChainIds { - Mainnet = 1, - Testnet = 2, - Devnet = 3, - Localnet = 4, -} - export type BrowserLinkType = 'address' | 'transaction'; export type BalanceMetadata = { @@ -43,28 +15,6 @@ export type BalanceMetadata = { symbol?: string; }; -export enum ChainType { - /** - * Ethereum virtual machine and EVM compatible chains - */ - EVM = 'EVM', - - /** - * Solana virtual machine - */ - SVM = 'SVM', - - /** - * Bitcoin chain - */ - Bitcoin = 'Bitcoin', - - /** - * Sui chain - */ - Sui = 'Sui', -} - export interface Chain { id: ChainIds | number; name: string; diff --git a/packages/web3/src/hooks/useAccount.ts b/packages/web3/src/hooks/useAccount.ts index fb9b57a5b..206a6aa6c 100644 --- a/packages/web3/src/hooks/useAccount.ts +++ b/packages/web3/src/hooks/useAccount.ts @@ -1,9 +1,7 @@ -import type { UniversalWeb3ProviderInterface } from '@ant-design/web3-common'; - import useProvider from './useProvider'; export default function useAccount() { - const { account } = useProvider() as UniversalWeb3ProviderInterface; + const { account } = useProvider(); return { account, diff --git a/packages/web3/src/hooks/useConnection.ts b/packages/web3/src/hooks/useConnection.ts index fd39d78ca..5fa2f2afb 100644 --- a/packages/web3/src/hooks/useConnection.ts +++ b/packages/web3/src/hooks/useConnection.ts @@ -1,9 +1,7 @@ -import type { UniversalWeb3ProviderInterface } from '@ant-design/web3-common'; - import useProvider from './useProvider'; export default function useConnection() { - const { connect, disconnect } = useProvider() as UniversalWeb3ProviderInterface; + const { connect, disconnect } = useProvider(); return { connect,