@reef-knot/wallet-adapter-safe 4.2.1 → 5.0.0-alpha.2

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.js CHANGED
@@ -1,75 +1,40 @@
1
- import { __awaiter } from './_virtual/_tslib.js';
2
- import { safe } from 'wagmi/connectors';
3
- import { withTimeout } from 'viem';
1
+ import { safe } from "wagmi/connectors";
2
+ import { withTimeout } from "viem";
4
3
 
5
- const id = 'safe';
6
- const name = 'Safe';
7
- const getSafeConnector = ({
8
- allowedDomains = []
9
- }) => safe({
10
- allowedDomains: [/app.safe.global$/, /app.safe.protofire.io$/, ...allowedDomains],
11
- debug: false
4
+ //#region src/index.ts
5
+ const id = "safe";
6
+ const name = "Safe";
7
+ const getSafeConnector = ({ allowedDomains = [] }) => safe({
8
+ allowedDomains: [
9
+ /app.safe.global$/,
10
+ /app.safe.protofire.io$/,
11
+ ...allowedDomains
12
+ ],
13
+ debug: false
12
14
  });
13
- const Safe = ({
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
- // It is a dependency of @wagmi/connectors
39
- // eslint-disable-next-line import/no-extraneous-dependencies
40
- const {
41
- default: SafeAppsSDK
42
- } = yield import('@safe-global/safe-apps-sdk');
43
- let SDK;
44
- if (typeof SafeAppsSDK !== 'function' && typeof SafeAppsSDK.default === 'function') {
45
- SDK = SafeAppsSDK.default;
46
- } else {
47
- SDK = SafeAppsSDK;
48
- }
49
- const parameters = {
50
- allowedDomains: safeAllowedDomains
51
- };
52
- const sdk = new SDK(parameters);
53
- // `getInfo` hangs when not used in Safe App iFrame
54
- // https://github.com/safe-global/safe-apps-sdk/issues/263#issuecomment-1029835840
55
- const safeSdk = yield withTimeout(() => sdk.safe.getInfo(), {
56
- timeout: 200
57
- });
58
- if (!safeSdk) return false;
59
- // It is a dependency of @wagmi/connectors
60
- // eslint-disable-next-line import/no-extraneous-dependencies
61
- const {
62
- SafeAppProvider
63
- } = yield import('@safe-global/safe-apps-provider');
64
- const provider = new SafeAppProvider(safeSdk, sdk);
65
- return !!provider;
66
- } catch (_b) {
67
- return false;
68
- }
69
- }),
70
- createConnectorFn: getSafeConnector({
71
- allowedDomains: safeAllowedDomains
72
- })
15
+ const Safe = ({ safeAllowedDomains }) => ({
16
+ walletName: name,
17
+ walletId: id,
18
+ type: safe.type,
19
+ autoConnectOnly: true,
20
+ detector: async () => {
21
+ if (!(globalThis.window && globalThis.window?.parent !== globalThis.window)) return false;
22
+ try {
23
+ const { default: SafeAppsSDK } = await import("@safe-global/safe-apps-sdk");
24
+ let SDK;
25
+ if (typeof SafeAppsSDK !== "function" && typeof SafeAppsSDK.default === "function") SDK = SafeAppsSDK.default;
26
+ else SDK = SafeAppsSDK;
27
+ const sdk = new SDK({ allowedDomains: safeAllowedDomains });
28
+ const safeSdk = await withTimeout(() => sdk.safe.getInfo(), { timeout: 200 });
29
+ if (!safeSdk) return false;
30
+ const { SafeAppProvider } = await import("@safe-global/safe-apps-provider");
31
+ return !!new SafeAppProvider(safeSdk, sdk);
32
+ } catch {
33
+ return false;
34
+ }
35
+ },
36
+ createConnectorFn: getSafeConnector({ allowedDomains: safeAllowedDomains })
73
37
  });
74
38
 
75
- export { Safe, id, name };
39
+ //#endregion
40
+ export { Safe, id, name };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/wallet-adapter-safe",
3
- "version": "4.2.1",
3
+ "version": "5.0.0-alpha.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "https://github.com/lidofinance/reef-knot.git",
27
+ "url": "git+https://github.com/lidofinance/reef-knot.git",
28
28
  "directory": "packages/wallets/safe"
29
29
  },
30
30
  "publishConfig": {
@@ -32,19 +32,24 @@
32
32
  "access": "public"
33
33
  },
34
34
  "scripts": {
35
- "build": "rollup -c",
36
- "dev": "dev=on rollup -c -w",
37
- "lint": "eslint --ext ts,tsx,js,mjs ."
35
+ "build": "yarn run -T tsdown",
36
+ "dev": "yarn run -T tsdown --watch",
37
+ "lint": "eslint --ext ts,tsx,js,mjs .",
38
+ "typecheck": "tsc --noEmit"
38
39
  },
39
40
  "devDependencies": {
40
- "@reef-knot/types": "4.2.0",
41
- "@svgr/rollup": "^6.5.1",
41
+ "@reef-knot/types": "5.0.0-alpha.2",
42
+ "@safe-global/safe-apps-provider": "^0.18.6",
43
+ "@safe-global/safe-apps-sdk": "^9.1.0",
44
+ "build-config": "*",
42
45
  "eslint-config-custom": "*"
43
46
  },
44
47
  "peerDependencies": {
45
- "@reef-knot/types": "4.2.0",
48
+ "@reef-knot/types": "5.0.0-alpha.2",
49
+ "@safe-global/safe-apps-provider": "^0.18.6",
50
+ "@safe-global/safe-apps-sdk": "^9.1.0",
46
51
  "@tanstack/react-query": "^5.29.0",
47
- "viem": ">=2.23",
48
- "wagmi": ">=2.14"
52
+ "viem": ">=2.44",
53
+ "wagmi": ">=3.3"
49
54
  }
50
55
  }
@@ -1,33 +0,0 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol */
16
-
17
-
18
- function __awaiter(thisArg, _arguments, P, generator) {
19
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
- return new (P || (P = Promise))(function (resolve, reject) {
21
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
- step((generator = generator.apply(thisArg, _arguments || [])).next());
25
- });
26
- }
27
-
28
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
29
- var e = new Error(message);
30
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
31
- };
32
-
33
- export { __awaiter };