@ant-design/web3-wagmi 1.1.1 → 1.2.0

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,12 +1,36 @@
1
1
  # @ant-design/web3-wagmi
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e5db9b7: feat: Add UniversalWallet for support TokenPocket and more wallets
8
+
9
+ ### Patch Changes
10
+
11
+ - 17ca201: perf: Modify import type
12
+ - Updated dependencies [e5db9b7]
13
+ - Updated dependencies [18def13]
14
+ - Updated dependencies [17ca201]
15
+ - @ant-design/web3-common@1.2.0
16
+ - @ant-design/web3-assets@1.1.3
17
+
18
+ ## 1.1.2
19
+
20
+ ### Patch Changes
21
+
22
+ - d6a5339: chore: release 1.1.2 for republish
23
+ - Updated dependencies [d6a5339]
24
+ - @ant-design/web3-assets@1.1.2
25
+ - @ant-design/web3-common@1.1.2
26
+
3
27
  ## 1.1.1
4
28
 
5
29
  ### Patch Changes
6
30
 
7
- - 754a9e7: chore: republish a new version 1.1.1
8
- - Updated dependencies [754a9e7]
9
- - @ant-design/web3-assets@2.0.1
31
+ - 32f276a: chore: 1.1.1
32
+ - Updated dependencies [32f276a]
33
+ - @ant-design/web3-assets@1.1.1
10
34
  - @ant-design/web3-common@1.1.1
11
35
 
12
36
  ## 1.1.0
@@ -27,7 +51,7 @@
27
51
  - Updated dependencies [3547f6b]
28
52
  - Updated dependencies [9de319c]
29
53
  - @ant-design/web3-common@1.1.0
30
- - @ant-design/web3-assets@2.0.0
54
+ - @ant-design/web3-assets@1.1.0
31
55
 
32
56
  ## 1.0.0
33
57
 
@@ -1,6 +1,9 @@
1
1
  import type { Wallet } from '@ant-design/web3-common';
2
2
  import type { Connector } from 'wagmi';
