@reef-knot/core-react 4.2.0 → 4.2.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.
@@ -1,9 +1,8 @@
1
1
  import type { WalletAdapterData } from '@reef-knot/types';
2
- import type { Chain } from 'wagmi/chains';
3
2
  import type { Config, ConnectReturnType } from '@wagmi/core';
4
3
  import type { ReefKnotModalContextValue } from '../context';
5
4
  type ConnectResult = ConnectReturnType;
6
- export declare const connectEagerly: (config: Config, adapters: WalletAdapterData[], openModalAsync: ReefKnotModalContextValue['openModalAsync'], supportedChains: readonly [Chain, ...Chain[]]) => Promise<ConnectResult | null>;
5
+ export declare const connectEagerly: (config: Config, adapters: WalletAdapterData[], openModalAsync: ReefKnotModalContextValue['openModalAsync']) => Promise<ConnectResult | null>;
7
6
  export declare const useEagerConnect: () => {
8
7
  eagerConnect: () => Promise<ConnectResult | null>;
9
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,KAAK,aAAa,GAAG,iBAAiB,CAAC;AA6CvC,eAAO,MAAM,cAAc,WACjB,MAAM,YACJ,iBAAiB,EAAE,kBACb,yBAAyB,CAAC,gBAAgB,CAAC,mBAC1C,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,KAC5C,QAAQ,aAAa,GAAG,IAAI,CA+C9B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAmB3B,CAAC"}
1
+ {"version":3,"file":"useEagerConnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useEagerConnect.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,KAAK,aAAa,GAAG,iBAAiB,CAAC;AAEvC,eAAO,MAAM,cAAc,WACjB,MAAM,YACJ,iBAAiB,EAAE,kBACb,yBAAyB,CAAC,gBAAgB,CAAC,KAC1D,QAAQ,aAAa,GAAG,IAAI,CA4C9B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAc3B,CAAC"}
@@ -3,53 +3,20 @@ import { useCallback } from 'react';
3
3
  import { useConfig } from 'wagmi';
4
4
  import { useReefKnotContext } from './useReefKnotContext.js';
5
5
  import { useReefKnotModal } from './useReefKnotModal.js';
6
- import { connect, disconnect } from 'wagmi/actions';
7
- import { getUnsupportedChainError } from '../helpers/getUnsupportedChainError.js';
6
+ import { connect } from 'wagmi/actions';
8
7
  import { checkTermsAccepted } from '../helpers/checkTermsAccepted.js';
9
8
 
10
- const connectToAdapter = (config, connector, supportedChains) => __awaiter(void 0, void 0, void 0, function* () {
9
+ const connectEagerly = (config, adapters, openModalAsync) => __awaiter(void 0, void 0, void 0, function* () {
11
10
  var _a;
12
- const connectResult = yield connect(config, {
13
- connector
14
- });
15
- if (connectResult && supportedChains.findIndex(({
16
- id
17
- }) => id === connectResult.chainId) === -1) {
18
- // No errors during connection, but the chain is unsupported.
19
- // This case is considered as error for now, and we explicitly call disconnect() here.
20
- // This logic comes from previously used web3-react connection logic, which wasn't reworked yet after web3-react removal.
21
- // web3-react logic was: if a chain is unsupported – break the connection, throw an error
22
- // wagmi logic is: if a chain is unsupported – connect anyway, without errors.
23
- // So, here we are trying to mimic the legacy logic, because we are not ready to rework it yet.
24
- const connectError = getUnsupportedChainError(supportedChains);
25
- yield disconnect(config);
26
- // A user may change a chain in a wallet app, prepare for that event.
27
- // There is a strong recommendation in the MetaMask documentation
28
- // to reload the page upon chain changes, unless there is a good reason not to.
29
- // This looks like a good general approach.
30
- if (config.state.current) {
31
- const activeConnector = (_a = config.state.connections.get(config.state.current)) === null || _a === void 0 ? void 0 : _a.connector;
32
- if (activeConnector) {
33
- const provider = yield activeConnector.getProvider();
34
- provider.once('chainChanged', () => {
35
- var _a;
36
- return (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.location.reload();
37
- });
38
- }
39
- }
40
- throw connectError;
41
- }
42
- return connectResult;
43
- });
44
- const connectEagerly = (config, adapters, openModalAsync, supportedChains) => __awaiter(void 0, void 0, void 0, function* () {
45
- var _b;
46
11
  const isTermsAccepted = checkTermsAccepted();
47
12
  for (const adapter of adapters) {
48
- if (yield (_b = adapter.detector) === null || _b === void 0 ? void 0 : _b.call(adapter)) {
13
+ if (yield (_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter)) {
49
14
  // wallet is detected
50
15
  let connectionResult = null;
51
16
  const tryConnection = () => __awaiter(void 0, void 0, void 0, function* () {
52
- const result = yield connectToAdapter(config, adapter.createConnectorFn, supportedChains);
17
+ const result = yield connect(config, {
18
+ connector: adapter.createConnectorFn
19
+ });
53
20
  connectionResult = result;
54
21
  return result;
55
22
  });
@@ -68,7 +35,7 @@ const connectEagerly = (config, adapters, openModalAsync, supportedChains) => __
68
35
  try {
69
36
  yield tryConnection();
70
37
  } catch (e) {
71
- // when failed open terms modal,allow user to see error and retry from it
38
+ // when failed, open the terms modal, allow user to see the error and retry the connection
72
39
  yield openModalAsync({
73
40
  type: 'eager',
74
41
  props: {
@@ -78,7 +45,6 @@ const connectEagerly = (config, adapters, openModalAsync, supportedChains) => __
78
45
  });
79
46
  }
80
47
  }
81
- // TS doesn't know we assigned in tryConnection
82
48
  return connectionResult;
83
49
  }
84
50
  }
@@ -90,15 +56,14 @@ const useEagerConnect = () => {
90
56
  openModalAsync
91
57
  } = useReefKnotModal();
92
58
  const {
93
- walletDataList,
94
- chains
59
+ walletDataList
95
60
  } = useReefKnotContext();
96
61
  const eagerConnect = useCallback(() => {
97
62
  const autoConnectOnlyAdapters = walletDataList.filter(({
98
63
  autoConnectOnly
99
64
  }) => autoConnectOnly);
100
- return connectEagerly(config, autoConnectOnlyAdapters, openModalAsync, chains);
101
- }, [openModalAsync, walletDataList, chains, config]);
65
+ return connectEagerly(config, autoConnectOnlyAdapters, openModalAsync);
66
+ }, [openModalAsync, walletDataList, config]);
102
67
  return {
103
68
  eagerConnect
104
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/core-react",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {