@ckb-ccc/connector 0.0.5-alpha.7 → 0.0.5-alpha.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.
@@ -1,5 +1,4 @@
1
1
  export * from "@ckb-ccc/ccc/advancedBarrel";
2
2
  export * from "./scenes";
3
- export * from "./signerOpenLink";
4
3
  export * from "./types";
5
4
  //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -1,4 +1,3 @@
1
1
  export * from "@ckb-ccc/ccc/advancedBarrel";
2
2
  export * from "./scenes";
3
- export * from "./signerOpenLink";
4
3
  export * from "./types";
@@ -5,8 +5,6 @@ export declare class WebComponentConnector extends LitElement {
5
5
  private wallets;
6
6
  signerFilter?: (signerInfo: ccc.SignerInfo, wallet: ccc.Wallet) => Promise<boolean>;
7
7
  private resetListeners;
8
- isOpen: boolean;
9
- setIsOpen(isOpen: boolean): void;
10
8
  name?: string;
11
9
  icon?: string;
12
10
  client: ccc.Client;
@@ -14,6 +12,7 @@ export declare class WebComponentConnector extends LitElement {
14
12
  private scene;
15
13
  private selectedWallet?;
16
14
  private selectedSigner?;
15
+ private connectingError?;
17
16
  private walletName?;
18
17
  private signerName?;
19
18
  wallet?: ccc.Wallet;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG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AAgB,CAAC,CAAS;IAElC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC,OAAO,CAAC,OAAO,CAAC,CAAU;YAEZ,gBAAgB;YAUhB,aAAa;IAYpB,UAAU;IAQjB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAUtB,iBAAiB,IAAI,IAAI;IAMzB,UAAU,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI;IAoCnD,OAAO,CAAC,aAAa;YA2FP,SAAS;IAyCvB,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAC3C,SAAS,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAC7C,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAE3C,MAAM;IA+FN,OAAO;IAUP,OAAO,CAAC,aAAa,CAgBnB;IAEF,OAAO,CAAC,qBAAqB,CAqC3B;IAEF,MAAM,CAAC,MAAM,0BAsPX;CACH"}
@@ -14,11 +14,10 @@ import { LEFT_SVG } from "../assets/left.svg";
14
14
  import { METAMASK_SVG } from "../assets/metamask.svg";
15
15
  import { OKX_SVG } from "../assets/okx.svg";
16
16
  import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
17
- import { WillUpdateEvent } from "../events";
17
+ import { ClosedEvent, WillUpdateEvent } from "../events";
18
18
  import { generateConnectingScene, generateSignersScene, generateWalletsScene, } from "../scenes";
19
19
  import { generateConnectedScene } from "../scenes/connected";
20
20
  import { generateNetworksScene } from "../scenes/networks";
21
- import { SignerOpenLink } from "../signerOpenLink";
22
21
  var Scene;
23
22
  (function (Scene) {
24
23
  Scene["SelectingWallets"] = "SelectingWallets";
@@ -32,7 +31,6 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
32
31
  super(...arguments);
33
32
  this.wallets = [];
34
33
  this.resetListeners = [];
35
- this.isOpen = false;
36
34
  this.client = new ccc.ClientPublicTestnet();
37
35
  this.scene = Scene.SelectingWallets;
38
36
  this.mainRef = createRef();
@@ -51,15 +49,31 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
51
49
  else if ([Scene.SwitchingNetworks].includes(this.scene)) {
52
50
  this.scene = Scene.Connected;
53
51
  }
54
- this.isOpen = false;
52
+ this.dispatchEvent(new ClosedEvent());
55
53
  };
56
54
  this.signerSelectedHandler = (wallet, signerInfo) => {
57
55
  this.scene = Scene.Connecting;
56
+ this.connectingError = undefined;
58
57
  this.selectedWallet = wallet;
59
58
  this.selectedSigner = signerInfo;
60
59
  (async () => {
61
60
  const { signer } = signerInfo;
62
- await signer.connect();
61
+ try {
62
+ await signer.connect();
63
+ }
64
+ catch (error) {
65
+ if (typeof error === "object") {
66
+ const message = error?.message;
67
+ if (typeof message === "string") {
68
+ this.connectingError = message;
69
+ }
70
+ else {
71
+ this.connectingError = JSON.stringify(message);
72
+ }
73
+ return;
74
+ }
75
+ this.connectingError = JSON.stringify(error);
76
+ }
63
77
  if (!(await signer.isConnected())) {
64
78
  return;
65
79
  }
@@ -74,9 +88,6 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
74
88
  })();
75
89
  };
76
90
  }
77
- setIsOpen(isOpen) {
78
- this.isOpen = isOpen;
79
- }
80
91
  setClient(client) {
81
92
  this.client = client;
82
93
  }
@@ -182,13 +193,13 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
182
193
  this.addSigner(`${signer.detail.info.name}`, "EVM", signer.detail.info.icon, signer);
183
194
  }));