3
+ export interface WalletUseInWagmiAdapter extends Wallet {
4
+ getWagmiConnector?: () => Connector | undefined;
5
+ }
3
6
  export interface WalletFactory {
4
- name: Connector['name'];
5
- create: (connector?: Connector) => Wallet;
7
+ name: Connector['name'] | Connector['name'][];
8
+ create: (connector?: Connector | Connector[]) => WalletUseInWagmiAdapter;
6
9
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { type Chain, Locale } from '@ant-design/web3-common';
3
- import { type Connector as WagmiConnector, type Chain as WagmiChain } from 'wagmi';
2
+ import { type Chain, type Locale } from '@ant-design/web3-common';
3
+ import { type Chain as WagmiChain, type Connector as WagmiConnector } from 'wagmi';
4
4
  import type { WalletFactory } from '../interface';
5
5
  export interface AntDesignWeb3ConfigProviderProps {
6
6
  locale?: Locale;
@@ -9,8 +9,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import React from 'react';
12
- import { Web3ConfigProvider, fillAddressWith0x } from '@ant-design/web3-common';
13
- import { useAccount, useConnect, useDisconnect, useNetwork, useSwitchNetwork, useBalance } from 'wagmi';
12
+ import { fillAddressWith0x, Web3ConfigProvider } from '@ant-design/web3-common';
13
+ import { useAccount, useBalance, useConnect, useDisconnect, useNetwork, useSwitchNetwork } from 'wagmi';
14
14
  import { addNameToAccount, getNFTMetadata } from "./methods";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(props) {
@@ -88,18 +88,47 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
88
88
  updateAccounts();
89
89
  }, [address, isDisconnected, chain, ens]);
90
90
  var wallets = React.useMemo(function () {
91
- return availableConnectors.map(function (connector) {
92
- var walletFactory = assets === null || assets === void 0 ? void 0 : assets.find(function (item) {
93
- return item.name === connector.name;
91
+ var walletFactorys = assets === null || assets === void 0 ? void 0 : assets.filter(function (item) {
92
+ return item.create;
93
+ });
94
+ availableConnectors.forEach(function (connector) {
95
+ // check use assets config and console.error for alert
96
+ var walletFactory = walletFactorys === null || walletFactorys === void 0 ? void 0 : walletFactorys.find(function (item) {
97
+ var _item$name;
98
+ return item.name === connector.name || ((_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.includes(connector.name));
94
99
  });
95
100
  if (!(walletFactory !== null && walletFactory !== void 0 && walletFactory.create)) {
96
101
  console.error("Can not find wallet factory for ".concat(connector.name, ", you should config it in WagmiWeb3ConfigProvider 'assets'."));
102
+ }
103
+ });
104
+
105
+ // Generate Wallet for @ant-design/web3
106
+ var allWallet = walletFactorys === null || walletFactorys === void 0 ? void 0 : walletFactorys.map(function (factory) {
107
+ var connector;
108
+ if (typeof factory.name === 'string') {
109
+ // this wallet factory only for one connector
110
+ connector = availableConnectors.find(function (item) {
111
+ return item.name === factory.name;
112
+ });
113
+ } else {
114
+ // for multiple connectors
115
+ connector = factory.name.map(function (name) {
116
+ return availableConnectors.find(function (item) {
117
+ return item.name === name;
118
+ });
119
+ }).filter(function (item) {
120
+ return item !== undefined;
121
+ });
122
+ }
123
+ if (!connector || Array.isArray(connector) && connector.length === 0) {
124
+ // Not config connector for this wallet factory, ignore it.
97
125
  return null;
98
126
  }
99
- return walletFactory.create(connector);
127
+ return factory.create(connector);
100
128
  }).filter(function (item) {
101
129
  return item !== null;
102
130
  });
131
+ return allWallet;
103
132
  }, [availableConnectors, assets]);
104
133
  var chainList = React.useMemo(function () {
105
134
  return availableChains.map(function (item) {
@@ -156,19 +185,23 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
156
185
  availableWallets: wallets,
157
186
  connect: /*#__PURE__*/function () {
158
187
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(wallet) {
188
+ var _getWagmiConnector, _ref3;
159
189
  var connector;
160
190
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
161
191
  while (1) switch (_context2.prev = _context2.next) {
162
192
  case 0:
163
- connector = availableConnectors.find(function (item) {
164
- return item.name === (wallet === null || wallet === void 0 ? void 0 : wallet.name);
165
- });
166
- _context2.next = 3;
193
+ connector = wallet === null || wallet === void 0 || (_getWagmiConnector = (_ref3 = wallet).getWagmiConnector) === null || _getWagmiConnector === void 0 ? void 0 : _getWagmiConnector.call(_ref3);
194
+ if (!connector) {
195
+ connector = availableConnectors.find(function (item) {
196
+ return item.name === (wallet === null || wallet === void 0 ? void 0 : wallet.name);
197
+ });
198
+ }
199
+ _context2.next = 4;
167
200
  return connectAsync({
168
201
  connector: connector,
169
202
  chainId: currentChain === null || currentChain === void 0 ? void 0 : currentChain.id
170
203
  });
171
- case 3:
204
+ case 4:
172
205
  case "end":
173
206
  return _context2.stop();
174
207
  }
@@ -191,7 +224,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
191
224
  }, _callee3);
192
225
  })),
193
226
  switchChain: /*#__PURE__*/function () {
194
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(c) {
227
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(c) {
195
228
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
196
229
  while (1) switch (_context4.prev = _context4.next) {
197
230
  case 0:
@@ -208,16 +241,16 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
208
241
  }, _callee4);
209
242
  }));
210
243
  return function (_x2) {
211
- return _ref4.apply(this, arguments);
244
+ return _ref5.apply(this, arguments);
212
245
  };
213
246
  }(),
214
247
  getNFTMetadata: /*#__PURE__*/function () {
215
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
248
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
216
249
  var contractAddress, tokenId;
217
250
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
218
251
  while (1) switch (_context5.prev = _context5.next) {
219
252
  case 0:
220
- contractAddress = _ref5.address, tokenId = _ref5.tokenId;
253
+ contractAddress = _ref6.address, tokenId = _ref6.tokenId;
221
254
  return _context5.abrupt("return", getNFTMetadata(contractAddress, tokenId, chain === null || chain === void 0 ? void 0 : chain.id));
222
255
  case 2:
223
256
  case "end":
@@ -226,7 +259,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
226
259
  }, _callee5);
227
260
  }));
228
261
  return function (_x3) {
229
- return _ref6.apply(this, arguments);
262
+ return _ref7.apply(this, arguments);
230
263
  };
231
264
  }(),
232
265
  children: children
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import type { PublicClient, WebSocketPublicClient, Config } from 'wagmi';
3
2
  import type { Chain, Locale } from '@ant-design/web3-common';
3
+ import type { Config, PublicClient, WebSocketPublicClient } from 'wagmi';
4
4
  import type { WalletFactory } from '../interface';
5
5
  export type WagmiWeb3ConfigProviderProps<TPublicClient extends PublicClient = PublicClient, TWebSocketPublicClient extends WebSocketPublicClient = WebSocketPublicClient> = {
6
6
  config: Config<TPublicClient, TWebSocketPublicClient>;
@@ -15,12 +15,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
15
15
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
16
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
17
17
  import React from 'react';
18
- import { WagmiConfig } from 'wagmi';
19
- import { AntDesignWeb3ConfigProvider } from "./config-provider";
20
18
  // Built in popular chains
21
- import { Mainnet, Goerli } from '@ant-design/web3-assets';
19
+ import { Goerli, Mainnet } from '@ant-design/web3-assets';
20
+ import { WagmiConfig } from 'wagmi';
22
21
  // MetaMask built-in
23
22
  import { MetaMask } from "../wallets";
23
+ import { AntDesignWeb3ConfigProvider } from "./config-provider";
24
24
  import { jsx as _jsx } from "react/jsx-runtime";
25
25
  export function WagmiWeb3ConfigProvider(_ref) {
26
26
  var children = _ref.children,
@@ -60,12 +60,19 @@ export function WagmiWeb3ConfigProvider(_ref) {
60
60
  });
61
61
  return chains;
62
62
  }, [config]);
