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

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,14 +1,18 @@
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;
@@ -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;AAE5C,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAAoB;IAEnC,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;IAWL,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"}
@@ -17,8 +17,9 @@ 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
25
  this.dispatchEvent(new SignerChangedEvent());
@@ -39,23 +40,35 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
39
40
  }
40
41
  connectedCallback() {
41
42
  super.connectedCallback();
42
- const client = new ccc.ClientPublicTestnet();
43
- const uniSatSigner = ccc.UniSat.getUniSatSigner(client);
43
+ this.refreshSigners();
44
+ }
45
+ willUpdate(changedProperties) {
46
+ if (changedProperties.get("client")) {
47
+ this.reset();
48
+ this.refreshSigners();
49
+ }
50
+ }
51
+ refreshSigners() {
52
+ const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
44
53
  if (uniSatSigner) {
45
54
  this.addSigner("UniSat", UNI_SAT_SVG, ccc.SignerType.BTC, uniSatSigner);
46
55
  }
47
- const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(client);
56
+ const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
48
57
  if (okxBitcoinSigner) {
49
58
  this.addSigner("OKX Wallet", OKX_SVG, ccc.SignerType.BTC, okxBitcoinSigner);
50
59
  }
51
- const eip6963Manager = new ccc.Eip6963.SignerFactory(client);
52
- eip6963Manager.subscribeSigners((signer) => {
53
- if (this.existedEip6963.indexOf(signer.detail.info.uuid) !== -1) {
54
- return;
55
- }
56
- this.existedEip6963.push(signer.detail.info.uuid);
60
+ const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
61
+ this.resetListeners.push(eip6963Manager.subscribeSigners((signer) => {
57
62
  this.addSigner(`${signer.detail.info.name}`, signer.detail.info.icon, ccc.SignerType.EVM, signer);
58
- });
63
+ }));
64
+ }
65
+ reset() {
66
+ this.wallets = [];
67
+ this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.SelectingSigner));
68
+ this.dispatchEvent(new SignerChangedEvent(undefined, undefined));
69
+ const resetListeners = this.resetListeners;
70
+ this.resetListeners = [];
71
+ resetListeners.forEach((listener) => listener());
59
72
  }
60
73
  addSigner(name, icon, type, signer) {
61
74
  const wallet = this.wallets.find((wallet) => wallet.name === name);
@@ -256,6 +269,9 @@ __decorate([
256
269
  __decorate([
257
270
  property()
258
271
  ], WebComponentConnector.prototype, "isOpen", void 0);
272
+ __decorate([
273
+ property()
274
+ ], WebComponentConnector.prototype, "client", void 0);
259
275
  __decorate([
260
276
  property()
261
277
  ], WebComponentConnector.prototype, "wallet", void 0);
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.10",
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.10",
41
41
  "lit": "^3.1.3"
42
42
  },
43
- "gitHead": "7dab1a1d6e3e380b26f43d0d0308bd4da1617029"
43
+ "gitHead": "dec13b260f57a1b244c69af5566e316a4c329e35"
44
44
  }
@@ -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";
@@ -16,11 +16,14 @@ import { ConnectorStatus } from "../status";
16
16
  export class WebComponentConnector extends LitElement {
17
17
  @state()
18
18
  private wallets: ccc.Wallet[] = [];
19
- private existedEip6963: string[] = [];
19
+
20
+ private resetListeners: (() => void)[] = [];
20
21
 
21
22
  @property()
22
23
  public isOpen: boolean = false;
23
24
 
25
+ @property()
26
+ public client: ccc.Client = new ccc.ClientPublicTestnet();
24
27
  @property()
25
28
  public wallet?: ccc.Wallet;
26
29
  @property()
@@ -30,14 +33,23 @@ export class WebComponentConnector extends LitElement {
30
33
 
31
34
  connectedCallback(): void {
32
35
  super.connectedCallback();
36
+ this.refreshSigners();
37
+ }
33
38
 
34
- const client = new ccc.ClientPublicTestnet();
35
- const uniSatSigner = ccc.UniSat.getUniSatSigner(client);
39
+ willUpdate(changedProperties: PropertyValues<this>): void {
40
+ if (changedProperties.get("client")) {
41
+ this.reset();
42
+ this.refreshSigners();
43
+ }
44
+ }
45
+
46
+ refreshSigners() {
47
+ const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
36
48
  if (uniSatSigner) {
37
49
  this.addSigner("UniSat", UNI_SAT_SVG, ccc.SignerType.BTC, uniSatSigner);
38
50
  }
39
51
 
40
- const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(client);
52
+ const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
41
53
  if (okxBitcoinSigner) {
42
54
  this.addSigner(
43
55
  "OKX Wallet",
@@ -47,19 +59,28 @@ export class WebComponentConnector extends LitElement {
47
59
  );
48
60
  }
49
61
 
50
- const eip6963Manager = new ccc.Eip6963.SignerFactory(client);
51
- eip6963Manager.subscribeSigners((signer) => {
52
- if (this.existedEip6963.indexOf(signer.detail.info.uuid) !== -1) {
53
- return;
54
- }
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
- });
62
+ const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
63
+ this.resetListeners.push(
64
+ eip6963Manager.subscribeSigners((signer) => {
65
+ this.addSigner(
66
+ `${signer.detail.info.name}`,
67
+ signer.detail.info.icon,
68
+ ccc.SignerType.EVM,
69
+ signer,
70
+ );
71
+ }),
72
+ );
73
+ }
74
+
75
+ reset() {
76
+ this.wallets = [];
77
+
78
+ this.dispatchEvent(new StatusChangedEvent(ConnectorStatus.SelectingSigner));
79
+ this.dispatchEvent(new SignerChangedEvent(undefined, undefined));
80
+
81
+ const resetListeners = this.resetListeners;
82
+ this.resetListeners = [];
83
+ resetListeners.forEach((listener) => listener());
63
84
  }
64
85
 
65
86
  addSigner(