@ant-design/web3-wagmi 2.7.3 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/esm/chains.d.ts +15 -0
  3. package/dist/esm/chains.js +79 -0
  4. package/dist/esm/index.d.ts +3 -1
  5. package/dist/esm/index.js +3 -1
  6. package/dist/esm/interface.d.ts +7 -2
  7. package/dist/esm/wagmi-provider/config-provider.d.ts +1 -1
  8. package/dist/esm/wagmi-provider/config-provider.js +10 -6
  9. package/dist/esm/wagmi-provider/index.d.ts +12 -5
  10. package/dist/esm/wagmi-provider/index.js +62 -7
  11. package/dist/esm/wallets/coinbase-wallet.d.ts +4 -2
  12. package/dist/esm/wallets/coinbase-wallet.js +5 -1
  13. package/dist/esm/wallets/im-token.js +4 -1
  14. package/dist/esm/wallets/meta-mask.js +4 -1
  15. package/dist/esm/wallets/okx-wallet.js +4 -1
  16. package/dist/esm/wallets/token-pocket.js +5 -0
  17. package/dist/esm/wallets/universal-wallet.d.ts +3 -2
  18. package/dist/esm/wallets/universal-wallet.js +3 -1
  19. package/dist/lib/chains.d.ts +15 -0
  20. package/dist/lib/chains.js +85 -0
  21. package/dist/lib/index.d.ts +3 -1
  22. package/dist/lib/index.js +26 -4
  23. package/dist/lib/interface.d.ts +7 -2
  24. package/dist/lib/wagmi-provider/config-provider.d.ts +1 -1
  25. package/dist/lib/wagmi-provider/config-provider.js +10 -6
  26. package/dist/lib/wagmi-provider/index.d.ts +12 -5
  27. package/dist/lib/wagmi-provider/index.js +60 -5
  28. package/dist/lib/wallets/coinbase-wallet.d.ts +4 -2
  29. package/dist/lib/wallets/coinbase-wallet.js +5 -1
  30. package/dist/lib/wallets/im-token.js +4 -1
  31. package/dist/lib/wallets/meta-mask.js +4 -1
  32. package/dist/lib/wallets/okx-wallet.js +4 -1
  33. package/dist/lib/wallets/token-pocket.js +5 -0
  34. package/dist/lib/wallets/universal-wallet.d.ts +3 -2
  35. package/dist/lib/wallets/universal-wallet.js +3 -1
  36. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @ant-design/web3-wagmi
2
2
 
3
+ ## 2.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c22eb4d: feat: @ant-design/web3-wagmi support auto generate config, and add @ant-design/web3-assets/wallets export
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [c22eb4d]
12
+ - @ant-design/web3-assets@1.11.0
13
+
14
+ ## 2.7.4
15
+
16
+ ### Patch Changes
17
+
18
+ - efbd948: fix(web3-wagmi): Correct spelling of "Factories"
19
+ - Updated dependencies [9bb1ea1]
20
+ - @ant-design/web3-common@1.13.0
21
+ - @ant-design/web3-assets@1.10.2
22
+
3
23
  ## 2.7.3
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,15 @@
1
+ import type { ChainAssetWithWagmiChain } from './interface';
2
+ export declare const Mainnet: ChainAssetWithWagmiChain;
3
+ export declare const Goerli: ChainAssetWithWagmiChain;
4
+ export declare const Sepolia: ChainAssetWithWagmiChain;
5
+ export declare const Holesky: ChainAssetWithWagmiChain;
6
+ export declare const Polygon: ChainAssetWithWagmiChain;
7
+ export declare const BSC: ChainAssetWithWagmiChain;
8
+ export declare const Arbitrum: ChainAssetWithWagmiChain;
9
+ export declare const Optimism: ChainAssetWithWagmiChain;
10
+ export declare const Avalanche: ChainAssetWithWagmiChain;
11
+ export declare const X1Testnet: ChainAssetWithWagmiChain;
12
+ export declare const Scroll: ChainAssetWithWagmiChain;
13
+ export declare const ScrollSepolia: ChainAssetWithWagmiChain;
14
+ export declare const Hardhat: ChainAssetWithWagmiChain;
15
+ export declare const Localhost: ChainAssetWithWagmiChain;
@@ -0,0 +1,79 @@
1
+ import { Arbitrum as ArbitrumAsset, Avalanche as AvalancheAsset, BSC as BSCAsset, Goerli as GoerliAsset, Hardhat as HardhatAsset, Holesky as HoleskyAsset, Localhost as LocalhostAsset, Mainnet as MainnetAsset, Optimism as OptimismAsset, Polygon as PolygonAsset, Scroll as ScrollAsset, ScrollSepolia as ScrollSepoliaAsset, Sepolia as SepoliaAsset, X1Testnet as X1TestnetAsset } from '@ant-design/web3-assets';
2
+ import { arbitrum, avalanche, bsc, goerli, hardhat, holesky, localhost, mainnet, optimism, polygon, scroll, scrollSepolia, sepolia } from 'wagmi/chains';
3
+ export const Mainnet = {
4
+ ...MainnetAsset,
5
+ wagmiChain: mainnet
6
+ };
7
+ export const Goerli = {
8
+ ...GoerliAsset,
9
+ wagmiChain: goerli
10
+ };
11
+ export const Sepolia = {
12
+ ...SepoliaAsset,
13
+ wagmiChain: sepolia
14
+ };
15
+ export const Holesky = {
16
+ ...HoleskyAsset,
17
+ wagmiChain: holesky
18
+ };
19
+ export const Polygon = {
20
+ ...PolygonAsset,
21
+ wagmiChain: polygon
22
+ };
23
+ export const BSC = {
24
+ ...BSCAsset,
25
+ wagmiChain: bsc
26
+ };
27
+ export const Arbitrum = {
28
+ ...ArbitrumAsset,
29
+ wagmiChain: arbitrum
30
+ };
31
+ export const Optimism = {
32
+ ...OptimismAsset,
33
+ wagmiChain: optimism
34
+ };
35
+ export const Avalanche = {
36
+ ...AvalancheAsset,
37
+ wagmiChain: avalanche
38
+ };
39
+
40
+ // OKX X1: https://www.okx.com/cn/x1/docs/developer/build-on-x1/quickstart
41
+ export const X1Testnet = {
42
+ ...X1TestnetAsset,
43
+ wagmiChain: {
44
+ id: X1TestnetAsset.id,
45
+ name: X1TestnetAsset.name,
46
+ nativeCurrency: {
47
+ name: 'OKB',
48
+ symbol: 'OKB',
49
+ decimals: 18
50
+ },
51
+ rpcUrls: {
52
+ default: {
53
+ http: ['https://testrpc.x1.tech']
54
+ }
55
+ },
56
+ blockExplorers: {
57
+ default: {
58
+ name: 'X1TestnetScan',
59
+ url: 'https://www.okx.com/explorer/x1-test'
60
+ }
61
+ }
62
+ }
63
+ };
64
+ export const Scroll = {
65
+ ...ScrollAsset,
66
+ wagmiChain: scroll
67
+ };
68
+ export const ScrollSepolia = {
69
+ ...ScrollSepoliaAsset,
70
+ wagmiChain: scrollSepolia
71
+ };
72
+ export const Hardhat = {
73
+ ...HardhatAsset,
74
+ wagmiChain: hardhat
75
+ };
76
+ export const Localhost = {
77
+ ...LocalhostAsset,
78
+ wagmiChain: localhost
79
+ };
@@ -1,4 +1,6 @@
1
1
  export * from './wagmi-provider';