63
+ var assetsWithDefault = [].concat(_toConsumableArray(assets), [Mainnet, Goerli]);
64
+ if (!assets.find(function (item) {
65
+ return item.name === 'MetaMask' || Array.isArray(item.name) && item.name.includes('MetaMask');
66
+ })) {
67
+ // If user not set MetaMask, we will add it to the first
68
+ assetsWithDefault.unshift(MetaMask);
69
+ }
63
70
  return /*#__PURE__*/_jsx(WagmiConfig, _objectSpread(_objectSpread({
64
71
  config: config
65
72
  }, restProps), {}, {
66
73
  children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
67
74
  locale: locale,
68
- assets: [].concat(_toConsumableArray(assets), [MetaMask, Mainnet, Goerli]),
75
+ assets: assetsWithDefault,
69
76
  availableChains: availableChains,
70
77
  availableConnectors: config.connectors || [],
71
78
  ens: ens,
@@ -2,7 +2,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- import { requestWeb3Asset, fillAddressWith0x } from '@ant-design/web3-common';
5
+ import { fillAddressWith0x, requestWeb3Asset } from '@ant-design/web3-common';
6
6
  import { readContract } from '@wagmi/core';
7
7
  export function getNFTMetadata(_x, _x2, _x3) {
8
8
  return _getNFTMetadata.apply(this, arguments);
@@ -3,3 +3,4 @@ export * from './wallet-connect';
3
3
  export * from './coinbase-wallet';
4
4
  export * from './token-pocket';
5
5
  export * from './safeheron';
6
+ export * from './universal-wallet';
@@ -2,4 +2,5 @@ export * from "./meta-mask";
2
2
  export * from "./wallet-connect";
3
3
  export * from "./coinbase-wallet";
4
4
  export * from "./token-pocket";
5
- export * from "./safeheron";
5
+ export * from "./safeheron";
6
+ export * from "./universal-wallet";
@@ -29,6 +29,24 @@ export var MetaMask = {
29
29
  return _hasWalletReady.apply(this, arguments);
30
30
  }
31
31
  return hasWalletReady;
32
+ }(),
33
+ hasExtensionInstalled: function () {
34
+ var _hasExtensionInstalled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
35
+ var _window$ethereum2;
36
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
37
+ while (1) switch (_context2.prev = _context2.next) {
38
+ case 0:
39
+ return _context2.abrupt("return", !!((_window$ethereum2 = window.ethereum) !== null && _window$ethereum2 !== void 0 && _window$ethereum2.isMetaMask));
40
+ case 1:
41
+ case "end":
42
+ return _context2.stop();
43
+ }
44
+ }, _callee2);
45
+ }));
46
+ function hasExtensionInstalled() {
47
+ return _hasExtensionInstalled.apply(this, arguments);
48
+ }
49
+ return hasExtensionInstalled;
32
50
  }()