184
195
  // === Dummy signers ===
185
- this.addSigner("MetaMask", "EVM", METAMASK_SVG, new SignerOpenLink(this.client, `https://metamask.app.link/dapp/${window.location.href}`, ccc.SignerType.EVM));
196
+ this.addSigner("MetaMask", "EVM", METAMASK_SVG, new ccc.SignerOpenLink(this.client, ccc.SignerType.EVM, `https://metamask.app.link/dapp/${window.location.href}`));
186
197
  [ccc.SignerType.EVM, ccc.SignerType.BTC].forEach((type) => {
187
- this.addSigner("OKX Wallet", type, OKX_SVG, new SignerOpenLink(this.client, "https://www.okx.com/download?deeplink=" +
198
+ this.addSigner("OKX Wallet", type, OKX_SVG, new ccc.SignerOpenLink(this.client, type, "https://www.okx.com/download?deeplink=" +
188
199
  encodeURIComponent("okx://wallet/dapp/url?dappUrl=" +
189
- encodeURIComponent(window.location.href)), type));
200
+ encodeURIComponent(window.location.href))));
190
201
  });
191
- this.addSigner("UniSat", ccc.SignerType.BTC, UNI_SAT_SVG, new SignerOpenLink(this.client, "https://unisat.io/download", ccc.SignerType.BTC));
202
+ this.addSigner("UniSat", ccc.SignerType.BTC, UNI_SAT_SVG, new ccc.SignerOpenLink(this.client, ccc.SignerType.BTC, "https://unisat.io/download"));
192
203
  // ===
193
204
  }
194
205
  async addSigner(walletName, signerName, icon, signer) {
@@ -204,7 +215,7 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
204
215
  }
205
216
  updated = true;
206
217
  const allSigners = [...wallet.signers, signerInfo];
207
- const signers = allSigners.filter(({ signer }) => !(signer instanceof SignerOpenLink));
218
+ const signers = allSigners.filter(({ signer }) => !(signer instanceof ccc.SignerDummy));
208
219
  return {
209
220
  ...wallet,
210
221
  signers: signers.length !== 0 ? signers : [signerInfo],
@@ -241,45 +252,32 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
241
252
  if (this.scene === Scene.SelectingSigners || !this.selectedSigner) {
242
253
  return generateSignersScene(this.selectedWallet, this.signerSelectedHandler);
243
254
  }
244
- return generateConnectingScene(this.selectedWallet, this.selectedSigner, this.signerSelectedHandler);
255
+ return generateConnectingScene(this.selectedWallet, this.selectedSigner, this.connectingError, this.signerSelectedHandler);
245
256
  })();
246
257
  const canBack = [
247
258
  Scene.SelectingSigners,
248
259
  Scene.Connecting,
249
260
  Scene.SwitchingNetworks,
250
261
  ].includes(this.scene);
