@ant-design/web3-wagmi 2.7.1 → 2.7.3

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,21 @@
1
1
  # @ant-design/web3-wagmi
2
2
 
3
+ ## 2.7.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 615d403: fix(web3-wagmi): Ensure AntDesignWeb3ConfigProvider component renders correctly when Wagmi config ssr is true
8
+ - 8760a03: feat(web3-wagmi): Add 'initialState' and 'reconnectOnMount' props to WagmiWeb3ConfigProviderProps
9
+
10
+ ## 2.7.2
11
+
12
+ ### Patch Changes
13
+
14
+ - 3f7d7a6: build: set targets chrome 100
15
+ - Updated dependencies [3f7d7a6]
16
+ - @ant-design/web3-assets@1.10.1
17
+ - @ant-design/web3-common@1.12.1
18
+
3
19
  ## 2.7.1
4
20
 
5
21
  ### Patch Changes
package/dist/esm/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { injected } from 'wagmi/connectors';
2
- var isEIP6963Connector = function isEIP6963Connector(connector) {
2
+ const isEIP6963Connector = connector => {
3
3
  if (connector.type === injected.type && connector.icon && connector.id && connector.name) {
4
4
  return true;
5
5
  }
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import { type Chain, type Locale } from '@ant-design/web3-common';
3
- import type { Chain as WagmiChain } from 'viem';
4
- import { type Connector as WagmiConnector } from 'wagmi';
3
+ import type { Config as WagmiConfig } from 'wagmi';
5
4
  import type { EIP6963Config, WalletFactory } from '../interface';
6
5
  export interface AntDesignWeb3ConfigProviderProps {
7
6
  chainAssets: Chain[];
@@ -11,7 +10,6 @@ export interface AntDesignWeb3ConfigProviderProps {
11
10
  ens?: boolean;
12
11
  balance?: boolean;
13
12
  eip6963?: EIP6963Config;
14
- readonly availableChains: readonly WagmiChain[];
15
- readonly availableConnectors: readonly WagmiConnector[];
13
+ wagimConfig: WagmiConfig;
16
14
  }
17
15
  export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
@@ -1,17 +1,3 @@
1
- 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; }
2
- 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); } }
3
- 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); }); }; }
4
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
- 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; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
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); }
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
14
- 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); }
15
1
  import React from 'react';
16
2
  import { Web3ConfigProvider } from '@ant-design/web3-common';
17
3
  import { useAccount, useBalance, useConfig, useConnect, useEnsAvatar, useEnsName, useSwitchChain } from 'wagmi';
@@ -20,125 +6,111 @@ import { isEIP6963Connector } from "../utils";
20
6
  import { EIP6963Wallet } from "../wallets/eip6963";
21
7
  import { getNFTMetadata } from "./methods";
22
8
  import { jsx as _jsx } from "react/jsx-runtime";
