@ant-design/web3-wagmi 2.4.3 → 2.4.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @ant-design/web3-wagmi
2
2
 
3
+ ## 2.4.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 518fd83: fix(wagmi): react max depth update exceeded
8
+ - 518fd83: chore: add storage props to config
9
+ - Updated dependencies [dd6366c]
10
+ - @ant-design/web3-common@1.10.0
11
+ - @ant-design/web3-assets@1.7.2
12
+
13
+ ## 2.4.4
14
+
15
+ ### Patch Changes
16
+
17
+ - 1270c95: chore(ethers): adjusted the compatibility form of the old version of etherjs
18
+ - 02e74aa: fix: set sideEffects false for enable treeshaking
19
+ - Updated dependencies [02e74aa]
20
+ - @ant-design/web3-assets@1.7.1
21
+ - @ant-design/web3-common@1.9.1
22
+
3
23
  ## 2.4.3
4
24
 
5
25
  ### Patch Changes
@@ -14,12 +14,14 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
14
14
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
15
  import React from 'react';
16
16
  import { fillAddressWith0x, Web3ConfigProvider } from '@ant-design/web3-common';
17
- import { useAccount, useBalance, useConfig, useConnect, useDisconnect, useSwitchChain } from 'wagmi';
17
+ import { disconnect, getAccount } from '@wagmi/core';
18
+ import { useAccount, useBalance, useConfig, useConnect, useSwitchChain } from 'wagmi';
18
19
  import { isEIP6963Connector } from "../utils";
19
20
  import { EIP6963Wallet } from "../wallets/eip6963";
20
21
  import { addNameToAccount, getNFTMetadata } from "./methods";
21
22
  import { jsx as _jsx } from "react/jsx-runtime";
22
23
  export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(props) {
24
+ var _availableChains$, _availableChains$2;
23
25
  var children = props.children,
24
26
  chainAssets = props.chainAssets,
25
27
  walletFactorys = props.walletFactorys,
@@ -42,12 +44,6 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
42
44
  connectAsync = _useConnect.connectAsync;
43
45
  var _useSwitchChain = useSwitchChain(),
44
46
  switchChain = _useSwitchChain.switchChain;
45
- var _useDisconnect = useDisconnect(),
46
- disconnectAsync = _useDisconnect.disconnectAsync;
47
- var _React$useState3 = React.useState(undefined),
48
- _React$useState4 = _slicedToArray(_React$useState3, 2),
49
- currentChain = _React$useState4[0],
50
- setCurrentChain = _React$useState4[1];
51
47
  var _useBalance = useBalance({
52
48
  address: balance && account ? fillAddressWith0x(account.address) : undefined
53
49
  }),
@@ -55,39 +51,39 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
55
51
  React.useEffect(function () {
56
52
  if (!address || isDisconnected) {
57
53
  setAccount(undefined);
58
- return;
54
+ } else {
55
+ var updateAccounts = /*#__PURE__*/function () {
56
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
57
+ var a;
58
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
59
+ while (1) switch (_context.prev = _context.next) {
60
+ case 0:
61
+ a = {
62
+ address: address
63
+ };
64
+ setAccount(a);
65
+ if (!ens) {
66
+ _context.next = 8;
67
+ break;
68
+ }
69
+ _context.t0 = setAccount;
70
+ _context.next = 6;
71
+ return addNameToAccount(config, a);
72
+ case 6:
73
+ _context.t1 = _context.sent;
74
+ (0, _context.t0)(_context.t1);
75
+ case 8:
76
+ case "end":
77
+ return _context.stop();
78
+ }
79
+ }, _callee);
80
+ }));
81
+ return function updateAccounts() {
82
+ return _ref.apply(this, arguments);
83
+ };
84
+ }();
85
+ updateAccounts();
59
86
  }
