@ant-design/web3-wagmi 0.1.0-alpha.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # @ant-design/web3-wagmi
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 2d7ae4f: refactor: auto config wagmi provider chains
8
+ - 39782e4: feat: ethereum adapter support show balance
9
+ - e4535ff: feat: add new wallet CoinbaseWallet
10
+ - Updated dependencies [2d7ae4f]
11
+ - Updated dependencies [0df085f]
12
+ - Updated dependencies [3fbd1eb]
13
+ - Updated dependencies [39782e4]
14
+ - Updated dependencies [c15bfdf]
15
+ - Updated dependencies [e4535ff]
16
+ - @ant-design/web3-assets@0.1.1
17
+ - @ant-design/web3-common@0.1.1
18
+
19
+ ## 0.1.0
20
+
21
+ ### Patch Changes
22
+
23
+ - Release new alpha version
24
+ - Updated dependencies
25
+ - @ant-design/web3-assets@0.1.0
26
+ - @ant-design/web3-common@0.1.0
@@ -1,2 +1,3 @@
1
1
  export * from './wagmi-provider';
2
2
  export * from './wallets';
3
+ export * from '@ant-design/web3-assets';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./wagmi-provider";
2
- export * from "./wallets";
2
+ export * from "./wallets";
3
+ export * from '@ant-design/web3-assets';
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import { type Chain } from '@ant-design/web3-common';
3
- import { type Chain as WagmiChain } from 'wagmi';
3
+ import { type Connector as WagmiConnector, type Chain as WagmiChain } from 'wagmi';
4
4
  import type { WalletFactory } from '../interface';
5
5
  export interface AntDesignWeb3ConfigProviderProps {
6
6
  assets?: (WalletFactory | Chain)[];
7
7
  children?: React.ReactNode;
8
8
  ens?: boolean;
9
+ balance?: boolean;
9
10
  availableChains: WagmiChain[];
11
+ availableConnectors: WagmiConnector[];
10
12
  }
11
13
  export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"config-provider.d.ts","sourceRoot":"","sources":["config-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAA6B,KAAK,KAAK,EAAsB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAML,KAAK,KAAK,IAAI,UAAU,EACzB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,gCAAgC;IAC/C,MAAM,CAAC,EAAE,CAAC,aAAa,GAAG,KAAK,CAAC,EAAE,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,eAAe,EAAE,UAAU,EAAE,CAAC;CAC/B;AAED,eAAO,MAAM,2BAA2B,EAAE,KAAK,CAAC,EAAE,CAAC,gCAAgC,CAiGlF,CAAC"}