23
- export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(props) {
24
- var _availableChains$, _availableChains$2;
25
- var children = props.children,
26
- chainAssets = props.chainAssets,
27
- walletFactorys = props.walletFactorys,
28
- availableChains = props.availableChains,
29
- availableConnectors = props.availableConnectors,
30
- _props$ens = props.ens,
31
- ens = _props$ens === void 0 ? true : _props$ens,
32
- balance = props.balance,
33
- locale = props.locale,
34
- eip6963 = props.eip6963;
35
- var _useAccount = useAccount(),
36
- address = _useAccount.address,
37
- isDisconnected = _useAccount.isDisconnected,
38
- chain = _useAccount.chain;
39
- var config = useConfig();
40
- var _useConnect = useConnect(),
41
- connectAsync = _useConnect.connectAsync;
42
- var _useSwitchChain = useSwitchChain(),
43
- switchChain = _useSwitchChain.switchChain;
44
- var _useBalance = useBalance({
45
- address: address
46
- }),
47
- balanceData = _useBalance.data;
48
- var _useEnsName = useEnsName({
49
- address: address
50
- }),
51
- ensName = _useEnsName.data;
52
- var _useEnsAvatar = useEnsAvatar({
53
- name: ensName !== null && ensName !== void 0 ? ensName : undefined
54
- }),
55
- ensAvatar = _useEnsAvatar.data;
56
- var account = address && !isDisconnected ? {
57
- address: address,
9
+ export const AntDesignWeb3ConfigProvider = props => {
10
+ const {
11
+ children,
12
+ chainAssets,
13
+ walletFactorys,
14
+ ens = true,
15
+ balance,
16
+ locale,
17
+ eip6963,
18
+ wagimConfig
19
+ } = props;
20
+ const {
21
+ address,
22
+ isDisconnected,
23
+ chain
24
+ } = useAccount();
25
+ const config = useConfig();
26
+ const {
27
+ connectAsync
28
+ } = useConnect();
29
+ const {
30
+ switchChain
31
+ } = useSwitchChain();
32
+ const {
33
+ data: balanceData
34
+ } = useBalance({
35
+ address
36
+ });
37
+ const {
38
+ data: ensName
39
+ } = useEnsName({
40
+ address
41
+ });
42
+ const {
43
+ data: ensAvatar
44
+ } = useEnsAvatar({
45
+ name: ensName ?? undefined
46
+ });
47
+ const account = address && !isDisconnected ? {
48
+ address,
58
49
  name: ensName && ens ? ensName : undefined,
59
- avatar: ensAvatar !== null && ensAvatar !== void 0 ? ensAvatar : undefined
50
+ avatar: ensAvatar ?? undefined
60
51
  } : undefined;
61
- var findConnectorByName = function findConnectorByName(name) {
62
- var commonConnector = availableConnectors.find(function (item) {
63
- return item.name === name && !isEIP6963Connector(item);
64
- });
52
+ const findConnectorByName = name => {
53
+ const commonConnector = wagimConfig.connectors.find(item => item.name === name && !isEIP6963Connector(item));
65
54
  if (!eip6963) {
66
55
  return commonConnector;
67
56
  }
68
- var eip6963Connector = availableConnectors.find(function (item) {
69
- return item.name === name && isEIP6963Connector(item);
70
- });
57
+ const eip6963Connector = wagimConfig.connectors.find(item => item.name === name && isEIP6963Connector(item));
71
58
  return eip6963Connector || commonConnector;
72
59
  };
73
- var wallets = React.useMemo(function () {
74
- var autoAddEIP6963Wallets = [];
75
- availableConnectors.forEach(function (connector) {
60
+ const wallets = React.useMemo(() => {
61
+ const autoAddEIP6963Wallets = [];
62
+ wagimConfig.connectors.forEach(connector => {
76
63
  if (isEIP6963Connector(connector)) {
77
64
  // check is need auto add eip6963 wallet
78
- if (_typeof(eip6963) === 'object' && eip6963 !== null && eip6963 !== void 0 && eip6963.autoAddInjectedWallets && !walletFactorys.find(function (item) {
79
- return item.connectors.includes(connector.name);
80
- })) {
65
+ if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactorys.find(item => item.connectors.includes(connector.name))) {
81
66
  // not config wallet and find the wallet in connectors, auto add it
82
67
  autoAddEIP6963Wallets.push(EIP6963Wallet().create([connector]));
83
68
  }
84
69
  // Do not need check eip6963 wallet
85
70
  return;
86
71
  }
87
- var walletFactory = walletFactorys.find(function (factory) {
88
- return factory.connectors.includes(connector.name);
89
- });
90
- if (!(walletFactory !== null && walletFactory !== void 0 && walletFactory.create)) {
72
+ const walletFactory = walletFactorys.find(factory => factory.connectors.includes(connector.name));
73
+ if (!walletFactory?.create) {
91
74
  // check user wallets config and console.error for alert
92
- console.error("Can not find wallet factory for ".concat(connector.name, ", you should config it in WagmiWeb3ConfigProvider 'wallets'."));
75
+ console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'wallets'.`);
93
76
  }
94
77
  });
95
78
 
96
79
  // Generate Wallet for @ant-design/web3
97
- var supportWallets = walletFactorys.map(function (factory) {
98
- var connectors = factory.connectors.map(findConnectorByName).filter(function (item) {
99
- return !!item;
100
- });
80
+ const supportWallets = walletFactorys.map(factory => {
81
+ const connectors = factory.connectors.map(findConnectorByName).filter(item => !!item);
101
82
  if (connectors.length === 0 && !eip6963) {
102
83
  // Not config connector for this wallet factory and not use eip6963, ignore it.
103
- console.error("Can not find connector for ".concat(factory.connectors.join(','), ", ignore the wallet. Please config connectors or add eip6963 config in WagmiWeb3ConfigProvider."));
84
+ console.error(`Can not find connector for ${factory.connectors.join(',')}, ignore the wallet. Please config connectors or add eip6963 config in WagmiWeb3ConfigProvider.`);
104
85
  return null;
105
86
  }
106
87
  return factory.create(connectors);
107
- }).filter(function (item) {
108
- return item !== null;
109
- });
110
- return [].concat(_toConsumableArray(supportWallets), autoAddEIP6963Wallets);
111
- }, [availableConnectors, walletFactorys, eip6963]);
112
- var chainList = React.useMemo(function () {
113
- return availableChains.map(function (item) {
114
- var c = chainAssets === null || chainAssets === void 0 ? void 0 : chainAssets.find(function (asset) {
88
+ }).filter(item => item !== null);
89
+ return [...supportWallets, ...autoAddEIP6963Wallets];
90
+ }, [wagimConfig.connectors, walletFactorys, eip6963]);
91
+ const chainList = React.useMemo(() => {
92
+ return wagimConfig.chains.map(item => {
93
+ const c = chainAssets?.find(asset => {
115
94
  return asset.id === item.id;
116
95
  });
117
- if (c !== null && c !== void 0 && c.id) {
96
+ if (c?.id) {
118
97
  return {
119
98
  id: c.id,
120
99
  name: c.name,
121
100
  icon: c.icon
122
101
  };
123
102
  }
124
- console.error("Can not find chain ".concat(item.id, ", you should config it in WagmiWeb3ConfigProvider 'chains'."));
103
+ console.error(`Can not find chain ${item.id}, you should config it in WagmiWeb3ConfigProvider 'chains'.`);
125
104
  return null;
126
- }).filter(function (item) {
127
- return item !== null;
128
- });
129
- }, [availableChains, chainAssets]);
130
- 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);
131
- 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);
132
- var _React$useState = React.useState(undefined),
133
- _React$useState2 = _slicedToArray(_React$useState, 2),
134
- currentChain = _React$useState2[0],
135
- setCurrentChain = _React$useState2[1];
136
- React.useEffect(function () {
137
- setCurrentChain(function (prevChain) {
105
+ }).filter(item => item !== null);
106
+ }, [wagimConfig.chains, chainAssets]);
107
+ const chainId = chain?.id || wagimConfig.chains?.[0]?.id;
108
+ const chainName = chain?.name || wagimConfig.chains?.[0]?.name;
109
+ const [currentChain, setCurrentChain] = React.useState(undefined);
110
+ React.useEffect(() => {
111
+ setCurrentChain(prevChain => {
138
112
  // not connected any chain, keep current chain
139
- var newChain = chainAssets === null || chainAssets === void 0 ? void 0 : chainAssets.find(function (item) {
140
- return (item === null || item === void 0 ? void 0 : item.id) === chainId;
141
- });
113
+ let newChain = chainAssets?.find(item => item?.id === chainId);
142
114
  if (!newChain && chainId) {
143
115
  newChain = {
144
116
  id: chainId,
@@ -147,122 +119,64 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
147
119
  }
148
120
  return newChain || prevChain;
149
121
  });
150
- }, [chainAssets, availableChains, chainId, chainName]);
151
- var currency = currentChain === null || currentChain === void 0 ? void 0 : currentChain.nativeCurrency;
152
- var getNFTMetadataFunc = React.useCallback( /*#__PURE__*/function () {
153
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
154
- var contractAddress, tokenId;
155
- return _regeneratorRuntime().wrap(function _callee$(_context) {
156
- while (1) switch (_context.prev = _context.next) {
157
- case 0:
158
- contractAddress = _ref.address, tokenId = _ref.tokenId;
159
- return _context.abrupt("return", getNFTMetadata(config, contractAddress, tokenId, chain === null || chain === void 0 ? void 0 : chain.id));
160
- case 2:
161
- case "end":
162
- return _context.stop();
163
- }
164
- }, _callee);
165
- }));
166
- return function (_x) {
167
- return _ref2.apply(this, arguments);
168
- };
169
- }(), [chain === null || chain === void 0 ? void 0 : chain.id]);
122
+ }, [chainAssets, wagimConfig.chains, chainId, chainName]);
123
+ const currency = currentChain?.nativeCurrency;
124
+ const getNFTMetadataFunc = React.useCallback(async ({
125
+ address: contractAddress,
126
+ tokenId
127
+ }) => getNFTMetadata(config, contractAddress, tokenId, chain?.id), [chain?.id]);
170
128
  return /*#__PURE__*/_jsx(Web3ConfigProvider, {
171
129
  locale: locale,
172
130
  availableChains: chainList,
173
131
  chain: currentChain,
174
132
  account: account,
175
133
  balance: balance ? {
176
- symbol: balanceData === null || balanceData === void 0 ? void 0 : balanceData.symbol,
177
- value: balanceData === null || balanceData === void 0 ? void 0 : balanceData.value,
178
- decimals: balanceData === null || balanceData === void 0 ? void 0 : balanceData.decimals,
179
- icon: currency === null || currency === void 0 ? void 0 : currency.icon
134
+ symbol: balanceData?.symbol,
135
+ value: balanceData?.value,
136
+ decimals: balanceData?.decimals,
137
+ icon: currency?.icon
180
138
  } : undefined,
181
139
  availableWallets: wallets,
182
140
  addressPrefix: "0x",
183
- connect: ( /*#__PURE__*/function () {
184
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(wallet, options) {
185
- var _getWagmiConnector, _ref4;
186
- var connector, _yield$connectAsync, accounts;
187
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
188
- while (1) switch (_context2.prev = _context2.next) {
189
- case 0:
190
- _context2.next = 2;
191
- return wallet === null || wallet === void 0 || (_getWagmiConnector = (_ref4 = wallet).getWagmiConnector) === null || _getWagmiConnector === void 0 ? void 0 : _getWagmiConnector.call(_ref4, options);
192
- case 2:
193
- connector = _context2.sent;
194
- if (!connector && wallet) {
195
- connector = findConnectorByName(wallet.name);
196
- }
197
- if (connector) {
198
- _context2.next = 6;
199
- break;
200
- }
201
- throw new Error("Can not find connector for ".concat(wallet === null || wallet === void 0 ? void 0 : wallet.name));
202
- case 6:
203
- _context2.next = 8;
204
- return connectAsync({
205
- connector: connector,
206
- chainId: currentChain === null || currentChain === void 0 ? void 0 : currentChain.id
207
- });
208
- case 8:
209
- _yield$connectAsync = _context2.sent;
210
- accounts = _yield$connectAsync.accounts;
211
- return _context2.abrupt("return", {
212
- address: accounts === null || accounts === void 0 ? void 0 : accounts[0]
213
- });
214
- case 11:
215
- case "end":
216
- return _context2.stop();
217
- }
218
- }, _callee2);
219
- }));
220
- return function (_x2, _x3) {
221
- return _ref3.apply(this, arguments);
222
- };
223
- }()),
224
- disconnect: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
225
- var _getAccount, connector;
226
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
227
- while (1) switch (_context3.prev = _context3.next) {
228
- case 0:
229
- // await disconnectAsync();
230
- // TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
231
- // 存在一些状态处理的 bug,暂时用更低阶 API 代替。
232
- _getAccount = getAccount(config), connector = _getAccount.connector;
233
- _context3.next = 3;
234
- return disconnect(config, {
235
- connector: connector
236
- });
237
- case 3:
238
- case "end":
239
- return _context3.stop();
240
- }
241
- }, _callee3);
242
- })),
243
- switchChain: ( /*#__PURE__*/function () {
244
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(newChain) {
245
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
246
- while (1) switch (_context4.prev = _context4.next) {
247
- case 0:
248
- if (!chain) {
249
- // hava not connected any chain
250
- setCurrentChain(newChain);
251
- } else {
252
- switchChain === null || switchChain === void 0 || switchChain({
253
- chainId: newChain.id
254
- });
255
- }
256
- case 1:
257
- case "end":
258
- return _context4.stop();
259
- }
260
- }, _callee4);
261
- }));
262
- return function (_x4) {
263
- return _ref6.apply(this, arguments);
141
+ connect: async (wallet, options) => {
142
+ let connector = await wallet?.getWagmiConnector?.(options);
143
+ if (!connector && wallet) {
144
+ connector = findConnectorByName(wallet.name);
145
+ }
146
+ if (!connector) {
147
+ throw new Error(`Can not find connector for ${wallet?.name}`);
148
+ }
149
+ const {
150
+ accounts
151
+ } = await connectAsync({
152
+ connector,
153
+ chainId: currentChain?.id
154
+ });
155
+ return {
156
+ address: accounts?.[0]
264
157
  };
265
- }()),
158
+ },
159
+ disconnect: async () => {
160
+ // await disconnectAsync();
161
+ // TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
162
+ // 存在一些状态处理的 bug,暂时用更低阶 API 代替。
163
+ const {
164
+ connector
165
+ } = getAccount(config);
166
+ await disconnect(config, {
167
+ connector
168
+ });
169
+ },
170
+ switchChain: async newChain => {
171
+ if (!chain) {
172
+ // hava not connected any chain
173
+ setCurrentChain(newChain);
174
+ } else {
175
+ switchChain?.({
176
+ chainId: newChain.id
177
+ });
178
+ }
179
+ },
266
180
  getNFTMetadata: getNFTMetadataFunc,
267
181
  children: children
268
182
  });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { Chain, Locale } from '@ant-design/web3-common';
3
3
  import { QueryClient } from '@tanstack/react-query';
4
- import type { Config } from 'wagmi';
4
+ import type { Config, State } from 'wagmi';
5
5
  import type { EIP6963Config, WalletFactory } from '../interface';
6
6
  export type WagmiWeb3ConfigProviderProps = {
7
7
  config: Config;
@@ -12,5 +12,7 @@ export type WagmiWeb3ConfigProviderProps = {
12
12
  queryClient?: QueryClient;
13
13
  balance?: boolean;
14
14
  eip6963?: EIP6963Config;
15
+ initialState?: State;
16
+ reconnectOnMount?: boolean;
15
17
  };
16
- export declare function WagmiWeb3ConfigProvider({ children, wallets, chains, ens, locale, balance, config, queryClient, eip6963, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
18
+ export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
@@ -1,18 +1,3 @@
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", "wallets", "chains", "ens", "locale", "balance", "config", "queryClient", "eip6963"];
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
- 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
- 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; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
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); }
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
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; }
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; }
16
1
  import React from 'react';
17
2
  // Built in popular chains
18
3
  import { Mainnet } from '@ant-design/web3-assets';
@@ -20,39 +5,37 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
20
5
  import { WagmiProvider } from 'wagmi';
21
6
  import { AntDesignWeb3ConfigProvider } from "./config-provider";
22
7
  import { jsx as _jsx } from "react/jsx-runtime";
23
- export function WagmiWeb3ConfigProvider(_ref) {
24
- var children = _ref.children,
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
- ens = _ref.ens,
30
- locale = _ref.locale,
31
- balance = _ref.balance,
32
- config = _ref.config,
33
- queryClient = _ref.queryClient,
34
- eip6963 = _ref.eip6963,
35
- restProps = _objectWithoutProperties(_ref, _excluded);
36
- var chainAssets = [].concat(_toConsumableArray(chains), [Mainnet]);
37
- var mergedQueryClient = React.useMemo(function () {
38
- return queryClient !== null && queryClient !== void 0 ? queryClient : new QueryClient();
8
+ export function WagmiWeb3ConfigProvider({
9
+ children,
10
+ config,
11
+ locale,
12
+ wallets = [],
13
+ chains = [],
14
+ ens,
15
+ queryClient,
16
+ balance,
17
+ eip6963,
18
+ ...restProps
19
+ }) {
20
+ const chainAssets = [...chains, Mainnet];
21
+ const mergedQueryClient = React.useMemo(() => {
22
+ return queryClient ?? new QueryClient();
39
23
  }, [queryClient]);
40
- return /*#__PURE__*/_jsx(WagmiProvider, _objectSpread(_objectSpread({
41
- config: config
42
- }, restProps), {}, {
24
+ return /*#__PURE__*/_jsx(WagmiProvider, {
25
+ config: config,
26
+ ...restProps,
43
27
  children: /*#__PURE__*/_jsx(QueryClientProvider, {
44
28
  client: mergedQueryClient,
45
29
  children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
46
30
  locale: locale,
47
31
  chainAssets: chainAssets,
48
32
  walletFactorys: wallets,
49
- availableChains: config.chains,
50
- availableConnectors: config.connectors,
51
33
  ens: ens,
52
34
  balance: balance,
53
35
  eip6963: eip6963,
36
+ wagimConfig: config,
54
37
  children: children
55
38
  })
56
39
  })
57
- }));
40
+ });
58
41
  }