60
- var updateAccounts = /*#__PURE__*/function () {
61
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
62
- var a;
63
- return _regeneratorRuntime().wrap(function _callee$(_context) {
64
- while (1) switch (_context.prev = _context.next) {
65
- case 0:
66
- a = {
67
- address: address
68
- };
69
- setAccount(a);
70
- if (!ens) {
71
- _context.next = 8;
72
- break;
73
- }
74
- _context.t0 = setAccount;
75
- _context.next = 6;
76
- return addNameToAccount(config, a);
77
- case 6:
78
- _context.t1 = _context.sent;
79
- (0, _context.t0)(_context.t1);
80
- case 8:
81
- case "end":
82
- return _context.stop();
83
- }
84
- }, _callee);
85
- }));
86
- return function updateAccounts() {
87
- return _ref.apply(this, arguments);
88
- };
89
- }();
90
- updateAccounts();
91
87
  }, [address, isDisconnected, chain, ens]);
92
88
  var findConnectorByName = function findConnectorByName(name) {
93
89
  var commonConnector = availableConnectors.find(function (item) {
@@ -158,28 +154,27 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
158
154
  return item !== null;
159
155
  });
160
156
  }, [availableChains, chainAssets]);
157
+ var chainId = (chain === null || chain === void 0 ? void 0 : chain.id) || (availableChains === null || availableChains === void 0 || (_availableChains$ = availableChains[0]) === null || _availableChains$ === void 0 ? void 0 : _availableChains$.id);
158
+ var chainName = (chain === null || chain === void 0 ? void 0 : chain.name) || (availableChains === null || availableChains === void 0 || (_availableChains$2 = availableChains[0]) === null || _availableChains$2 === void 0 ? void 0 : _availableChains$2.name);
159
+ var _React$useState3 = React.useState(undefined),
160
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
161
+ currentChain = _React$useState4[0],
162
+ setCurrentChain = _React$useState4[1];
161
163
  React.useEffect(function () {
162
- var _c;
163
- if (!chain && currentChain) {
164
+ setCurrentChain(function (prevChain) {
164
165
  // not connected any chain, keep current chain
165
- return;
166
- }
167
- var currentWagmiChain = chain !== null && chain !== void 0 ? chain : availableChains[0];
168
- if (!currentWagmiChain) {
169
- return;
170
- }
171
- var c = chainAssets === null || chainAssets === void 0 ? void 0 : chainAssets.find(function (item) {
172
- return item.id === (currentWagmiChain === null || currentWagmiChain === void 0 ? void 0 : currentWagmiChain.id);
166
+ var newChain = chainAssets === null || chainAssets === void 0 ? void 0 : chainAssets.find(function (item) {
167
+ return (item === null || item === void 0 ? void 0 : item.id) === chainId;
168
+ });
169
+ if (!newChain && chainId) {
170
+ newChain = {
171
+ id: chainId,
172
+ name: chainName
173
+ };
174
+ }
175
+ return newChain || prevChain;
173
176
  });
174
- if (!((_c = c) !== null && _c !== void 0 && _c.id)) {
175
- c = {
176
- id: currentWagmiChain.id,
177
- name: currentWagmiChain.name
178
- };
179
- }
180
- setCurrentChain(c);
181
- return;
182
- }, [chain, chainAssets, availableChains, currentChain]);
177
+ }, [chainAssets, availableChains, chainId, chainName]);
183
178
  var currency = currentChain === null || currentChain === void 0 ? void 0 : currentChain.nativeCurrency;
184
179
  var getNFTMetadataFunc = React.useCallback( /*#__PURE__*/function () {
185
180
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
@@ -248,34 +243,38 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
248
243
  };
249
244
  }()),
250
245
  disconnect: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
246
+ var _getAccount, connector;
251
247
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
252
248
  while (1) switch (_context4.prev = _context4.next) {
253
249
  case 0:
254
- _context4.next = 2;
255
- return disconnectAsync();
256
- case 2:
250
+ // await disconnectAsync();
251
+ // TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
252
+ // 存在一些状态处理的 bug,暂时用更低阶 API 代替。
253
+ _getAccount = getAccount(config), connector = _getAccount.connector;
254
+ _context4.next = 3;
255
+ return disconnect(config, {
256
+ connector: connector
257
+ });
258
+ case 3:
257
259
  case "end":
258
260
  return _context4.stop();
259
261
  }
260
262
  }, _callee4);
261
263
  })),
