@ckb-ccc/connector 0.0.4-alpha.1 → 0.0.4-alpha.11

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/README.md CHANGED
@@ -1,12 +1,17 @@
1
- <h1 align="center" style="font-size: 64px;">
2
- CCC
1
+ <h1 align="center" style="font-size: 48px;">
2
+ CCC Connector
3
3
  </h1>
4
4
 
5
5
  <p align="center">
6
- <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc">
7
- <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master">
8
- <img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production">
9
- <img alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fckbccc-demo.vercel.app%2F&label=Demo">
6
+ <a href="https://www.npmjs.com/package/@ckb-ccc/connector"><img
7
+ alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fconnector"
8
+ /></a>
9
+ <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
10
+ <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
11
+ <img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production" />
12
+ <a href="https://ckbccc-demo.vercel.app/"><img
13
+ alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fckbccc-demo.vercel.app%2F&label=Demo"
14
+ /></a>
10
15
  </p>
11
16
 
12
17
  <p align="center">
@@ -29,4 +34,4 @@ This project is still under active development, and we are looking forward to yo
29
34
 
30
35
  <h3 align="center">
31
36
  Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
32
- </h3>
37
+ </h3>
@@ -1,3 +1,4 @@
1
1
  export * from "@ckb-ccc/ccc/advancedBarrel";
2
2
  export * from "./scenes";
3
+ export * from "./types";
3
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"}
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,2 +1,3 @@
1
1
  export * from "@ckb-ccc/ccc/advancedBarrel";
2
2
  export * from "./scenes";
3
+ export * from "./types";
@@ -1,17 +1,22 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
- import { LitElement } from "lit";
2
+ import { LitElement, PropertyValues } from "lit";
3
3
  import { ConnectorStatus } from "../status";
4
4
  export declare class WebComponentConnector extends LitElement {
5
5
  private wallets;
6
- private existedEip6963;
6
+ private resetListeners;
7
7
  isOpen: boolean;
8
+ client: ccc.Client;
8
9
  wallet?: ccc.Wallet;
9
10
  signer?: ccc.SignerInfo;
10
11
  status: ConnectorStatus;
11
12
  connectedCallback(): void;
13
+ willUpdate(changedProperties: PropertyValues<this>): void;
14
+ refreshSigners(): void;
15
+ reset(): void;
12
16
  addSigner(name: string, icon: string, type: ccc.SignerType, signer: ccc.Signer): void;
13
17
  render(): import("lit").TemplateResult<1>;
14
18
  private onClose;
19
+ private onReset;
15
20
  private onWalletSelected;
16
21
  private onSignerSelected;
17
22
  static styles: import("lit").CSSResult;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAW5C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,cAAc,CAAgB;IAG/B,MAAM,EAAE,OAAO,CAAS;IAGxB,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAEpB,MAAM,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IAExB,MAAM,EAAE,eAAe,CAAmC;IAEjE,iBAAiB,IAAI,IAAI;IAkCzB,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,MAAM,EAAE,GAAG,CAAC,MAAM;IAkBpB,MAAM;IAmDN,OAAO,CAAC,OAAO,CAGb;IAEF,OAAO,CAAC,gBAAgB,CAEtB;IAEF,OAAO,CAAC,gBAAgB,CAStB;IAEF,MAAM,CAAC,MAAM,0BAqIX;CACH"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAa,MAAM,KAAK,CAAC;AAW5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG5C,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAA2B;IAE1C,OAAO,CAAC,cAAc,CAAsB;IAGrC,MAAM,EAAE,OAAO,CAAS;IAGxB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAiC;IAEnD,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAEpB,MAAM,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IAExB,MAAM,EAAE,eAAe,CAAmC;IAEjE,iBAAiB,IAAI,IAAI;IAKzB,UAAU,CAAC,iBAAiB,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IAOzD,cAAc;IA6Bd,KAAK;IAwBL,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,MAAM,EAAE,GAAG,CAAC,MAAM;IAkBpB,MAAM;IAyDN,OAAO,CAAC,OAAO,CAKb;IAEF,OAAO,CAAC,OAAO,CAGb;IAEF,OAAO,CAAC,gBAAgB,CAEtB;IAEF,OAAO,CAAC,gBAAgB,CAetB;IAEF,MAAM,CAAC,MAAM,0BAqIX;CACH"}