251
- return html `<style>
252
- :host {
253
- ${this.isOpen ? "" : "display: none;"}
254
- --background: #fff;
255
- --divider: #eee;
256
- --btn-primary: #f8f8f8;
257
- --btn-primary-hover: #efeeee;
258
- --btn-secondary: #ddd;
259
- --btn-secondary-hover: #ccc;
260
- color: #1e1e1e;
261
- --tip-color: #666;
262
- }
263
- </style>
264
- <div
265
- class="background"
266
- @click=${(event) => {
262
+ return html ` <div
263
+ class="background"
264
+ @click=${(event) => {
267
265
  if (event.target === event.currentTarget) {
268
266
  this.closedHandler();
269
267
  }
270
268
  }}
271
- >
272
- <div class="main" ${ref(this.mainRef)}>
273
- <div
274
- class="header text-bold fs-lg ${title == null
269
+ >
270
+ <div class="main" ${ref(this.mainRef)}>
271
+ <div
272
+ class="header text-bold fs-lg ${title == null
275
273
  ? ""
276
274
  : "header-divider"}"
277
- ${ref(this.headerRef)}
278
- >
279
- <img
280
- class="back ${canBack ? "active" : ""}"
281
- src=${LEFT_SVG}
282
- @click=${() => {
275
+ ${ref(this.headerRef)}
276
+ >
277
+ <img
278
+ class="back ${canBack ? "active" : ""}"
279
+ src=${LEFT_SVG}
280
+ @click=${() => {
283
281
  if (this.scene === Scene.Connecting) {
284
282
  if ((this.selectedWallet?.signers.length ?? 0) <= 1) {
285
283
  this.scene = Scene.SelectingWallets;
@@ -295,17 +293,17 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
295
293
  this.scene = Scene.Connected;
296
294
  }
297
295
  }}
298
- />
299
- ${title}
300
- <img
301
- class="close active"
302
- src=${CLOSE_SVG}
303
- @click=${this.closedHandler}
304
- />
305
- </div>
306
- <div class="body" ${ref(this.bodyRef)}>${body}</div>
296
+ />
297
+ ${title}
298
+ <img
299
+ class="close active"
300
+ src=${CLOSE_SVG}
301
+ @click=${this.closedHandler}
302
+ />
307
303
  </div>
308
- </div>`;
304
+ <div class="body" ${ref(this.bodyRef)}>${body}</div>
305
+ </div>
306
+ </div>`;
309
307
  }
310
308
  updated() {
311
309
  if (!this.mainRef.value) {
@@ -568,9 +566,6 @@ __decorate([
568
566
  __decorate([
569
567
  property()
570
568
  ], WebComponentConnector.prototype, "signerFilter", void 0);
571
- __decorate([
572
- state()
573
- ], WebComponentConnector.prototype, "isOpen", void 0);
574
569
  __decorate([
575
570
  property()
576
571
  ], WebComponentConnector.prototype, "name", void 0);
@@ -589,6 +584,9 @@ __decorate([
589
584
  __decorate([
590
585
  state()
591
586
  ], WebComponentConnector.prototype, "selectedSigner", void 0);
587
+ __decorate([
588
+ state()
589
+ ], WebComponentConnector.prototype, "connectingError", void 0);
592
590
  __decorate([
593
591
  state()
594
592
  ], WebComponentConnector.prototype, "walletName", void 0);
@@ -1,4 +1,7 @@
1
1
  export declare class WillUpdateEvent extends Event {
2
2
  constructor();
3
3
  }
4
+ export declare class ClosedEvent extends Event {
5
+ constructor();
6
+ }
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;;CAIzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;;CAIzC;AAED,qBAAa,WAAY,SAAQ,KAAK;;CAIrC"}
@@ -3,3 +3,8 @@ export class WillUpdateEvent extends Event {
3
3
  super("willUpdate", { composed: true });
4
4
  }
5
5
  }
6
+ export class ClosedEvent extends Event {
7
+ constructor() {
8
+ super("closed", { composed: true });
9
+ }
10
+ }
@@ -1,4 +1,4 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
2
  import { WalletWithSigners } from "../types";
3
- export declare function generateConnectingScene(wallet: WalletWithSigners, signer: ccc.SignerInfo, onSignerSelected: (wallet: WalletWithSigners, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
3
+ export declare function generateConnectingScene(wallet: WalletWithSigners, signer: ccc.SignerInfo, error: string | undefined, onSignerSelected: (wallet: WalletWithSigners, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
4
4
  //# sourceMappingURL=connecting.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connecting.d.ts","sourceRoot":"","sources":["../../src/scenes/connecting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,gBAAgB,EAAE,CAChB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDAqBb"}
1
+ {"version":3,"file":"connecting.d.ts","sourceRoot":"","sources":["../../src/scenes/connecting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,gBAAgB,EAAE,CAChB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDA2Bb"}
@@ -1,6 +1,6 @@
1
1
  import { html } from "lit";
2
2
  import { RETRY_SVG } from "../assets/retry.svg";
3
- export function generateConnectingScene(wallet, signer, onSignerSelected) {
3
+ export function generateConnectingScene(wallet, signer, error, onSignerSelected) {
4
4
  return [
5
5
  wallet.name,
6
6
  html `
@@ -9,8 +9,14 @@ export function generateConnectingScene(wallet, signer, onSignerSelected) {
9
9
  src=${wallet.icon}
10
10
  alt=${wallet.name}
11
11
  />
12
- <span class="text-bold">Opening ${wallet.name}...</span>
13
- <span class="text-tip">Confirm connection in the wallet</span>
12
+ <span class="text-bold"
13
+ >${error
14
+ ? `Failed to open ${wallet.name}`
15
+ : `Opening ${wallet.name}...`}</span
16
+ >
17
+ <span class="text-tip text-center"
18
+ >${error ?? "Confirm connection in the wallet"}</span
19
+ >
14
20
  <button
15
21
  class="btn-secondary mt-2 mb-2"
16
22
  @click=${() => onSignerSelected(wallet, signer)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/connector",
3
- "version": "0.0.5-alpha.7",
3
+ "version": "0.0.5-alpha.9",
4
4
  "description": "Common Chains Connector UI",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -37,8 +37,8 @@
37
37
  "access": "public"
38
38
  },
39
39
  "dependencies": {
40
- "@ckb-ccc/ccc": "0.0.5-alpha.7",
40
+ "@ckb-ccc/ccc": "0.0.5-alpha.8",
41
41
  "lit": "^3.1.3"
42
42
  },
43
- "gitHead": "efbdcebedb8375237b3dd98be358ca7df9765cfd"
43
+ "gitHead": "086c38557153da6819615bdc08f80f56b00d79ca"
44
44
  }
@@ -1,4 +1,3 @@
1
1
  export * from "@ckb-ccc/ccc/advancedBarrel";
2
2
  export * from "./scenes";
3
- export * from "./signerOpenLink";
4
3
  export * from "./types";
@@ -8,7 +8,7 @@ import { LEFT_SVG } from "../assets/left.svg";
8
8
  import { METAMASK_SVG } from "../assets/metamask.svg";
9
9
  import { OKX_SVG } from "../assets/okx.svg";
10
10
  import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
11
- import { WillUpdateEvent } from "../events";
11
+ import { ClosedEvent, WillUpdateEvent } from "../events";
12
12
  import {
13
13
  generateConnectingScene,
14
14
  generateSignersScene,
@@ -16,7 +16,6 @@ import {
16
16
  } from "../scenes";
17
17
  import { generateConnectedScene } from "../scenes/connected";
18
18
  import { generateNetworksScene } from "../scenes/networks";
19
- import { SignerOpenLink } from "../signerOpenLink";
20
19
  import { WalletWithSigners } from "../types";
21
20
 
22
21
  enum Scene {
@@ -39,12 +38,6 @@ export class WebComponentConnector extends LitElement {
39
38
 
40
39
  private resetListeners: (() => void)[] = [];
41
40
 
42
- @state()
43
- public isOpen: boolean = false;
44
- public setIsOpen(isOpen: boolean) {
45
- this.isOpen = isOpen;
46
- }
47
-
48
41
  @property()
49
42
  public name?: string;
50
43
  @property()
@@ -62,6 +55,8 @@ export class WebComponentConnector extends LitElement {
62
55
  private selectedWallet?: WalletWithSigners;
63
56
  @state()
64
57
  private selectedSigner?: ccc.SignerInfo;
58
+ @state()
59
+ private connectingError?: string;
65
60
 
66
61
  @state()
67
62
  private walletName?: string;
@@ -229,10 +224,10 @@ export class WebComponentConnector extends LitElement {
229
224
  "MetaMask",
230
225
  "EVM",
231
226
  METAMASK_SVG,
232
- new SignerOpenLink(
227
+ new ccc.SignerOpenLink(
233
228
  this.client,
234
- `https://metamask.app.link/dapp/${window.location.href}`,
235
229
  ccc.SignerType.EVM,
230
+ `https://metamask.app.link/dapp/${window.location.href}`,
236
231
  ),
237
232
  );
238
233
  [ccc.SignerType.EVM, ccc.SignerType.BTC].forEach((type) => {
@@ -240,14 +235,14 @@ export class WebComponentConnector extends LitElement {
240
235
  "OKX Wallet",
241
236
  type,
242
237
  OKX_SVG,
243
- new SignerOpenLink(
238
+ new ccc.SignerOpenLink(
244
239
  this.client,
240
+ type,
245
241
  "https://www.okx.com/download?deeplink=" +
246
242
  encodeURIComponent(
247
243
  "okx://wallet/dapp/url?dappUrl=" +
248
244
  encodeURIComponent(window.location.href),
249
245
  ),
250
- type,
251
246
  ),
252
247
  );
253
248
  });
@@ -255,10 +250,10 @@ export class WebComponentConnector extends LitElement {
255
250
  "UniSat",
256
251
  ccc.SignerType.BTC,
257
252
  UNI_SAT_SVG,
258
- new SignerOpenLink(
253
+ new ccc.SignerOpenLink(
259
254
  this.client,
260
- "https://unisat.io/download",
261
255
  ccc.SignerType.BTC,
256
+ "https://unisat.io/download",
262
257
  ),
263
258
  );
264
259
  // ===
@@ -286,7 +281,7 @@ export class WebComponentConnector extends LitElement {
286
281
  updated = true;
287
282
  const allSigners = [...wallet.signers, signerInfo];
288
283
  const signers = allSigners.filter(
289
- ({ signer }) => !(signer instanceof SignerOpenLink),
284
+ ({ signer }) => !(signer instanceof ccc.SignerDummy),
290
285
  );
291
286
  return {
292
287
  ...wallet,
@@ -349,6 +344,7 @@ export class WebComponentConnector extends LitElement {
349
344
  return generateConnectingScene(
350
345
  this.selectedWallet,
351
346
  this.selectedSigner,
347
+ this.connectingError,
352
348
  this.signerSelectedHandler,
353
349
  );
354
350
  })();
@@ -359,61 +355,48 @@ export class WebComponentConnector extends LitElement {
359
355
  Scene.SwitchingNetworks,
360
356
  ].includes(this.scene);
361
357
 
362
- return html`<style>
363
- :host {
364
- ${this.isOpen ? "" : "display: none;"}
365
- --background: #fff;
366
- --divider: #eee;
367
- --btn-primary: #f8f8f8;
368
- --btn-primary-hover: #efeeee;
369
- --btn-secondary: #ddd;
370
- --btn-secondary-hover: #ccc;
371
- color: #1e1e1e;
372
- --tip-color: #666;
358
+ return html` <div
359
+ class="background"
360
+ @click=${(event: Event) => {
361
+ if (event.target === event.currentTarget) {
362
+ this.closedHandler();
373
363
  }
374
- </style>
375
- <div
376
- class="background"
377
- @click=${(event: Event) => {
378
- if (event.target === event.currentTarget) {
379
- this.closedHandler();
380
- }
381
- }}
382
- >
383
- <div class="main" ${ref(this.mainRef)}>
384
- <div
385
- class="header text-bold fs-lg ${title == null
386
- ? ""
387
- : "header-divider"}"
388
- ${ref(this.headerRef)}
389
- >
390
- <img
391
- class="back ${canBack ? "active" : ""}"
392
- src=${LEFT_SVG}
393
- @click=${() => {
394
- if (this.scene === Scene.Connecting) {
395
- if ((this.selectedWallet?.signers.length ?? 0) <= 1) {
396
- this.scene = Scene.SelectingWallets;
397
- } else {
398
- this.scene = Scene.SelectingSigners;
399
- }
400
- } else if (this.scene === Scene.SelectingSigners) {
364
+ }}
365
+ >
366
+ <div class="main" ${ref(this.mainRef)}>
367
+ <div
368
+ class="header text-bold fs-lg ${title == null
369
+ ? ""
370
+ : "header-divider"}"
371
+ ${ref(this.headerRef)}
372
+ >
373
+ <img
374
+ class="back ${canBack ? "active" : ""}"
375
+ src=${LEFT_SVG}
376
+ @click=${() => {
377
+ if (this.scene === Scene.Connecting) {
378
+ if ((this.selectedWallet?.signers.length ?? 0) <= 1) {
401
379
  this.scene = Scene.SelectingWallets;
402
- } else if (this.scene === Scene.SwitchingNetworks) {
403
- this.scene = Scene.Connected;
380
+ } else {
381
+ this.scene = Scene.SelectingSigners;
404
382
  }
405
- }}
406
- />
407
- ${title}
408
- <img
409
- class="close active"
410
- src=${CLOSE_SVG}
411
- @click=${this.closedHandler}
412
- />
413
- </div>
414
- <div class="body" ${ref(this.bodyRef)}>${body}</div>
383
+ } else if (this.scene === Scene.SelectingSigners) {
384
+ this.scene = Scene.SelectingWallets;
385
+ } else if (this.scene === Scene.SwitchingNetworks) {
386
+ this.scene = Scene.Connected;
387
+ }
388
+ }}
389
+ />
390
+ ${title}
391
+ <img
392
+ class="close active"
393
+ src=${CLOSE_SVG}
394
+ @click=${this.closedHandler}
395
+ />
415
396
  </div>
416
- </div>`;
397
+ <div class="body" ${ref(this.bodyRef)}>${body}</div>
398
+ </div>
399
+ </div>`;
417
400
  }
418
401
 
419
402
  updated() {
@@ -441,7 +424,7 @@ export class WebComponentConnector extends LitElement {
441
424
  this.scene = Scene.Connected;
442
425
  }
443
426
 
444
- this.isOpen = false;
427
+ this.dispatchEvent(new ClosedEvent());
445
428
  };
446
429
 
447
430
  private signerSelectedHandler = (
@@ -449,11 +432,26 @@ export class WebComponentConnector extends LitElement {
449
432
  signerInfo: ccc.SignerInfo,
450
433
  ) => {
451
434
  this.scene = Scene.Connecting;
435
+ this.connectingError = undefined;
452
436
  this.selectedWallet = wallet;
453
437
  this.selectedSigner = signerInfo;
454
438
  (async () => {
455
439
  const { signer } = signerInfo;
456
- await signer.connect();
440
+ try {
441
+ await signer.connect();
442
+ } catch (error) {
443
+ if (typeof error === "object") {
444
+ const message = (error as { message: unknown })?.message;
445
+ if (typeof message === "string") {
446
+ this.connectingError = message;
447
+ } else {
448
+ this.connectingError = JSON.stringify(message);
449
+ }
450
+ return;
451
+ }
452
+
453
+ this.connectingError = JSON.stringify(error);
454
+ }
457
455
  if (!(await signer.isConnected())) {
458
456
  return;
459
457
  }
@@ -3,3 +3,9 @@ export class WillUpdateEvent extends Event {
3
3
  super("willUpdate", { composed: true });
4
4
  }
5
5
  }
6
+
7
+ export class ClosedEvent extends Event {
8
+ constructor() {
9
+ super("closed", { composed: true });
10
+ }
11
+ }
@@ -6,6 +6,7 @@ import { WalletWithSigners } from "../types";
6
6
  export function generateConnectingScene(
7
7
  wallet: WalletWithSigners,
8
8
  signer: ccc.SignerInfo,
9
+ error: string | undefined,
9
10
  onSignerSelected: (
10
11
  wallet: WalletWithSigners,
11
12
  signer: ccc.SignerInfo,
@@ -19,8 +20,14 @@ export function generateConnectingScene(
19
20
  src=${wallet.icon}
20
21
  alt=${wallet.name}
21
22
  />
22
- <span class="text-bold">Opening ${wallet.name}...</span>
23
- <span class="text-tip">Confirm connection in the wallet</span>
23
+ <span class="text-bold"
24
+ >${error
25
+ ? `Failed to open ${wallet.name}`
26
+ : `Opening ${wallet.name}...`}</span
27
+ >
28
+ <span class="text-tip text-center"
29
+ >${error ?? "Confirm connection in the wallet"}</span
30
+ >
24
31
  <button
25
32
  class="btn-secondary mt-2 mb-2"
26
33
  @click=${() => onSignerSelected(wallet, signer)}
@@ -1,13 +0,0 @@
1
- import { ccc } from "@ckb-ccc/ccc";
2
- export declare class SignerOpenLink extends ccc.Signer {
3
- private readonly link;
4
- readonly type: ccc.SignerType;
5
- get signType(): ccc.SignerSignType;
6
- constructor(client: ccc.Client, link: string, type: ccc.SignerType);
7
- replaceClient(client: ccc.Client): Promise<SignerOpenLink>;
8
- isConnected(): Promise<boolean>;
9
- connect(): Promise<void>;
10
- getInternalAddress(): Promise<string>;
11
- getAddressObjs(): Promise<ccc.Address[]>;
12
- }
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signerOpenLink/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,qBAAa,cAAe,SAAQ,GAAG,CAAC,MAAM;IAO1C,OAAO,CAAC,QAAQ,CAAC,IAAI;aACL,IAAI,EAAE,GAAG,CAAC,UAAU;IAPtC,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;gBAGC,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACb,IAAI,EAAE,GAAG,CAAC,UAAU;IAKhC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAI1D,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;CAG/C"}
@@ -1,26 +0,0 @@
1
- import { ccc } from "@ckb-ccc/ccc";
2
- export class SignerOpenLink extends ccc.Signer {
3
- get signType() {
4
- return ccc.SignerSignType.Unknown;
5
- }
6
- constructor(client, link, type) {
7
- super(client);
8
- this.link = link;
9
- this.type = type;
10
- }
11
- async replaceClient(client) {
12
- return new SignerOpenLink(client, this.link, this.type);
13
- }
14
- async isConnected() {
15
- return false;
16
- }
17
- async connect() {
18
- window.open(this.link, "_blank")?.focus();
19
- }
20
- async getInternalAddress() {
21
- throw new Error("Can't get address from SignerOpenLink");
22
- }
23
- async getAddressObjs() {
24
- throw new Error("Can't get addresses from SignerOpenLink");
25
- }
26
- }
@@ -1,35 +0,0 @@
1
- import { ccc } from "@ckb-ccc/ccc";
2
-
3
- export class SignerOpenLink extends ccc.Signer {
4
- get signType(): ccc.SignerSignType {
5
- return ccc.SignerSignType.Unknown;
6
- }
7
-
8
- constructor(
9
- client: ccc.Client,
10
- private readonly link: string,
11
- public readonly type: ccc.SignerType,
12
- ) {
13
- super(client);
14
- }
15
-
16
- async replaceClient(client: ccc.Client): Promise<SignerOpenLink> {
17
- return new SignerOpenLink(client, this.link, this.type);
18
- }
19
-
20
- async isConnected(): Promise<boolean> {
21
- return false;
22
- }
23
-
24
- async connect(): Promise<void> {
25
- window.open(this.link, "_blank")?.focus();
26
- }
27
-
28
- async getInternalAddress(): Promise<string> {
29
- throw new Error("Can't get address from SignerOpenLink");
30
- }
31
-
32
- async getAddressObjs(): Promise<ccc.Address[]> {
33
- throw new Error("Can't get addresses from SignerOpenLink");
34
- }
35
- }