@ant-design/web3-wagmi 1.1.2 → 2.0.1

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 (48) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/esm/interface.d.ts +7 -3
  3. package/dist/esm/wagmi-provider/config-provider.d.ts +7 -5
  4. package/dist/esm/wagmi-provider/config-provider.js +64 -31
  5. package/dist/esm/wagmi-provider/index.d.ts +8 -5
  6. package/dist/esm/wagmi-provider/index.js +28 -48
  7. package/dist/esm/wagmi-provider/methods/addNameToAccount.d.ts +2 -1
  8. package/dist/esm/wagmi-provider/methods/addNameToAccount.js +4 -4
  9. package/dist/esm/wagmi-provider/methods/getNFTMetadata.d.ts +2 -1
  10. package/dist/esm/wagmi-provider/methods/getNFTMetadata.js +4 -4
  11. package/dist/esm/wallets/coinbase-wallet.d.ts +2 -2
  12. package/dist/esm/wallets/coinbase-wallet.js +25 -23
  13. package/dist/esm/wallets/index.d.ts +1 -0
  14. package/dist/esm/wallets/index.js +2 -1
  15. package/dist/esm/wallets/meta-mask.d.ts +2 -2
  16. package/dist/esm/wallets/meta-mask.js +44 -24
  17. package/dist/esm/wallets/safeheron.d.ts +2 -2
  18. package/dist/esm/wallets/safeheron.js +50 -23
  19. package/dist/esm/wallets/token-pocket.d.ts +2 -2
  20. package/dist/esm/wallets/token-pocket.js +3 -26
  21. package/dist/esm/wallets/universal-wallet.d.ts +9 -0
  22. package/dist/esm/wallets/universal-wallet.js +151 -0
  23. package/dist/esm/wallets/wallet-connect.d.ts +6 -1
  24. package/dist/esm/wallets/wallet-connect.js +57 -47
  25. package/dist/lib/interface.d.ts +7 -3
  26. package/dist/lib/wagmi-provider/config-provider.d.ts +7 -5
  27. package/dist/lib/wagmi-provider/config-provider.js +38 -20
  28. package/dist/lib/wagmi-provider/index.d.ts +8 -5
  29. package/dist/lib/wagmi-provider/index.js +22 -29
  30. package/dist/lib/wagmi-provider/methods/addNameToAccount.d.ts +2 -1
  31. package/dist/lib/wagmi-provider/methods/addNameToAccount.js +2 -2
  32. package/dist/lib/wagmi-provider/methods/getNFTMetadata.d.ts +2 -1
  33. package/dist/lib/wagmi-provider/methods/getNFTMetadata.js +2 -2
  34. package/dist/lib/wallets/coinbase-wallet.d.ts +2 -2
  35. package/dist/lib/wallets/coinbase-wallet.js +15 -11
  36. package/dist/lib/wallets/index.d.ts +1 -0
  37. package/dist/lib/wallets/index.js +11 -0
  38. package/dist/lib/wallets/meta-mask.d.ts +2 -2
  39. package/dist/lib/wallets/meta-mask.js +18 -11
  40. package/dist/lib/wallets/safeheron.d.ts +2 -2
  41. package/dist/lib/wallets/safeheron.js +18 -11
  42. package/dist/lib/wallets/token-pocket.d.ts +2 -2
  43. package/dist/lib/wallets/token-pocket.js +8 -11
  44. package/dist/lib/wallets/universal-wallet.d.ts +9 -0
  45. package/dist/lib/wallets/universal-wallet.js +57 -0
  46. package/dist/lib/wallets/wallet-connect.d.ts +6 -1
  47. package/dist/lib/wallets/wallet-connect.js +28 -20
  48. package/package.json +7 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @ant-design/web3-wagmi
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 47a879d: chore: release @ant-design/web3-wagmi 2.x for wagmi 2.x
8
+
9
+ ## 2.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - 337971f: feat: upgrade wagmi to 2.0
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [879548d]
18
+ - @ant-design/web3-common@1.3.0
19
+ - @ant-design/web3-assets@1.1.4
20
+
21
+ ## 1.2.0
22
+
23
+ ### Minor Changes
24
+
25
+ - e5db9b7: feat: Add UniversalWallet for support TokenPocket and more wallets
26
+
27
+ ### Patch Changes
28
+
29
+ - 17ca201: perf: Modify import type
30
+ - Updated dependencies [e5db9b7]
31
+ - Updated dependencies [18def13]
32
+ - Updated dependencies [17ca201]
33
+ - @ant-design/web3-common@1.2.0
34
+ - @ant-design/web3-assets@1.1.3
35
+
3
36
  ## 1.1.2