@@ -17,21 +17,30 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
17
17
  constructor() {
18
18
  super(...arguments);
19
19
  this.wallets = [];
20
- this.existedEip6963 = [];
20
+ this.resetListeners = [];
21
21
  this.isOpen = false;
22
+ this.client = new ccc.ClientPublicTestnet();
22
23
  this.status = ConnectorStatus.SelectingSigner;
23
24
  this.onClose = () => {
24
- this.dispatchEvent(new SignerChangedEvent());
25
+ if (this.status === ConnectorStatus.SelectingSigner) {
26
+ this.onReset();
27
+ }
25
28
  this.dispatchEvent(new CloseEvent());
26
29
  };
30
+ this.onReset = () => {
31
+ this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.SelectingSigner));
32
+ this.dispatchEvent(new SignerChangedEvent());
33
+ };
27
34
  this.onWalletSelected = (wallet) => {
28
35
  this.dispatchEvent(new SignerChangedEvent(wallet, this.signer));
29
36
  };
30
37
  this.onSignerSelected = (wallet, signer) => {
31
- this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.Connecting));
32
- this.dispatchEvent(new SignerChangedEvent(wallet, signer));
33
38
  (async () => {
34
- await signer.signer.connect();
39
+ this.dispatchEvent(new SignerChangedEvent(wallet, signer));
40
+ if (!(await signer.signer.isConnected())) {
41
+ this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.Connecting));
42
+ await signer.signer.connect();
43
+ }
35
44
  this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.Idle));
36
45
  this.dispatchEvent(new CloseEvent());
37
46
  })();
@@ -39,23 +48,48 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
39
48
  }
