@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 CHANGED
@@ -1,4 +1,4 @@
1
- import { WalletAdapterType } from '@reef-knot/types';
1
+ import type { WalletAdapterType } from '@reef-knot/types';
2
2
  export declare const id = "safe";
3
3
  export declare const name = "Safe";
4
4
  export declare const Safe: WalletAdapterType;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,eAAO,MAAM,EAAE,SAAS,CAAC;AACzB,eAAO,MAAM,IAAI,SAAS,CAAC;AAE3B,eAAO,MAAM,IAAI,EAAE,iBAoClB,CAAC"}
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 { SafeConnector } from 'wagmi/connectors/safe';
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
- chains
8
- }) => {
9
- const safeConnector = new SafeConnector({
10
- chains,
11
- options: {
12
- allowedDomains: [/app.safe.global$/, /holesky-safe.protofire.io$/],
13
- debug: false
14
- }
15
- });
16
- return {
17
- walletName: name,
18
- walletId: id,
19
- autoConnectOnly: true,
20
- detector: () => __awaiter(void 0, void 0, void 0, function* () {
21
- // If opened in an iframe. This is an important check for Safe.
22
- // The updated wagmi SafeConnector already has this check, but the currently used SafeConnector for wagmi 0.x hasn't.
23
- if (globalThis.window && globalThis.window.parent !== globalThis.window) {
24
- // The Promise.race is needed to handle regular iframes, not related to Safe,
25
- // because in such iframes Safe SDK Promises can get stuck without resolving,
26
- // so we are using a small timeout for them.
27
- return Promise.race([new Promise(resolve => {
28
- safeConnector.getProvider().then(() => resolve(true)).catch(() => resolve(false));
29
- }), new Promise(resolve => {
30
- setTimeout(() => resolve(false), 200);
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
- connector: safeConnector
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": "1.2.0",
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": "^1.7.0",
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
- "wagmi": "^0.12.19",
41
- "@reef-knot/types": "^1.2.1"
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
  }