@tomo-inc/embedded-wallet-providers 0.0.7 → 0.0.9

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.cjs CHANGED
@@ -32,7 +32,8 @@ var dogeDappPopups = {
32
32
  requestTransaction: "/dapp-doge/tx-send",
33
33
  requestAvailableDRC20Transaction: "/dapp-doge/drc20-inscribe",
34
34
  requestInscriptionTransaction: "/dapp-doge/drc20-tx",
35
- requestDunesTransaction: "/dapp-doge/dunes-tx"
35
+ requestDunesTransaction: "/dapp-doge/dunes-tx",
36
+ sendDogecoin: "/dapp-doge/tx-send"
36
37
  };
37
38
  var solanaDappPopups = {
38
39
  connect: "/dapp/connect",
@@ -157,11 +158,20 @@ var EmbeddedWallet = class _EmbeddedWallet {
157
158
  this.maskZIndex = 999;
158
159
  this.loginByGoogle = null;
159
160
  this.loginByX = null;
161
+ this.loginStatusCallback = null;
160
162
  this.walletCloseHandler = ({ origin, data }) => {
161
163
  if ((data == null ? void 0 : data.type) === "wallet-close" && origin === this.walletOrigin) {
162
164
  this.close();
163
165
  }
164
166
  };
167
+ this.logoutListener = ({ origin, data }) => {
168
+ if ((data == null ? void 0 : data.type) === "wallet-response" && origin === this.walletOrigin && (data == null ? void 0 : data.method) === "logout") {
169
+ this.logout();
170
+ if (this.loginStatusCallback) {
171
+ this == null ? void 0 : this.loginStatusCallback({ type: "logout" });
172
+ }
173
+ }
174
+ };
165
175
  }
166
176
  static getInstance() {
167
177
  if (!_EmbeddedWallet.instance) {
@@ -254,6 +264,9 @@ var EmbeddedWallet = class _EmbeddedWallet {
254
264
  if ((data == null ? void 0 : data.type) === "wallet-ready" && origin === this.walletOrigin) {
255
265
  this.isAvailable = ((_a = data == null ? void 0 : data.data) == null ? void 0 : _a.isAvailable) || false;
256
266
  resolve(data == null ? void 0 : data.data);
267
+ if (this.loginStatusCallback) {
268
+ this == null ? void 0 : this.loginStatusCallback({ type: "login" });
269
+ }
257
270
  window.removeEventListener("message", receiveResponse);
258
271
  }
259
272
  if ((data == null ? void 0 : data.type) === "wallet-close" && origin === this.walletOrigin) {
@@ -287,6 +300,7 @@ var EmbeddedWallet = class _EmbeddedWallet {
287
300
  this.walletIframe.src = `${this.walletOrigin}#logout=true`;
288
301
  }
289
302
  window.removeEventListener("message", this.walletCloseHandler);
303
+ window.removeEventListener("message", this.logoutListener);
290
304
  this.request("logout");
291
305
  return true;
292
306
  }
@@ -335,6 +349,10 @@ var EmbeddedWallet = class _EmbeddedWallet {
335
349
  window.addEventListener("message", receiveResponse);
336
350
  });
337
351
  }
352
+ onLoginStatusChanged(callback) {
353
+ this.loginStatusCallback = callback;
354
+ window.addEventListener("message", this.logoutListener);
355
+ }
338
356
  /**
339
357
  * wallet features page
340
358
  */
package/dist/index.d.cts CHANGED
@@ -39,6 +39,9 @@ declare class EmbeddedWallet {
39
39
  private static instance;
40
40
  loginByGoogle: (() => Promise<string>) | null;
41
41
  loginByX: (() => Promise<string>) | null;
42
+ loginStatusCallback: (({ type }: {
43
+ type: string;
44
+ }) => void) | null;
42
45
  constructor();
43
46
  static getInstance(): EmbeddedWallet;
44
47
  init(config: InitConfig): Promise<{
@@ -68,11 +71,15 @@ declare class EmbeddedWallet {
68
71
  loginByEmail({ email }: {
69
72
  email?: string;
70
73
  }): Promise<string>;
74
+ private logoutListener;
71
75
  /**
72
76
  * wallet feature apis
73
77
  * wallet action without user approve
74
78
  */
75
79
  request(method: WalletRequestMethod, params?: any): Promise<any>;
80
+ onLoginStatusChanged(callback: ({ type }: {
81
+ type: string;
82
+ }) => void): void;
76
83
  /**
77
84
  * wallet features page
78
85
  */
package/dist/index.d.ts CHANGED
@@ -39,6 +39,9 @@ declare class EmbeddedWallet {
39
39
  private static instance;
40
40
  loginByGoogle: (() => Promise<string>) | null;
41
41
  loginByX: (() => Promise<string>) | null;
42
+ loginStatusCallback: (({ type }: {
43
+ type: string;
44
+ }) => void) | null;
42
45
  constructor();
43
46
  static getInstance(): EmbeddedWallet;
44
47
  init(config: InitConfig): Promise<{
@@ -68,11 +71,15 @@ declare class EmbeddedWallet {
68
71
  loginByEmail({ email }: {
69
72
  email?: string;
70
73
  }): Promise<string>;
74
+ private logoutListener;
71
75
  /**
72
76
  * wallet feature apis
73
77
  * wallet action without user approve
74
78
  */
75
79
  request(method: WalletRequestMethod, params?: any): Promise<any>;
80
+ onLoginStatusChanged(callback: ({ type }: {
81
+ type: string;
82
+ }) => void): void;
76
83
  /**
77
84
  * wallet features page
78
85
  */
package/dist/index.js CHANGED
@@ -30,7 +30,8 @@ var dogeDappPopups = {
30
30
  requestTransaction: "/dapp-doge/tx-send",
31
31
  requestAvailableDRC20Transaction: "/dapp-doge/drc20-inscribe",
32
32
  requestInscriptionTransaction: "/dapp-doge/drc20-tx",
33
- requestDunesTransaction: "/dapp-doge/dunes-tx"
33
+ requestDunesTransaction: "/dapp-doge/dunes-tx",
34
+ sendDogecoin: "/dapp-doge/tx-send"
34
35
  };
35
36
  var solanaDappPopups = {
36
37
  connect: "/dapp/connect",
@@ -155,11 +156,20 @@ var EmbeddedWallet = class _EmbeddedWallet {
155
156
  this.maskZIndex = 999;
156
157
  this.loginByGoogle = null;
157
158
  this.loginByX = null;
159
+ this.loginStatusCallback = null;
158
160
  this.walletCloseHandler = ({ origin, data }) => {
159
161
  if ((data == null ? void 0 : data.type) === "wallet-close" && origin === this.walletOrigin) {
160
162
  this.close();
161
163
  }
162
164
  };
165
+ this.logoutListener = ({ origin, data }) => {
166
+ if ((data == null ? void 0 : data.type) === "wallet-response" && origin === this.walletOrigin && (data == null ? void 0 : data.method) === "logout") {
167
+ this.logout();
168
+ if (this.loginStatusCallback) {
169
+ this == null ? void 0 : this.loginStatusCallback({ type: "logout" });
170
+ }
171
+ }
172
+ };
163
173
  }
164
174
  static getInstance() {
165
175
  if (!_EmbeddedWallet.instance) {
@@ -252,6 +262,9 @@ var EmbeddedWallet = class _EmbeddedWallet {
252
262
  if ((data == null ? void 0 : data.type) === "wallet-ready" && origin === this.walletOrigin) {
253
263
  this.isAvailable = ((_a = data == null ? void 0 : data.data) == null ? void 0 : _a.isAvailable) || false;
254
264
  resolve(data == null ? void 0 : data.data);
265
+ if (this.loginStatusCallback) {
266
+ this == null ? void 0 : this.loginStatusCallback({ type: "login" });
267
+ }
255
268
  window.removeEventListener("message", receiveResponse);
256
269
  }
257
270
  if ((data == null ? void 0 : data.type) === "wallet-close" && origin === this.walletOrigin) {
@@ -285,6 +298,7 @@ var EmbeddedWallet = class _EmbeddedWallet {
285
298
  this.walletIframe.src = `${this.walletOrigin}#logout=true`;
286
299
  }
287
300
  window.removeEventListener("message", this.walletCloseHandler);
301
+ window.removeEventListener("message", this.logoutListener);
288
302
  this.request("logout");
289
303
  return true;
290
304
  }
@@ -333,6 +347,10 @@ var EmbeddedWallet = class _EmbeddedWallet {
333
347
  window.addEventListener("message", receiveResponse);
334
348
  });
335
349
  }
350
+ onLoginStatusChanged(callback) {
351
+ this.loginStatusCallback = callback;
352
+ window.addEventListener("message", this.logoutListener);
353
+ }
336
354
  /**
337
355
  * wallet features page
338
356
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/embedded-wallet-providers",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -16,9 +16,9 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@tomo-inc/oidc-auth": "0.0.7",
20
- "@tomo-inc/wallet-utils": "0.0.7",
21
- "@tomo-inc/inject-providers": "0.0.5"
19
+ "@tomo-inc/oidc-auth": "0.0.9",
20
+ "@tomo-inc/wallet-utils": "0.0.9",
21
+ "@tomo-inc/inject-providers": "0.0.7"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^20.0.0",
@@ -20,6 +20,7 @@ export class EmbeddedWallet {
20
20
  private static instance: EmbeddedWallet;
21
21
  public loginByGoogle: (() => Promise<string>) | null = null;
22
22
  public loginByX: (() => Promise<string>) | null = null;
23
+ public loginStatusCallback: (({ type }: { type: string }) => void) | null = null;
23
24
  public constructor() {}
24
25
 
25
26
  public static getInstance() {
@@ -128,6 +129,9 @@ export class EmbeddedWallet {
128
129
  if (data?.type === "wallet-ready" && origin === this.walletOrigin) {
129
130
  this.isAvailable = data?.data?.isAvailable || false;
130
131
  resolve(data?.data);
132
+ if (this.loginStatusCallback) {
133
+ this?.loginStatusCallback({ type: "login" });
134
+ }
131
135
  window.removeEventListener("message", receiveResponse);
132
136
  }
133
137
  if (data?.type === "wallet-close" && origin === this.walletOrigin) {
@@ -178,6 +182,7 @@ export class EmbeddedWallet {
178
182
  this.walletIframe.src = `${this.walletOrigin}#logout=true`;
179
183
  }
180
184
  window.removeEventListener("message", this.walletCloseHandler);
185
+ window.removeEventListener("message", this.logoutListener);
181
186
  this.request("logout");
182
187
  return true;
183
188
  }
@@ -212,6 +217,15 @@ export class EmbeddedWallet {
212
217
  });
213
218
  }
214
219
 
220
+ private logoutListener = ({ origin, data }: { origin: string; data: any }) => {
221
+ if (data?.type === "wallet-response" && origin === this.walletOrigin && data?.method === "logout") {
222
+ this.logout();
223
+ if (this.loginStatusCallback) {
224
+ this?.loginStatusCallback({ type: "logout" });
225
+ }
226
+ }
227
+ };
228
+
215
229
  /**
216
230
  * wallet feature apis
217
231
  * wallet action without user approve
@@ -232,6 +246,11 @@ export class EmbeddedWallet {
232
246
  });
233
247
  }
234
248
 
249
+ public onLoginStatusChanged(callback: ({ type }: { type: string }) => void) {
250
+ this.loginStatusCallback = callback;
251
+ window.addEventListener("message", this.logoutListener);
252
+ }
253
+
235
254
  /**
236
255
  * wallet features page
237
256
  */
@@ -35,6 +35,7 @@ const dogeDappPopups = {
35
35
  requestAvailableDRC20Transaction: "/dapp-doge/drc20-inscribe",
36
36
  requestInscriptionTransaction: "/dapp-doge/drc20-tx",
37
37
  requestDunesTransaction: "/dapp-doge/dunes-tx",
38
+ sendDogecoin: "/dapp-doge/tx-send",
38
39
  };
39
40
 
40
41
  const solanaDappPopups = {
@@ -101,4 +102,4 @@ const dappPopups = {
101
102
  shop: shopDappPopups,
102
103
  };
103
104
 
104
- export { dappPopups, evmDappPopups, dogeDappPopups, solanaDappPopups, tronDappPopups, shopDappPopups, btcDappPopups };
105
+ export { btcDappPopups, dappPopups, dogeDappPopups, evmDappPopups, shopDappPopups, solanaDappPopups, tronDappPopups };