33
51
  });
34
52
  }
@@ -28,6 +28,23 @@ export var SafeheronWallet = {
28
28
  return _hasWalletReady.apply(this, arguments);
29
29
  }
30
30
  return hasWalletReady;
31
+ }(),
32
+ hasExtensionInstalled: function () {
33
+ var _hasExtensionInstalled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
34
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
35
+ while (1) switch (_context2.prev = _context2.next) {
36
+ case 0:
37
+ return _context2.abrupt("return", !!(connector !== null && connector !== void 0 && connector.ready));
38
+ case 1:
39
+ case "end":
40
+ return _context2.stop();
41
+ }
42
+ }, _callee2);
43
+ }));
44
+ function hasExtensionInstalled() {
45
+ return _hasExtensionInstalled.apply(this, arguments);
46
+ }
47
+ return hasExtensionInstalled;
31
48
  }()
32
49
  });
33
50
  }
@@ -1,2 +1,2 @@
1
- import type { WalletFactory } from '../interface';
2
- export declare const TokenPocket: WalletFactory;
1
+ import { UniversalWallet } from './universal-wallet';
2
+ export declare const TokenPocket: UniversalWallet;
@@ -1,34 +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
- 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
- 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; }
6
- 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; }
7
- 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; }
8
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
1
  import { metadata_TokenPocket } from '@ant-design/web3-assets';
11
- export var TokenPocket = {
12
- name: 'TokenPocket',
13
- create: function create() {
14
- return _objectSpread(_objectSpread({}, metadata_TokenPocket), {}, {
15
- hasWalletReady: function () {
16
- var _hasWalletReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17
- return _regeneratorRuntime().wrap(function _callee$(_context) {
18
- while (1) switch (_context.prev = _context.next) {
19
- case 0:
20
- return _context.abrupt("return", true);
21
- case 1:
22
- case "end":
23
- return _context.stop();
24
- }
25
- }, _callee);
26
- }));
27
- function hasWalletReady() {
28
- return _hasWalletReady.apply(this, arguments);
29
- }
30
- return hasWalletReady;
31
- }()
32
- });
33
- }
34
- };
2
+ import { UniversalWallet } from "./universal-wallet";
3
+ export var TokenPocket = new UniversalWallet(metadata_TokenPocket);
@@ -0,0 +1,9 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ import type { Connector } from 'wagmi';
3
+ import type { WalletFactory, WalletUseInWagmiAdapter } from '../interface';
4
+ export declare class UniversalWallet implements WalletFactory {
5
+ private wallet;
6
+ name: string[];
7
+ constructor(wallet: WalletMetadata);
8
+ create: (connector?: Connector | Connector[]) => WalletUseInWagmiAdapter;
9
+ }
@@ -0,0 +1,112 @@
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 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; }
3
+ 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; }
4
+ 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; }
5
+ 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); } }
6
+ 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); }); }; }
7
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
8
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ 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; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
13
+ export var UniversalWallet = /*#__PURE__*/_createClass(function UniversalWallet(wallet) {
14
+ var _this = this;
15
+ _classCallCheck(this, UniversalWallet);
16
+ _defineProperty(this, "name", []);
17
+ _defineProperty(this, "create", function (connector) {
18
+ var _walletConnector$opti;
19
+ var connectors = connector;
20
+ var walletConnector = connectors.find(function (item) {
21
+ return item.name === 'WalletConnect';
22
+ });
23
+ var injectedConnector = connectors.find(function (item) {
24
+ return item.name === _this.wallet.name;
25
+ });
26
+ var getQrCode = /*#__PURE__*/function () {
27
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
28
+ var provider;
29
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
30
+ while (1) switch (_context.prev = _context.next) {
31
+ case 0:
32
+ _context.next = 2;
33
+ return walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.getProvider();
34
+ case 2:
35
+ provider = _context.sent;
36
+ return _context.abrupt("return", new Promise(function (resolve) {
37
+ provider.on('display_uri', function (uri) {
38
+ resolve({
39
+ uri: uri
40
+ });
41
+ });
42
+ }));
43
+ case 4:
44
+ case "end":
45
+ return _context.stop();
46
+ }
47
+ }, _callee);
48
+ }));
49
+ return function getQrCode() {
50
+ return _ref.apply(this, arguments);
51
+ };
52
+ }();
53
+ var _hasExtensionInstalled = function hasExtensionInstalled() {
54
+ var _injectedConnector$op;
55
+ var provider = injectedConnector === null || injectedConnector === void 0 || (_injectedConnector$op = injectedConnector.options) === null || _injectedConnector$op === void 0 ? void 0 : _injectedConnector$op.getProvider();
56
+ return !!provider;
57
+ };
58
+ return _objectSpread(_objectSpread({}, _this.wallet), {}, {
59
+ getWagmiConnector: function getWagmiConnector() {
60
+ if (_hasExtensionInstalled()) {
61
+ return injectedConnector;
62
+ }
63
+ return walletConnector;
64
+ },
65
+ hasExtensionInstalled: function () {
66
+ var _hasExtensionInstalled2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
67
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
68
+ while (1) switch (_context2.prev = _context2.next) {
69
+ case 0:
70
+ return _context2.abrupt("return", _hasExtensionInstalled());
71
+ case 1:
72
+ case "end":
73
+ return _context2.stop();
74
+ }
75
+ }, _callee2);
76
+ }));
77
+ function hasExtensionInstalled() {
78
+ return _hasExtensionInstalled2.apply(this, arguments);
79
+ }
80
+ return hasExtensionInstalled;
81
+ }(),
82
+ hasWalletReady: function () {
83
+ var _hasWalletReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
84
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
85
+ while (1) switch (_context3.prev = _context3.next) {
86
+ case 0:
87
+ return _context3.abrupt("return", !!(_hasExtensionInstalled() || walletConnector));
88
+ case 1:
89
+ case "end":
90
+ return _context3.stop();
91
+ }
92
+ }, _callee3);
93
+ }));
94
+ function hasWalletReady() {
95
+ return _hasWalletReady.apply(this, arguments);
96
+ }
97
+ return hasWalletReady;
98
+ }(),
99
+ getQrCode: (walletConnector === null || walletConnector === void 0 || (_walletConnector$opti = walletConnector.options) === null || _walletConnector$opti === void 0 ? void 0 : _walletConnector$opti.showQrModal) === false ? getQrCode : undefined
100
+ });
101
+ });
102
+ this.wallet = wallet;
103
+ if (wallet.extensions) {
104
+ // support injected connector
105
+ // https://wagmi.sh/react/connectors/injected
106
+ this.name.push(wallet.name);
107
+ }
108
+ if (wallet.app) {
109
+ // support WalletConnect https://wagmi.sh/react/connectors/walletConnect
110
+ this.name.push('WalletConnect');
111
+ }
112
+ });
@@ -1,6 +1,9 @@
1
1
  import type { Wallet } from '@ant-design/web3-common';