262
264
  switchChain: ( /*#__PURE__*/function () {
263
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(c) {
265
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(newChain) {
264
266
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
265
267
  while (1) switch (_context5.prev = _context5.next) {
266
268
  case 0:
267
- if (chain) {
268
- _context5.next = 3;
269
- break;
269
+ if (!chain) {
270
+ // hava not connected any chain
271
+ setCurrentChain(newChain);
272
+ } else {
273
+ switchChain === null || switchChain === void 0 || switchChain({
274
+ chainId: newChain.id
275
+ });
270
276
  }
271
- // hava not connected any chain
272
- setCurrentChain(c);
273
- return _context5.abrupt("return");
274
- case 3:
275
- switchChain === null || switchChain === void 0 || switchChain({
276
- chainId: c.id
277
- });
278
- case 4:
277
+ case 1:
279
278
  case "end":
280
279
  return _context5.stop();
281
280
  }
@@ -1,3 +1,3 @@
1
1
  import type { Account } from '@ant-design/web3-common';
2
- import { type Config } from '@wagmi/core';
2
+ import type { Config } from 'wagmi';
3
3
  export declare function addNameToAccount(config: Config, account: Account, chainId?: number): Promise<Account>;
@@ -1,3 +1,3 @@
1
1
  import { type NFTMetadata } from '@ant-design/web3-common';
2
- import { type Config } from '@wagmi/core';
2
+ import type { Config } from 'wagmi';
3
3
  export declare function getNFTMetadata(config: Config, address: string, tokenId: bigint, chainId?: number): Promise<NFTMetadata>;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.AntDesignWeb3ConfigProvider = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _web3Common = require("@ant-design/web3-common");
9
+ var _core = require("@wagmi/core");
9
10
  var _wagmi = require("wagmi");
10
11
  var _utils = require("../utils");
11
12
  var _eip = require("../wallets/eip6963");
@@ -37,10 +38,6 @@ const AntDesignWeb3ConfigProvider = props => {
37
38
  const {
38
39
  switchChain
39
40
  } = (0, _wagmi.useSwitchChain)();
40
- const {
41
- disconnectAsync
42
- } = (0, _wagmi.useDisconnect)();
43
- const [currentChain, setCurrentChain] = _react.default.useState(undefined);
44
41
  const {
45
42
  data: balanceData
46
43
  } = (0, _wagmi.useBalance)({
@@ -49,18 +46,18 @@ const AntDesignWeb3ConfigProvider = props => {
49
46
  _react.default.useEffect(() => {
50
47
  if (!address || isDisconnected) {
51
48
  setAccount(undefined);
52
- return;
53
- }
54
- const updateAccounts = async () => {
55
- const a = {
56
- address
49
+ } else {
50
+ const updateAccounts = async () => {
51
+ const a = {
52
+ address
53
+ };
54
+ setAccount(a);
55
+ if (ens) {
56
+ setAccount(await (0, _methods.addNameToAccount)(config, a));
57
+ }
57
58
  };
58
- setAccount(a);
59
- if (ens) {
60
- setAccount(await (0, _methods.addNameToAccount)(config, a));
61
- }
62
- };
63
- updateAccounts();
59
+ updateAccounts();
60
+ }
64
61
  }, [address, isDisconnected, chain, ens]);
65
62
  const findConnectorByName = name => {
66
63
  const commonConnector = availableConnectors.find(item => item.name === name && !(0, _utils.isEIP6963Connector)(item));
@@ -117,25 +114,22 @@ const AntDesignWeb3ConfigProvider = props => {
117
114
  return null;
118
115
  }).filter(item => item !== null);
119
116
  }, [availableChains, chainAssets]);
117
+ const chainId = chain?.id || availableChains?.[0]?.id;
118
+ const chainName = chain?.name || availableChains?.[0]?.name;
119
+ const [currentChain, setCurrentChain] = _react.default.useState(undefined);
120
120
  _react.default.useEffect(() => {
121
- if (!chain && currentChain) {
121
+ setCurrentChain(prevChain => {
122
122
  // not connected any chain, keep current chain
123
- return;
124
- }
125
- const currentWagmiChain = chain ?? availableChains[0];
126
- if (!currentWagmiChain) {
127
- return;
128
- }
129
- let c = chainAssets?.find(item => item.id === currentWagmiChain?.id);
130
- if (!c?.id) {
131
- c = {
132
- id: currentWagmiChain.id,
133
- name: currentWagmiChain.name
134
- };
135
- }
136
- setCurrentChain(c);
137
- return;
138
- }, [chain, chainAssets, availableChains, currentChain]);
123
+ let newChain = chainAssets?.find(item => item?.id === chainId);
124
+ if (!newChain && chainId) {
125
+ newChain = {
126
+ id: chainId,
127
+ name: chainName
128
+ };
129
+ }
130
+ return newChain || prevChain;
131
+ });
132
+ }, [chainAssets, availableChains, chainId, chainName]);
139
133
  const currency = currentChain?.nativeCurrency;
140
134
  const getNFTMetadataFunc = _react.default.useCallback(async ({
141
135
  address: contractAddress,
@@ -168,17 +162,25 @@ const AntDesignWeb3ConfigProvider = props => {
168
162
  });
169
163
  },
170
164
  disconnect: async () => {
171
- await disconnectAsync();
165
+ // await disconnectAsync();
166
+ // TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
167
+ // 存在一些状态处理的 bug,暂时用更低阶 API 代替。
168
+ const {
169
+ connector
170
+ } = (0, _core.getAccount)(config);
171
+ await (0, _core.disconnect)(config, {
172
+ connector
173
+ });
172
174
  },
173
- switchChain: async c => {
175
+ switchChain: async newChain => {
174
176
  if (!chain) {
175
177
  // hava not connected any chain
176
- setCurrentChain(c);
177
- return;
178
+ setCurrentChain(newChain);
179
+ } else {
180
+ switchChain?.({
181
+ chainId: newChain.id
182
+ });
178
183
  }
179
- switchChain?.({
180
- chainId: c.id
181
- });
182
184
  },
183
185
  getNFTMetadata: getNFTMetadataFunc,
184
186
  children: children
@@ -1,3 +1,3 @@
1
1
  import type { Account } from '@ant-design/web3-common';
2
- import { type Config } from '@wagmi/core';
2
+ import type { Config } from 'wagmi';
3
3
  export declare function addNameToAccount(config: Config, account: Account, chainId?: number): Promise<Account>;
@@ -1,3 +1,3 @@
1
1
  import { type NFTMetadata } from '@ant-design/web3-common';
2
- import { type Config } from '@wagmi/core';
2
+ import type { Config } from 'wagmi';
3
3
  export declare function getNFTMetadata(config: Config, address: string, tokenId: bigint, chainId?: number): Promise<NFTMetadata>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/web3-wagmi",
3
- "version": "2.4.3",
3
+ "version": "2.4.5",
4
4
  "type": "module",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -10,6 +10,7 @@
10
10
  "require": "./dist/lib/index.js",
11
11
  "types": "./dist/esm/index.d.ts"
12
12
  },
13
+ "sideEffects": false,
13
14
  "files": [
14
15
  "dist",
15
16
  "CHANGELOG.md",
@@ -37,22 +38,23 @@
37
38
  },
38
39
  "dependencies": {
39
40
  "debug": "^4.3.4",
40
- "@wagmi/core": "^2.6.5",
41
- "@ant-design/web3-assets": "1.7.0",
42
- "@ant-design/web3-common": "1.9.0"
41
+ "@wagmi/core": "^2.9.6",
42
+ "@ant-design/web3-assets": "1.7.2",
43
+ "@ant-design/web3-common": "1.10.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/debug": "^4.1.12",
47
+ "@wagmi/core": "^2.9.3",
46
48
  "father": "^4.4.0",
47
49
  "typescript": "^5.4.4",
48
- "wagmi": "^2.5.7",
49
- "@tanstack/react-query": "^5.28.4",
50
- "viem": ">=2.9.25"
50
+ "wagmi": "^2.8.6",
51
+ "@tanstack/react-query": "^5.37.1",
52
+ "viem": "^2.10.3"
51
53
  },
52
54
  "peerDependencies": {
53
- "wagmi": "^2.5.7",
54
- "@tanstack/react-query": "^5.28.4",
55
- "viem": ">=2.9.25"
55
+ "wagmi": "^2.8.6",
56
+ "@tanstack/react-query": "^5.37.1",
57
+ "viem": ">=2.0.0"
56
58
  },
57
59
  "publishConfig": {
58
60
  "registry": "https://registry.npmjs.org",