4
37
 
5
38
  ### Patch Changes
@@ -1,6 +1,10 @@
1
- import type { Wallet } from '@ant-design/web3-common';
1
+ import type { Wallet, WalletMetadata } from '@ant-design/web3-common';
2
2
  import type { Connector } from 'wagmi';
3
+ export interface WalletUseInWagmiAdapter extends Wallet {
4
+ getWagmiConnector?: () => Promise<Connector | undefined>;
5
+ }
6
+ export type EthereumWallet = (metadata?: Partial<WalletMetadata>) => WalletFactory;
3
7
  export interface WalletFactory {
4
- name: Connector['name'];
5
- create: (connector?: Connector) => Wallet;
8
+ connectors: Connector['name'][];
9
+ create: (connector?: readonly Connector[]) => WalletUseInWagmiAdapter;
6
10
  }
@@ -1,14 +1,16 @@
1
1
  import React from 'react';
2
- import { type Chain, Locale } from '@ant-design/web3-common';
3
- import { type Connector as WagmiConnector, type Chain as WagmiChain } from 'wagmi';
2
+ import { type Chain, type Locale } from '@ant-design/web3-common';
3
+ import { Chain as WagmiChain } from 'viem';
4
+ import { type Connector as WagmiConnector } from 'wagmi';
4
5
  import type { WalletFactory } from '../interface';
5
6
  export interface AntDesignWeb3ConfigProviderProps {
7
+ chainAssets: Chain[];
8
+ walletFactorys: WalletFactory[];
6
9
  locale?: Locale;
7
- assets?: (WalletFactory | Chain)[];
8
10
  children?: React.ReactNode;
9
11
  ens?: boolean;
10
12
  balance?: boolean;
11
- availableChains: WagmiChain[];
12
- availableConnectors: WagmiConnector[];
13
+ readonly availableChains: readonly WagmiChain[];
14
+ readonly availableConnectors: readonly WagmiConnector[];
13
15
  }
14
16
  export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
@@ -9,14 +9,15 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import React from 'react';
12
- import { Web3ConfigProvider, fillAddressWith0x } from '@ant-design/web3-common';
13
- import { useAccount, useConnect, useDisconnect, useNetwork, useSwitchNetwork, useBalance } from 'wagmi';
12
+ import { fillAddressWith0x, Web3ConfigProvider } from '@ant-design/web3-common';
13
+ import { useAccount, useBalance, useConfig, useConnect, useDisconnect, useSwitchChain } from 'wagmi';
14
14
  import { addNameToAccount, getNFTMetadata } from "./methods";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(props) {
17
17
  var _currentChain$nativeC;
18
18
  var children = props.children,
19
- assets = props.assets,
19
+ chainAssets = props.chainAssets,
20
+ walletFactorys = props.walletFactorys,
20
21
  availableChains = props.availableChains,
21
22
  availableConnectors = props.availableConnectors,
22
23
  ens = props.ens,
@@ -24,17 +25,17 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
24
25
  locale = props.locale;
25
26
  var _useAccount = useAccount(),
26
27
  address = _useAccount.address,
27
- isDisconnected = _useAccount.isDisconnected;
28
+ isDisconnected = _useAccount.isDisconnected,
29
+ chain = _useAccount.chain;
30
+ var config = useConfig();
28
31
  var _React$useState = React.useState(),
29
32
  _React$useState2 = _slicedToArray(_React$useState, 2),
30
33
  account = _React$useState2[0],
31
34
  setAccount = _React$useState2[1];
32
35
  var _useConnect = useConnect(),
33
36
  connectAsync = _useConnect.connectAsync;
34
- var _useSwitchNetwork = useSwitchNetwork(),
35
- switchNetwork = _useSwitchNetwork.switchNetwork;
36
- var _useNetwork = useNetwork(),
37
- chain = _useNetwork.chain;
37
+ var _useSwitchChain = useSwitchChain(),
38
+ switchChain = _useSwitchChain.switchChain;
38
39
  var _useDisconnect = useDisconnect(),
39
40
  disconnectAsync = _useDisconnect.disconnectAsync;
40
41
  var _React$useState3 = React.useState(undefined),
@@ -65,7 +66,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
65
66
  break;
66
67
  }