2
2
  import type { Connector } from 'wagmi';
3
+ export interface WalletUseInWagmiAdapter extends Wallet {
4
+ getWagmiConnector?: () => Connector | undefined;
5
+ }
3
6
  export interface WalletFactory {
4
- name: Connector['name'];
5
- create: (connector?: Connector) => Wallet;
7
+ name: Connector['name'] | Connector['name'][];
8
+ create: (connector?: Connector | Connector[]) => WalletUseInWagmiAdapter;
6
9
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { type Chain, Locale } from '@ant-design/web3-common';
3
- import { type Connector as WagmiConnector, type Chain as WagmiChain } from 'wagmi';
2
+ import { type Chain, type Locale } from '@ant-design/web3-common';
3
+ import { type Chain as WagmiChain, type Connector as WagmiConnector } from 'wagmi';
4
4
  import type { WalletFactory } from '../interface';
5
5
  export interface AntDesignWeb3ConfigProviderProps {
6
6
  locale?: Locale;
@@ -57,14 +57,32 @@ const AntDesignWeb3ConfigProvider = props => {
57
57
  updateAccounts();
58
58
  }, [address, isDisconnected, chain, ens]);
59
59
  const wallets = _react.default.useMemo(() => {
60
- return availableConnectors.map(connector => {
61
- const walletFactory = assets?.find(item => item.name === connector.name);
60
+ const walletFactorys = assets?.filter(item => item.create);
61
+ availableConnectors.forEach(connector => {
62
+ // check use assets config and console.error for alert
63
+ const walletFactory = walletFactorys?.find(item => item.name === connector.name || item.name?.includes(connector.name));
62
64
  if (!walletFactory?.create) {
63
65
  console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'assets'.`);
66
+ }
67
+ });
68
+
69
+ // Generate Wallet for @ant-design/web3
70
+ const allWallet = walletFactorys?.map(factory => {
71
+ let connector;
72
+ if (typeof factory.name === 'string') {
73
+ // this wallet factory only for one connector
74
+ connector = availableConnectors.find(item => item.name === factory.name);
75
+ } else {
76
+ // for multiple connectors
77
+ connector = factory.name.map(name => availableConnectors.find(item => item.name === name)).filter(item => item !== undefined);
78
+ }
79
+ if (!connector || Array.isArray(connector) && connector.length === 0) {
80
+ // Not config connector for this wallet factory, ignore it.
64
81
  return null;
65
82
  }
66
- return walletFactory.create(connector);
83
+ return factory.create(connector);
67
84
  }).filter(item => item !== null);
85
+ return allWallet;
68
86
  }, [availableConnectors, assets]);
69
87
  const chainList = _react.default.useMemo(() => {
70
88
  return availableChains.map(item => {
@@ -115,7 +133,10 @@ const AntDesignWeb3ConfigProvider = props => {
115
133
  } : undefined,
116
134
  availableWallets: wallets,
117
135
  connect: async wallet => {
118
- const connector = availableConnectors.find(item => item.name === wallet?.name);
136
+ let connector = wallet?.getWagmiConnector?.();
137
+ if (!connector) {
138
+ connector = availableConnectors.find(item => item.name === wallet?.name);
139
+ }
119
140
  await connectAsync({
120
141
  connector,
121
142
  chainId: currentChain?.id
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import type { PublicClient, WebSocketPublicClient, Config } from 'wagmi';
3
2
  import type { Chain, Locale } from '@ant-design/web3-common';
3
+ import type { Config, PublicClient, WebSocketPublicClient } from 'wagmi';
4
4
  import type { WalletFactory } from '../interface';
5
5
  export type WagmiWeb3ConfigProviderProps<TPublicClient extends PublicClient = PublicClient, TWebSocketPublicClient extends WebSocketPublicClient = WebSocketPublicClient> = {
6
6
  config: Config<TPublicClient, TWebSocketPublicClient>;
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.WagmiWeb3ConfigProvider = WagmiWeb3ConfigProvider;
7
7
  var _react = _interopRequireDefault(require("react"));
8
- var _wagmi = require("wagmi");
9
- var _configProvider = require("./config-provider");
10
8
  var _web3Assets = require("@ant-design/web3-assets");
9
+ var _wagmi = require("wagmi");
11
10
  var _wallets = require("../wallets");
11
+ var _configProvider = require("./config-provider");
12
12
  var _jsxRuntime = require("react/jsx-runtime");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  // Built in popular chains
@@ -39,12 +39,19 @@ function WagmiWeb3ConfigProvider({
39
39
  });
40
40
  return chains;
41
41
  }, [config]);
42
+ const assetsWithDefault = [...assets, _web3Assets.Mainnet, _web3Assets.Goerli];
43
+ if (!assets.find(item => {
44
+ return item.name === 'MetaMask' || Array.isArray(item.name) && item.name.includes('MetaMask');
45
+ })) {
46
+ // If user not set MetaMask, we will add it to the first
47
+ assetsWithDefault.unshift(_wallets.MetaMask);
48
+ }
42
49
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_wagmi.WagmiConfig, {
43
50
  config: config,
44
51
  ...restProps,
45
52
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
46
53
  locale: locale,
47
- assets: [...assets, _wallets.MetaMask, _web3Assets.Mainnet, _web3Assets.Goerli],
54
+ assets: assetsWithDefault,
48
55
  availableChains: availableChains,
49
56
  availableConnectors: config.connectors || [],
50
57
  ens: ens,
@@ -3,3 +3,4 @@ export * from './wallet-connect';
3
3
  export * from './coinbase-wallet';
4
4
  export * from './token-pocket';
5
5
  export * from './safeheron';
6
+ export * from './universal-wallet';
@@ -57,4 +57,15 @@ Object.keys(_safeheron).forEach(function (key) {
57
57
  return _safeheron[key];
58
58
  }
59
59
  });
60
+ });
61
+ var _universalWallet = require("./universal-wallet");
62
+ Object.keys(_universalWallet).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (key in exports && exports[key] === _universalWallet[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _universalWallet[key];
69
+ }
70
+ });
60
71
  });
@@ -12,6 +12,9 @@ const MetaMask = exports.MetaMask = {
12
12
  ..._web3Assets.metadata_MetaMask,
13
13
  hasWalletReady: async () => {
14
14
  return !!window.ethereum?.isMetaMask;
15
+ },
16
+ hasExtensionInstalled: async () => {
17
+ return !!window.ethereum?.isMetaMask;
15
18
  }
16
19
  };
17
20
  }
@@ -12,6 +12,9 @@ const SafeheronWallet = exports.SafeheronWallet = {
12
12
  ..._web3Assets.metadata_Safeheron,
13
13
  hasWalletReady: async () => {
14
14
  return !!connector?.ready;
15
+ },
16
+ hasExtensionInstalled: async () => {
17
+ return !!connector?.ready;
15
18
  }
16
19
  };
17
20
  }
@@ -1,2 +1,2 @@
1
- import type { WalletFactory } from '../interface';
2
- export declare const TokenPocket: WalletFactory;
1
+ import { UniversalWallet } from './universal-wallet';
2
+ export declare const TokenPocket: UniversalWallet;
@@ -5,14 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.TokenPocket = void 0;
7
7
  var _web3Assets = require("@ant-design/web3-assets");
8
- const TokenPocket = exports.TokenPocket = {
9
- name: 'TokenPocket',
10
- create: () => {
11
- return {
12
- ..._web3Assets.metadata_TokenPocket,
13
- hasWalletReady: async () => {
14
- return true;
15
- }
16
- };
17
- }
18
- };
8
+ var _universalWallet = require("./universal-wallet");
9
+ const TokenPocket = exports.TokenPocket = new _universalWallet.UniversalWallet(_web3Assets.metadata_TokenPocket);
@@ -0,0 +1,9 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ import type { Connector } from 'wagmi';
3
+ import type { WalletFactory, WalletUseInWagmiAdapter } from '../interface';
4
+ export declare class UniversalWallet implements WalletFactory {
5
+ private wallet;
6
+ name: string[];
7
+ constructor(wallet: WalletMetadata);
8
+ create: (connector?: Connector | Connector[]) => WalletUseInWagmiAdapter;
9
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UniversalWallet = void 0;
7
+ class UniversalWallet {
8
+ name = [];
9
+ constructor(wallet) {
10
+ this.wallet = wallet;
11
+ if (wallet.extensions) {
12
+ // support injected connector
13
+ // https://wagmi.sh/react/connectors/injected
14
+ this.name.push(wallet.name);
15
+ }
16
+ if (wallet.app) {
17
+ // support WalletConnect https://wagmi.sh/react/connectors/walletConnect
18
+ this.name.push('WalletConnect');
19
+ }
20
+ }
21
+ create = connector => {
22
+ const connectors = connector;
23
+ const walletConnector = connectors.find(item => item.name === 'WalletConnect');
24
+ const injectedConnector = connectors.find(item => item.name === this.wallet.name);
25
+ const getQrCode = async () => {
26
+ const provider = await walletConnector?.getProvider();
27
+ return new Promise(resolve => {
28
+ provider.on('display_uri', uri => {
29
+ resolve({
30
+ uri
31
+ });
32
+ });
33
+ });
34
+ };
35
+ const hasExtensionInstalled = () => {
36
+ const provider = injectedConnector?.options?.getProvider();
37
+ return !!provider;
38
+ };
39
+ return {
40
+ ...this.wallet,
41
+ getWagmiConnector: () => {
42
+ if (hasExtensionInstalled()) {
43
+ return injectedConnector;
44
+ }
45
+ return walletConnector;
46
+ },
47
+ hasExtensionInstalled: async () => {
48
+ return hasExtensionInstalled();
49
+ },
50
+ hasWalletReady: async () => {
51
+ return !!(hasExtensionInstalled() || walletConnector);
52
+ },
53
+ getQrCode: walletConnector?.options?.showQrModal === false ? getQrCode : undefined
54
+ };
55
+ };
56
+ }
57
+ exports.UniversalWallet = UniversalWallet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/web3-wagmi",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "main": "dist/lib/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "typings": "dist/esm/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "debug": "^4.3.4",
34
- "@ant-design/web3-assets": "2.0.1",
35
- "@ant-design/web3-common": "1.1.1"
34
+ "@ant-design/web3-common": "1.2.0",
35
+ "@ant-design/web3-assets": "1.1.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/debug": "^4.1.12",