@ant-design/web3-wagmi 0.0.0-alpha-20260209094036

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 (90) hide show
  1. package/CHANGELOG.md +517 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/dist/esm/chains.d.ts +16 -0
  5. package/dist/esm/chains.js +83 -0
  6. package/dist/esm/global.d.ts +3 -0
  7. package/dist/esm/index.d.ts +6 -0
  8. package/dist/esm/index.js +6 -0
  9. package/dist/esm/interface.d.ts +26 -0
  10. package/dist/esm/interface.js +1 -0
  11. package/dist/esm/utils.d.ts +3 -0
  12. package/dist/esm/utils.js +8 -0
  13. package/dist/esm/wagmi-provider/__mocks__/wagmiBaseMock.d.ts +76 -0
  14. package/dist/esm/wagmi-provider/__mocks__/wagmiBaseMock.js +36 -0
  15. package/dist/esm/wagmi-provider/config-provider.d.ts +23 -0
  16. package/dist/esm/wagmi-provider/config-provider.js +243 -0
  17. package/dist/esm/wagmi-provider/index.d.ts +32 -0
  18. package/dist/esm/wagmi-provider/index.js +102 -0
  19. package/dist/esm/wagmi-provider/methods/getNFTMetadata.d.ts +3 -0
  20. package/dist/esm/wagmi-provider/methods/getNFTMetadata.js +25 -0
  21. package/dist/esm/wagmi-provider/methods/index.d.ts +1 -0
  22. package/dist/esm/wagmi-provider/methods/index.js +1 -0
  23. package/dist/esm/wallets/coinbase-wallet.d.ts +4 -0
  24. package/dist/esm/wallets/coinbase-wallet.js +19 -0
  25. package/dist/esm/wallets/eip6963.d.ts +3 -0
  26. package/dist/esm/wallets/eip6963.js +27 -0
  27. package/dist/esm/wallets/im-token.d.ts +2 -0
  28. package/dist/esm/wallets/im-token.js +11 -0
  29. package/dist/esm/wallets/index.d.ts +10 -0
  30. package/dist/esm/wallets/index.js +10 -0
  31. package/dist/esm/wallets/meta-mask.d.ts +2 -0
  32. package/dist/esm/wallets/meta-mask.js +11 -0
  33. package/dist/esm/wallets/mobile-wallet.d.ts +2 -0
  34. package/dist/esm/wallets/mobile-wallet.js +8 -0
  35. package/dist/esm/wallets/okx-wallet.d.ts +2 -0
  36. package/dist/esm/wallets/okx-wallet.js +11 -0
  37. package/dist/esm/wallets/rainbow-wallet.d.ts +2 -0
  38. package/dist/esm/wallets/rainbow-wallet.js +11 -0
  39. package/dist/esm/wallets/safeheron.d.ts +2 -0
  40. package/dist/esm/wallets/safeheron.js +19 -0
  41. package/dist/esm/wallets/token-pocket.d.ts +2 -0
  42. package/dist/esm/wallets/token-pocket.js +13 -0
  43. package/dist/esm/wallets/universal-wallet.d.ts +11 -0
  44. package/dist/esm/wallets/universal-wallet.js +66 -0
  45. package/dist/esm/wallets/wallet-connect.d.ts +6 -0
  46. package/dist/esm/wallets/wallet-connect.js +42 -0
  47. package/dist/lib/chains.d.ts +16 -0
  48. package/dist/lib/chains.js +89 -0
  49. package/dist/lib/global.d.ts +3 -0
  50. package/dist/lib/index.d.ts +6 -0
  51. package/dist/lib/index.js +71 -0
  52. package/dist/lib/interface.d.ts +26 -0
  53. package/dist/lib/interface.js +5 -0
  54. package/dist/lib/utils.d.ts +3 -0
  55. package/dist/lib/utils.js +14 -0
  56. package/dist/lib/wagmi-provider/__mocks__/wagmiBaseMock.d.ts +76 -0
  57. package/dist/lib/wagmi-provider/__mocks__/wagmiBaseMock.js +42 -0
  58. package/dist/lib/wagmi-provider/config-provider.d.ts +23 -0
  59. package/dist/lib/wagmi-provider/config-provider.js +251 -0
  60. package/dist/lib/wagmi-provider/index.d.ts +32 -0
  61. package/dist/lib/wagmi-provider/index.js +110 -0
  62. package/dist/lib/wagmi-provider/methods/getNFTMetadata.d.ts +3 -0
  63. package/dist/lib/wagmi-provider/methods/getNFTMetadata.js +31 -0
  64. package/dist/lib/wagmi-provider/methods/index.d.ts +1 -0
  65. package/dist/lib/wagmi-provider/methods/index.js +16 -0
  66. package/dist/lib/wallets/coinbase-wallet.d.ts +4 -0
  67. package/dist/lib/wallets/coinbase-wallet.js +26 -0
  68. package/dist/lib/wallets/eip6963.d.ts +3 -0
  69. package/dist/lib/wallets/eip6963.js +34 -0
  70. package/dist/lib/wallets/im-token.d.ts +2 -0
  71. package/dist/lib/wallets/im-token.js +18 -0
  72. package/dist/lib/wallets/index.d.ts +10 -0
  73. package/dist/lib/wallets/index.js +115 -0
  74. package/dist/lib/wallets/meta-mask.d.ts +2 -0
  75. package/dist/lib/wallets/meta-mask.js +18 -0
  76. package/dist/lib/wallets/mobile-wallet.d.ts +2 -0
  77. package/dist/lib/wallets/mobile-wallet.js +15 -0
  78. package/dist/lib/wallets/okx-wallet.d.ts +2 -0
  79. package/dist/lib/wallets/okx-wallet.js +18 -0
  80. package/dist/lib/wallets/rainbow-wallet.d.ts +2 -0
  81. package/dist/lib/wallets/rainbow-wallet.js +18 -0
  82. package/dist/lib/wallets/safeheron.d.ts +2 -0
  83. package/dist/lib/wallets/safeheron.js +27 -0
  84. package/dist/lib/wallets/token-pocket.d.ts +2 -0
  85. package/dist/lib/wallets/token-pocket.js +20 -0
  86. package/dist/lib/wallets/universal-wallet.d.ts +11 -0
  87. package/dist/lib/wallets/universal-wallet.js +73 -0
  88. package/dist/lib/wallets/wallet-connect.d.ts +6 -0
  89. package/dist/lib/wallets/wallet-connect.js +49 -0
  90. package/package.json +73 -0
