@reef-knot/core-react 3.0.0 → 3.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.
@@ -1,4 +1,5 @@
1
1
  export declare const useAutoConnectCheck: () => {
2
- isAutoConnectionSuitable: boolean;
2
+ checkIfShouldAutoConnect: () => Promise<boolean>;
3
+ getAutoConnectOnlyConnectors: () => import("@wagmi/connectors/dist/base-84a689bb").C<any, any, any>[];
3
4
  };
4
5
  //# sourceMappingURL=useAutoConnectCheck.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoConnectCheck.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnectCheck.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;CAY/B,CAAC"}
1
+ {"version":3,"file":"useAutoConnectCheck.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoConnectCheck.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;;CAyB/B,CAAC"}
@@ -1,18 +1,30 @@
1
+ import { __awaiter } from '../_virtual/_tslib.js';
1
2
  import { useReefKnotContext } from './useReefKnotContext.js';
2
3
 
3
4
  const useAutoConnectCheck = () => {
4
5
  const {
5
6
  walletDataList
6
7
  } = useReefKnotContext();
7
- const autoConnectOnlyAdapters = walletDataList.filter(({
8
- autoConnectOnly
9
- }) => autoConnectOnly);
10
- const isAutoConnectionSuitable = autoConnectOnlyAdapters.some(adapter => {
8
+ const checkIfShouldAutoConnect = () => __awaiter(void 0, void 0, void 0, function* () {
11
9
  var _a;
12
- return (_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter);
10
+ const autoConnectOnlyAdapters = walletDataList.filter(({
11
+ autoConnectOnly
12
+ }) => autoConnectOnly);
13
+ for (const adapter of autoConnectOnlyAdapters) {
14
+ // Try to detect at least one wallet, marked as for auto connection only
15
+ if (yield (_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter)) return true;
16
+ }
17
+ return false;
13
18
  });
19
+ const getAutoConnectOnlyConnectors = () => {
20
+ const autoConnectOnlyAdapters = walletDataList.filter(({
21
+ autoConnectOnly
22
+ }) => autoConnectOnly);
23
+ return autoConnectOnlyAdapters.map(adapter => adapter.connector);
24
+ };
14
25
  return {
15
- isAutoConnectionSuitable
26
+ checkIfShouldAutoConnect,
27
+ getAutoConnectOnlyConnectors
16
28
  };
17
29
  };
18
30
 
@@ -9,13 +9,13 @@ const useConnect = () => {
9
9
  openModalAsync
10
10
  } = useReefKnotModal();
11
11
  const {
12
- isAutoConnectionSuitable
12
+ checkIfShouldAutoConnect
13
13
  } = useAutoConnectCheck();
14
14
  const {
15
15
  eagerConnect
16
16
  } = useEagerConnect();
17
17
  const connect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
18
- if (isAutoConnectionSuitable) {
18
+ if (yield checkIfShouldAutoConnect()) {
19
19
  const result = yield eagerConnect();
20
20
  return {
21
21
  success: !!result
@@ -25,7 +25,7 @@ const useConnect = () => {
25
25
  type: 'wallet'
26
26
  });
27
27
  }
28
- }), [eagerConnect, openModalAsync, isAutoConnectionSuitable]);
28
+ }), [checkIfShouldAutoConnect, eagerConnect, openModalAsync]);
29
29
  return {
30
30
  connect
31
31
  };
@@ -3,5 +3,6 @@ export declare const useForceDisconnect: () => {
3
3
  };
4
4
  export declare const useDisconnect: () => {
5
5
  disconnect?: (() => void) | undefined;
6
+ checkIfDisconnectMakesSense: () => boolean;
6
7
  };
7
8
  //# sourceMappingURL=useDisconnect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDisconnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useDisconnect.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB;;CAU9B,CAAC;AAEF,eAAO,MAAM,aAAa;wBACL,IAAI;CAWxB,CAAC"}
1
+ {"version":3,"file":"useDisconnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useDisconnect.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB;;CAU9B,CAAC;AAEF,eAAO,MAAM,aAAa;wBACL,IAAI;iCACM,MAAM,OAAO;CAoB3C,CAAC"}
@@ -20,17 +20,25 @@ const useForceDisconnect = () => {
20
20
  };
21
21
  const useDisconnect = () => {
22
22
  const {
23
- isConnected
23
+ isConnected,
24
+ connector
24
25
  } = useAccount();
25
26
  const {
26
27
  disconnect
27
28
  } = useDisconnect$1();
28
29
  const {
29
- isAutoConnectionSuitable
30
+ getAutoConnectOnlyConnectors
30
31
  } = useAutoConnectCheck();
31
- const available = isConnected && !isAutoConnectionSuitable;
32
+ const checkIfDisconnectMakesSense = () => {
33
+ // It doesn't make sense to offer a user the ability to disconnect if the user is not connected yet,
34
+ // or if the user was connected automatically
35
+ const autoConnectOnlyConnectors = getAutoConnectOnlyConnectors();
36
+ const isConnectorNotAutoConnectOnly = autoConnectOnlyConnectors.every(c => c.id !== (connector === null || connector === void 0 ? void 0 : connector.id));
37
+ return isConnected && isConnectorNotAutoConnectOnly;
38
+ };
32
39
  return {
33
- disconnect: available ? disconnect : undefined
40
+ disconnect: checkIfDisconnectMakesSense() ? disconnect : undefined,
41
+ checkIfDisconnectMakesSense
34
42
  };
35
43
  };
36
44
 
@@ -36,14 +36,14 @@ const connectEagerly = (adapters, openModalAsync, supportedChains) => __awaiter(
36
36
  var _a;
37
37
  const isTermsAccepted = checkTermsAccepted();
38
38
  for (const adapter of adapters) {
39
- if ((_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter)) {
39
+ if (yield (_a = adapter.detector) === null || _a === void 0 ? void 0 : _a.call(adapter)) {
40
40
  // wallet is detected
41
41
  let connectionResult = null;
42
42
  const tryConnection = () => connectToAdapter(adapter.connector, supportedChains).then(result => {
43
43
  connectionResult = result;
44
44
  return result;
45
45
  });
46
- // if terms are not accepted, show modal and wait for user to try connect from it
46
+ // if terms are not accepted, show modal and wait for user to try to connect from it
47
47
  if (!isTermsAccepted) {
48
48
  // Terms of service were not accepted previously.
49
49
  // So, for legal reasons, we must ask a user to accept the terms before connecting.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/core-react",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -41,8 +41,8 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@reef-knot/ledger-connector": "^3.0.0",
44
- "@reef-knot/wallets-list": "^1.12.0",
45
- "@reef-knot/types": "^1.5.0",
44
+ "@reef-knot/wallets-list": "^1.13.1",
45
+ "@reef-knot/types": "^1.7.0",
46
46
  "@reef-knot/ui-react": "^1.0.8",
47
47
  "@types/ua-parser-js": "^0.7.36",
48
48
  "eslint-config-custom": "*",