40
49
  connectedCallback() {
41
50
  super.connectedCallback();
42
- const client = new ccc.ClientPublicTestnet();
43
- const uniSatSigner = ccc.UniSat.getUniSatSigner(client);
51
+ this.refreshSigners();
52
+ }
53
+ willUpdate(changedProperties) {
54
+ if (changedProperties.get("client")) {
55
+ this.reset();
56
+ this.refreshSigners();
57
+ }
58
+ }
59
+ refreshSigners() {
60
+ const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
44
61
  if (uniSatSigner) {
45
62
  this.addSigner("UniSat", UNI_SAT_SVG, ccc.SignerType.BTC, uniSatSigner);
46
63
  }
47
- const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(client);
64
+ const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
48
65
  if (okxBitcoinSigner) {
49
66
  this.addSigner("OKX Wallet", OKX_SVG, ccc.SignerType.BTC, okxBitcoinSigner);
50
67
  }
51
- const eip6963Manager = new ccc.Eip6963.SignerFactory(client);
52
- eip6963Manager.subscribeSigners((signer) => {
53
- if (this.existedEip6963.indexOf(signer.detail.info.uuid) !== -1) {
68
+ const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
69
+ this.resetListeners.push(eip6963Manager.subscribeSigners((signer) => {
70
+ this.addSigner(`${signer.detail.info.name}`, signer.detail.info.icon, ccc.SignerType.EVM, signer);
71
+ }));
72
+ }
73
+ reset() {
74
+ this.wallets = [];
75
+ (async () => {
76
+ if (!this.signer) {
54
77
  return;
55
78
  }
56
- this.existedEip6963.push(signer.detail.info.uuid);
57
- this.addSigner(`${signer.detail.info.name}`, signer.detail.info.icon, ccc.SignerType.EVM, signer);
58
- });
79
+ const newSigner = await this.signer.signer.replaceClient(this.client);
80
+ if (newSigner) {
81
+ this.onSignerSelected(this.wallet, {
82
+ ...this.signer,
83
+ signer: newSigner,
84
+ });
85
+ }
86
+ else {
87
+ this.onReset();
88
+ }
89
+ })();
90
+ const resetListeners = this.resetListeners;
91
+ this.resetListeners = [];
92
+ resetListeners.forEach((listener) => listener());
59
93
  }
60
94
  addSigner(name, icon, type, signer) {
61
95
  const wallet = this.wallets.find((wallet) => wallet.name === name);
@@ -76,13 +110,14 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
76
110
  }
77
111
  render() {
78
112
  const [title, body] = (() => {
79
- if (!this.wallet) {
113
+ const wallet = ccc.apply((wallet) => this.wallets.find((w) => w.name === wallet.name), this.wallet);
114
+ if (!wallet) {
80
115
  return generateWalletsScene(this.wallets, this.onWalletSelected, this.onSignerSelected);
81
116
  }
82
117
  if (!this.signer) {
83
- return generateSignersScene(this.wallet, this.onSignerSelected);
118
+ return generateSignersScene(wallet, this.onSignerSelected);
84
119
  }
85
- return generateConnectingScene(this.wallet, this.signer, this.onSignerSelected);
120
+ return generateConnectingScene(wallet, this.signer, this.onSignerSelected);
86
121
  })();
87
122
  return html `<style>
88
123
  :host {
@@ -256,6 +291,9 @@ __decorate([
256
291
  __decorate([
257
292
  property()
258
293
  ], WebComponentConnector.prototype, "isOpen", void 0);
294
+ __decorate([
295
+ property()
296
+ ], WebComponentConnector.prototype, "client", void 0);
259
297
  __decorate([
260
298
  property()
261
299
  ], WebComponentConnector.prototype, "wallet", void 0);
@@ -1,3 +1,3 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
- export declare function generateConnectingScene(wallet: ccc.Wallet, signer: ccc.SignerInfo, onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
2
+ export declare function generateConnectingScene(wallet: ccc.Wallet, signer: ccc.SignerInfo, onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
3
3
  //# 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;AAInC,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,OAAO,gDAqB1E"}
1
+ {"version":3,"file":"connecting.d.ts","sourceRoot":"","sources":["../../src/scenes/connecting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,OAAO,gDAqBtF"}
@@ -1,4 +1,5 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
+ import { WalletWithSigners } from "../types";
2
3
  export declare function signerTypeToIcon(type: ccc.SignerType): string;
3
- export declare function generateSignersScene(wallet: ccc.Wallet, onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
4
+ export declare function generateSignersScene(wallet: WalletWithSigners, onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
4
5
  //# sourceMappingURL=signers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signers.d.ts","sourceRoot":"","sources":["../../src/scenes/signers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAKnC,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,CAK7D;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,OAAO,gDAyB1E"}
1
+ {"version":3,"file":"signers.d.ts","sourceRoot":"","sources":["../../src/scenes/signers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,CAK7D;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,EACzB,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,OAAO,gDAyBtF"}
@@ -1,3 +1,4 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
- export declare function generateWalletsScene(wallets: ccc.Wallet[], onWalletSelected: (wallet: ccc.Wallet) => unknown, onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown): unknown[];
2
+ import { WalletWithSigners } from "../types";
3
+ export declare function generateWalletsScene(wallets: WalletWithSigners[], onWalletSelected: (wallet: ccc.Wallet) => unknown, onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown): unknown[];
3
4
  //# sourceMappingURL=wallets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/scenes/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,EACrB,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,OAAO,EACjD,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,OAAO,aAwB1E"}
1
+ {"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/scenes/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,iBAAiB,EAAE,EAC5B,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,OAAO,EACjD,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,OAAO,aAwBtF"}
@@ -0,0 +1,5 @@
1
+ import { ccc } from "@ckb-ccc/ccc";
2
+ export type WalletWithSigners = ccc.Wallet & {
3
+ signers: ccc.SignerInfo[];
4
+ };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,GAAG;IAC3C,OAAO,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;CAC3B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/connector",
3
- "version": "0.0.4-alpha.1",
3
+ "version": "0.0.4-alpha.11",
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.4-alpha.1",
40
+ "@ckb-ccc/ccc": "0.0.4-alpha.11",
41
41
  "lit": "^3.1.3"
42
42
  },
43
- "gitHead": "7dab1a1d6e3e380b26f43d0d0308bd4da1617029"
43
+ "gitHead": "db0297c0753349e2650d2845f42f546316078d5d"
44
44
  }
@@ -1,2 +1,3 @@
1
1
  export * from "@ckb-ccc/ccc/advancedBarrel";
2
2
  export * from "./scenes";
3
+ export * from "./types";
@@ -1,5 +1,5 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
- import { LitElement, css, html } from "lit";
2
+ import { LitElement, PropertyValues, css, html } from "lit";
3
3
  import { customElement, property, state } from "lit/decorators.js";
4
4
  import { CLOSE_SVG } from "../assets/close.svg";
5
5
  import { OKX_SVG } from "../assets/okx.svg";
@@ -11,16 +11,20 @@ import {
11
11
  generateWalletsScene,
12
12
  } from "../scenes";
13
13
  import { ConnectorStatus } from "../status";
14
+ import { WalletWithSigners } from "../types";
14
15
 
15
16
  @customElement("ccc-connector")
16
17
  export class WebComponentConnector extends LitElement {
17
18
  @state()
18
- private wallets: ccc.Wallet[] = [];
19
- private existedEip6963: string[] = [];
19
+ private wallets: WalletWithSigners[] = [];
20
+
21
+ private resetListeners: (() => void)[] = [];
20
22
 
21
23
  @property()
22
24
  public isOpen: boolean = false;
23
25
 
26
+ @property()
27
+ public client: ccc.Client = new ccc.ClientPublicTestnet();
24
28
  @property()
25
29
  public wallet?: ccc.Wallet;
26
30
  @property()
@@ -30,14 +34,23 @@ export class WebComponentConnector extends LitElement {
30
34
 
31
35
  connectedCallback(): void {
32
36
  super.connectedCallback();
37
+ this.refreshSigners();
38
+ }
39
+
40
+ willUpdate(changedProperties: PropertyValues<this>): void {
41
+ if (changedProperties.get("client")) {
42
+ this.reset();
43
+ this.refreshSigners();
44
+ }
45
+ }
33
46
 
34
- const client = new ccc.ClientPublicTestnet();
35
- const uniSatSigner = ccc.UniSat.getUniSatSigner(client);
47
+ refreshSigners() {
48
+ const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
36
49
  if (uniSatSigner) {
37
50
  this.addSigner("UniSat", UNI_SAT_SVG, ccc.SignerType.BTC, uniSatSigner);
38
51
  }
39
52
 
40
- const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(client);
53
+ const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
41
54
  if (okxBitcoinSigner) {
42
55
  this.addSigner(
43
56
  "OKX Wallet",
@@ -47,19 +60,41 @@ export class WebComponentConnector extends LitElement {
47
60
  );
48
61
  }
49
62
 
50
- const eip6963Manager = new ccc.Eip6963.SignerFactory(client);
51
- eip6963Manager.subscribeSigners((signer) => {
52
- if (this.existedEip6963.indexOf(signer.detail.info.uuid) !== -1) {
63
+ const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
64
+ this.resetListeners.push(
65
+ eip6963Manager.subscribeSigners((signer) => {
66
+ this.addSigner(
67
+ `${signer.detail.info.name}`,
68
+ signer.detail.info.icon,
69
+ ccc.SignerType.EVM,
70
+ signer,
71
+ );
72
+ }),
73
+ );
74
+ }
75
+
76
+ reset() {
77
+ this.wallets = [];
78
+
79
+ (async () => {
80
+ if (!this.signer) {
53
81
  return;
54
82
  }
55
- this.existedEip6963.push(signer.detail.info.uuid);
56
- this.addSigner(
57
- `${signer.detail.info.name}`,
58
- signer.detail.info.icon,
59
- ccc.SignerType.EVM,
60
- signer,
61
- );
62
- });
83
+
84
+ const newSigner = await this.signer.signer.replaceClient(this.client);
85
+ if (newSigner) {
86
+ this.onSignerSelected(this.wallet, {
87
+ ...this.signer,
88
+ signer: newSigner,
89
+ });
90
+ } else {
91
+ this.onReset();
92
+ }
93
+ })();
94
+
95
+ const resetListeners = this.resetListeners;
96
+ this.resetListeners = [];
97
+ resetListeners.forEach((listener) => listener());
63
98
  }
64
99
 
65
100
  addSigner(
@@ -86,7 +121,13 @@ export class WebComponentConnector extends LitElement {
86
121
 
87
122
  render() {
88
123
  const [title, body] = (() => {
89
- if (!this.wallet) {
124
+ const wallet = ccc.apply(
125
+ (wallet: ccc.Wallet) =>
126
+ this.wallets.find((w) => w.name === wallet.name),
127
+ this.wallet,
128
+ );
129
+
130
+ if (!wallet) {
90
131
  return generateWalletsScene(
91
132
  this.wallets,
92
133
  this.onWalletSelected,
@@ -94,10 +135,10 @@ export class WebComponentConnector extends LitElement {
94
135
  );
95
136
  }
96
137
  if (!this.signer) {
97
- return generateSignersScene(this.wallet, this.onSignerSelected);
138
+ return generateSignersScene(wallet, this.onSignerSelected);
98
139
  }
99
140
  return generateConnectingScene(
100
- this.wallet,
141
+ wallet,
101
142
  this.signer,
102
143
  this.onSignerSelected,
103
144
  );
@@ -136,20 +177,33 @@ export class WebComponentConnector extends LitElement {
136
177
  }
137
178
 
138
179
  private onClose = () => {
139
- this.dispatchEvent(new SignerChangedEvent());
180
+ if (this.status === ConnectorStatus.SelectingSigner) {
181
+ this.onReset();
182
+ }
140
183
  this.dispatchEvent(new CloseEvent());
141
184
  };
142
185
 
186
+ private onReset = () => {
187
+ this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.SelectingSigner));
188
+ this.dispatchEvent(new SignerChangedEvent());
189
+ };
190
+
143
191
  private onWalletSelected = (wallet: ccc.Wallet) => {
144
192
  this.dispatchEvent(new SignerChangedEvent(wallet, this.signer));
145
193
  };
146
194
 
147
- private onSignerSelected = (wallet: ccc.Wallet, signer: ccc.SignerInfo) => {
148
- this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.Connecting));
149
- this.dispatchEvent(new SignerChangedEvent(wallet, signer));
150
-
195
+ private onSignerSelected = (
196
+ wallet: ccc.Wallet | undefined,
197
+ signer: ccc.SignerInfo,
198
+ ) => {
151
199
  (async () => {
152
- await signer.signer.connect();
200
+ this.dispatchEvent(new SignerChangedEvent(wallet, signer));
201
+
202
+ if (!(await signer.signer.isConnected())) {
203
+ this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.Connecting));
204
+ await signer.signer.connect();
205
+ }
206
+
153
207
  this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.Idle));
154
208
  this.dispatchEvent(new CloseEvent());
155
209
  })();
@@ -5,7 +5,7 @@ import { RETRY_SVG } from "../assets/retry.svg";
5
5
  export function generateConnectingScene(
6
6
  wallet: ccc.Wallet,
7
7
  signer: ccc.SignerInfo,
8
- onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown,
8
+ onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown,
9
9
  ) {
10
10
  return [
11
11
  wallet.name,
@@ -2,6 +2,7 @@ import { ccc } from "@ckb-ccc/ccc";
2
2
  import { html } from "lit";
3
3
  import { repeat } from "lit/directives/repeat.js";
4
4
  import { BTC_SVG, ETH_SVG } from "../assets/chains";
5
+ import { WalletWithSigners } from "../types";
5
6
 
6
7
  export function signerTypeToIcon(type: ccc.SignerType): string {
7
8
  return {
@@ -11,8 +12,8 @@ export function signerTypeToIcon(type: ccc.SignerType): string {
11
12
  }
12
13
 
13
14
  export function generateSignersScene(
14
- wallet: ccc.Wallet,
15
- onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown,
15
+ wallet: WalletWithSigners,
16
+ onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown,
16
17
  ) {
17
18
  return [
18
19
  "Select a Chain",
@@ -1,11 +1,12 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
2
  import { html } from "lit";
3
3
  import { repeat } from "lit/directives/repeat.js";
4
+ import { WalletWithSigners } from "../types";
4
5
 
5
6
  export function generateWalletsScene(
6
- wallets: ccc.Wallet[],
7
+ wallets: WalletWithSigners[],
7
8
  onWalletSelected: (wallet: ccc.Wallet) => unknown,
8
- onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown,
9
+ onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown,
9
10
  ) {
10
11
  return [
11
12
  "Connect Wallet",
@@ -0,0 +1,5 @@
1
+ import { ccc } from "@ckb-ccc/ccc";
2
+
3
+ export type WalletWithSigners = ccc.Wallet & {
4
+ signers: ccc.SignerInfo[];
5
+ };