1
+ {"version":3,"file":"config-provider.d.ts","sourceRoot":"","sources":["config-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAGL,KAAK,KAAK,EAGX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAOL,KAAK,SAAS,IAAI,cAAc,EAChC,KAAK,KAAK,IAAI,UAAU,EACzB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,gCAAgC;IAC/C,MAAM,CAAC,EAAE,CAAC,aAAa,GAAG,KAAK,CAAC,EAAE,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,UAAU,EAAE,CAAC;IAC9B,mBAAmB,EAAE,cAAc,EAAE,CAAC;CACvC;AAED,eAAO,MAAM,2BAA2B,EAAE,KAAK,CAAC,EAAE,CAAC,gCAAgC,CAyHlF,CAAC"}
@@ -9,15 +9,18 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import React from 'react';
12
- import { Web3ConfigProvider } from '@ant-design/web3-common';
13
- import { useAccount, useConnect, useDisconnect, useNetwork, useSwitchNetwork } from 'wagmi';
12
+ import { Web3ConfigProvider, fillAddressWith0x } from '@ant-design/web3-common';
13
+ import { useAccount, useConnect, useDisconnect, useNetwork, useSwitchNetwork, useBalance } from 'wagmi';
14
14
  import { addNameToAccount, getNFTMetadata } from "./methods";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(props) {
17
+ var _currentChain$nativeC;
17
18
  var children = props.children,
18
19
  assets = props.assets,
19
20
  availableChains = props.availableChains,
20
- ens = props.ens;
21
+ availableConnectors = props.availableConnectors,
22
+ ens = props.ens,
23
+ balance = props.balance;
21
24
  var _useAccount = useAccount(),
22
25
  address = _useAccount.address,
23
26
  isDisconnected = _useAccount.isDisconnected;
@@ -26,7 +29,6 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
26
29
  account = _React$useState2[0],
27
30
  setAccount = _React$useState2[1];
28
31
  var _useConnect = useConnect(),
29
- connectors = _useConnect.connectors,
30
32
  connectAsync = _useConnect.connectAsync;
31
33
  var _useSwitchNetwork = useSwitchNetwork(),
32
34
  switchNetwork = _useSwitchNetwork.switchNetwork;
@@ -38,6 +40,10 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
38
40
  _React$useState4 = _slicedToArray(_React$useState3, 2),
39
41
  currentChain = _React$useState4[0],
40
42
  setCurrentChain = _React$useState4[1];
43
+ var _useBalance = useBalance({
44
+ address: balance && account ? fillAddressWith0x(account.address) : undefined
45
+ }),
46
+ balanceData = _useBalance.data;
41
47
  React.useEffect(function () {
42
48
  if (!address || isDisconnected) {
43
49
  setAccount(undefined);
@@ -81,28 +87,35 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
81
87
  updateAccounts();
82
88
  }, [address, isDisconnected, chain, ens]);
83
89
  var wallets = React.useMemo(function () {
84
- return connectors.map(function (connector) {
90
+ return availableConnectors.map(function (connector) {
85
91
  var walletFactory = assets === null || assets === void 0 ? void 0 : assets.find(function (item) {
86
92
  return item.name === connector.name;
87
93
  });
88
94
  if (!(walletFactory !== null && walletFactory !== void 0 && walletFactory.create)) {
89
- throw new Error("Can not find wallet factory for ".concat(connector.name));
95
+ console.error("Can not find wallet factory for ".concat(connector.name, ", you shold config it in WagmiWeb3ConfigProvider 'assets'."));
96
+ return null;
90
97
  }
91
98
  return walletFactory.create(connector);
99
+ }).filter(function (item) {
100
+ return item !== null;
92
101
  });
93
- }, [connectors, assets]);
102
+ }, [availableConnectors, assets]);
94
103
  var chainList = React.useMemo(function () {
95
104
  return availableChains.map(function (item) {
96
105
  var c = assets === null || assets === void 0 ? void 0 : assets.find(function (asset) {
97
106
  return asset.id === item.id;
98
107
  });
99
- if (!(c !== null && c !== void 0 && c.id)) {
108
+ if (c !== null && c !== void 0 && c.id) {
100
109
  return {
101
110
  id: c.id,
102
111
  name: c.name
103
112
  };
113
+ } else {
114
+ console.error("Can not find chain ".concat(item.id, ", you shold config it in WagmiWeb3ConfigProvider 'assets'."));
115
+ return null;
104
116
  }
105
- return c;
117
+ }).filter(function (item) {
118
+ return item !== null;
106
119
  });
107
120
  }, [availableChains, assets]);
108
121
  React.useEffect(function () {
@@ -131,6 +144,12 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
131
144
  availableChains: chainList,
132
145
  chain: currentChain,
133
146
  account: account,
147
+ balance: balance ? {
148
+ symbol: balanceData === null || balanceData === void 0 ? void 0 : balanceData.symbol,
149
+ value: balanceData === null || balanceData === void 0 ? void 0 : balanceData.value,
150
+ decimals: balanceData === null || balanceData === void 0 ? void 0 : balanceData.decimals,
151
+ icon: currentChain === null || currentChain === void 0 ? void 0 : (_currentChain$nativeC = currentChain.nativeCurrency) === null || _currentChain$nativeC === void 0 ? void 0 : _currentChain$nativeC.icon
152
+ } : undefined,
134
153
  availableWallets: wallets,
135
154
  connect: /*#__PURE__*/function () {
136
155
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(wallet) {
@@ -138,7 +157,7 @@ export var AntDesignWeb3ConfigProvider = function AntDesignWeb3ConfigProvider(pr
138
157
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
139
158
  while (1) switch (_context2.prev = _context2.next) {
140
159
  case 0:
141
- connector = connectors.find(function (item) {
160
+ connector = availableConnectors.find(function (item) {
142
161
  return item.name === (wallet === null || wallet === void 0 ? void 0 : wallet.name);
143
162
  });
144
163
  _context2.next = 3;
@@ -1,11 +1,11 @@
1
- /// <reference types="react" />
2
- import type { PublicClient, WebSocketPublicClient, Config, Chain as WagmiChain } from 'wagmi';
1
+ import React from 'react';
2
+ import type { PublicClient, WebSocketPublicClient, Config } from 'wagmi';
3
3
  import type { Chain } from '@ant-design/web3-common';
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>;
7
- availableChains?: WagmiChain[];
8
7
  assets?: (Chain | WalletFactory)[];
9
8
  ens?: boolean;
9
+ balance?: boolean;
10
10
  };
11
- export declare function WagmiWeb3ConfigProvider<TPublicClient extends PublicClient, TWebSocketPublicClient extends WebSocketPublicClient>({ children, assets, availableChains, ens, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps<TPublicClient, TWebSocketPublicClient>>): React.ReactElement;
11
+ export declare function WagmiWeb3ConfigProvider<TPublicClient extends PublicClient, TWebSocketPublicClient extends WebSocketPublicClient>({ children, assets, ens, balance, config, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps<TPublicClient, TWebSocketPublicClient>>): React.ReactElement;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAE9F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMlD,MAAM,MAAM,4BAA4B,CACtC,aAAa,SAAS,YAAY,GAAG,YAAY,EACjD,sBAAsB,SAAS,qBAAqB,GAAG,qBAAqB,IAC1E;IACF,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;IACtD,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC;IACnC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,aAAa,SAAS,YAAY,EAClC,sBAAsB,SAAS,qBAAqB,EACpD,EACA,QAAQ,EACR,MAAW,EACX,eAA2B,EAC3B,GAAG,EACH,GAAG,SAAS,EACb,EAAE,KAAK,CAAC,iBAAiB,CACxB,4BAA4B,CAAC,aAAa,EAAE,sBAAsB,CAAC,CACpE,GAAG,KAAK,CAAC,YAAY,CAYrB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,EAAuB,MAAM,OAAO,CAAC;AAE9F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAOlD,MAAM,MAAM,4BAA4B,CACtC,aAAa,SAAS,YAAY,GAAG,YAAY,EACjD,sBAAsB,SAAS,qBAAqB,GAAG,qBAAqB,IAC1E;IACF,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;IACtD,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC;IACnC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,aAAa,SAAS,YAAY,EAClC,sBAAsB,SAAS,qBAAqB,EACpD,EACA,QAAQ,EACR,MAAW,EACX,GAAG,EACH,OAAO,EACP,MAAM,EACN,GAAG,SAAS,EACb,EAAE,KAAK,CAAC,iBAAiB,CACxB,4BAA4B,CAAC,aAAa,EAAE,sBAAsB,CAAC,CACpE,GAAG,KAAK,CAAC,YAAY,CAgCrB"}
@@ -1,5 +1,5 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- var _excluded = ["children", "assets", "availableChains", "ens"];
2
+ var _excluded = ["children", "assets", "ens", "balance", "config"];
3
3
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
4
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -7,32 +7,67 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
7
7
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
9
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
10
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
11
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
14
  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
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; }
15
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; }
16
- import { WagmiConfig, mainnet } from 'wagmi';
17
+ import React from 'react';
18
+ import { WagmiConfig } from 'wagmi';
17
19
  import { AntDesignWeb3ConfigProvider } from "./config-provider";
18
20
  // Built in popular chains
19
- import { Mainnet, Polygon, BSC, Goerli } from '@ant-design/web3-assets';
20
- // MetaMask and WalletConnect built-in
21
- import { MetaMask, WalletConnect } from "../wallets";
21
+ import { Mainnet, Goerli } from '@ant-design/web3-assets';
22
+ // MetaMask built-in
23
+ import { MetaMask } from "../wallets";
22
24
  import { jsx as _jsx } from "react/jsx-runtime";
23
25
  export function WagmiWeb3ConfigProvider(_ref) {
24
26
  var children = _ref.children,
25
27
  _ref$assets = _ref.assets,
26
28
  assets = _ref$assets === void 0 ? [] : _ref$assets,
27
- _ref$availableChains = _ref.availableChains,
28
- availableChains = _ref$availableChains === void 0 ? [mainnet] : _ref$availableChains,
29
29
  ens = _ref.ens,
30
+ balance = _ref.balance,
31
+ config = _ref.config,
30
32
  restProps = _objectWithoutProperties(_ref, _excluded);
31
- return /*#__PURE__*/_jsx(WagmiConfig, _objectSpread(_objectSpread({}, restProps), {}, {
33
+ var availableChains = React.useMemo(function () {
34
+ var _config$publicClient$;
35
+ // merge all available chains fro user select
36
+ var chains = [];
37
+ var _iterator = _createForOfIteratorHelper(config.connectors),
38
+ _step;
39
+ try {
40
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
41
+ var connector = _step.value;
42
+ connector.chains.forEach(function (chain) {
43
+ if (chains.find(function (c) {
44
+ return c.id === chain.id;
45
+ })) return;
46
+ chains.push(chain);
47
+ });
48
+ }
49
+ } catch (err) {
50
+ _iterator.e(err);
51
+ } finally {
52
+ _iterator.f();
53
+ }
54
+ (_config$publicClient$ = config.publicClient.chains) === null || _config$publicClient$ === void 0 ? void 0 : _config$publicClient$.forEach(function (chain) {
55
+ if (chains.find(function (c) {
56
+ return c.id === chain.id;
57
+ })) return;
58
+ chains.push(chain);
59
+ });
60
+ return chains;
61
+ }, [config]);
62
+ return /*#__PURE__*/_jsx(WagmiConfig, _objectSpread(_objectSpread({
63
+ config: config
64
+ }, restProps), {}, {
32
65
  children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
33
- assets: [].concat(_toConsumableArray(assets), [MetaMask, WalletConnect, Mainnet, Polygon, BSC, Goerli]),
66
+ assets: [].concat(_toConsumableArray(assets), [MetaMask, Mainnet, Goerli]),
34
67
  availableChains: availableChains,
68
+ availableConnectors: config.connectors || [],
35
69
  ens: ens,
70
+ balance: balance,
36
71
  children: children
37
72
  })
38
73
  }));
@@ -0,0 +1,2 @@
1
+ import type { WalletFactory } from '../interface';
2
+ export declare const CoinbaseWallet: WalletFactory;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coinbase-wallet.d.ts","sourceRoot":"","sources":["coinbase-wallet.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,eAAO,MAAM,cAAc,EAAE,aAW5B,CAAC"}
@@ -0,0 +1,34 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
+ import { metadata_CoinbaseWallet } from '@ant-design/web3-assets';
11
+ export var CoinbaseWallet = {
12
+ name: 'Coinbase Wallet',
13
+ create: function create() {
14
+ return _objectSpread(_objectSpread({}, metadata_CoinbaseWallet), {}, {
15
+ hasBrowserExtensionInstalled: function () {
16
+ var _hasBrowserExtensionInstalled = _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", !!window.coinbaseWalletExtension);
21
+ case 1:
22
+ case "end":
23
+ return _context.stop();
24
+ }
25
+ }, _callee);
26
+ }));
27
+ function hasBrowserExtensionInstalled() {
28
+ return _hasBrowserExtensionInstalled.apply(this, arguments);
29
+ }
30
+ return hasBrowserExtensionInstalled;
31
+ }()
32
+ });
33
+ }
34
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './meta-mask';
2
2
  export * from './wallet-connect';
3
+ export * from './coinbase-wallet';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./meta-mask";
2
- export * from "./wallet-connect";
2
+ export * from "./wallet-connect";
3
+ export * from "./coinbase-wallet";
@@ -1,2 +1,3 @@
1
1
  export * from './wagmi-provider';
2
2
  export * from './wallets';
3
+ export * from '@ant-design/web3-assets';
package/dist/lib/index.js CHANGED
@@ -24,4 +24,15 @@ Object.keys(_wallets).forEach(function (key) {
24
24
  return _wallets[key];
25
25
  }
26
26
  });
27
+ });
28
+ var _web3Assets = require("@ant-design/web3-assets");
29
+ Object.keys(_web3Assets).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _web3Assets[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _web3Assets[key];
36
+ }
37
+ });
27
38
  });
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import { type Chain } from '@ant-design/web3-common';
3
- import { type Chain as WagmiChain } from 'wagmi';
3
+ import { type Connector as WagmiConnector, type Chain as WagmiChain } from 'wagmi';
4
4
  import type { WalletFactory } from '../interface';
