@reef-knot/wallet-adapter-safe 1.2.0 → 2.0.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -30
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,eAAO,MAAM,EAAE,SAAS,CAAC;AACzB,eAAO,MAAM,IAAI,SAAS,CAAC;AAgB3B,eAAO,MAAM,IAAI,EAAE,iBA8DjB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,71 @@
|
|
|
1
1
|
import { __awaiter } from './_virtual/_tslib.js';
|
|
2
|
-
import {
|
|
2
|
+
import { safe } from 'wagmi/connectors';
|
|
3
|
+
import { withTimeout } from 'viem';
|
|
3
4
|
|
|
4
5
|
const id = 'safe';
|
|
5
6
|
const name = 'Safe';
|
|
7
|
+
const getSafeConnector = ({
|
|
8
|
+
allowedDomains = []
|
|
9
|
+
}) => safe({
|
|
10
|
+
allowedDomains: [/app.safe.global$/, /holesky-safe.protofire.io$/, ...allowedDomains],
|
|
11
|
+
debug: false
|
|
12
|
+
});
|
|
6
13
|
const Safe = ({
|
|
7
|
-
|
|
8
|
-
}) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
safeAllowedDomains
|
|
15
|
+
}) => ({
|
|
16
|
+
walletName: name,
|
|
17
|
+
walletId: id,
|
|
18
|
+
type: safe.type,
|
|
19
|
+
autoConnectOnly: true,
|
|
20
|
+
detector: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
// We cannot longer use `safeConnector.getProvider()` directly
|
|
22
|
+
// because in the current wagmi version it must be initialized
|
|
23
|
+
// with `wagmi/createConfig/setup` otherewise the `getProvider` method is not accessible.
|
|
24
|
+
// https://github.com/wevm/wagmi/blob/fa5864bfb3ebfb0dc147b35003152a17a785ade6/packages/core/src/createConfig.ts#L96-L111
|
|
25
|
+
//
|
|
26
|
+
// We also do not use wagmi config here because we prefer to create a connection on flight
|
|
27
|
+
// when the connect button is clicked. This approach helps us to avoid connector collisions
|
|
28
|
+
// that appear in wagmi sometimes when it has multiple injected connectors in the config list
|
|
29
|
+
// which leading to some bugs detected during manual ui tests.
|
|
30
|
+
//
|
|
31
|
+
// So, with that being said, as we do not have an access to `safeConnector.getProvider`
|
|
32
|
+
// we forced to copy an implementation from its original source to implement a wallet detector:
|
|
33
|
+
// https://github.com/wevm/wagmi/blob/fa5864bfb3ebfb0dc147b35003152a17a785ade6/packages/connectors/src/safe.ts#L85-L116
|
|
34
|
+
var _a;
|
|
35
|
+
const isIframe = globalThis.window && ((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.parent) !== globalThis.window;
|
|
36
|
+
if (!isIframe) return false;
|
|
37
|
+
try {
|
|
38
|
+
const {
|
|
39
|
+
default: SafeAppsSDK
|
|
40
|
+
} = yield import('@safe-global/safe-apps-sdk');
|
|
41
|
+
let SDK;
|
|
42
|
+
if (typeof SafeAppsSDK !== 'function' && typeof SafeAppsSDK.default === 'function') {
|
|
43
|
+
SDK = SafeAppsSDK.default;
|
|
44
|
+
} else {
|
|
45
|
+
SDK = SafeAppsSDK;
|
|
32
46
|
}
|
|
47
|
+
const parameters = {
|
|
48
|
+
allowedDomains: safeAllowedDomains
|
|
49
|
+
};
|
|
50
|
+
const sdk = new SDK(parameters);
|
|
51
|
+
// `getInfo` hangs when not used in Safe App iFrame
|
|
52
|
+
// https://github.com/safe-global/safe-apps-sdk/issues/263#issuecomment-1029835840
|
|
53
|
+
const safeSdk = yield withTimeout(() => sdk.safe.getInfo(), {
|
|
54
|
+
timeout: 200
|
|
55
|
+
});
|
|
56
|
+
if (!safeSdk) return false;
|
|
57
|
+
const {
|
|
58
|
+
SafeAppProvider
|
|
59
|
+
} = yield import('@safe-global/safe-apps-provider');
|
|
60
|
+
const provider = new SafeAppProvider(safeSdk, sdk);
|
|
61
|
+
return !!provider;
|
|
62
|
+
} catch (_b) {
|
|
33
63
|
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
createConnectorFn: getSafeConnector({
|
|
67
|
+
allowedDomains: safeAllowedDomains
|
|
68
|
+
})
|
|
69
|
+
});
|
|
38
70
|
|
|
39
71
|
export { Safe, id, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reef-knot/wallet-adapter-safe",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -32,12 +32,14 @@
|
|
|
32
32
|
"lint": "eslint --ext ts,tsx,js,mjs ."
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@reef-knot/types": "^
|
|
35
|
+
"@reef-knot/types": "^2.0.0",
|
|
36
36
|
"@svgr/rollup": "^6.5.1",
|
|
37
37
|
"eslint-config-custom": "*"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"viem": "2.13.3",
|
|
41
|
+
"wagmi": "2.10.4",
|
|
42
|
+
"@reef-knot/types": "^2.0.0",
|
|
43
|
+
"@tanstack/react-query": "^5.29.0"
|
|
42
44
|
}
|
|
43
45
|
}
|