67
68
  _context.next = 5;
68
- return addNameToAccount(a);
69
+ return addNameToAccount(config, a);
69
70
  case 5:
70
71
  _context.t1 = _context.sent;
71
72
  _context.next = 9;
@@ -88,22 +89,39 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
88
89
  updateAccounts();
89
90
  }, [address, isDisconnected, chain, ens]);
90
91
  var wallets = React.useMemo(function () {
91
- return availableConnectors.map(function (connector) {
92
- var walletFactory = assets === null || assets === void 0 ? void 0 : assets.find(function (item) {
93
- return item.name === connector.name;
92
+ availableConnectors.forEach(function (connector) {
93
+ // check use assets config and console.error for alert
94
+ var walletFactory = walletFactorys === null || walletFactorys === void 0 ? void 0 : walletFactorys.find(function (item) {
95
+ var _item$connectors;
96
+ return (_item$connectors = item.connectors) === null || _item$connectors === void 0 ? void 0 : _item$connectors.includes(connector.name);
94
97
  });
95
98
  if (!(walletFactory !== null && walletFactory !== void 0 && walletFactory.create)) {
96
- console.error("Can not find wallet factory for ".concat(connector.name, ", you should config it in WagmiWeb3ConfigProvider 'assets'."));
99
+ console.error("Can not find wallet factory for ".concat(connector.name, ", you should config it in WagmiWeb3ConfigProvider 'wallets'."));
100
+ }
101
+ });
102
+
103
+ // Generate Wallet for @ant-design/web3
104
+ var allWallet = walletFactorys === null || walletFactorys === void 0 ? void 0 : walletFactorys.map(function (factory) {
105
+ var connectors = factory.connectors.map(function (name) {
106
+ return availableConnectors.find(function (item) {
107
+ return item.name === name;
108
+ });
109
+ }).filter(function (item) {
110
+ return !!item;
111
+ });
112
+ if (connectors.length === 0) {
113
+ // Not config connector for this wallet factory, ignore it.
97
114
  return null;
98
115
  }
99
- return walletFactory.create(connector);
116
+ return factory.create(connectors);
100
117
  }).filter(function (item) {
101
118
  return item !== null;
102
119
  });
103
- }, [availableConnectors, assets]);
120
+ return allWallet;
121
+ }, [availableConnectors, walletFactorys]);
104
122
  var chainList = React.useMemo(function () {
105
123
  return availableChains.map(function (item) {
106
- var c = assets === null || assets === void 0 ? void 0 : assets.find(function (asset) {
124
+ var c = chainAssets === null || chainAssets === void 0 ? void 0 : chainAssets.find(function (asset) {
107
125
  return asset.id === item.id;
108
126
  });
109
127
  if (c !== null && c !== void 0 && c.id) {
@@ -119,7 +137,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
119
137
  }).filter(function (item) {
120
138
  return item !== null;
121
139
  });
122
- }, [availableChains, assets]);
140
+ }, [availableChains, chainAssets]);
123
141
  React.useEffect(function () {
124
142
  var _c;
125
143
  if (!chain && currentChain) {
@@ -130,7 +148,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
130
148
  if (!currentWagmiChain) {
131
149
  return;
132
150
  }
133
- var c = assets === null || assets === void 0 ? void 0 : assets.find(function (item) {
151
+ var c = chainAssets === null || chainAssets === void 0 ? void 0 : chainAssets.find(function (item) {
134
152
  return item.id === (currentWagmiChain === null || currentWagmiChain === void 0 ? void 0 : currentWagmiChain.id);
135
153
  });
136
154
  if (!((_c = c) !== null && _c !== void 0 && _c.id)) {
@@ -141,7 +159,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
141
159
  }
142
160
  setCurrentChain(c);
143
161
  return;
144
- }, [chain, assets, availableChains, currentChain]);
162
+ }, [chain, chainAssets, availableChains, currentChain]);
145
163
  return /*#__PURE__*/_jsx(Web3ConfigProvider, {
146
164
  locale: locale,
147
165
  availableChains: chainList,
@@ -156,19 +174,32 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
156
174
  availableWallets: wallets,
157
175
  connect: /*#__PURE__*/function () {
158
176
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(wallet) {
177
+ var _getWagmiConnector, _ref3;
159
178
  var connector;
160
179
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
161
180
  while (1) switch (_context2.prev = _context2.next) {
162
181
  case 0:
163
- connector = availableConnectors.find(function (item) {
164
- return item.name === (wallet === null || wallet === void 0 ? void 0 : wallet.name);
165
- });
166
- _context2.next = 3;
182
+ _context2.next = 2;
183
+ return wallet === null || wallet === void 0 || (_getWagmiConnector = (_ref3 = wallet).getWagmiConnector) === null || _getWagmiConnector === void 0 ? void 0 : _getWagmiConnector.call(_ref3);
184
+ case 2:
185
+ connector = _context2.sent;
186
+ if (!connector) {
187
+ connector = availableConnectors.find(function (item) {
188
+ return item.name === (wallet === null || wallet === void 0 ? void 0 : wallet.name);
189
+ });
190
+ }
191
+ if (connector) {
192
+ _context2.next = 6;
193
+ break;
194
+ }
195
+ throw new Error("Can not find connector for ".concat(wallet === null || wallet === void 0 ? void 0 : wallet.name));
196
+ case 6:
197
+ _context2.next = 8;
167
198
  return connectAsync({
168
199
  connector: connector,
169
200
  chainId: currentChain === null || currentChain === void 0 ? void 0 : currentChain.id
170
201
  });
171
- case 3:
202
+ case 8:
172
203
  case "end":
173
204
  return _context2.stop();
174
205
  }
@@ -191,7 +222,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
191
222
  }, _callee3);
192
223
  })),
193
224
  switchChain: /*#__PURE__*/function () {
194
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(c) {
225
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(c) {
195
226
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
196
227
  while (1) switch (_context4.prev = _context4.next) {
197
228
  case 0:
@@ -199,7 +230,9 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
199
230
  // hava not connected any chain
200
231
  setCurrentChain(c);
201
232
  } else {
202
- switchNetwork === null || switchNetwork === void 0 || switchNetwork(c.id);
233
+ switchChain === null || switchChain === void 0 || switchChain({
234
+ chainId: c.id
235
+ });
203
236
  }
204
237
  case 1:
205
238
  case "end":
@@ -208,17 +241,17 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
208
241
  }, _callee4);
209
242
  }));
210
243
  return function (_x2) {
211
- return _ref4.apply(this, arguments);
244
+ return _ref5.apply(this, arguments);
212
245
  };
213
246
  }(),
