@cartridge/controller 0.7.13 → 0.7.14-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cartridge/controller",
3
- "version": "0.7.13",
3
+ "version": "0.7.14-alpha.0",
4
4
  "description": "Cartridge Controller",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,8 +36,8 @@
36
36
  "cbor-x": "^1.5.0",
37
37
  "mipd": "^0.0.7",
38
38
  "@walletconnect/ethereum-provider": "^2.20.0",
39
- "@cartridge/account-wasm": "0.7.13",
40
- "@cartridge/utils": "0.7.13"
39
+ "@cartridge/account-wasm": "0.7.14-alpha.0",
40
+ "@cartridge/utils": "0.7.14-alpha.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/jest": "^29.5.14",
@@ -53,7 +53,7 @@
53
53
  "vite-plugin-node-polyfills": "^0.22.0",
54
54
  "vite-plugin-top-level-await": "^1.4.4",
55
55
  "vite-plugin-wasm": "^3.4.1",
56
- "@cartridge/tsconfig": "0.7.13"
56
+ "@cartridge/tsconfig": "0.7.14-alpha.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build:deps": "pnpm build",
package/src/controller.ts CHANGED
@@ -116,7 +116,7 @@ export default class ControllerProvider extends BaseProvider {
116
116
  return;
117
117
  }
118
118
 
119
- if (!!document.hasStorageAccess) {
119
+ if (typeof document !== "undefined" && !!document.hasStorageAccess) {
120
120
  const ok = await document.hasStorageAccess();
121
121
  if (!ok) {
122
122
  await document.requestStorageAccess();
@@ -187,7 +187,7 @@ export default class ControllerProvider extends BaseProvider {
187
187
  return;
188
188
  }
189
189
 
190
- if (!!document.hasStorageAccess) {
190
+ if (typeof document !== "undefined" && !!document.hasStorageAccess) {
191
191
  const ok = await document.hasStorageAccess();
192
192
  if (!ok) {
193
193
  await document.requestStorageAccess();
@@ -29,7 +29,7 @@ export class IFrame<CallSender extends {}> implements Modal {
29
29
  onConnect: (child: AsyncMethodReturns<CallSender>) => void;
30
30
  methods?: { [key: string]: (...args: any[]) => void };
31
31
  }) {
32
- if (typeof document === "undefined") {
32
+ if (typeof document === "undefined" || typeof window === "undefined") {
33
33
  return;
34
34
  }
35
35
 
@@ -91,7 +91,9 @@ export class IFrame<CallSender extends {}> implements Modal {
91
91
  container.style.opacity = "0";
92
92
  }
93
93
  });
94
- document.body.style.overflow = "auto";
94
+ if (document.body) {
95
+ document.body.style.overflow = "auto";
96
+ }
95
97
  },
96
98
  reload: (_origin: string) => () => window.location.reload(),
97
99
  ...methods,
@@ -102,6 +104,7 @@ export class IFrame<CallSender extends {}> implements Modal {
102
104
  window.addEventListener("resize", () => this.resize());
103
105
 
104
106
  const observer = new MutationObserver(() => {
107
+ if (typeof document === "undefined") return;
105
108
  const existingController = document.getElementById("controller");
106
109
  if (document.body) {
107
110
  if (
@@ -133,7 +136,8 @@ export class IFrame<CallSender extends {}> implements Modal {
133
136
  }
134
137
 
135
138
  open() {
136
- if (!this.container) return;
139
+ if (!this.container || typeof document === "undefined" || !document.body)
140
+ return;
137
141
  document.body.style.overflow = "hidden";
138
142
 
139
143
  this.container.style.visibility = "visible";
@@ -141,7 +145,8 @@ export class IFrame<CallSender extends {}> implements Modal {
141
145
  }
142
146
 
143
147
  close() {
144
- if (!this.container) return;
148
+ if (!this.container || typeof document === "undefined" || !document.body)
149
+ return;
145
150
  this.onClose?.();
146
151
 
147
152
  document.body.style.overflow = "auto";
@@ -161,7 +166,7 @@ export class IFrame<CallSender extends {}> implements Modal {
161
166
  }
162
167
 
163
168
  private resize() {
164
- if (!this.iframe) return;
169
+ if (!this.iframe || typeof window === "undefined") return;
165
170
 
166
171
  this.iframe.style.userSelect = "none";
167
172
 
@@ -20,7 +20,7 @@ export class MetaMaskWallet implements WalletAdapter {
20
20
  this.MMSDK = new MetaMaskSDK({
21
21
  dappMetadata: {
22
22
  name: "Cartridge Controller",
23
- url: window.location.href,
23
+ url: typeof window !== "undefined" ? window.location.href : "",
24
24
  },
25
25
  });
26
26
  if (this.isAvailable()) {
@@ -40,7 +40,7 @@ export class RabbyWallet implements WalletAdapter {
40
40
  }
41
41
 
42
42
  isAvailable(): boolean {
43
- return !!this.provider;
43
+ return typeof window !== "undefined" && !!this.provider;
44
44
  }
45
45
 
46
46
  getInfo(): ExternalWallet {
@@ -25,7 +25,7 @@ export class WalletConnectWallet implements WalletAdapter {
25
25
  }
26
26
 
27
27
  isAvailable(): boolean {
28
- return !!this.provider;
28
+ return typeof window !== "undefined" && !!this.provider;
29
29
  }
30
30
 
31
31
  getInfo(): ExternalWallet {