@ant-design/web3-wagmi 2.7.0 → 2.7.2
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 +18 -0
- package/dist/esm/utils.d.ts +1 -3
- package/dist/esm/utils.js +2 -6
- package/dist/esm/wagmi-provider/config-provider.js +116 -201
- package/dist/esm/wagmi-provider/index.js +19 -35
- package/dist/esm/wagmi-provider/methods/getNFTMetadata.js +22 -47
- package/dist/esm/wallets/coinbase-wallet.js +9 -30
- package/dist/esm/wallets/eip6963.js +18 -59
- package/dist/esm/wallets/im-token.js +5 -8
- package/dist/esm/wallets/meta-mask.js +5 -8
- package/dist/esm/wallets/mobile-wallet.js +5 -8
- package/dist/esm/wallets/okx-wallet.js +5 -8
- package/dist/esm/wallets/safeheron.js +13 -55
- package/dist/esm/wallets/token-pocket.js +5 -8
- package/dist/esm/wallets/universal-wallet.js +59 -164
- package/dist/esm/wallets/wallet-connect.js +34 -90
- package/dist/lib/utils.d.ts +1 -3
- package/dist/lib/utils.js +1 -7
- package/dist/lib/wallets/safeheron.js +2 -0
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ant-design/web3-wagmi
|
|
2
2
|
|
|
3
|
+
## 2.7.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3f7d7a6: build: set targets chrome 100
|
|
8
|
+
- Updated dependencies [3f7d7a6]
|
|
9
|
+
- @ant-design/web3-assets@1.10.1
|
|
10
|
+
- @ant-design/web3-common@1.12.1
|
|
11
|
+
|
|
12
|
+
## 2.7.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 3727e20: chore: code style format
|
|
17
|
+
- Updated dependencies [8f3430b]
|
|
18
|
+
- Updated dependencies [d663c3b]
|
|
19
|
+
- @ant-design/web3-assets@1.10.0
|
|
20
|
+
|
|
3
21
|
## 2.7.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import debug from 'debug';
|
|
2
1
|
import type { Connector as WagmiConnector } from 'wagmi';
|
|
3
|
-
declare const createDebug: (namespace: string) => debug.Debugger;
|
|
4
2
|
declare const isEIP6963Connector: (connector: WagmiConnector) => boolean;
|
|
5
|
-
export {
|
|
3
|
+
export { isEIP6963Connector };
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import debug from 'debug';
|
|
2
1
|
import { injected } from 'wagmi/connectors';
|
|
3
|
-
|
|
4
|
-
return debug("antd-web3:wagmi:".concat(namespace));
|
|
5
|
-
};
|
|
6
|
-
var isEIP6963Connector = function isEIP6963Connector(connector) {
|
|
2
|
+
const isEIP6963Connector = connector => {
|
|
7
3
|
if (connector.type === injected.type && connector.icon && connector.id && connector.name) {
|
|
8
4
|
return true;
|
|
9
5
|
}
|
|
10
6
|
return false;
|
|
11
7
|
};
|
|
12
|
-
export {
|
|
8
|
+
export { isEIP6963Connector };
|
|
@@ -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,112 @@ 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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
chainAssets
|
|
27
|
-
walletFactorys
|
|
28
|
-
availableChains
|
|
29
|
-
availableConnectors
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
address
|
|
37
|
-
isDisconnected
|
|
38
|
-
chain
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
9
|
+
export const AntDesignWeb3ConfigProvider = props => {
|
|
10
|
+
const {
|
|
11
|
+
children,
|
|
12
|
+
chainAssets,
|
|
13
|
+
walletFactorys,
|
|
14
|
+
availableChains,
|
|
15
|
+
availableConnectors,
|
|
16
|
+
ens = true,
|
|
17
|
+
balance,
|
|
18
|
+
locale,
|
|
19
|
+
eip6963
|
|
20
|
+
} = props;
|
|
21
|
+
const {
|
|
22
|
+
address,
|
|
23
|
+
isDisconnected,
|
|
24
|
+
chain
|
|
25
|
+
} = useAccount();
|
|
26
|
+
const config = useConfig();
|
|
27
|
+
const {
|
|
28
|
+
connectAsync
|
|
29
|
+
} = useConnect();
|
|
30
|
+
const {
|
|
31
|
+
switchChain
|
|
32
|
+
} = useSwitchChain();
|
|
33
|
+
const {
|
|
34
|
+
data: balanceData
|
|
35
|
+
} = useBalance({
|
|
36
|
+
address
|
|
37
|
+
});
|
|
38
|
+
const {
|
|
39
|
+
data: ensName
|
|
40
|
+
} = useEnsName({
|
|
41
|
+
address
|
|
42
|
+
});
|
|
43
|
+
const {
|
|
44
|
+
data: ensAvatar
|
|
45
|
+
} = useEnsAvatar({
|
|
46
|
+
name: ensName ?? undefined
|
|
47
|
+
});
|
|
48
|
+
const account = address && !isDisconnected ? {
|
|
49
|
+
address,
|
|
58
50
|
name: ensName && ens ? ensName : undefined,
|
|
59
|
-
avatar: ensAvatar
|
|
51
|
+
avatar: ensAvatar ?? undefined
|
|
60
52
|
} : undefined;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return item.name === name && !isEIP6963Connector(item);
|
|
64
|
-
});
|
|
53
|
+
const findConnectorByName = name => {
|
|
54
|
+
const commonConnector = availableConnectors.find(item => item.name === name && !isEIP6963Connector(item));
|
|
65
55
|
if (!eip6963) {
|
|
66
56
|
return commonConnector;
|
|
67
57
|
}
|
|
68
|
-
|
|
69
|
-
return item.name === name && isEIP6963Connector(item);
|
|
70
|
-
});
|
|
58
|
+
const eip6963Connector = availableConnectors.find(item => item.name === name && isEIP6963Connector(item));
|
|
71
59
|
return eip6963Connector || commonConnector;
|
|
72
60
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
availableConnectors.forEach(
|
|
61
|
+
const wallets = React.useMemo(() => {
|
|
62
|
+
const autoAddEIP6963Wallets = [];
|
|
63
|
+
availableConnectors.forEach(connector => {
|
|
76
64
|
if (isEIP6963Connector(connector)) {
|
|
77
65
|
// check is need auto add eip6963 wallet
|
|
78
|
-
if (
|
|
79
|
-
return item.connectors.includes(connector.name);
|
|
80
|
-
})) {
|
|
66
|
+
if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactorys.find(item => item.connectors.includes(connector.name))) {
|
|
81
67
|
// not config wallet and find the wallet in connectors, auto add it
|
|
82
68
|
autoAddEIP6963Wallets.push(EIP6963Wallet().create([connector]));
|
|
83
69
|
}
|
|
84
70
|
// Do not need check eip6963 wallet
|
|
85
71
|
return;
|
|
86
72
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
if (!(walletFactory !== null && walletFactory !== void 0 && walletFactory.create)) {
|
|
73
|
+
const walletFactory = walletFactorys.find(factory => factory.connectors.includes(connector.name));
|
|
74
|
+
if (!walletFactory?.create) {
|
|
91
75
|
// check user wallets config and console.error for alert
|
|
92
|
-
console.error(
|
|
76
|
+
console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'wallets'.`);
|
|
93
77
|
}
|
|
94
78
|
});
|
|
95
79
|
|
|
96
80
|
// Generate Wallet for @ant-design/web3
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return !!item;
|
|
100
|
-
});
|
|
81
|
+
const supportWallets = walletFactorys.map(factory => {
|
|
82
|
+
const connectors = factory.connectors.map(findConnectorByName).filter(item => !!item);
|
|
101
83
|
if (connectors.length === 0 && !eip6963) {
|
|
102
84
|
// Not config connector for this wallet factory and not use eip6963, ignore it.
|
|
103
|
-
console.error(
|
|
85
|
+
console.error(`Can not find connector for ${factory.connectors.join(',')}, ignore the wallet. Please config connectors or add eip6963 config in WagmiWeb3ConfigProvider.`);
|
|
104
86
|
return null;
|
|
105
87
|
}
|
|
106
88
|
return factory.create(connectors);
|
|
107
|
-
}).filter(
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
return [].concat(_toConsumableArray(supportWallets), autoAddEIP6963Wallets);
|
|
89
|
+
}).filter(item => item !== null);
|
|
90
|
+
return [...supportWallets, ...autoAddEIP6963Wallets];
|
|
111
91
|
}, [availableConnectors, walletFactorys, eip6963]);
|
|
112
|
-
|
|
113
|
-
return availableChains.map(
|
|
114
|
-
|
|
92
|
+
const chainList = React.useMemo(() => {
|
|
93
|
+
return availableChains.map(item => {
|
|
94
|
+
const c = chainAssets?.find(asset => {
|
|
115
95
|
return asset.id === item.id;
|
|
116
96
|
});
|
|
117
|
-
if (c
|
|
97
|
+
if (c?.id) {
|
|
118
98
|
return {
|
|
119
99
|
id: c.id,
|
|
120
100
|
name: c.name,
|
|
121
101
|
icon: c.icon
|
|
122
102
|
};
|
|
123
103
|
}
|
|
124
|
-
console.error(
|
|
104
|
+
console.error(`Can not find chain ${item.id}, you should config it in WagmiWeb3ConfigProvider 'chains'.`);
|
|
125
105
|
return null;
|
|
126
|
-
}).filter(
|
|
127
|
-
return item !== null;
|
|
128
|
-
});
|
|
106
|
+
}).filter(item => item !== null);
|
|
129
107
|
}, [availableChains, chainAssets]);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
setCurrentChain = _React$useState2[1];
|
|
136
|
-
React.useEffect(function () {
|
|
137
|
-
setCurrentChain(function (prevChain) {
|
|
108
|
+
const chainId = chain?.id || availableChains?.[0]?.id;
|
|
109
|
+
const chainName = chain?.name || availableChains?.[0]?.name;
|
|
110
|
+
const [currentChain, setCurrentChain] = React.useState(undefined);
|
|
111
|
+
React.useEffect(() => {
|
|
112
|
+
setCurrentChain(prevChain => {
|
|
138
113
|
// not connected any chain, keep current chain
|
|
139
|
-
|
|
140
|
-
return (item === null || item === void 0 ? void 0 : item.id) === chainId;
|
|
141
|
-
});
|
|
114
|
+
let newChain = chainAssets?.find(item => item?.id === chainId);
|
|
142
115
|
if (!newChain && chainId) {
|
|
143
116
|
newChain = {
|
|
144
117
|
id: chainId,
|
|
@@ -148,121 +121,63 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
|
|
|
148
121
|
return newChain || prevChain;
|
|
149
122
|
});
|
|
150
123
|
}, [chainAssets, availableChains, chainId, chainName]);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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]);
|
|
124
|
+
const currency = currentChain?.nativeCurrency;
|
|
125
|
+
const getNFTMetadataFunc = React.useCallback(async ({
|
|
126
|
+
address: contractAddress,
|
|
127
|
+
tokenId
|
|
128
|
+
}) => getNFTMetadata(config, contractAddress, tokenId, chain?.id), [chain?.id]);
|
|
170
129
|
return /*#__PURE__*/_jsx(Web3ConfigProvider, {
|
|
171
130
|
locale: locale,
|
|
172
131
|
availableChains: chainList,
|
|
173
132
|
chain: currentChain,
|
|
174
133
|
account: account,
|
|
175
134
|
balance: balance ? {
|
|
176
|
-
symbol: balanceData
|
|
177
|
-
value: balanceData
|
|
178
|
-
decimals: balanceData
|
|
179
|
-
icon: currency
|
|
135
|
+
symbol: balanceData?.symbol,
|
|
136
|
+
value: balanceData?.value,
|
|
137
|
+
decimals: balanceData?.decimals,
|
|
138
|
+
icon: currency?.icon
|
|
180
139
|
} : undefined,
|
|
181
140
|
availableWallets: wallets,
|
|
182
141
|
addressPrefix: "0x",
|
|
183
|
-
connect: (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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);
|
|
142
|
+
connect: async (wallet, options) => {
|
|
143
|
+
let connector = await wallet?.getWagmiConnector?.(options);
|
|
144
|
+
if (!connector && wallet) {
|
|
145
|
+
connector = findConnectorByName(wallet.name);
|
|
146
|
+
}
|
|
147
|
+
if (!connector) {
|
|
148
|
+
throw new Error(`Can not find connector for ${wallet?.name}`);
|
|
149
|
+
}
|
|
150
|
+
const {
|
|
151
|
+
accounts
|
|
152
|
+
} = await connectAsync({
|
|
153
|
+
connector,
|
|
154
|
+
chainId: currentChain?.id
|
|
155
|
+
});
|
|
156
|
+
return {
|
|
157
|
+
address: accounts?.[0]
|
|
264
158
|
};
|
|
265
|
-
}
|
|
159
|
+
},
|
|
160
|
+
disconnect: async () => {
|
|
161
|
+
// await disconnectAsync();
|
|
162
|
+
// TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
|
|
163
|
+
// 存在一些状态处理的 bug,暂时用更低阶 API 代替。
|
|
164
|
+
const {
|
|
165
|
+
connector
|
|
166
|
+
} = getAccount(config);
|
|
167
|
+
await disconnect(config, {
|
|
168
|
+
connector
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
switchChain: async newChain => {
|
|
172
|
+
if (!chain) {
|
|
173
|
+
// hava not connected any chain
|
|
174
|
+
setCurrentChain(newChain);
|
|
175
|
+
} else {
|
|
176
|
+
switchChain?.({
|
|
177
|
+
chainId: newChain.id
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
},
|
|
266
181
|
getNFTMetadata: getNFTMetadataFunc,
|
|
267
182
|
children: children
|
|
268
183
|
});
|
|
@@ -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,26 +5,25 @@ 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(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return queryClient !== null && queryClient !== void 0 ? queryClient : new QueryClient();
|
|
8
|
+
export function WagmiWeb3ConfigProvider({
|
|
9
|
+
children,
|
|
10
|
+
wallets = [],
|
|
11
|
+
chains = [],
|
|
12
|
+
ens,
|
|
13
|
+
locale,
|
|
14
|
+
balance,
|
|
15
|
+
config,
|
|
16
|
+
queryClient,
|
|
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,
|
|
41
|
-
config: config
|
|
42
|
-
|
|
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, {
|
|
@@ -54,5 +38,5 @@ export function WagmiWeb3ConfigProvider(_ref) {
|
|
|
54
38
|
children: children
|
|
55
39
|
})
|
|
56
40
|
})
|
|
57
|
-
})
|
|
41
|
+
});
|
|
58
42
|
}
|
|
@@ -1,50 +1,25 @@
|
|
|
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
|
-
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
|
-
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
|
-
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
1
|
import { fillAddressWith0x, requestWeb3Asset } from '@ant-design/web3-common';
|
|
6
2
|
import { readContract } from 'wagmi/actions';
|
|
7
|
-
export function getNFTMetadata(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: 'string'
|
|
30
|
-
}],
|
|
31
|
-
stateMutability: 'view',
|
|
32
|
-
type: 'function'
|
|
33
|
-
}],
|
|
34
|
-
functionName: 'tokenURI'
|
|
35
|
-
});
|
|
36
|
-
case 2:
|
|
37
|
-
tokenURI = _context.sent;
|
|
38
|
-
_context.next = 5;
|
|
39
|
-
return requestWeb3Asset(tokenURI);
|
|
40
|
-
case 5:
|
|
41
|
-
metaInfo = _context.sent;
|
|
42
|
-
return _context.abrupt("return", metaInfo);
|
|
43
|
-
case 7:
|
|
44
|
-
case "end":
|
|
45
|
-
return _context.stop();
|
|
46
|
-
}
|
|
47
|
-
}, _callee);
|
|
48
|
-
}));
|
|
49
|
-
return _getNFTMetadata.apply(this, arguments);
|
|
3
|
+
export async function getNFTMetadata(config, address, tokenId, chainId) {
|
|
4
|
+
const tokenURI = await readContract(config, {
|
|
5
|
+
address: fillAddressWith0x(address),
|
|
6
|
+
args: [tokenId],
|
|
7
|
+
chainId,
|
|
8
|
+
abi: [{
|
|
9
|
+
name: 'tokenURI',
|
|
10
|
+
inputs: [{
|
|
11
|
+
name: 'tokenId',
|
|
12
|
+
type: 'uint256'
|
|
13
|
+
}],
|
|
14
|
+
outputs: [{
|
|
15
|
+
name: '',
|
|
16
|
+
type: 'string'
|
|
17
|
+
}],
|
|
18
|
+
stateMutability: 'view',
|
|
19
|
+
type: 'function'
|
|
20
|
+
}],
|
|
21
|
+
functionName: 'tokenURI'
|
|
22
|
+
});
|
|
23
|
+
const metaInfo = await requestWeb3Asset(tokenURI);
|
|
24
|
+
return metaInfo;
|
|
50
25
|
}
|