2
2
  export * from './wallets';
3
3
  export * from './interface';
4
- export * from '@ant-design/web3-assets';
4
+ export * from './chains';
5
+ export * from '@ant-design/web3-assets/tokens';
6
+ export * from '@ant-design/web3-assets/wallets';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./wagmi-provider";
2
2
  export * from "./wallets";
3
3
  export * from "./interface";
4
- export * from '@ant-design/web3-assets';
4
+ export * from "./chains";
5
+ export * from '@ant-design/web3-assets/tokens';
6
+ export * from '@ant-design/web3-assets/wallets';
@@ -1,5 +1,6 @@
1
- import type { ConnectOptions, UniversalEIP6963Config, Wallet, WalletMetadata } from '@ant-design/web3-common';
2
- import type { Connector } from 'wagmi';
1
+ import type { Chain, ConnectOptions, UniversalEIP6963Config, Wallet, WalletMetadata } from '@ant-design/web3-common';
2
+ import type { Chain as WagmiChain } from 'viem';
3
+ import type { Connector, CreateConnectorFn } from 'wagmi';
3
4
  export interface WalletUseInWagmiAdapter extends Wallet {
4
5
  getWagmiConnector?: (options?: ConnectOptions) => Promise<Connector | undefined>;
5
6
  }
@@ -8,5 +9,9 @@ export interface WalletFactory {
8
9
  name?: string;
9
10
  connectors: Connector['name'][];
10
11
  create: (connector?: readonly Connector[]) => WalletUseInWagmiAdapter;
12
+ createWagmiConnector?: () => CreateConnectorFn;
11
13
  }
12
14
  export type EIP6963Config = boolean | UniversalEIP6963Config;
15
+ export type ChainAssetWithWagmiChain = Chain & {
16
+ wagmiChain?: WagmiChain;
17
+ };
@@ -4,7 +4,7 @@ import type { Config as WagmiConfig } from 'wagmi';
4
4
  import type { EIP6963Config, WalletFactory } from '../interface';
