@reef-knot/web3-react 1.7.0 → 1.8.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.
@@ -6,7 +6,7 @@ import { CHAINS } from '@lido-sdk/constants';
6
6
  import { getStaticRpcBatchProvider } from '@lido-sdk/providers';
7
7
  import { ProviderSDK as ProviderSDK$1 } from '@lido-sdk/react';
8
8
  import { Web3ReactProvider, useWeb3React } from '@web3-react/core';
9
- import { ReefKnot } from '@reef-knot/core-react';
9
+ import { holesky, ReefKnot } from '@reef-knot/core-react';
10
10
  import { useAccount } from 'wagmi';
11
11
  import * as wagmiChains from 'wagmi/chains';
12
12
  import { useWeb3 } from '../hooks/useWeb3.js';
@@ -103,7 +103,9 @@ var ProviderWeb3 = props => {
103
103
  appLogoUrl,
104
104
  defaultChainId
105
105
  };
106
- var wagmiChainsArray = Object.values(wagmiChains);
106
+ var wagmiChainsArray = Object.values(Object.assign(Object.assign({}, wagmiChains), {
107
+ holesky
108
+ }));
107
109
  var supportedWagmiChains = wagmiChainsArray.filter(chain => supportedChainIds.includes(chain.id));
108
110
  var defaultWagmiChain = wagmiChainsArray.find(chain => chain.id === defaultChainId);
109
111
  return /*#__PURE__*/React.createElement(Web3ReactProvider, {
@@ -3,4 +3,5 @@ export * from './ua';
3
3
  export * from './openWindow';
4
4
  export { default as isUrl } from './isUrl';
5
5
  export * from './interceptLedgerError';
6
+ export * from './unsupportedChainError';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
@@ -3,3 +3,4 @@ export { browser, checkIfBraveBrowser, device, isAndroid, isEdge, isFirefox, isI
3
3
  export { openWindow } from './openWindow.js';
4
4
  export { default as isUrl } from './isUrl.js';
5
5
  export { LedgerErrorsDict, interceptLedgerError } from './interceptLedgerError.js';
6
+ export { getUnsupportedChainError } from './unsupportedChainError.js';
@@ -0,0 +1,3 @@
1
+ import { Chain } from 'wagmi/chains';
2
+ export declare const getUnsupportedChainError: (supportedChains: Chain[]) => Error;
3
+ //# sourceMappingURL=unsupportedChainError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsupportedChainError.d.ts","sourceRoot":"","sources":["../../src/helpers/unsupportedChainError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,eAAO,MAAM,wBAAwB,oBAAqB,KAAK,EAAE,UAahE,CAAC"}
@@ -0,0 +1,16 @@
1
+ var getUnsupportedChainError = supportedChains => {
2
+ // Get names of supported chains to suggest them in case of "unsupported network" error
3
+ var supportedChainsNames = (() => {
4
+ var chains = supportedChains.map(_ref => {
5
+ var {
6
+ name
7
+ } = _ref;
8
+ return name;
9
+ }).filter(chainName => chainName !== 'unknown');
10
+ var lastChain = chains.pop();
11
+ return [chains.join(', '), lastChain].filter(chain => chain).join(' or ');
12
+ })();
13
+ return new Error("Unsupported chain. Please switch to ".concat(supportedChainsNames, " in your wallet and restart the page."));
14
+ };
15
+
16
+ export { getUnsupportedChainError };
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnect.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,eAAO,MAAM,cAAc,eAAgB,sBAAsB,SAKhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAAgB,sBAAsB,SAmEnE,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,IAwBvC,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAO,IAgB3C,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,IAexC,CAAC"}
1
+ {"version":3,"file":"useAutoConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnect.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,eAAO,MAAM,cAAc,eAAgB,sBAAsB,SAKhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAAgB,sBAAsB,SA6EnE,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,IAwBvC,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAO,IAgB3C,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,IAexC,CAAC"}
@@ -54,12 +54,22 @@ var useEagerConnector = connectors => {
54
54
  })();
55
55
  if (!connector) return;
56
56
  var connectWallet = () => __awaiter(void 0, void 0, void 0, function* () {
57
- var _d;
58
- yield activate(connector, undefined, true);
59
- // Hide the modal if a user approved the connection in a wallet's UI.
60
- // If a user rejects the connection, then an error is thrown
61
- // and the following code is not being reached, the modal stays visible.
62
- (_d = acceptTermsModal.setVisible) === null || _d === void 0 ? void 0 : _d.call(acceptTermsModal, false);
57
+ var _d, _e, _f, _g;
58
+ var error = undefined;
59
+ try {
60
+ yield activate(connector, undefined, true);
61
+ } catch (e) {
62
+ error = e;
63
+ }
64
+ if (shouldAutoConnectApp) {
65
+ if (!termsAccepted || error) {
66
+ (_d = acceptTermsModal.setError) === null || _d === void 0 ? void 0 : _d.call(acceptTermsModal, error);
67
+ (_e = acceptTermsModal.setVisible) === null || _e === void 0 ? void 0 : _e.call(acceptTermsModal, true);
68
+ } else {
69
+ (_f = acceptTermsModal.setVisible) === null || _f === void 0 ? void 0 : _f.call(acceptTermsModal, false);
70
+ (_g = acceptTermsModal.setError) === null || _g === void 0 ? void 0 : _g.call(acceptTermsModal, undefined);
71
+ }
72
+ }
63
73
  });
64
74
  var termsAccepted = false;
65
75
  if (typeof window !== 'undefined') {
@@ -1 +1 @@
1
- {"version":3,"file":"useConnectorError.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnectorError.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,QAAO,KAAK,GAAG,SAa5C,CAAC"}
1
+ {"version":3,"file":"useConnectorError.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnectorError.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB,QAAO,KAAK,GAAG,SAmB5C,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import { useWeb3 } from './useWeb3.js';
2
+ import { useReefKnotContext } from '@reef-knot/core-react';
2
3
  import '../helpers/ua.js';
3
4
  import { interceptLedgerError } from '../helpers/interceptLedgerError.js';
5
+ import { getUnsupportedChainError } from '../helpers/unsupportedChainError.js';
4
6
  import { useConnectorInfo } from './useConnectorInfo.js';
7
+ import { useSupportedChains } from './useSupportedChains.js';
5
8
 
6
9
  var useConnectorError = () => {
7
10
  var {
@@ -10,9 +13,18 @@ var useConnectorError = () => {
10
13
  var {
11
14
  isLedger
12
15
  } = useConnectorInfo();
16
+ var {
17
+ isUnsupported
18
+ } = useSupportedChains();
19
+ var {
20
+ chains: supportedChains
21
+ } = useReefKnotContext();
13
22
  if (!error) {
14
23
  return;
15
24
  }
25
+ if (isUnsupported) {
26
+ return getUnsupportedChainError(supportedChains);
27
+ }
16
28
  if (isLedger) {
17
29
  return interceptLedgerError(error);
18
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/web3-react",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -49,7 +49,7 @@
49
49
  "@lido-sdk/constants": "^3.2.0",
50
50
  "@lido-sdk/providers": "^1.4.13",
51
51
  "@lido-sdk/react": "^2.0.2",
52
- "@reef-knot/core-react": "^1.5.1",
52
+ "@reef-knot/core-react": "^1.7.0",
53
53
  "@reef-knot/ledger-connector": "^1.1.0",
54
54
  "@testing-library/react": "^12.1.5",
55
55
  "@testing-library/react-hooks": "^7.0.2",