@@ -0,0 +1,76 @@
1
+ export declare const wagmiBaseMock: {
2
+ useAccount: () => {
3
+ chain: {
4
+ blockExplorers: {
5
+ readonly default: {
6
+ readonly name: "Etherscan";
7
+ readonly url: "https://etherscan.io";
8
+ readonly apiUrl: "https://api.etherscan.io/api";
9
+ };
10
+ };
11
+ blockTime?: number | undefined;
12
+ contracts: {
13
+ readonly ensRegistry: {
14
+ readonly address: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
15
+ };
16
+ readonly ensUniversalResolver: {
17
+ readonly address: "0xce01f8eee7E479C928F8919abD53E553a36CeF67";
18
+ readonly blockCreated: 19258213;
19
+ };
20
+ readonly multicall3: {
21
+ readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
22
+ readonly blockCreated: 14353601;
23
+ };
24
+ };
25
+ ensTlds?: readonly string[] | undefined;
26
+ id: 1;
27
+ name: "Ethereum";
28
+ nativeCurrency: {
29
+ readonly name: "Ether";
30
+ readonly symbol: "ETH";
31
+ readonly decimals: 18;
32
+ };
33
+ experimental_preconfirmationTime?: number | undefined;
34
+ rpcUrls: {
35
+ readonly default: {
36
+ readonly http: readonly ["https://eth.merkle.io"];
37
+ };
38
+ };
39
+ sourceId?: number | undefined;
40
+ testnet?: boolean | undefined;
41
+ custom?: Record<string, unknown> | undefined;
42
+ fees?: import("viem").ChainFees<undefined> | undefined;
43
+ formatters?: undefined;
44
+ serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable<bigint, number>> | undefined;
45
+ };
46
+ address: string;
47
+ connector: {
48
+ name: string;
49
+ };
50
+ };
51
+ useConfig: () => {};
52
+ useBalance: () => {
53
+ data: {};
54
+ };
55
+ useSwitchChain: () => {
56
+ switchChain: () => void;
57
+ };
58
+ useConnect: () => {
59
+ connectors: {
60
+ name: string;
61
+ }[];
62
+ connectAsync: () => Promise<{}>;
63
+ };
64
+ useDisconnect: () => {
65
+ disconnectAsync: () => void;
66
+ };
67
+ useEnsName: () => {
68
+ data: null;
69
+ };
70
+ useEnsAvatar: () => {
71
+ data: null;
72
+ };
73
+ useSignMessage: () => {
74
+ signMessageAsync: () => Promise<string>;
75
+ };
76
+ };
@@ -0,0 +1,36 @@
1
+ import { mainnet } from 'wagmi/chains';
2
+ const mockConnector = {
3
+ name: 'MetaMask'
4
+ };
5
+ export const wagmiBaseMock = {
6
+ useAccount: () => {
7
+ return {
8
+ chain: mainnet,
9
+ address: '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B',
10
+ connector: mockConnector
11
+ };
12
+ },
13
+ useConfig: () => ({}),
14
+ useBalance: () => ({
15
+ data: {}
16
+ }),
17
+ useSwitchChain: () => ({
18
+ switchChain: () => {}
19
+ }),
20
+ useConnect: () => ({
21
+ connectors: [mockConnector],
22
+ connectAsync: async () => ({})
23
+ }),
24
+ useDisconnect: () => ({
25
+ disconnectAsync: () => {}
26
+ }),
27
+ useEnsName: () => ({
28
+ data: null
29
+ }),
30
+ useEnsAvatar: () => ({
31
+ data: null
32
+ }),
33
+ useSignMessage: () => ({
34
+ signMessageAsync: async () => 'signMessage'
35
+ })
36
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { type Chain, type Locale } from '@ant-design/web3-common';
3
+ import type { Config as WagmiConfig } from 'wagmi';
4
+ import type { EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
5
+ export interface AntDesignWeb3ConfigProviderProps {
6
+ chainAssets: Chain[];
7
+ walletFactories: WalletFactory[];
8
+ locale?: Locale;
9
+ children?: React.ReactNode;
10
+ ens?: boolean;
11
+ balance?: boolean;
12
+ eip6963?: EIP6963Config;
13
+ wagimConfig: WagmiConfig;
14
+ useWalletConnectOfficialModal?: boolean;
15
+ siwe?: SIWEConfig;
16
+ /**
17
+ * If true, this provider's configuration will be ignored when merging with parent context.
18
+ * This is useful when you have multiple chain providers and want to switch between them
19
+ * without causing page flickering. Only the active provider should not have this flag set.
20
+ */
21
+ ignoreConfig?: boolean;
22
+ }
23
+ export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
@@ -0,0 +1,243 @@
1
+ import React from 'react';
2
+ import { ConnectStatus, Web3ConfigProvider } from '@ant-design/web3-common';
3
+ import { useAccount, useBalance, useConfig, useConnect, useEnsAvatar, useEnsName, useSignMessage, useSwitchChain } from 'wagmi';
4
+ import { disconnect, getAccount } from 'wagmi/actions';
5
+ import { Mainnet } from "../chains";
6
+ import { isEIP6963Connector } from "../utils";
7
+ import { EIP6963Wallet } from "../wallets/eip6963";
8
+ import { getNFTMetadata } from "./methods";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ export const AntDesignWeb3ConfigProvider = props => {
11
+ const {
12
+ children,
13
+ chainAssets,
14
+ walletFactories,
15
+ ens = true,
16
+ balance,
17
+ locale,
18
+ eip6963,
19
+ wagimConfig,
20
+ useWalletConnectOfficialModal,
21
+ siwe,
22
+ ignoreConfig
23
+ } = props;
24
+ const {
25
+ address,
26
+ isDisconnected,
27
+ chain,
28
+ addresses
29
+ } = useAccount();
30
+ const config = useConfig();
31
+ const {
32
+ connectAsync
33
+ } = useConnect();
34
+ const {
35
+ switchChain
36
+ } = useSwitchChain();
37
+ const {
38
+ data: balanceData
39
+ } = useBalance({
40
+ address
41
+ });
42
+ const {
43
+ data: ensName
44
+ } = useEnsName({
45
+ address
46
+ });
47
+ const {
48
+ data: ensAvatar
49
+ } = useEnsAvatar({
50
+ name: ensName ?? undefined
51
+ });
52
+ const {
53
+ signMessageAsync
54
+ } = useSignMessage();
55
+ const [status, setStatus] = React.useState(ConnectStatus.Disconnected);
56
+ React.useEffect(() => {
57
+ setStatus(isDisconnected ? ConnectStatus.Disconnected : ConnectStatus.Connected);
58
+ }, [isDisconnected]);
59
+ const account = address && !isDisconnected ? {
60
+ address,
61
+ name: ensName && ens ? ensName : undefined,
62
+ avatar: ensAvatar ?? undefined,
63
+ addresses,
64
+ status: status
65
+ } : undefined;
66
+ const isConnectorNameMatch = (aName, bName) => {
67
+ // match connector name like okxWallet, Okx Wallet, OKX Wallet
68
+ return aName.replace(/ /g, '').toLowerCase() === bName.replace(/ /g, '').toLowerCase();
69
+ };
70
+ const findConnectorByName = name => {
71
+ const commonConnector = wagimConfig.connectors.find(item => isConnectorNameMatch(item.name, name) && !isEIP6963Connector(item));
72
+ if (!eip6963) {
73
+ return commonConnector;
74
+ }
75
+ const eip6963Connector = wagimConfig.connectors.find(item => item.name === name && isEIP6963Connector(item));
76
+ return eip6963Connector || commonConnector;
77
+ };
78
+ const wallets = React.useMemo(() => {
79
+ const autoAddEIP6963Wallets = [];
80
+ wagimConfig.connectors.forEach(connector => {
81
+ if (isEIP6963Connector(connector)) {
82
+ // check is need auto add eip6963 wallet
83
+ if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactories.find(item => item.connectors.some(aName => isConnectorNameMatch(aName, connector.name)))) {
84
+ // not config wallet and find the wallet in connectors, auto add it
85
+ autoAddEIP6963Wallets.push(EIP6963Wallet().create([connector], {
86
+ useWalletConnectOfficialModal
87
+ }));
88
+ }
89
+ // Do not need check eip6963 wallet
90
+ return;
91
+ }
92
+ const walletFactory = walletFactories.find(factory => factory.connectors.some(aName => isConnectorNameMatch(aName, connector.name)));
93
+ if (!walletFactory?.create) {
94
+ // check user wallets config and console.error for alert
95
+ console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'wallets'.`);
96
+ }
97
+ });
98
+
99
+ // Generate Wallet for @ant-design/web3
100
+ const supportWallets = walletFactories.map(factory => {
101
+ const connectors = factory.connectors.map(findConnectorByName).filter(item => !!item);
102
+ if (connectors.length === 0 && !eip6963) {
103
+ // Not config connector for this wallet factory and not use eip6963, ignore it.
104
+ console.error(`Can not find connector for ${factory.connectors.join(',')}, ignore the wallet. Please config connectors or add eip6963 config in WagmiWeb3ConfigProvider.`);
105
+ return null;
106
+ }
107
+ return factory.create(connectors, {
108
+ useWalletConnectOfficialModal
109
+ });
110
+ }).filter(item => item !== null);
111
+ return [...supportWallets, ...autoAddEIP6963Wallets];
112
+ }, [wagimConfig.connectors, walletFactories, eip6963]);
113
+ const chainList = React.useMemo(() => {
114
+ return wagimConfig.chains.map(item => {
115
+ const c = chainAssets?.find(asset => {
116
+ return asset.id === item.id;
117
+ });
118
+ if (c?.id) {
119
+ return {
120
+ id: c.id,
121
+ name: c.name,
122
+ icon: c.icon
123
+ };
124
+ }
125
+ console.error(`Can not find chain ${item.id}, you should config it in WagmiWeb3ConfigProvider 'chains'.`);
126
+ return null;
127
+ }).filter(item => item !== null);
128
+ }, [wagimConfig.chains, chainAssets]);
129
+ const chainId = chain?.id || wagimConfig.chains?.[0]?.id;
130
+ const chainName = chain?.name || wagimConfig.chains?.[0]?.name;
131
+ const [currentChain, setCurrentChain] = React.useState(undefined);
132
+ React.useEffect(() => {
133
+ setCurrentChain(prevChain => {
134
+ // not connected any chain, keep current chain
135
+ let newChain = chainAssets?.find(item => item?.id === chainId);
136
+ if (!newChain && chainId) {
137
+ newChain = {
138
+ id: chainId,
139
+ name: chainName
140
+ };
141
+ }
142
+
143
+ /* v8 ignore next */
144
+ return newChain || prevChain;
145
+ });
146
+ }, [chainAssets, wagimConfig.chains, chainId, chainName]);
147
+ const currency = currentChain?.nativeCurrency;
148
+ const getNFTMetadataFunc = React.useCallback(async ({
149
+ address: contractAddress,
150
+ tokenId
151
+ }) => getNFTMetadata(config, contractAddress, tokenId, chain?.id), [chain?.id]);
152
+ const signIn = React.useCallback(async signAddress => {
153
+ const {
154
+ getNonce,
155
+ createMessage,
156
+ verifyMessage
157
+ } = siwe;
158
+ let msg;
159
+ let signature;
160
+ try {
161
+ // get nonce
162
+ const nonce = await getNonce(signAddress);
163
+ msg = createMessage({
164
+ domain: window?.location ? window.location.hostname : '',
165
+ address: signAddress,
166
+ uri: window?.location ? window.location.origin : '',
167
+ nonce,
168
+ // Default config
169
+ version: '1',
170
+ chainId: currentChain?.id ?? Mainnet.id
171
+ });
172
+ if (signMessageAsync) {
173
+ signature = await signMessageAsync?.({
174
+ message: msg
175
+ });
176
+ await verifyMessage(msg, signature);
177
+ setStatus(ConnectStatus.Signed);
178
+ }
179
+ } catch (error) {
180
+ throw new Error(error.message);
181
+ }
182
+ }, [siwe, currentChain, signMessageAsync]);
183
+ return /*#__PURE__*/_jsx(Web3ConfigProvider, {
184
+ locale: locale,
185
+ availableChains: chainList,
186
+ chain: currentChain,
187
+ account: account,
188
+ sign: siwe && {
189
+ signIn
190
+ },
191
+ balance: balance ? {
192
+ symbol: balanceData?.symbol,
193
+ value: balanceData?.value,
194
+ decimals: balanceData?.decimals,
195
+ icon: currency?.icon
196
+ } : undefined,
197
+ availableWallets: wallets,
198
+ addressPrefix: "0x",
199
+ connect: async (wallet, options) => {
200
+ let connector = await wallet?.getWagmiConnector?.(options);
201
+ if (!connector && wallet) {
202
+ connector = findConnectorByName(wallet.name);
203
+ }
204
+ if (!connector) {
205
+ throw new Error(`Can not find connector for ${wallet?.name}`);
206
+ }
207
+ const {
208
+ accounts
209
+ } = await connectAsync({
210
+ connector,
211
+ chainId: currentChain?.id
212
+ });
213
+ return {
214
+ address: accounts?.[0],
215
+ addresses: accounts
216
+ };
217
+ },
218
+ disconnect: async () => {
219
+ // await disconnectAsync();
220
+ // TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
221
+ // 存在一些状态处理的 bug,暂时用更低阶 API 代替。
222
+ const {
223
+ connector
224
+ } = getAccount(config);
225
+ await disconnect(config, {
226
+ connector
227
+ });
228
+ },
229
+ switchChain: async newChain => {
230
+ if (!chain) {
231
+ // hava not connected any chain
232
+ setCurrentChain(newChain);
233
+ } else {
234
+ switchChain?.({
235
+ chainId: newChain.id
236
+ });
237
+ }
238
+ },
239
+ getNFTMetadata: getNFTMetadataFunc,
240
+ ignoreConfig: ignoreConfig,
241
+ children: children
242
+ });
243
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import type { Locale } from '@ant-design/web3-common';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import type { Transport } from 'viem';
5
+ import type { Config, State } from 'wagmi';
6
+ import type { WalletConnectParameters } from 'wagmi/connectors';
7
+ import type { ChainAssetWithWagmiChain, EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
8
+ export interface WalletConnectOptions extends Pick<WalletConnectParameters, 'disableProviderPing' | 'isNewChainsStale' | 'projectId' | 'metadata' | 'relayUrl' | 'storageOptions' | 'qrModalOptions'> {
9
+ useWalletConnectOfficialModal?: boolean;
10
+ }
11
+ export interface WagmiWeb3ConfigProviderProps {
12
+ config?: Config;
13
+ locale?: Locale;
14
+ wallets?: WalletFactory[];
15
+ chains?: ChainAssetWithWagmiChain[];
16
+ ens?: boolean;
17
+ queryClient?: QueryClient;
18
+ balance?: boolean;
19
+ eip6963?: EIP6963Config;
20
+ initialState?: State;
21
+ reconnectOnMount?: boolean;
22
+ walletConnect?: false | WalletConnectOptions;
23
+ transports?: Record<number, Transport>;
24
+ siwe?: SIWEConfig;
25
+ /**
26
+ * If true, this provider's configuration will be ignored when merging with parent context.
27
+ * This is useful when you have multiple chain providers and want to switch between them
28
+ * without causing page flickering. Only the active provider should not have this flag set.
29
+ */
30
+ ignoreConfig?: boolean;
31
+ }
32
+ export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, walletConnect, transports, siwe, ignoreConfig, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
@@ -0,0 +1,102 @@
1
+ import React from 'react';
2
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
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";
8
+ import { AntDesignWeb3ConfigProvider } from "./config-provider";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ export function WagmiWeb3ConfigProvider({
11
+ children,
12
+ config,
13
+ locale,
14
+ wallets = [],
15
+ chains = [],
16
+ ens,
17
+ queryClient,
18
+ balance,
19
+ eip6963,
20
+ walletConnect,
21
+ transports,
22
+ siwe,
23
+ ignoreConfig,
24
+ ...restProps
25
+ }) {
26
+ // When user custom config, add Mainnet by default
27
+ // When user not provide config, auto generate config, chains use user provided chains
28
+ const chainAssets = config ? [Mainnet, ...chains] : chains?.length ? chains : [Mainnet];
29
+ const generateConfigFlag = () => {
30
+ return `${JSON.stringify(walletConnect)}-${chains.map(item => item.id).join(',')}-${wallets.map(item => item.name).join(',')}`;
31
+ };
32
+ const generateConfig = () => {
33
+ // Auto generate config
34
+ const connectors = [];
35
+ // biome-ignore lint/complexity/useOptionalChain: <explanation>
36
+ if (walletConnect && walletConnect.projectId) {
37
+ connectors.push(wagmiWalletConnect({
38
+ ...walletConnect,
39
+ showQrModal: walletConnect.useWalletConnectOfficialModal ?? false
40
+ }));
41
+ }
42
+ wallets.forEach(wallet => {
43
+ const connector = wallet.createWagmiConnector?.();
44
+ if (connector) {
45
+ connectors.push(connector);
46
+ }
47
+ });
48
+ const autoGenerateConfig = createConfig({
49
+ chains: chainAssets.map(chain => chain.wagmiChain),
50
+ transports: transports ?? {
51
+ [mainnet.id]: http()
52
+ },
53
+ connectors
54
+ });
55
+ return {
56
+ flag: generateConfigFlag(),
57
+ config: autoGenerateConfig
58
+ };
59
+ };
60
+ const [autoConfig, setAutoConfig] = React.useState(() => {
61
+ if (config) {
62
+ return {
63
+ config
64
+ };
65
+ }
66
+ return generateConfig();
67
+ });
68
+ const mergedQueryClient = React.useMemo(() => {
69
+ return queryClient ?? new QueryClient();
70
+ }, [queryClient]);
71
+ React.useEffect(() => {
72
+ if (config) {
73
+ return;
74
+ }
75
+ const flag = generateConfigFlag();
76
+ if (flag !== autoConfig.flag) {
77
+ // Need recreate wagmi config
78
+ setAutoConfig(generateConfig());
79
+ }
80
+ }, [config, wallets, chains, walletConnect]);
81
+ const wagmiConfig = config || autoConfig.config;
82
+ return /*#__PURE__*/_jsx(WagmiProvider, {
83
+ config: wagmiConfig,
84
+ ...restProps,
85
+ children: /*#__PURE__*/_jsx(QueryClientProvider, {
86
+ client: mergedQueryClient,
87
+ children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
88
+ locale: locale,
89
+ siwe: siwe,
90
+ chainAssets: chainAssets,
91
+ walletFactories: wallets,
92
+ ens: ens,
93
+ balance: balance,
94
+ eip6963: eip6963,
95
+ wagimConfig: wagmiConfig,
96
+ useWalletConnectOfficialModal: typeof walletConnect === 'object' && walletConnect?.useWalletConnectOfficialModal,
97
+ ignoreConfig: ignoreConfig,
98
+ children: children
99
+ })
100
+ })
101
+ });
102
+ }
@@ -0,0 +1,3 @@
1
+ import { type NFTMetadata } from '@ant-design/web3-common';
2
+ import type { Config } from 'wagmi';
3
+ export declare function getNFTMetadata(config: Config, address: string, tokenId: bigint, chainId?: number): Promise<NFTMetadata>;
@@ -0,0 +1,25 @@
1
+ import { fillAddressWith0x, requestWeb3Asset } from '@ant-design/web3-common';
2
+ import { readContract } from 'wagmi/actions';
3
+ export async function getNFTMetadata(config, address, tokenId, chainId) {
4
+ const tokenURI = await readContract(config, {
5
+ address: fillAddressWith0x(address),
6
+ args: [tokenId],
7
+ chainId,
8
+ abi: [{
9
+ name: 'tokenURI',
10
+ inputs: [{
11
+ name: 'tokenId',
12
+ type: 'uint256'
13
+ }],
14
+ outputs: [{
15
+ name: '',
16
+ type: 'string'
17
+ }],
18
+ stateMutability: 'view',
19
+ type: 'function'
20
+ }],
21
+ functionName: 'tokenURI'
22
+ });
23
+ const metaInfo = await requestWeb3Asset(tokenURI);
24
+ return metaInfo;
25
+ }
@@ -0,0 +1 @@
1
+ export * from './getNFTMetadata';
@@ -0,0 +1 @@
1
+ export * from "./getNFTMetadata";
@@ -0,0 +1,4 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ import { type CoinbaseWalletParameters } from 'wagmi/connectors';
3
+ import type { WalletFactory } from '../interface';
4
+ export declare const CoinbaseWallet: (metadata?: Partial<WalletMetadata>, coinbaseConfig?: CoinbaseWalletParameters) => WalletFactory;
@@ -0,0 +1,19 @@
1
+ import { metadata_CoinbaseWallet } from '@ant-design/web3-assets';
2
+ import { coinbaseWallet } from 'wagmi/connectors';
3
+ export const CoinbaseWallet = (metadata, coinbaseConfig) => {
4
+ return {
5
+ connectors: ['Coinbase Wallet'],
6
+ create: () => {
7
+ return {
8
+ ...metadata_CoinbaseWallet,
9
+ hasWalletReady: async () => {
10
+ return true;
11
+ },
12
+ ...metadata
13
+ };
14
+ },
15
+ createWagmiConnector: () => {
16
+ return coinbaseWallet(coinbaseConfig);
17
+ }
18
+ };
19
+ };
@@ -0,0 +1,3 @@
1
+ import type { EthereumWallet } from '../interface';
2
+ export declare const EIP6963_CONNECTOR = "EIP6963";
3
+ export declare const EIP6963Wallet: EthereumWallet;
@@ -0,0 +1,27 @@
1
+ export const EIP6963_CONNECTOR = 'EIP6963';
2
+
3
+ // EIP6963Wallet not export from @ant-design/web3-wagmi, only used in internal
4
+ export const EIP6963Wallet = metadata => {
5
+ return {
6
+ connectors: [EIP6963_CONNECTOR],
7
+ create: connectors => {
8
+ const connector = connectors?.[0];
9
+ const metadata_eip6963 = {
10
+ icon: connector?.icon,
11
+ name: connector.name,
12
+ remark: `Wallet ${connector?.name} detected`,
13
+ key: connector?.id
14
+ };
15
+ return {
16
+ ...metadata_eip6963,
17
+ hasWalletReady: async () => {
18
+ return !!(await connector?.getProvider());
19
+ },
20
+ hasExtensionInstalled: async () => {
21
+ return !!(await connector?.getProvider());
22
+ },
23
+ ...metadata
24
+ };
25
+ }
26
+ };
27
+ };
@@ -0,0 +1,2 @@
1
+ import type { EthereumWallet } from '../interface';
2
+ export declare const ImToken: EthereumWallet;
@@ -0,0 +1,11 @@
1
+ import { metadata_imToken } from '@ant-design/web3-assets';
2
+ import { injected } from 'wagmi/connectors';
3
+ import { UniversalWallet } from "./universal-wallet";
4
+ export const ImToken = metadata => {
5
+ return new UniversalWallet({
6
+ ...metadata_imToken,
7
+ ...metadata
8
+ }, () => injected({
9
+ target: 'imToken'
10
+ }));
11
+ };
@@ -0,0 +1,10 @@
1
+ export * from './meta-mask';
2
+ export * from './wallet-connect';
3
+ export * from './coinbase-wallet';
4
+ export * from './token-pocket';
5
+ export * from './safeheron';
6
+ export * from './universal-wallet';
7
+ export * from './okx-wallet';
8
+ export * from './im-token';
9
+ export * from './mobile-wallet';
10
+ export * from './rainbow-wallet';
@@ -0,0 +1,10 @@
1
+ export * from "./meta-mask";
2
+ export * from "./wallet-connect";
3
+ export * from "./coinbase-wallet";
4
+ export * from "./token-pocket";
5
+ export * from "./safeheron";
6
+ export * from "./universal-wallet";
7
+ export * from "./okx-wallet";
8
+ export * from "./im-token";
9
+ export * from "./mobile-wallet";
10
+ export * from "./rainbow-wallet";
@@ -0,0 +1,2 @@
1
+ import type { EthereumWallet } from '../interface';
2
+ export declare const MetaMask: EthereumWallet;
@@ -0,0 +1,11 @@
1
+ import { metadata_MetaMask } from '@ant-design/web3-assets';
2
+ import { injected } from 'wagmi/connectors';
3
+ import { UniversalWallet } from "./universal-wallet";
4
+ export const MetaMask = metadata => {
5
+ return new UniversalWallet({
6
+ ...metadata_MetaMask,
7
+ ...metadata
8
+ }, () => injected({
9
+ target: 'metaMask'
10
+ }));
11
+ };
@@ -0,0 +1,2 @@
1
+ import { type EthereumWalletConnect } from './wallet-connect';
2
+ export declare const MobileWallet: EthereumWalletConnect;
@@ -0,0 +1,8 @@
1
+ import { metadata_MobileConnect } from '@ant-design/web3-assets';
2
+ import { WalletConnect } from "./wallet-connect";
3
+ export const MobileWallet = metadata => {
4
+ return WalletConnect({
5
+ ...metadata_MobileConnect,
6
+ ...metadata
7
+ });
8
+ };