214
247
  getNFTMetadata: /*#__PURE__*/function () {
215
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
248
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
216
249
  var contractAddress, tokenId;
217
250
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
218
251
  while (1) switch (_context5.prev = _context5.next) {
219
252
  case 0:
220
- contractAddress = _ref5.address, tokenId = _ref5.tokenId;
221
- return _context5.abrupt("return", getNFTMetadata(contractAddress, tokenId, chain === null || chain === void 0 ? void 0 : chain.id));
253
+ contractAddress = _ref6.address, tokenId = _ref6.tokenId;
254
+ return _context5.abrupt("return", getNFTMetadata(config, contractAddress, tokenId, chain === null || chain === void 0 ? void 0 : chain.id));
222
255
  case 2:
223
256
  case "end":
224
257
  return _context5.stop();
@@ -226,7 +259,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
226
259
  }, _callee5);
227
260
  }));
228
261
  return function (_x3) {
229
- return _ref6.apply(this, arguments);
262
+ return _ref7.apply(this, arguments);
230
263
  };
231
264
  }(),
232
265
  children: children
@@ -1,12 +1,15 @@
1
1
  import React from 'react';
2
- import type { PublicClient, WebSocketPublicClient, Config } from 'wagmi';
3
2
  import type { Chain, Locale } from '@ant-design/web3-common';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import type { Config } from 'wagmi';