5
5
  export interface AntDesignWeb3ConfigProviderProps {
6
6
  assets?: (WalletFactory | Chain)[];
7
7
  children?: React.ReactNode;
8
8
  ens?: boolean;
9
+ balance?: boolean;
9
10
  availableChains: WagmiChain[];
11
+ availableConnectors: WagmiConnector[];
10
12
  }
11
13
  export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
@@ -15,7 +15,9 @@ const AntDesignWeb3ConfigProvider = props => {
15
15
  children,
16
16
  assets,
17
17
  availableChains,
18
- ens
18
+ availableConnectors,
19
+ ens,
20
+ balance
19
21
  } = props;
20
22
  const {
21
23
  address,
@@ -23,7 +25,6 @@ const AntDesignWeb3ConfigProvider = props => {
23
25
  } = (0, _wagmi.useAccount)();
24
26
  const [account, setAccount] = _react.default.useState();
25
27
  const {
26
- connectors,
27
28
  connectAsync
28
29
  } = (0, _wagmi.useConnect)();
29
30
  const {
@@ -36,6 +37,11 @@ const AntDesignWeb3ConfigProvider = props => {
36
37
  disconnectAsync
37
38
  } = (0, _wagmi.useDisconnect)();
38
39
  const [currentChain, setCurrentChain] = _react.default.useState(undefined);
40
+ const {
41
+ data: balanceData
42
+ } = (0, _wagmi.useBalance)({
43
+ address: balance && account ? (0, _web3Common.fillAddressWith0x)(account.address) : undefined
44
+ });
39
45
  _react.default.useEffect(() => {
40
46
  if (!address || isDisconnected) {
41
47
  setAccount(undefined);
@@ -50,27 +56,30 @@ const AntDesignWeb3ConfigProvider = props => {
50
56
  updateAccounts();
51
57
  }, [address, isDisconnected, chain, ens]);
52
58
  const wallets = _react.default.useMemo(() => {
53
- return connectors.map(connector => {
59
+ return availableConnectors.map(connector => {
54
60
  const walletFactory = assets?.find(item => item.name === connector.name);
55
61
  if (!walletFactory?.create) {
56
- throw new Error(`Can not find wallet factory for ${connector.name}`);
62
+ console.error(`Can not find wallet factory for ${connector.name}, you shold config it in WagmiWeb3ConfigProvider 'assets'.`);
63
+ return null;
57
64
  }
58
65
  return walletFactory.create(connector);
59
- });
60
- }, [connectors, assets]);
66
+ }).filter(item => item !== null);
67
+ }, [availableConnectors, assets]);
61
68
  const chainList = _react.default.useMemo(() => {
62
69
  return availableChains.map(item => {
63
70
  const c = assets?.find(asset => {
64
71
  return asset.id === item.id;
65
72
  });
66
- if (!c?.id) {
73
+ if (c?.id) {
67
74
  return {
68
75
  id: c.id,
69
76
  name: c.name
70
77
  };
78
+ } else {
79
+ console.error(`Can not find chain ${item.id}, you shold config it in WagmiWeb3ConfigProvider 'assets'.`);
80
+ return null;
71
81
  }
72
- return c;
73
- });
82
+ }).filter(item => item !== null);
74
83
  }, [availableChains, assets]);
75
84
  _react.default.useEffect(() => {
76
85
  if (!chain && currentChain) {
@@ -95,9 +104,15 @@ const AntDesignWeb3ConfigProvider = props => {
95
104
  availableChains: chainList,
96
105
  chain: currentChain,
97
106
  account: account,
107
+ balance: balance ? {
108
+ symbol: balanceData?.symbol,
109
+ value: balanceData?.value,
110
+ decimals: balanceData?.decimals,
111
+ icon: currentChain?.nativeCurrency?.icon
112
+ } : undefined,
98
113
  availableWallets: wallets,
99
114
  connect: async wallet => {
100
- const connector = connectors.find(item => item.name === wallet?.name);
115
+ const connector = availableConnectors.find(item => item.name === wallet?.name);
101
116
  await connectAsync({
102
117
  connector,
103
118
  chainId: currentChain?.id
@@ -1,11 +1,11 @@
1
- /// <reference types="react" />
2
- import type { PublicClient, WebSocketPublicClient, Config, Chain as WagmiChain } from 'wagmi';
1
+ import React from 'react';
2
+ import type { PublicClient, WebSocketPublicClient, Config } from 'wagmi';
3
3
  import type { Chain } from '@ant-design/web3-common';
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>;
7
- availableChains?: WagmiChain[];
8
7
  assets?: (Chain | WalletFactory)[];
9
8
  ens?: boolean;
9
+ balance?: boolean;
10
10
  };
11
- export declare function WagmiWeb3ConfigProvider<TPublicClient extends PublicClient, TWebSocketPublicClient extends WebSocketPublicClient>({ children, assets, availableChains, ens, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps<TPublicClient, TWebSocketPublicClient>>): React.ReactElement;
11
+ export declare function WagmiWeb3ConfigProvider<TPublicClient extends PublicClient, TWebSocketPublicClient extends WebSocketPublicClient>({ children, assets, ens, balance, config, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps<TPublicClient, TWebSocketPublicClient>>): React.ReactElement;
@@ -4,28 +4,49 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WagmiWeb3ConfigProvider = WagmiWeb3ConfigProvider;
7
+ var _react = _interopRequireDefault(require("react"));
7
8
  var _wagmi = require("wagmi");
8
9
  var _configProvider = require("./config-provider");
9
10
  var _web3Assets = require("@ant-design/web3-assets");
10
11
  var _wallets = require("../wallets");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
14
  // Built in popular chains
13
15
 
14
- // MetaMask and WalletConnect built-in
16
+ // MetaMask built-in
15
17
 
16
18
  function WagmiWeb3ConfigProvider({
17
19
  children,
18
20
  assets = [],
19
- availableChains = [_wagmi.mainnet],
20
21
  ens,
22
+ balance,
23
+ config,
21
24
  ...restProps
22
25
  }) {
26
+ const availableChains = _react.default.useMemo(() => {
27
+ // merge all available chains fro user select
28
+ const chains = [];
29
+ for (const connector of config.connectors) {
30
+ connector.chains.forEach(chain => {
31
+ if (chains.find(c => c.id === chain.id)) return;
32
+ chains.push(chain);
33
+ });
34
+ }
35
+ config.publicClient.chains?.forEach(chain => {
36
+ if (chains.find(c => c.id === chain.id)) return;
37
+ chains.push(chain);
38
+ });
39
+ return chains;
40
+ }, [config]);
23
41
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_wagmi.WagmiConfig, {
42
+ config: config,
24
43
  ...restProps,
25
44
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
26
- assets: [...assets, _wallets.MetaMask, _wallets.WalletConnect, _web3Assets.Mainnet, _web3Assets.Polygon, _web3Assets.BSC, _web3Assets.Goerli],
45
+ assets: [...assets, _wallets.MetaMask, _web3Assets.Mainnet, _web3Assets.Goerli],
27
46
  availableChains: availableChains,
47
+ availableConnectors: config.connectors || [],
28
48
  ens: ens,
49
+ balance: balance,
29
50
  children: children
30
51
  })
31
52
  });
@@ -0,0 +1,2 @@
1
+ import type { WalletFactory } from '../interface';
2
+ export declare const CoinbaseWallet: WalletFactory;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CoinbaseWallet = void 0;
7
+ var _web3Assets = require("@ant-design/web3-assets");
8
+ const CoinbaseWallet = {
9
+ name: 'Coinbase Wallet',
10
+ create: () => {
11
+ return {
12
+ ..._web3Assets.metadata_CoinbaseWallet,
13
+ hasBrowserExtensionInstalled: async () => {
14
+ // @ts-ignore
15
+ return !!window.coinbaseWalletExtension;
16
+ }
17
+ };
18
+ }
19
+ };
20
+ exports.CoinbaseWallet = CoinbaseWallet;
@@ -1,2 +1,3 @@
1
1
  export * from './meta-mask';
2
2
  export * from './wallet-connect';
3
+ export * from './coinbase-wallet';
@@ -24,4 +24,15 @@ Object.keys(_walletConnect).forEach(function (key) {
24
24
  return _walletConnect[key];
25
25
  }
26
26
  });
27
+ });
28
+ var _coinbaseWallet = require("./coinbase-wallet");
29
+ Object.keys(_coinbaseWallet).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _coinbaseWallet[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _coinbaseWallet[key];
36
+ }
37
+ });
27
38
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/web3-wagmi",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.1",
4
4
  "exports": {
5
5
  "import": "./dist/esm/index.js",
6
6
  "require": "./dist/lib/index.js",
@@ -13,8 +13,8 @@
13
13
  ],
14
14
  "dependencies": {
15
15
  "debug": "^4.3.4",
16
- "@ant-design/web3-common": "0.1.0-alpha.1",
17
- "@ant-design/web3-assets": "0.1.0-alpha.1"
16
+ "@ant-design/web3-common": "0.1.1",
17
+ "@ant-design/web3-assets": "0.1.1"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/debug": "^4.1.9",