@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.
- package/dist/hooks/useAutoConnectCheck.d.ts +2 -1
- package/dist/hooks/useAutoConnectCheck.d.ts.map +1 -1
- package/dist/hooks/useAutoConnectCheck.js +18 -6
- package/dist/hooks/useConnect.js +3 -3
- package/dist/hooks/useDisconnect.d.ts +1 -0
- package/dist/hooks/useDisconnect.d.ts.map +1 -1
- package/dist/hooks/useDisconnect.js +12 -4
- package/dist/hooks/useEagerConnect.js +2 -2
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const useAutoConnectCheck: () => {
|
|
2
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
checkIfShouldAutoConnect,
|
|
27
|
+
getAutoConnectOnlyConnectors
|
|
16
28
|
};
|
|
17
29
|
};
|
|
18
30
|
|
package/dist/hooks/useConnect.js
CHANGED
|
@@ -9,13 +9,13 @@ const useConnect = () => {
|
|
|
9
9
|
openModalAsync
|
|
10
10
|
} = useReefKnotModal();
|
|
11
11
|
const {
|
|
12
|
-
|
|
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 (
|
|
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
|
|
28
|
+
}), [checkIfShouldAutoConnect, eagerConnect, openModalAsync]);
|
|
29
29
|
return {
|
|
30
30
|
connect
|
|
31
31
|
};
|
|
@@ -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;
|
|
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
|
-
|
|
30
|
+
getAutoConnectOnlyConnectors
|
|
30
31
|
} = useAutoConnectCheck();
|
|
31
|
-
const
|
|
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:
|
|
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.
|
|
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.
|
|
45
|
-
"@reef-knot/types": "^1.
|
|
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": "*",
|