5
5
  export interface AntDesignWeb3ConfigProviderProps {
6
6
  chainAssets: Chain[];
7
- walletFactorys: WalletFactory[];
7
+ walletFactories: WalletFactory[];
8
8
  locale?: Locale;
9
9
  children?: React.ReactNode;
10
10
  ens?: boolean;
@@ -10,7 +10,7 @@ export const AntDesignWeb3ConfigProvider = props => {
10
10
  const {
11
11
  children,
12
12
  chainAssets,
13
- walletFactorys,
13
+ walletFactories,
14
14
  ens = true,
15
15
  balance,
16
16
  locale,
@@ -49,8 +49,12 @@ export const AntDesignWeb3ConfigProvider = props => {
49
49
  name: ensName && ens ? ensName : undefined,
50
50
  avatar: ensAvatar ?? undefined
51
51
  } : undefined;
52
+ const isConnectorNameMatch = (aName, bName) => {
53
+ // match connector name like okxWallet, Okx Wallet, OKX Wallet
54
+ return aName.replace(/ /g, '').toLowerCase() === bName.replace(/ /g, '').toLowerCase();
55
+ };
52
56
  const findConnectorByName = name => {
53
- const commonConnector = wagimConfig.connectors.find(item => item.name === name && !isEIP6963Connector(item));
57
+ const commonConnector = wagimConfig.connectors.find(item => isConnectorNameMatch(item.name, name) && !isEIP6963Connector(item));
54
58
  if (!eip6963) {
55
59
  return commonConnector;
56
60
  }
@@ -62,14 +66,14 @@ export const AntDesignWeb3ConfigProvider = props => {
62
66
  wagimConfig.connectors.forEach(connector => {
63
67
  if (isEIP6963Connector(connector)) {
64
68
  // check is need auto add eip6963 wallet
65
- if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactorys.find(item => item.connectors.includes(connector.name))) {
69
+ if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactories.find(item => item.connectors.some(aName => isConnectorNameMatch(aName, connector.name)))) {
66
70
  // not config wallet and find the wallet in connectors, auto add it
67
71
  autoAddEIP6963Wallets.push(EIP6963Wallet().create([connector]));
68
72
  }
69
73
  // Do not need check eip6963 wallet
70
74
  return;
71
75
  }
72
- const walletFactory = walletFactorys.find(factory => factory.connectors.includes(connector.name));
76
+ const walletFactory = walletFactories.find(factory => factory.connectors.some(aName => isConnectorNameMatch(aName, connector.name)));
73
77
  if (!walletFactory?.create) {
74
78
  // check user wallets config and console.error for alert
75
79
  console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'wallets'.`);
@@ -77,7 +81,7 @@ export const AntDesignWeb3ConfigProvider = props => {
77
81
  });
78
82
 
79
83
  // Generate Wallet for @ant-design/web3
80
- const supportWallets = walletFactorys.map(factory => {
84
+ const supportWallets = walletFactories.map(factory => {
81
85
  const connectors = factory.connectors.map(findConnectorByName).filter(item => !!item);
82
86
  if (connectors.length === 0 && !eip6963) {
83
87
  // Not config connector for this wallet factory and not use eip6963, ignore it.
@@ -87,7 +91,7 @@ export const AntDesignWeb3ConfigProvider = props => {
87
91
  return factory.create(connectors);
88
92
  }).filter(item => item !== null);
89
93
  return [...supportWallets, ...autoAddEIP6963Wallets];
90
- }, [wagimConfig.connectors, walletFactorys, eip6963]);
94
+ }, [wagimConfig.connectors, walletFactories, eip6963]);
91
95
  const chainList = React.useMemo(() => {
92
96
  return wagimConfig.chains.map(item => {
93
97
  const c = chainAssets?.find(asset => {
@@ -1,18 +1,25 @@
1
1
  import React from 'react';
2
- import type { Chain, Locale } from '@ant-design/web3-common';
2
+ import type { Locale } from '@ant-design/web3-common';
3
3
  import { QueryClient } from '@tanstack/react-query';
4
+ import type { Transport } from 'viem';
4
5
  import type { Config, State } from 'wagmi';
5
- import type { EIP6963Config, WalletFactory } from '../interface';
6
+ import type { WalletConnectParameters } from 'wagmi/connectors';
7
+ import type { ChainAssetWithWagmiChain, EIP6963Config, WalletFactory } from '../interface';
8
+ export interface WalletConnectOptions extends Pick<WalletConnectParameters, 'disableProviderPing' | 'isNewChainsStale' | 'projectId' | 'metadata' | 'relayUrl' | 'storageOptions' | 'qrModalOptions'> {
9
+ useWalletConnectOfficialModal?: boolean;
10
+ }
6
11
  export type WagmiWeb3ConfigProviderProps = {
7
- config: Config;
12
+ config?: Config;
8
13
  locale?: Locale;
9
14
  wallets?: WalletFactory[];
10
- chains?: Chain[];
15
+ chains?: ChainAssetWithWagmiChain[];
11
16
  ens?: boolean;
12
17
  queryClient?: QueryClient;
13
18
  balance?: boolean;
14
19
  eip6963?: EIP6963Config;
15
20
  initialState?: State;
16
21
  reconnectOnMount?: boolean;
22
+ walletConnect?: false | WalletConnectOptions;
23
+ transports?: Record<number, Transport>;
17
24
  };
18
- export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
25
+ export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, walletConnect, transports, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
- // Built in popular chains
3
- import { Mainnet } from '@ant-design/web3-assets';
4
2
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5
- import { WagmiProvider } from 'wagmi';
3
+ import { createConfig, http, WagmiProvider } from 'wagmi';
4
+ import { mainnet } from 'wagmi/chains';
5
+ import { walletConnect as wagmiWalletConnect } from 'wagmi/connectors';
6
+ // Built in popular chains
7
+ import { Mainnet } from "../chains";
6
8
  import { AntDesignWeb3ConfigProvider } from "./config-provider";
7
9
  import { jsx as _jsx } from "react/jsx-runtime";
8
10
  export function WagmiWeb3ConfigProvider({
@@ -15,25 +17,78 @@ export function WagmiWeb3ConfigProvider({
15
17
  queryClient,
16
18
  balance,
17
19
  eip6963,
20
+ walletConnect,
21
+ transports,
18
22
  ...restProps
19
23
  }) {
20
- const chainAssets = [...chains, Mainnet];
24
+ // When user custom config, add Mainnet by default
25
+ // When user not provide config, auto generate config, chains use user provided chains
26
+ const chainAssets = config ? [Mainnet, ...chains] : chains?.length ? chains : [Mainnet];
27
+ const generateConfigFlag = () => {
28
+ return `${JSON.stringify(walletConnect)}-${chains.map(item => item.id).join(',')}-${wallets.map(item => item.name).join(',')}`;
29
+ };
30
+ const generateConfig = () => {
31
+ // Auto generate config
32
+ const connectors = [];
33
+ if (walletConnect && walletConnect.projectId) {
34
+ connectors.push(wagmiWalletConnect({
35
+ ...walletConnect,
36
+ showQrModal: walletConnect.useWalletConnectOfficialModal ?? false
37
+ }));
38
+ }
39
+ wallets.forEach(wallet => {
40
+ const connector = wallet.createWagmiConnector?.();
41
+ if (connector) {
42
+ connectors.push(connector);
43
+ }
44
+ });
45
+ const autoGenerateConfig = createConfig({
46
+ chains: chainAssets.map(chain => chain.wagmiChain),
47
+ transports: transports ?? {
48
+ [mainnet.id]: http()
49
+ },
50
+ connectors
51
+ });
52
+ return {
53
+ flag: generateConfigFlag(),
54
+ config: autoGenerateConfig
55
+ };
56
+ };
57
+ const [autoConfig, setAutoConfig] = React.useState(() => {
58
+ if (config) {
59
+ return {
60
+ config
61
+ };
62
+ }
63
+ return generateConfig();
64
+ });
21
65
  const mergedQueryClient = React.useMemo(() => {
22
66
  return queryClient ?? new QueryClient();
23
67
  }, [queryClient]);
68
+ React.useEffect(() => {
69
+ if (config) {
70
+ return;
71
+ }
72
+ const flag = generateConfigFlag();
73
+ if (flag !== autoConfig.flag) {
74
+ // Need recreate wagmi config
75
+ setAutoConfig(generateConfig());
76
+ }
77
+ }, [config, wallets, chains, walletConnect]);
78
+ const wagmiConfig = config || autoConfig.config;
24
79
  return /*#__PURE__*/_jsx(WagmiProvider, {
25
- config: config,
80
+ config: wagmiConfig,
26
81
  ...restProps,
27
82
  children: /*#__PURE__*/_jsx(QueryClientProvider, {
28
83
  client: mergedQueryClient,
29
84
  children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
30
85
  locale: locale,
31
86
  chainAssets: chainAssets,
32
- walletFactorys: wallets,
87
+ walletFactories: wallets,
33
88
  ens: ens,
34
89
  balance: balance,
35
90
  eip6963: eip6963,
36
- wagimConfig: config,
91
+ wagimConfig: wagmiConfig,
37
92
  children: children
38
93
  })
39
94
  })
@@ -1,2 +1,4 @@
1
- import type { EthereumWallet } from '../interface';
2
- export declare const CoinbaseWallet: EthereumWallet;
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ import { type CoinbaseWalletParameters } from 'wagmi/connectors';
3
+ import { WalletFactory } from '../interface';
4
+ export declare const CoinbaseWallet: (metadata?: Partial<WalletMetadata>, coinbaseConfig?: CoinbaseWalletParameters) => WalletFactory;
@@ -1,5 +1,6 @@
1
1
  import { metadata_CoinbaseWallet } from '@ant-design/web3-assets';
2
- export const CoinbaseWallet = metadata => {
2
+ import { coinbaseWallet } from 'wagmi/connectors';
3
+ export const CoinbaseWallet = (metadata, coinbaseConfig) => {
3
4
  return {
4
5
  connectors: ['Coinbase Wallet'],
5
6
  create: () => {
@@ -10,6 +11,9 @@ export const CoinbaseWallet = metadata => {
10
11
  },
11
12
  ...metadata
12
13
  };
14
+ },
15
+ createWagmiConnector: () => {
16
+ return coinbaseWallet(coinbaseConfig);
13
17
  }
14
18
  };
15
19
  };
@@ -1,8 +1,11 @@
1
1
  import { metadata_imToken } from '@ant-design/web3-assets';
2
+ import { injected } from 'wagmi/connectors';
2
3
  import { UniversalWallet } from "./universal-wallet";
3
4
  export const ImToken = metadata => {
4
5
  return new UniversalWallet({
5
6
  ...metadata_imToken,
6
7
  ...metadata
7
- });
8
+ }, () => injected({
9
+ target: 'imToken'
10
+ }));
8
11
  };
@@ -1,8 +1,11 @@
1
1
  import { metadata_MetaMask } from '@ant-design/web3-assets';
2
+ import { injected } from 'wagmi/connectors';
2
3
  import { UniversalWallet } from "./universal-wallet";
3
4
  export const MetaMask = metadata => {
4
5
  return new UniversalWallet({
5
6
  ...metadata_MetaMask,
6
7
  ...metadata
7
- });
8
+ }, () => injected({
9
+ target: 'metaMask'
10
+ }));
8
11
  };
@@ -1,8 +1,11 @@
1
1
  import { metadata_OkxWallet } from '@ant-design/web3-assets';
2
+ import { injected } from 'wagmi/connectors';
2
3
  import { UniversalWallet } from "./universal-wallet";
3
4
  export const OkxWallet = metadata => {
4
5
  return new UniversalWallet({
5
6
  ...metadata_OkxWallet,
6
7
  ...metadata
7
- });
8
+ }, () => injected({
9
+ target: 'okxWallet'
10
+ }));
8
11
  };
@@ -1,8 +1,13 @@
1
1
  import { metadata_TokenPocket } from '@ant-design/web3-assets';
2
+ import { injected } from 'wagmi/connectors';
2
3
  import { UniversalWallet } from "./universal-wallet";
3
4
  export const TokenPocket = metadata => {
4
5
  return new UniversalWallet({
5
6
  ...metadata_TokenPocket,
6
7
  ...metadata
8
+ }, () => {
9
+ return injected({
10
+ target: 'tokenPocket'
11
+ });
7
12
  });
8
13
  };
@@ -1,10 +1,11 @@
1
1
  import type { WalletMetadata } from '@ant-design/web3-common';
2
- import type { Connector } from 'wagmi';
2
+ import type { Connector, CreateConnectorFn } from 'wagmi';
3
3
  import type { WalletFactory, WalletUseInWagmiAdapter } from '../interface';
4
4
  export declare class UniversalWallet implements WalletFactory {
5
5
  private wallet;
6
6
  name?: string;
7
+ createWagmiConnector?: () => CreateConnectorFn;
7
8
  connectors: string[];
8
- constructor(wallet: WalletMetadata);
9
+ constructor(wallet: WalletMetadata, createWagmiConnector?: () => CreateConnectorFn);
9
10
  create: (connectors?: readonly Connector[]) => WalletUseInWagmiAdapter;
10
11
  }
@@ -1,9 +1,11 @@
1
1
  export class UniversalWallet {
2
2
  name;
3
+ createWagmiConnector;
3
4
  connectors = [];
4
- constructor(wallet) {
5
+ constructor(wallet, createWagmiConnector) {
5
6
  this.wallet = wallet;
6
7
  this.name = wallet.name;
8
+ this.createWagmiConnector = createWagmiConnector;
7
9
  if (wallet.extensions) {
8
10
  // support injected connector
9
11
  // https://wagmi.sh/react/connectors/injected
@@ -0,0 +1,15 @@
1
+ import type { ChainAssetWithWagmiChain } from './interface';
2
+ export declare const Mainnet: ChainAssetWithWagmiChain;
3
+ export declare const Goerli: ChainAssetWithWagmiChain;
4
+ export declare const Sepolia: ChainAssetWithWagmiChain;
5
+ export declare const Holesky: ChainAssetWithWagmiChain;
6
+ export declare const Polygon: ChainAssetWithWagmiChain;
7
+ export declare const BSC: ChainAssetWithWagmiChain;
8
+ export declare const Arbitrum: ChainAssetWithWagmiChain;
9
+ export declare const Optimism: ChainAssetWithWagmiChain;
10
+ export declare const Avalanche: ChainAssetWithWagmiChain;
11
+ export declare const X1Testnet: ChainAssetWithWagmiChain;
12
+ export declare const Scroll: ChainAssetWithWagmiChain;
13
+ export declare const ScrollSepolia: ChainAssetWithWagmiChain;
14
+ export declare const Hardhat: ChainAssetWithWagmiChain;
15
+ export declare const Localhost: ChainAssetWithWagmiChain;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.X1Testnet = exports.Sepolia = exports.ScrollSepolia = exports.Scroll = exports.Polygon = exports.Optimism = exports.Mainnet = exports.Localhost = exports.Holesky = exports.Hardhat = exports.Goerli = exports.BSC = exports.Avalanche = exports.Arbitrum = void 0;
7
+ var _web3Assets = require("@ant-design/web3-assets");
8
+ var _chains = require("wagmi/chains");
9
+ const Mainnet = exports.Mainnet = {
10
+ ..._web3Assets.Mainnet,
11
+ wagmiChain: _chains.mainnet
12
+ };
13
+ const Goerli = exports.Goerli = {
14
+ ..._web3Assets.Goerli,
15
+ wagmiChain: _chains.goerli
16
+ };
17
+ const Sepolia = exports.Sepolia = {
18
+ ..._web3Assets.Sepolia,
19
+ wagmiChain: _chains.sepolia
20
+ };
21
+ const Holesky = exports.Holesky = {
22
+ ..._web3Assets.Holesky,
23
+ wagmiChain: _chains.holesky
24
+ };
25
+ const Polygon = exports.Polygon = {
26
+ ..._web3Assets.Polygon,
27
+ wagmiChain: _chains.polygon
28
+ };
29
+ const BSC = exports.BSC = {
30
+ ..._web3Assets.BSC,
31
+ wagmiChain: _chains.bsc
32
+ };
33
+ const Arbitrum = exports.Arbitrum = {
34
+ ..._web3Assets.Arbitrum,
35
+ wagmiChain: _chains.arbitrum
36
+ };
37
+ const Optimism = exports.Optimism = {
38
+ ..._web3Assets.Optimism,
39
+ wagmiChain: _chains.optimism
40
+ };
41
+ const Avalanche = exports.Avalanche = {
42
+ ..._web3Assets.Avalanche,
43
+ wagmiChain: _chains.avalanche
44
+ };
45
+
46
+ // OKX X1: https://www.okx.com/cn/x1/docs/developer/build-on-x1/quickstart
47
+ const X1Testnet = exports.X1Testnet = {
48
+ ..._web3Assets.X1Testnet,
49
+ wagmiChain: {
50
+ id: _web3Assets.X1Testnet.id,
51
+ name: _web3Assets.X1Testnet.name,
52
+ nativeCurrency: {
53
+ name: 'OKB',
54
+ symbol: 'OKB',
55
+ decimals: 18
56
+ },
57
+ rpcUrls: {
58
+ default: {
59
+ http: ['https://testrpc.x1.tech']
60
+ }
61
+ },
62
+ blockExplorers: {
63
+ default: {
64
+ name: 'X1TestnetScan',
65
+ url: 'https://www.okx.com/explorer/x1-test'
66
+ }
67
+ }
68
+ }
69
+ };
70
+ const Scroll = exports.Scroll = {
71
+ ..._web3Assets.Scroll,
72
+ wagmiChain: _chains.scroll
73
+ };
74
+ const ScrollSepolia = exports.ScrollSepolia = {
75
+ ..._web3Assets.ScrollSepolia,
76
+ wagmiChain: _chains.scrollSepolia
77
+ };
78
+ const Hardhat = exports.Hardhat = {
79
+ ..._web3Assets.Hardhat,
80
+ wagmiChain: _chains.hardhat
81
+ };
82
+ const Localhost = exports.Localhost = {
83
+ ..._web3Assets.Localhost,
84
+ wagmiChain: _chains.localhost
85
+ };
@@ -1,4 +1,6 @@
1
1
  export * from './wagmi-provider';
2
2
  export * from './wallets';
3
3
  export * from './interface';
4
- export * from '@ant-design/web3-assets';
4
+ export * from './chains';
5
+ export * from '@ant-design/web3-assets/tokens';
6
+ export * from '@ant-design/web3-assets/wallets';
package/dist/lib/index.js CHANGED
@@ -36,14 +36,36 @@ Object.keys(_interface).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
- var _web3Assets = require("@ant-design/web3-assets");
40
- Object.keys(_web3Assets).forEach(function (key) {
39
+ var _chains = require("./chains");
40
+ Object.keys(_chains).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _web3Assets[key]) return;
42
+ if (key in exports && exports[key] === _chains[key]) return;
43
43
  Object.defineProperty(exports, key, {
44
44
  enumerable: true,
45
45
  get: function () {
46
- return _web3Assets[key];
46
+ return _chains[key];
47
+ }
48
+ });
49
+ });
50
+ var _tokens = require("@ant-design/web3-assets/tokens");
51
+ Object.keys(_tokens).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _tokens[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _tokens[key];
58
+ }
59
+ });
60
+ });
61
+ var _wallets2 = require("@ant-design/web3-assets/wallets");
62
+ Object.keys(_wallets2).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (key in exports && exports[key] === _wallets2[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _wallets2[key];
47
69
  }
48
70
  });
49
71
  });
@@ -1,5 +1,6 @@
1
- import type { ConnectOptions, UniversalEIP6963Config, Wallet, WalletMetadata } from '@ant-design/web3-common';
2
- import type { Connector } from 'wagmi';
1
+ import type { Chain, ConnectOptions, UniversalEIP6963Config, Wallet, WalletMetadata } from '@ant-design/web3-common';
2
+ import type { Chain as WagmiChain } from 'viem';
3
+ import type { Connector, CreateConnectorFn } from 'wagmi';
3
4
  export interface WalletUseInWagmiAdapter extends Wallet {
4
5
  getWagmiConnector?: (options?: ConnectOptions) => Promise<Connector | undefined>;
5
6
  }
@@ -8,5 +9,9 @@ export interface WalletFactory {
8
9
  name?: string;
9
10
  connectors: Connector['name'][];
10
11
  create: (connector?: readonly Connector[]) => WalletUseInWagmiAdapter;
12
+ createWagmiConnector?: () => CreateConnectorFn;
11
13
  }
12
14
  export type EIP6963Config = boolean | UniversalEIP6963Config;
15
+ export type ChainAssetWithWagmiChain = Chain & {
16
+ wagmiChain?: WagmiChain;
17
+ };
@@ -4,7 +4,7 @@ import type { Config as WagmiConfig } from 'wagmi';
4
4
  import type { EIP6963Config, WalletFactory } from '../interface';
5
5
  export interface AntDesignWeb3ConfigProviderProps {
6
6
  chainAssets: Chain[];
7
- walletFactorys: WalletFactory[];
7
+ walletFactories: WalletFactory[];
8
8
  locale?: Locale;
9
9
  children?: React.ReactNode;
10
10
  ens?: boolean;
@@ -17,7 +17,7 @@ const AntDesignWeb3ConfigProvider = props => {
17
17
  const {
18
18
  children,
19
19
  chainAssets,
20
- walletFactorys,
20
+ walletFactories,
21
21
  ens = true,
22
22
  balance,
23
23
  locale,
@@ -56,8 +56,12 @@ const AntDesignWeb3ConfigProvider = props => {
56
56
  name: ensName && ens ? ensName : undefined,
57
57
  avatar: ensAvatar ?? undefined
58
58
  } : undefined;
59
+ const isConnectorNameMatch = (aName, bName) => {
60
+ // match connector name like okxWallet, Okx Wallet, OKX Wallet
61
+ return aName.replace(/ /g, '').toLowerCase() === bName.replace(/ /g, '').toLowerCase();
62
+ };
59
63
  const findConnectorByName = name => {
60
- const commonConnector = wagimConfig.connectors.find(item => item.name === name && !(0, _utils.isEIP6963Connector)(item));
64
+ const commonConnector = wagimConfig.connectors.find(item => isConnectorNameMatch(item.name, name) && !(0, _utils.isEIP6963Connector)(item));
61
65
  if (!eip6963) {
62
66
  return commonConnector;
63
67
  }
@@ -69,14 +73,14 @@ const AntDesignWeb3ConfigProvider = props => {
69
73
  wagimConfig.connectors.forEach(connector => {
70
74
  if ((0, _utils.isEIP6963Connector)(connector)) {
71
75
  // check is need auto add eip6963 wallet
72
- if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactorys.find(item => item.connectors.includes(connector.name))) {
76
+ if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactories.find(item => item.connectors.some(aName => isConnectorNameMatch(aName, connector.name)))) {
73
77
  // not config wallet and find the wallet in connectors, auto add it
74
78
  autoAddEIP6963Wallets.push((0, _eip.EIP6963Wallet)().create([connector]));
75
79
  }
76
80
  // Do not need check eip6963 wallet
77
81
  return;
78
82
  }
79
- const walletFactory = walletFactorys.find(factory => factory.connectors.includes(connector.name));
83
+ const walletFactory = walletFactories.find(factory => factory.connectors.some(aName => isConnectorNameMatch(aName, connector.name)));
80
84
  if (!walletFactory?.create) {
81
85
  // check user wallets config and console.error for alert
82
86
  console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'wallets'.`);
@@ -84,7 +88,7 @@ const AntDesignWeb3ConfigProvider = props => {
84
88
  });
85
89
 
86
90
  // Generate Wallet for @ant-design/web3
87
- const supportWallets = walletFactorys.map(factory => {
91
+ const supportWallets = walletFactories.map(factory => {
88
92
  const connectors = factory.connectors.map(findConnectorByName).filter(item => !!item);
89
93
  if (connectors.length === 0 && !eip6963) {
90
94
  // Not config connector for this wallet factory and not use eip6963, ignore it.
@@ -94,7 +98,7 @@ const AntDesignWeb3ConfigProvider = props => {
94
98
  return factory.create(connectors);
95
99
  }).filter(item => item !== null);
96
100
  return [...supportWallets, ...autoAddEIP6963Wallets];
97
- }, [wagimConfig.connectors, walletFactorys, eip6963]);
101
+ }, [wagimConfig.connectors, walletFactories, eip6963]);
98
102
  const chainList = _react.default.useMemo(() => {
99
103
  return wagimConfig.chains.map(item => {
100
104
  const c = chainAssets?.find(asset => {
@@ -1,18 +1,25 @@
1
1
  import React from 'react';
2
- import type { Chain, Locale } from '@ant-design/web3-common';
2
+ import type { Locale } from '@ant-design/web3-common';
3
3
  import { QueryClient } from '@tanstack/react-query';
4
+ import type { Transport } from 'viem';
4
5
  import type { Config, State } from 'wagmi';
5
- import type { EIP6963Config, WalletFactory } from '../interface';
6
+ import type { WalletConnectParameters } from 'wagmi/connectors';
7
+ import type { ChainAssetWithWagmiChain, EIP6963Config, WalletFactory } from '../interface';
8
+ export interface WalletConnectOptions extends Pick<WalletConnectParameters, 'disableProviderPing' | 'isNewChainsStale' | 'projectId' | 'metadata' | 'relayUrl' | 'storageOptions' | 'qrModalOptions'> {
9
+ useWalletConnectOfficialModal?: boolean;
10
+ }
6
11
  export type WagmiWeb3ConfigProviderProps = {
7
- config: Config;
12
+ config?: Config;
8
13
  locale?: Locale;
9
14
  wallets?: WalletFactory[];
10
- chains?: Chain[];
15
+ chains?: ChainAssetWithWagmiChain[];
11
16
  ens?: boolean;
12
17
  queryClient?: QueryClient;
13
18
  balance?: boolean;
14
19
  eip6963?: EIP6963Config;
15
20
  initialState?: State;
16
21
  reconnectOnMount?: boolean;
22
+ walletConnect?: false | WalletConnectOptions;
23
+ transports?: Record<number, Transport>;
17
24
  };
18
- export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
25
+ export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, walletConnect, transports, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.WagmiWeb3ConfigProvider = WagmiWeb3ConfigProvider;
7
7
  var _react = _interopRequireDefault(require("react"));
8
- var _web3Assets = require("@ant-design/web3-assets");
9
8
  var _reactQuery = require("@tanstack/react-query");
10
9
  var _wagmi = require("wagmi");
10
+ var _chains = require("wagmi/chains");
11
+ var _connectors = require("wagmi/connectors");
12
+ var _chains2 = require("../chains");
11
13
  var _configProvider = require("./config-provider");
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -23,25 +25,78 @@ function WagmiWeb3ConfigProvider({
23
25
  queryClient,
24
26
  balance,
25
27
  eip6963,
28
+ walletConnect,
29
+ transports,
26
30
  ...restProps
27
31
  }) {
28
- const chainAssets = [...chains, _web3Assets.Mainnet];
32
+ // When user custom config, add Mainnet by default
33
+ // When user not provide config, auto generate config, chains use user provided chains
34
+ const chainAssets = config ? [_chains2.Mainnet, ...chains] : chains?.length ? chains : [_chains2.Mainnet];
35
+ const generateConfigFlag = () => {
36
+ return `${JSON.stringify(walletConnect)}-${chains.map(item => item.id).join(',')}-${wallets.map(item => item.name).join(',')}`;
37
+ };
38
+ const generateConfig = () => {
39
+ // Auto generate config
40
+ const connectors = [];
41
+ if (walletConnect && walletConnect.projectId) {
42
+ connectors.push((0, _connectors.walletConnect)({
43
+ ...walletConnect,
44
+ showQrModal: walletConnect.useWalletConnectOfficialModal ?? false
45
+ }));
46
+ }
47
+ wallets.forEach(wallet => {
48
+ const connector = wallet.createWagmiConnector?.();
49
+ if (connector) {
50
+ connectors.push(connector);
51
+ }
52
+ });
53
+ const autoGenerateConfig = (0, _wagmi.createConfig)({
54
+ chains: chainAssets.map(chain => chain.wagmiChain),
55
+ transports: transports ?? {
56
+ [_chains.mainnet.id]: (0, _wagmi.http)()
57
+ },
58
+ connectors
59
+ });
60
+ return {
61
+ flag: generateConfigFlag(),
62
+ config: autoGenerateConfig
63
+ };
64
+ };
65
+ const [autoConfig, setAutoConfig] = _react.default.useState(() => {
66
+ if (config) {
67
+ return {
68
+ config
69
+ };
70
+ }
71
+ return generateConfig();
72
+ });
29
73
  const mergedQueryClient = _react.default.useMemo(() => {
30
74
  return queryClient ?? new _reactQuery.QueryClient();
31
75
  }, [queryClient]);
76
+ _react.default.useEffect(() => {
77
+ if (config) {
78
+ return;
79
+ }
80
+ const flag = generateConfigFlag();
81
+ if (flag !== autoConfig.flag) {
82
+ // Need recreate wagmi config
83
+ setAutoConfig(generateConfig());
84
+ }
85
+ }, [config, wallets, chains, walletConnect]);
86
+ const wagmiConfig = config || autoConfig.config;
32
87
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_wagmi.WagmiProvider, {
33
- config: config,
88
+ config: wagmiConfig,
34
89
  ...restProps,
35
90
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
36
91
  client: mergedQueryClient,
37
92
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
38
93
  locale: locale,
39
94
  chainAssets: chainAssets,
40
- walletFactorys: wallets,
95
+ walletFactories: wallets,
41
96
  ens: ens,
42
97
  balance: balance,
43
98
  eip6963: eip6963,
44
- wagimConfig: config,
99
+ wagimConfig: wagmiConfig,
45
100
  children: children
46
101
  })
47
102
  })
@@ -1,2 +1,4 @@
1
- import type { EthereumWallet } from '../interface';
2
- export declare const CoinbaseWallet: EthereumWallet;
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ import { type CoinbaseWalletParameters } from 'wagmi/connectors';
3
+ import { WalletFactory } from '../interface';
4
+ export declare const CoinbaseWallet: (metadata?: Partial<WalletMetadata>, coinbaseConfig?: CoinbaseWalletParameters) => WalletFactory;
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.CoinbaseWallet = void 0;
7
7
  var _web3Assets = require("@ant-design/web3-assets");
8
- const CoinbaseWallet = metadata => {
8
+ var _connectors = require("wagmi/connectors");
9
+ const CoinbaseWallet = (metadata, coinbaseConfig) => {
9
10
  return {
10
11
  connectors: ['Coinbase Wallet'],
11
12
  create: () => {
@@ -16,6 +17,9 @@ const CoinbaseWallet = metadata => {
16
17
  },
17
18
  ...metadata
18
19
  };
20
+ },
21
+ createWagmiConnector: () => {
22
+ return (0, _connectors.coinbaseWallet)(coinbaseConfig);
19
23
  }
20
24
  };
21
25
  };
@@ -5,11 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ImToken = void 0;
7
7
  var _web3Assets = require("@ant-design/web3-assets");
8
+ var _connectors = require("wagmi/connectors");
8
9
  var _universalWallet = require("./universal-wallet");
9
10
  const ImToken = metadata => {
10
11
  return new _universalWallet.UniversalWallet({
11
12
  ..._web3Assets.metadata_imToken,
12
13
  ...metadata
13
- });
14
+ }, () => (0, _connectors.injected)({
15
+ target: 'imToken'
16
+ }));
14
17
  };
15
18
  exports.ImToken = ImToken;
@@ -5,11 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.MetaMask = void 0;
7
7
  var _web3Assets = require("@ant-design/web3-assets");
8
+ var _connectors = require("wagmi/connectors");
8
9
  var _universalWallet = require("./universal-wallet");
9
10
  const MetaMask = metadata => {
10
11
  return new _universalWallet.UniversalWallet({
11
12
  ..._web3Assets.metadata_MetaMask,
12
13
  ...metadata
13
- });
14
+ }, () => (0, _connectors.injected)({
15
+ target: 'metaMask'
16
+ }));
14
17
  };
15
18
  exports.MetaMask = MetaMask;
@@ -5,11 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.OkxWallet = void 0;
7
7
  var _web3Assets = require("@ant-design/web3-assets");
8
+ var _connectors = require("wagmi/connectors");
8
9
  var _universalWallet = require("./universal-wallet");
9
10
  const OkxWallet = metadata => {
10
11
  return new _universalWallet.UniversalWallet({
11
12
  ..._web3Assets.metadata_OkxWallet,
12
13
  ...metadata
13
- });
14
+ }, () => (0, _connectors.injected)({
15
+ target: 'okxWallet'
16
+ }));
14
17
  };
15
18
  exports.OkxWallet = OkxWallet;
@@ -5,11 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.TokenPocket = void 0;
7
7
  var _web3Assets = require("@ant-design/web3-assets");
8
+ var _connectors = require("wagmi/connectors");
8
9
  var _universalWallet = require("./universal-wallet");
9
10
  const TokenPocket = metadata => {
10
11
  return new _universalWallet.UniversalWallet({
11
12
  ..._web3Assets.metadata_TokenPocket,
12
13
  ...metadata
14
+ }, () => {
15
+ return (0, _connectors.injected)({
16
+ target: 'tokenPocket'
17
+ });
13
18
  });
14
19
  };
15
20
  exports.TokenPocket = TokenPocket;
@@ -1,10 +1,11 @@
1
1
  import type { WalletMetadata } from '@ant-design/web3-common';
2
- import type { Connector } from 'wagmi';
2
+ import type { Connector, CreateConnectorFn } from 'wagmi';
3
3
  import type { WalletFactory, WalletUseInWagmiAdapter } from '../interface';
4
4
  export declare class UniversalWallet implements WalletFactory {
5
5
  private wallet;
6
6
  name?: string;
7
+ createWagmiConnector?: () => CreateConnectorFn;
7
8
  connectors: string[];
8
- constructor(wallet: WalletMetadata);
9
+ constructor(wallet: WalletMetadata, createWagmiConnector?: () => CreateConnectorFn);
9
10
  create: (connectors?: readonly Connector[]) => WalletUseInWagmiAdapter;
10
11
  }
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.UniversalWallet = void 0;
7
7
  class UniversalWallet {
8
8
  name;
9
+ createWagmiConnector;
9
10
  connectors = [];
10
- constructor(wallet) {
11
+ constructor(wallet, createWagmiConnector) {
11
12
  this.wallet = wallet;
12
13
  this.name = wallet.name;
14
+ this.createWagmiConnector = createWagmiConnector;
13
15
  if (wallet.extensions) {
14
16
  // support injected connector
15
17
  // https://wagmi.sh/react/connectors/injected
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/web3-wagmi",
3
- "version": "2.7.3",
3
+ "version": "2.8.0",
4
4
  "type": "module",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -38,8 +38,8 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "debug": "^4.3.5",
41
- "@ant-design/web3-assets": "1.10.1",
42
- "@ant-design/web3-common": "1.12.1"
41
+ "@ant-design/web3-assets": "1.11.0",
42
+ "@ant-design/web3-common": "1.13.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/debug": "^4.1.12",