4
5
  import type { WalletFactory } from '../interface';
5
- export type WagmiWeb3ConfigProviderProps<TPublicClient extends PublicClient = PublicClient, TWebSocketPublicClient extends WebSocketPublicClient = WebSocketPublicClient> = {
6
- config: Config<TPublicClient, TWebSocketPublicClient>;
6
+ export type WagmiWeb3ConfigProviderProps = {
7
+ config: Config;
7
8
  locale?: Locale;
8
- assets?: (Chain | WalletFactory)[];
9
+ wallets?: WalletFactory[];
10
+ chains?: Chain[];
9
11
  ens?: boolean;
12
+ queryClient?: QueryClient;
10
13
  balance?: boolean;
11
14
  };
12
- export declare function WagmiWeb3ConfigProvider<TPublicClient extends PublicClient, TWebSocketPublicClient extends WebSocketPublicClient>({ children, assets, ens, locale, balance, config, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps<TPublicClient, TWebSocketPublicClient>>): React.ReactElement;
15
+ export declare function WagmiWeb3ConfigProvider({ children, wallets, chains, ens, locale, balance, config, queryClient, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["children", "assets", "ens", "locale", "balance", "config"];
2
+ var _excluded = ["children", "wallets", "chains", "ens", "locale", "balance", "config", "queryClient"];
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -7,70 +7,50 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
7
7
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
9
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
13
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
14
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
15
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
17
16
  import React from 'react';
18
- import { WagmiConfig } from 'wagmi';
19
- import { AntDesignWeb3ConfigProvider } from "./config-provider";
20
17
  // Built in popular chains
21
- import { Mainnet, Goerli } from '@ant-design/web3-assets';
22
- // MetaMask built-in
23
- import { MetaMask } from "../wallets";
18
+ import { Mainnet } from '@ant-design/web3-assets';
19
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
20
+ import { WagmiProvider } from 'wagmi';
21
+ import { AntDesignWeb3ConfigProvider } from "./config-provider";
24
22
  import { jsx as _jsx } from "react/jsx-runtime";
25
23
  export function WagmiWeb3ConfigProvider(_ref) {
26
24
  var children = _ref.children,
27
- _ref$assets = _ref.assets,
28
- assets = _ref$assets === void 0 ? [] : _ref$assets,
25
+ _ref$wallets = _ref.wallets,
26
+ wallets = _ref$wallets === void 0 ? [] : _ref$wallets,
27
+ _ref$chains = _ref.chains,
28
+ chains = _ref$chains === void 0 ? [] : _ref$chains,
29
29
  ens = _ref.ens,
30
30
  locale = _ref.locale,
31
31
  balance = _ref.balance,
32
32
  config = _ref.config,
33
+ queryClient = _ref.queryClient,
33
34
  restProps = _objectWithoutProperties(_ref, _excluded);
34
- var availableChains = React.useMemo(function () {
35
- var _config$publicClient$;
36
- // merge all available chains fro user select
37
- var chains = [];
38
- var _iterator = _createForOfIteratorHelper(config.connectors),
39
- _step;
40
- try {
41
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
- var connector = _step.value;
43
- connector.chains.forEach(function (chain) {
44
- if (chains.find(function (c) {
45
- return c.id === chain.id;
46
- })) return;
47
- chains.push(chain);
48
- });
49
- }
50
- } catch (err) {
51
- _iterator.e(err);
52
- } finally {
53
- _iterator.f();
54
- }
55
- (_config$publicClient$ = config.publicClient.chains) === null || _config$publicClient$ === void 0 || _config$publicClient$.forEach(function (chain) {
56
- if (chains.find(function (c) {
57
- return c.id === chain.id;
58
- })) return;
59
- chains.push(chain);
60
- });
61
- return chains;
62
- }, [config]);
63
- return /*#__PURE__*/_jsx(WagmiConfig, _objectSpread(_objectSpread({
35
+ var chainAssets = [].concat(_toConsumableArray(chains), [Mainnet]);
36
+ var mergedQueryClient = React.useMemo(function () {
37
+ return queryClient !== null && queryClient !== void 0 ? queryClient : new QueryClient();
38
+ }, [queryClient]);
39
+ return /*#__PURE__*/_jsx(WagmiProvider, _objectSpread(_objectSpread({
64
40
  config: config
65
41
  }, restProps), {}, {
66
- children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
67
- locale: locale,
68
- assets: [].concat(_toConsumableArray(assets), [MetaMask, Mainnet, Goerli]),
69
- availableChains: availableChains,
70
- availableConnectors: config.connectors || [],
71
- ens: ens,
72
- balance: balance,
73
- children: children
42
+ children: /*#__PURE__*/_jsx(QueryClientProvider, {
43
+ client: mergedQueryClient,
44
+ children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
45
+ locale: locale,
46
+ chainAssets: chainAssets,
47
+ walletFactorys: wallets,
48
+ availableChains: config.chains,
49
+ availableConnectors: config.connectors,
50
+ ens: ens,
51
+ balance: balance,
52
+ children: children
53
+ })
74
54
  })
75
55
  }));
76
56
  }
@@ -1,2 +1,3 @@
1
1
  import type { Account } from '@ant-design/web3-common';
2
- export declare function addNameToAccount(account: Account, chainId?: number): Promise<Account>;
2
+ import { type Config } from '@wagmi/core';
3
+ export declare function addNameToAccount(config: Config, account: Account, chainId?: number): Promise<Account>;
@@ -7,18 +7,18 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
7
7
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
8
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
9
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
- import { fetchEnsName } from '@wagmi/core';
11
- export function addNameToAccount(_x, _x2) {
10
+ import { getEnsName } from '@wagmi/core';
11
+ export function addNameToAccount(_x, _x2, _x3) {
12
12
  return _addNameToAccount.apply(this, arguments);
13
13
  }
14
14
  function _addNameToAccount() {
15
- _addNameToAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(account, chainId) {
15
+ _addNameToAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, account, chainId) {
16
16
  var name;
17
17
  return _regeneratorRuntime().wrap(function _callee$(_context) {
18
18
  while (1) switch (_context.prev = _context.next) {
19
19
  case 0:
20
20
  _context.next = 2;
21
- return fetchEnsName({
21
+ return getEnsName(config, {
22
22
  address: account.address,
23
23
  chainId: chainId
24
24
  });
@@ -1,2 +1,3 @@
1
1
  import { type NFTMetadata } from '@ant-design/web3-common';
2
- export declare function getNFTMetadata(address: string, tokenId: bigint, chainId?: number): Promise<NFTMetadata>;
2
+ import { type Config } from '@wagmi/core';
3
+ export declare function getNFTMetadata(config: Config, address: string, tokenId: bigint, chainId?: number): Promise<NFTMetadata>;
@@ -2,19 +2,19 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- import { requestWeb3Asset, fillAddressWith0x } from '@ant-design/web3-common';
5
+ import { fillAddressWith0x, requestWeb3Asset } from '@ant-design/web3-common';
6
6
  import { readContract } from '@wagmi/core';
7
- export function getNFTMetadata(_x, _x2, _x3) {
7
+ export function getNFTMetadata(_x, _x2, _x3, _x4) {
8
8
  return _getNFTMetadata.apply(this, arguments);
9
9
  }
10
10
  function _getNFTMetadata() {
11
- _getNFTMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(address, tokenId, chainId) {
11
+ _getNFTMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, address, tokenId, chainId) {
12
12
  var tokenURI, metaInfo;
13
13
  return _regeneratorRuntime().wrap(function _callee$(_context) {
14
14
  while (1) switch (_context.prev = _context.next) {
15
15
  case 0:
16
16
  _context.next = 2;
17
- return readContract({
17
+ return readContract(config, {
18
18
  address: fillAddressWith0x(address),
19
19
  args: [tokenId],
20
20
  chainId: chainId,
@@ -1,2 +1,2 @@
1
- import type { WalletFactory } from '../interface';
2
- export declare const CoinbaseWallet: WalletFactory;
1
+ import type { EthereumWallet } from '../interface';
2
+ export declare const CoinbaseWallet: EthereumWallet;
@@ -8,27 +8,29 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
8
8
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
9
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
10
  import { metadata_CoinbaseWallet } from '@ant-design/web3-assets';
11
- export var CoinbaseWallet = {
12
- name: 'Coinbase Wallet',
13
- create: function create() {
14
- return _objectSpread(_objectSpread({}, metadata_CoinbaseWallet), {}, {
15
- hasWalletReady: function () {
16
- var _hasWalletReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17
- return _regeneratorRuntime().wrap(function _callee$(_context) {
18
- while (1) switch (_context.prev = _context.next) {
19
- case 0:
20
- return _context.abrupt("return", true);
21
- case 1:
22
- case "end":
23
- return _context.stop();
24
- }
25
- }, _callee);
26
- }));
27
- function hasWalletReady() {
28
- return _hasWalletReady.apply(this, arguments);
29
- }
30
- return hasWalletReady;
31
- }()
32
- });
33
- }
11
+ export var CoinbaseWallet = function CoinbaseWallet(metadata) {
12
+ return {
13
+ connectors: ['Coinbase Wallet'],
14
+ create: function create() {
15
+ return _objectSpread(_objectSpread({}, metadata_CoinbaseWallet), {}, {
16
+ hasWalletReady: function () {
17
+ var _hasWalletReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
18
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
19
+ while (1) switch (_context.prev = _context.next) {
20
+ case 0:
21
+ return _context.abrupt("return", true);
22
+ case 1:
23
+ case "end":
24
+ return _context.stop();
25
+ }
26
+ }, _callee);
27
+ }));
28
+ function hasWalletReady() {
29
+ return _hasWalletReady.apply(this, arguments);
30
+ }
31
+ return hasWalletReady;
32
+ }()
33
+ }, metadata);
34
+ }
35
+ };
34
36
  };
@@ -3,3 +3,4 @@ export * from './wallet-connect';
3
3
  export * from './coinbase-wallet';
4
4
  export * from './token-pocket';
5
5
  export * from './safeheron';
6
+ export * from './universal-wallet';
@@ -2,4 +2,5 @@ export * from "./meta-mask";
2
2
  export * from "./wallet-connect";
3
3
  export * from "./coinbase-wallet";
4
4
  export * from "./token-pocket";
5
- export * from "./safeheron";
5
+ export * from "./safeheron";
6
+ export * from "./universal-wallet";
@@ -1,2 +1,2 @@
1
- import type { WalletFactory } from '../interface';
2
- export declare const MetaMask: WalletFactory;
1
+ import type { EthereumWallet } from '../interface';
2
+ export declare const MetaMask: EthereumWallet;