@reef-knot/wallet-adapter-safe 1.1.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.
@@ -0,0 +1,31 @@
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
+
16
+ function __awaiter(thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ }
25
+
26
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
27
+ var e = new Error(message);
28
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
29
+ };
30
+
31
+ export { __awaiter };
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,iBAgBjB,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,24 +1,70 @@
1
- import { SafeConnector } from 'wagmi/connectors/safe';
1
+ import { __awaiter } from './_virtual/_tslib.js';
2
+ import { safe } from 'wagmi/connectors';
3
+ import { withTimeout } from 'viem';
2
4
 
3
5
  const id = 'safe';
4
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
+ });
5
13
  const Safe = ({
6
- chains
14
+ safeAllowedDomains
7
15
  }) => ({
8
16
  walletName: name,
9
17
  walletId: id,
18
+ type: safe.type,
10
19
  autoConnectOnly: true,
11
- detector: () => {
12
- // iframe check
13
- // A more precise check will occur during SafeConnector connection.
14
- return globalThis.window && globalThis.window.parent !== globalThis.window;
15
- },
16
- connector: new SafeConnector({
17
- chains,
18
- options: {
19
- allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/],
20
- debug: false
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;
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) {
63
+ return false;
21
64
  }
65
+ }),
66
+ createConnectorFn: getSafeConnector({
67
+ allowedDomains: safeAllowedDomains
22
68
  })
23
69
  });
24
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reef-knot/wallet-adapter-safe",
3
- "version": "1.1.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.6.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
  }