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

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.
Files changed (42) hide show
  1. package/README.md +6 -0
  2. package/dist/assets/chains/ckb.svg.d.ts +2 -0
  3. package/dist/assets/chains/ckb.svg.d.ts.map +1 -0
  4. package/dist/assets/chains/ckb.svg.js +2 -0
  5. package/dist/assets/chains/index.d.ts +1 -0
  6. package/dist/assets/chains/index.d.ts.map +1 -1
  7. package/dist/assets/chains/index.js +1 -0
  8. package/dist/assets/joy-id.svg.d.ts +2 -0
  9. package/dist/assets/joy-id.svg.d.ts.map +1 -0
  10. package/dist/assets/joy-id.svg.js +2 -0
  11. package/dist/assets/left.svg.d.ts +2 -0
  12. package/dist/assets/left.svg.d.ts.map +1 -0
  13. package/dist/assets/left.svg.js +2 -0
  14. package/dist/assets/metamask.svg.d.ts +2 -0
  15. package/dist/assets/metamask.svg.d.ts.map +1 -0
  16. package/dist/assets/metamask.svg.js +2 -0
  17. package/dist/connector/index.d.ts +11 -7
  18. package/dist/connector/index.d.ts.map +1 -1
  19. package/dist/connector/index.js +130 -73
  20. package/dist/scenes/connecting.d.ts +2 -1
  21. package/dist/scenes/connecting.d.ts.map +1 -1
  22. package/dist/scenes/signers.d.ts +1 -1
  23. package/dist/scenes/signers.d.ts.map +1 -1
  24. package/dist/scenes/signers.js +3 -2
  25. package/dist/scenes/wallets.d.ts +1 -1
  26. package/dist/scenes/wallets.d.ts.map +1 -1
  27. package/dist/scenes/wallets.js +44 -9
  28. package/dist/types/index.d.ts +5 -0
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/package.json +3 -3
  31. package/src/assets/chains/ckb.svg.ts +5 -0
  32. package/src/assets/chains/index.ts +1 -0
  33. package/src/assets/joy-id.svg.ts +5 -0
  34. package/src/assets/left.svg.ts +5 -0
  35. package/src/assets/metamask.svg.ts +5 -0
  36. package/src/connector/index.ts +153 -80
  37. package/src/scenes/connecting.ts +3 -2
  38. package/src/scenes/signers.ts +4 -3
  39. package/src/scenes/wallets.ts +68 -22
  40. package/src/types/index.ts +6 -0
  41. package/tsconfig.base.json +0 -21
  42. package/tsconfig.commonjs.json +0 -8
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ <p align="center">
2
+ <a href="https://ckbccc-demo.vercel.app/">
3
+ <img alt="Logo" src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/logo.svg" width="20%" />
4
+ </a>
5
+ </p>
6
+
1
7
  <h1 align="center" style="font-size: 48px;">
2
8
  CCC Connector
3
9
  </h1>
@@ -0,0 +1,2 @@
1
+ export declare const CKB_SVG: string;
2
+ //# sourceMappingURL=ckb.svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ckb.svg.d.ts","sourceRoot":"","sources":["../../../src/assets/chains/ckb.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,QAEnB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { encodeSvgToImgSrc } from "../utils";
2
+ export const CKB_SVG = encodeSvgToImgSrc('<svg width="668" height="666.66669" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><polygon points="170.265,206.318 223.416,206.318 223.416,93.897 264.161,93.897 170.265,0 " transform="matrix(1.8256046,0,0,1.8256046,-166.4037,144.47964)" /><polygon points="324.79,112.422 284.046,112.422 377.941,206.318 377.941,0 324.79,0 " transform="matrix(1.8256046,0,0,1.8256046,-166.4037,144.47964)" /></svg>');
@@ -1,3 +1,4 @@
1
1
  export * from "./btc.svg";
2
+ export * from "./ckb.svg";
2
3
  export * from "./eth.svg";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/assets/chains/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/assets/chains/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./btc.svg";
2
+ export * from "./ckb.svg";
2
3
  export * from "./eth.svg";
@@ -0,0 +1,2 @@
1
+ export declare const JOY_ID_SVG: string;
2
+ //# sourceMappingURL=joy-id.svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joy-id.svg.d.ts","sourceRoot":"","sources":["../../src/assets/joy-id.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAEtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { encodeSvgToImgSrc } from "./utils";
2
+ export const JOY_ID_SVG = encodeSvgToImgSrc('<svg xmlns="http://www.w3.org/2000/svg" width="420" height="420" viewBox="0 0 420 420" fill="none"><circle cx="210" cy="210" r="210" fill="#333333"/><path d="M271.127 204.419C279.096 204.419 285.555 197.959 285.555 189.991C285.555 182.022 279.096 175.562 271.127 175.562C263.159 175.562 256.699 182.022 256.699 189.991C256.699 197.959 263.159 204.419 271.127 204.419Z" fill="#8CDD00"/><path d="M173.995 175.562C166.773 175.562 160.91 181.425 160.91 188.648C160.91 195.87 166.773 201.733 173.995 201.733C181.218 201.733 187.081 195.87 187.081 188.648C187.064 181.425 181.218 175.562 173.995 175.562Z" fill="#8CDD00"/><path d="M213.43 164.836L198.969 233.586C197.626 240.006 191.878 244.657 185.327 244.657C181.086 244.657 177.139 242.757 174.47 239.465C172.39 236.894 171.342 233.734 171.391 230.491L145.27 237.238C146.383 244.084 149.2 250.618 153.687 256.203C161.434 265.816 172.963 271.335 185.311 271.335C204.407 271.335 221.111 257.775 225.041 239.089L240.665 164.852H213.43V164.836Z" fill="#C1C1C1"/><path d="M335.83 115.983C327.068 105.19 314.065 99 300.161 99H267.981L262.363 125.662H300.161C305.991 125.662 311.445 128.249 315.113 132.786C318.782 137.306 320.207 143.185 319.011 148.884L313.394 175.562H340.645L345.116 154.387C347.965 140.778 344.592 126.775 335.83 115.983Z" fill="#8CDD00"/><path d="M295.216 261.999C291.285 280.669 274.597 294.212 255.518 294.212H226.875L221.258 320.874H255.518C287.126 320.874 314.803 298.421 321.304 267.485L326.021 245.049H298.77L295.216 261.999Z" fill="#8CDD00"/><path d="M98.8061 152.39L93.9258 175.58H121.177L124.894 157.892C128.825 139.223 145.513 125.679 164.592 125.679H192.04L197.657 99.0176H164.592C132.985 99.0012 105.308 121.454 98.8061 152.39Z" fill="#8CDD00"/><path d="M104.998 287.072C101.33 282.552 99.9049 276.673 101.1 270.974L106.079 247.342L77.2555 254.777L74.9956 265.487C72.1296 279.097 75.5196 293.099 84.2813 303.891C93.0429 314.684 106.046 320.874 119.95 320.874H150.935L156.553 294.212H119.95C114.12 294.196 108.666 291.608 104.998 287.072Z" fill="#8CDD00"/></svg>');
@@ -0,0 +1,2 @@
1
+ export declare const LEFT_SVG: string;
2
+ //# sourceMappingURL=left.svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"left.svg.d.ts","sourceRoot":"","sources":["../../src/assets/left.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,QAEpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { encodeSvgToImgSrc } from "./utils";
2
+ export const LEFT_SVG = encodeSvgToImgSrc('<svg width="8" height="14" viewBox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.74554 13.5C6.54646 13.5 6.35454 13.4177 6.21275 13.2695L0.720203 7.55253C0.426599 7.24573 0.426599 6.75035 0.720203 6.44355L6.21275 0.725059C6.50779 0.422747 6.98185 0.42574 7.27402 0.729549C7.5662 1.03485 7.56763 1.52723 7.27832 1.83404L2.31999 6.99729L7.27975 12.162C7.49459 12.3865 7.55904 12.7233 7.44303 13.0166C7.32415 13.3084 7.0506 13.5 6.74554 13.5Z" stroke="#1E1E1E" stroke-width="1"/></svg>');
@@ -0,0 +1,2 @@
1
+ export declare const METAMASK_SVG: string;
2
+ //# sourceMappingURL=metamask.svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metamask.svg.d.ts","sourceRoot":"","sources":["../../src/assets/metamask.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,QAExB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { encodeSvgToImgSrc } from "./utils";
2
+ export const METAMASK_SVG = encodeSvgToImgSrc(`<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" id="Layer_1" x="0" y="0" version="1.1" viewBox="0 0 318.6 318.6"><style>.st1,.st6{fill:#e4761b;stroke:#e4761b;stroke-linecap:round;stroke-linejoin:round}.st6{fill:#f6851b;stroke:#f6851b}</style><path fill="#e2761b" stroke="#e2761b" stroke-linecap="round" stroke-linejoin="round" d="m274.1 35.5-99.5 73.9L193 65.8z"/><path d="m44.4 35.5 98.7 74.6-17.5-44.3zm193.9 171.3-26.5 40.6 56.7 15.6 16.3-55.3zm-204.4.9L50.1 263l56.7-15.6-26.5-40.6z" class="st1"/><path d="m103.6 138.2-15.8 23.9 56.3 2.5-2-60.5zm111.3 0-39-34.8-1.3 61.2 56.2-2.5zM106.8 247.4l33.8-16.5-29.2-22.8zm71.1-16.5 33.9 16.5-4.7-39.3z" class="st1"/><path fill="#d7c1b3" stroke="#d7c1b3" stroke-linecap="round" stroke-linejoin="round" d="m211.8 247.4-33.9-16.5 2.7 22.1-.3 9.3zm-105 0 31.5 14.9-.2-9.3 2.5-22.1z"/><path fill="#233447" stroke="#233447" stroke-linecap="round" stroke-linejoin="round" d="m138.8 193.5-28.2-8.3 19.9-9.1zm40.9 0 8.3-17.4 20 9.1z"/><path fill="#cd6116" stroke="#cd6116" stroke-linecap="round" stroke-linejoin="round" d="m106.8 247.4 4.8-40.6-31.3.9zM207 206.8l4.8 40.6 26.5-39.7zm23.8-44.7-56.2 2.5 5.2 28.9 8.3-17.4 20 9.1zm-120.2 23.1 20-9.1 8.2 17.4 5.3-28.9-56.3-2.5z"/><path fill="#e4751f" stroke="#e4751f" stroke-linecap="round" stroke-linejoin="round" d="m87.8 162.1 23.6 46-.8-22.9zm120.3 23.1-1 22.9 23.7-46zm-64-20.6-5.3 28.9 6.6 34.1 1.5-44.9zm30.5 0-2.7 18 1.2 45 6.7-34.1z"/><path d="m179.8 193.5-6.7 34.1 4.8 3.3 29.2-22.8 1-22.9zm-69.2-8.3.8 22.9 29.2 22.8 4.8-3.3-6.6-34.1z" class="st6"/><path fill="#c0ad9e" stroke="#c0ad9e" stroke-linecap="round" stroke-linejoin="round" d="m180.3 262.3.3-9.3-2.5-2.2h-37.7l-2.3 2.2.2 9.3-31.5-14.9 11 9 22.3 15.5h38.3l22.4-15.5 11-9z"/><path fill="#161616" stroke="#161616" stroke-linecap="round" stroke-linejoin="round" d="m177.9 230.9-4.8-3.3h-27.7l-4.8 3.3-2.5 22.1 2.3-2.2h37.7l2.5 2.2z"/><path fill="#763d16" stroke="#763d16" stroke-linecap="round" stroke-linejoin="round" d="m278.3 114.2 8.5-40.8-12.7-37.9-96.2 71.4 37 31.3 52.3 15.3 11.6-13.5-5-3.6 8-7.3-6.2-4.8 8-6.1zM31.8 73.4l8.5 40.8-5.4 4 8 6.1-6.1 4.8 8 7.3-5 3.6 11.5 13.5 52.3-15.3 37-31.3-96.2-71.4z"/><path d="m267.2 153.5-52.3-15.3 15.9 23.9-23.7 46 31.2-.4h46.5zm-163.6-15.3-52.3 15.3-17.4 54.2h46.4l31.1.4-23.6-46zm71 26.4 3.3-57.7 15.2-41.1h-67.5l15 41.1 3.5 57.7 1.2 18.2.1 44.8h27.7l.2-44.8z" class="st6"/><script xmlns=""/></svg>`);
@@ -1,22 +1,22 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
2
  import { LitElement, PropertyValues } from "lit";
3
- import { WalletWithSigners } from "../types";
3
+ import { Ref } from "lit/directives/ref.js";
4
4
  export declare class WebComponentConnector extends LitElement {
5
5
  private wallets;
6
6
  private resetListeners;
7
7
  isOpen: boolean;
8
8
  setIsOpen(isOpen: boolean): void;
9
+ name?: string;
10
+ icon?: string;
9
11
  client: ccc.Client;
10
12
  setClient(client: ccc.Client): void;
11
- private walletName?;
12
- private signerType?;
13
+ private scene;
13
14
  private selectedWallet?;
14
- private updateWallet;
15
15
  private selectedSigner?;
16
- private updateSigner;
17
- wallet?: WalletWithSigners;
16
+ private walletName?;
17
+ private signerName?;
18
+ wallet?: ccc.Wallet;
18
19
  signer?: ccc.SignerInfo;
19
- private canConnect;
20
20
  private prepareSigner;
21
21
  disconnect(): void;
22
22
  private loadConnection;
@@ -25,7 +25,11 @@ export declare class WebComponentConnector extends LitElement {
25
25
  willUpdate(changedProperties: PropertyValues): void;
26
26
  private reloadSigners;
27
27
  private addSigner;
28
+ mainRef: Ref<HTMLDivElement>;
29
+ headerRef: Ref<HTMLDivElement>;
30
+ bodyRef: Ref<HTMLDivElement>;
28
31
  render(): import("lit").TemplateResult<1>;
32
+ updated(): void;
29
33
  private closedHandler;
30
34
  private signerSelectedHandler;
31
35
  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,EAAE,cAAc,EAAa,MAAM,KAAK,CAAC;AAW5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAA2B;IAE1C,OAAO,CAAC,cAAc,CAAsB;IAGrC,MAAM,EAAE,OAAO,CAAS;IACxB,SAAS,CAAC,MAAM,EAAE,OAAO;IAKzB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAiC;IACnD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM;IAKnC,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B,OAAO,CAAC,UAAU,CAAC,CAAiB;IAEpC,OAAO,CAAC,cAAc,CAAC,CAAoB;IAC3C,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,YAAY;IAMb,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B,MAAM,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IAC/B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa;IAuBd,UAAU;IAQjB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAUtB,iBAAiB,IAAI,IAAI;IAMzB,UAAU,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI;IAuBnD,OAAO,CAAC,aAAa;IAoDrB,OAAO,CAAC,SAAS;IA8BjB,MAAM;IAsDN,OAAO,CAAC,aAAa,CAKnB;IAEF,OAAO,CAAC,qBAAqB,CAO3B;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;AAE5D,OAAO,EAAE,GAAG,EAAkB,MAAM,uBAAuB,CAAC;AAqB5D,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAA2B;IAE1C,OAAO,CAAC,cAAc,CAAsB;IAGrC,MAAM,EAAE,OAAO,CAAS;IACxB,SAAS,CAAC,MAAM,EAAE,OAAO;IAKzB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,MAAM,EAAE,GAAG,CAAC,MAAM,CAAiC;IACnD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM;IAKnC,OAAO,CAAC,KAAK,CAAiC;IAE9C,OAAO,CAAC,cAAc,CAAC,CAAoB;IAE3C,OAAO,CAAC,cAAc,CAAC,CAAiB;IAGxC,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B,OAAO,CAAC,UAAU,CAAC,CAAS;IAErB,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAEpB,MAAM,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IAC/B,OAAO,CAAC,aAAa;IAad,UAAU;IAOjB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAUtB,iBAAiB,IAAI,IAAI;IAMzB,UAAU,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI;IA0BnD,OAAO,CAAC,aAAa;IAiErB,OAAO,CAAC,SAAS;IA+BjB,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;IA0EN,OAAO;IAUP,OAAO,CAAC,aAAa,CAanB;IAEF,OAAO,CAAC,qBAAqB,CAkB3B;IAEF,MAAM,CAAC,MAAM,0BA4IX;CACH"}
@@ -7,11 +7,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { ccc } from "@ckb-ccc/ccc";
8
8
  import { LitElement, css, html } from "lit";
9
9
  import { customElement, property, state } from "lit/decorators.js";
10
+ import { createRef, ref } from "lit/directives/ref.js";
10
11
  import { CLOSE_SVG } from "../assets/close.svg";
12
+ import { JOY_ID_SVG } from "../assets/joy-id.svg";
13
+ import { LEFT_SVG } from "../assets/left.svg";
11
14
  import { OKX_SVG } from "../assets/okx.svg";
12
15
  import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
13
16
  import { WillUpdateEvent } from "../events";
14
17
  import { generateConnectingScene, generateSignersScene, generateWalletsScene, } from "../scenes";
18
+ var Scene;
19
+ (function (Scene) {
20
+ Scene["SelectingWallets"] = "SelectingWallets";
21
+ Scene["SelectingSigners"] = "SelectingSigners";
22
+ Scene["Connecting"] = "Connecting";
23
+ Scene["Connected"] = "Connected";
24
+ })(Scene || (Scene = {}));
15
25
  let WebComponentConnector = class WebComponentConnector extends LitElement {
16
26
  constructor() {
17
27
  super(...arguments);
@@ -19,17 +29,37 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
19
29
  this.resetListeners = [];
20
30
  this.isOpen = false;
21
31
  this.client = new ccc.ClientPublicTestnet();
22
- this.canConnect = false;
32
+ this.scene = Scene.SelectingWallets;
33
+ this.mainRef = createRef();
34
+ this.headerRef = createRef();
35
+ this.bodyRef = createRef();
23
36
  this.closedHandler = () => {
24
- if (this.signer === undefined) {
25
- this.disconnect();
37
+ if ([
38
+ Scene.SelectingSigners,
39
+ Scene.SelectingWallets,
40
+ Scene.Connecting,
41
+ ].includes(this.scene)) {
42
+ this.scene = Scene.SelectingWallets;
43
+ this.selectedSigner = undefined;
44
+ this.selectedWallet = undefined;
26
45
  }
27
46
  this.isOpen = false;
28
47
  };
29
48
  this.signerSelectedHandler = (wallet, signer) => {
30
- this.walletName = wallet?.name;
31
- this.signerType = signer?.type;
32
- this.canConnect = true;
49
+ this.scene = Scene.Connecting;
50
+ this.selectedWallet = wallet;
51
+ this.selectedSigner = signer;
52
+ (async () => {
53
+ await signer.signer.connect();
54
+ if (!(await signer.signer.isConnected())) {
55
+ return;
56
+ }
57
+ this.scene = Scene.Connected;
58
+ this.walletName = wallet.name;
59
+ this.signerName = signer.name;
60
+ this.saveConnection();
61
+ this.closedHandler();
62
+ })();
33
63
  };
34
64
  }
35
65
  setIsOpen(isOpen) {
@@ -38,47 +68,31 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
38
68
  setClient(client) {
39
69
  this.client = client;
40
70
  }
41
- updateWallet() {
42
- this.selectedWallet = this.wallets.find((wallet) => this.walletName === wallet.name);
43
- }
44
- updateSigner() {
45
- this.selectedSigner = this.selectedWallet?.signers.find(({ type }) => type === this.signerType);
46
- }
47
71
  prepareSigner() {
48
72
  (async () => {
49
- if (!this.selectedSigner) {
50
- this.wallet = undefined;
51
- this.signer = undefined;
73
+ if (this.signer && (await this.signer.signer.isConnected())) {
74
+ this.scene = Scene.Connected;
52
75
  return;
53
76
  }
54
- if (!(await this.selectedSigner.signer.isConnected())) {
55
- if (!this.canConnect) {
56
- this.disconnect();
57
- return;
58
- }
59
- await this.selectedSigner.signer.connect();
60
- }
61
- this.saveConnection();
62
- this.wallet = this.selectedWallet;
63
- this.signer = this.selectedSigner;
64
- this.closedHandler();
77
+ this.wallet = undefined;
78
+ this.signer = undefined;
79
+ this.scene = Scene.SelectingWallets;
65
80
  })();
66
81
  }
67
82
  disconnect() {
83
+ this.signer?.signer?.disconnect();
68
84
  this.walletName = undefined;
69
- this.wallet = undefined;
70
- this.signerType = undefined;
71
- this.signer = undefined;
85
+ this.signerName = undefined;
72
86
  this.saveConnection();
73
87
  }
74
88
  loadConnection() {
75
- const { signerType, walletName, } = JSON.parse(window.localStorage.getItem("ccc-connection-info") ?? "{}");
76
- this.signerType = signerType;
89
+ const { signerName, walletName, } = JSON.parse(window.localStorage.getItem("ccc-connection-info") ?? "{}");
90
+ this.signerName = signerName;
77
91
  this.walletName = walletName;
78
92
  }
79
93
  saveConnection() {
80
94
  window.localStorage.setItem("ccc-connection-info", JSON.stringify({
81
- signerType: this.signerType,
95
+ signerName: this.signerName,
82
96
  walletName: this.walletName,
83
97
  }));
84
98
  }
@@ -93,13 +107,14 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
93
107
  }
94
108
  if (changedProperties.has("walletName") ||
95
109
  changedProperties.has("wallets")) {
96
- this.updateWallet();
110
+ this.wallet = this.wallets.find(({ name }) => name === this.walletName);
97
111
  }
98
- if (changedProperties.has("signerType") ||
99
- changedProperties.has("selectedWallet")) {
100
- this.updateSigner();
112
+ if (changedProperties.has("signerName") ||
113
+ changedProperties.has("wallet")) {
114
+ const wallet = this.wallets.find(({ name }) => name === this.walletName);
115
+ this.signer = wallet?.signers.find(({ name }) => name === this.signerName);
101
116
  }
102
- if (changedProperties.has("selectedSigner")) {
117
+ if (changedProperties.has("signer")) {
103
118
  this.prepareSigner();
104
119
  }
105
120
  this.dispatchEvent(new WillUpdateEvent());
@@ -107,66 +122,71 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
107
122
  reloadSigners() {
108
123
  this.wallets = [];
109
124
  (async () => {
110
- if (!this.selectedSigner) {
125
+ if (!this.signer) {
111
126
  return;
112
127
  }
113
- const newSigner = await this.selectedSigner.signer.replaceClient(this.client);
114
- if (newSigner) {
115
- this.selectedSigner = {
116
- ...this.selectedSigner,
117
- signer: newSigner,
118
- };
119
- }
120
- else {
121
- this.disconnect();
122
- }
128
+ this.signer = {
129
+ ...this.signer,
130
+ signer: await this.signer.signer.replaceClient(this.client),
131
+ };
123
132
  })();
124
133
  this.resetListeners.forEach((listener) => listener());
125
134
  this.resetListeners = [];
135
+ const name = this.name ??
136
+ document.querySelector("head title").text;
137
+ const icon = this.icon ??
138
+ document.querySelector('link[rel="icon"]').href;
139
+ ccc.JoyId.getJoyIdSigners(this.client, name, icon).forEach(({ signer, type, name }) => {
140
+ this.addSigner("JoyID", name, JOY_ID_SVG, type, signer);
141
+ });
126
142
  const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
127
143
  if (uniSatSigner) {
128
- this.addSigner("UniSat", UNI_SAT_SVG, ccc.SignerType.BTC, uniSatSigner);
144
+ this.addSigner("UniSat", "BTC", UNI_SAT_SVG, ccc.SignerType.BTC, uniSatSigner);
129
145
  }
130
146
  const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
131
147
  if (okxBitcoinSigner) {
132
- this.addSigner("OKX Wallet", OKX_SVG, ccc.SignerType.BTC, okxBitcoinSigner);
148
+ this.addSigner("OKX Wallet", "BTC", OKX_SVG, ccc.SignerType.BTC, okxBitcoinSigner);
133
149
  }
134
150
  const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
135
151
  this.resetListeners.push(eip6963Manager.subscribeSigners((signer) => {
136
- this.addSigner(`${signer.detail.info.name}`, signer.detail.info.icon, ccc.SignerType.EVM, signer);
152
+ this.addSigner(`${signer.detail.info.name}`, "EVM", signer.detail.info.icon, ccc.SignerType.EVM, signer);
137
153
  }));
138
154
  }
139
- addSigner(name, icon, type, signer) {
155
+ addSigner(walletName, signerName, icon, type, signer) {
140
156
  let updated = false;
141
157
  const wallets = this.wallets.map((wallet) => {
142
- if (wallet.name !== name) {
158
+ if (wallet.name !== walletName) {
143
159
  return wallet;
144
160
  }
145
161
  updated = true;
146
162
  return {
147
163
  ...wallet,
148
- signers: [...wallet.signers, { type, signer }],
164
+ signers: [...wallet.signers, { type, name: signerName, signer }],
149
165
  };
150
166
  });
151
167
  if (!updated) {
152
168
  wallets.push({
153
- name,
169
+ name: walletName,
154
170
  icon,
155
- signers: [{ type, signer }],
171
+ signers: [{ type, name: signerName, signer }],
156
172
  });
157
173
  }
158
174
  this.wallets = wallets;
159
175
  }
160
176
  render() {
161
177
  const [title, body] = (() => {
162
- if (!this.selectedWallet) {
163
- return generateWalletsScene(this.wallets, this.signerSelectedHandler, this.signerSelectedHandler);
178
+ if (this.scene === Scene.SelectingWallets || !this.selectedWallet) {
179
+ return generateWalletsScene(this.wallets, (wallet) => {
180
+ this.selectedWallet = wallet;
181
+ this.scene = Scene.SelectingSigners;
182
+ }, this.signerSelectedHandler);
164
183
  }
165
- if (!this.selectedSigner) {
184
+ if (this.scene === Scene.SelectingSigners || !this.selectedSigner) {
166
185
  return generateSignersScene(this.selectedWallet, this.signerSelectedHandler);
167
186
  }
168
187
  return generateConnectingScene(this.selectedWallet, this.selectedSigner, this.signerSelectedHandler);
169
188
  })();
189
+ const canBack = [Scene.SelectingSigners, Scene.Connecting].includes(this.scene);
170
190
  return html `<style>
171
191
  :host {
172
192
  ${this.isOpen ? "" : "display: none;"}
@@ -175,7 +195,6 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
175
195
  --btn-primary: #f8f8f8;
176
196
  --btn-primary-hover: #efeeee;
177
197
  --btn-secondary: #ddd;
178
- --btn-icon: #e9e4de;
179
198
  color: #1e1e1e;
180
199
  --tip-color: #666;
181
200
  }
@@ -188,16 +207,38 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
188
207
  }
189
208
  }}
190
209
  >
191
- <div class="main">
192
- <div class="header text-bold fs-big">
193
- <div class="back"></div>
210
+ <div class="main" ${ref(this.mainRef)}>
211
+ <div class="header text-bold fs-big" ${ref(this.headerRef)}>
212
+ <img
213
+ class="back ${canBack ? "active" : ""}"
214
+ src=${LEFT_SVG}
215
+ @click=${() => {
216
+ if (this.scene === Scene.Connecting) {
217
+ this.scene = Scene.SelectingSigners;
218
+ }
219
+ else if (this.scene === Scene.SelectingSigners) {
220
+ this.scene = Scene.SelectingWallets;
221
+ }
222
+ }}
223
+ />
194
224
  ${title}
195
- <img class="close" src=${CLOSE_SVG} @click=${this.closedHandler} />
225
+ <img
226
+ class="close active"
227
+ src=${CLOSE_SVG}
228
+ @click=${this.closedHandler}
229
+ />
196
230
  </div>
197
- <div class="body">${body}</div>
231
+ <div class="body" ${ref(this.bodyRef)}>${body}</div>
198
232
  </div>
199
233
  </div>`;
200
234
  }
235
+ updated() {
236
+ if (!this.mainRef.value) {
237
+ return;
238
+ }
239
+ this.mainRef.value.style.height = `${(this.bodyRef.value?.clientHeight ?? 0) +
240
+ (this.headerRef.value?.clientHeight ?? 0)}px`;
241
+ }
201
242
  };
202
243
  WebComponentConnector.styles = css `
203
244
  :host {
@@ -256,6 +297,8 @@ WebComponentConnector.styles = css `
256
297
  transform: translate(-50%, -50%);
257
298
  background: var(--background);
258
299
  border-radius: 1.2rem;
300
+ overflow: hidden;
301
+ transition: height 0.15s ease-out;
259
302
  }
260
303
 
261
304
  .header {
@@ -270,6 +313,13 @@ WebComponentConnector.styles = css `
270
313
  .back {
271
314
  width: 0.8rem;
272
315
  height: 0.8rem;
316
+ opacity: 0;
317
+ transition: opacity 0.15s ease-in-out;
318
+ }
319
+
320
+ .close.active,
321
+ .back.active {
322
+ opacity: 1;
273
323
  cursor: pointer;
274
324
  }
275
325
 
@@ -289,7 +339,7 @@ WebComponentConnector.styles = css `
289
339
  padding: 0.75rem 1rem;
290
340
  background: var(--btn-primary);
291
341
  border-radius: 0.4rem;
292
- transition: background 0.3s ease-in-out;
342
+ transition: background 0.15s ease-in-out;
293
343
  }
294
344
 
295
345
  .btn-primary img {
@@ -297,7 +347,6 @@ WebComponentConnector.styles = css `
297
347
  height: 2rem;
298
348
  margin-right: 1rem;
299
349
  border-radius: 0.4rem;
300
- background: var(--btn-icon);
301
350
  }
302
351
 
303
352
  .btn-primary:hover {
@@ -310,7 +359,7 @@ WebComponentConnector.styles = css `
310
359
  padding: 0.25rem 1rem;
311
360
  background: var(--btn-secondary);
312
361
  border-radius: 9999px;
313
- transition: background 0.3s ease-in-out;
362
+ transition: background 0.15s ease-in-out;
314
363
  }
315
364
 
316
365
  .btn-secondary img {
@@ -324,7 +373,6 @@ WebComponentConnector.styles = css `
324
373
  height: 4rem;
325
374
  margin-bottom: 0.5rem;
326
375
  border-radius: 0.8rem;
327
- background: var(--btn-icon);
328
376
  }
329
377
 
330
378
  .connecting-wallet-icon {
@@ -341,19 +389,28 @@ __decorate([
341
389
  ], WebComponentConnector.prototype, "isOpen", void 0);
342
390
  __decorate([
343
391
  property()
344
- ], WebComponentConnector.prototype, "client", void 0);
392
+ ], WebComponentConnector.prototype, "name", void 0);
345
393
  __decorate([
346
- state()
347
- ], WebComponentConnector.prototype, "walletName", void 0);
394
+ property()
395
+ ], WebComponentConnector.prototype, "icon", void 0);
396
+ __decorate([
397
+ property()
398
+ ], WebComponentConnector.prototype, "client", void 0);
348
399
  __decorate([
349
400
  state()
350
- ], WebComponentConnector.prototype, "signerType", void 0);
401
+ ], WebComponentConnector.prototype, "scene", void 0);
351
402
  __decorate([
352
403
  state()
353
404
  ], WebComponentConnector.prototype, "selectedWallet", void 0);
354
405
  __decorate([
355
406
  state()
356
407
  ], WebComponentConnector.prototype, "selectedSigner", void 0);
408
+ __decorate([
409
+ state()
410
+ ], WebComponentConnector.prototype, "walletName", void 0);
411
+ __decorate([
412
+ state()
413
+ ], WebComponentConnector.prototype, "signerName", void 0);
357
414
  __decorate([
358
415
  state()
359
416
  ], WebComponentConnector.prototype, "wallet", void 0);
@@ -1,3 +1,4 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
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>)[];
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
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;AAInC,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,gBAAgB,EAAE,CAChB,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,EAC9B,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,gBAAgB,EAAE,CAChB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDAqBb"}
@@ -1,5 +1,5 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
2
  import { WalletWithSigners } from "../types";
3
3
  export declare function signerTypeToIcon(type: ccc.SignerType): string;
4
- export declare function generateSignersScene(wallet: WalletWithSigners, onSignerSelected: (wallet: ccc.Wallet | undefined, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
4
+ export declare function generateSignersScene(wallet: WalletWithSigners, onSignerSelected: (wallet: WalletWithSigners, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
5
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;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,CAChB,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,EAC9B,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDAyBb"}
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,CAM7D;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,EACzB,gBAAgB,EAAE,CAChB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDAyBb"}
@@ -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 { BTC_SVG, ETH_SVG } from "../assets/chains";
4
+ import { BTC_SVG, CKB_SVG, ETH_SVG } from "../assets/chains";
5
5
  export function signerTypeToIcon(type) {
6
6
  return {
7
7
  [ccc.SignerType.BTC]: BTC_SVG,
8
8
  [ccc.SignerType.EVM]: ETH_SVG,
9
+ [ccc.SignerType.CKB]: CKB_SVG,
9
10
  }[type];
10
11
  }
11
12
  export function generateSignersScene(wallet, onSignerSelected) {
@@ -22,7 +23,7 @@ export function generateSignersScene(wallet, onSignerSelected) {
22
23
  }}
23
24
  >
24
25
  <img src=${signerTypeToIcon(signer.type)} alt=${signer.type} />
25
- ${signer.type}
26
+ ${signer.name}
26
27
  </button>
27
28
  `)}
28
29
  `,
@@ -1,4 +1,4 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
2
  import { WalletWithSigners } from "../types";
3
- export declare function generateWalletsScene(wallets: WalletWithSigners[], onWalletSelected: (wallet: ccc.Wallet) => unknown, onSignerSelected: (wallet: ccc.Wallet, signer: ccc.SignerInfo) => unknown): unknown[];
3
+ export declare function generateWalletsScene(wallets: WalletWithSigners[], onWalletSelected: (wallet: WalletWithSigners) => unknown, onSignerSelected: (wallet: WalletWithSigners, signer: ccc.SignerInfo) => unknown): (string | import("lit").TemplateResult<1>)[];
4
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;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,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;AAMnC,OAAO,EAAc,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEzD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,iBAAiB,EAAE,EAC5B,gBAAgB,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,EACxD,gBAAgB,EAAE,CAChB,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDAgEb"}
@@ -1,12 +1,45 @@
1
1
  import { html } from "lit";
2
2
  import { repeat } from "lit/directives/repeat.js";
3
+ import { METAMASK_SVG } from "../assets/metamask.svg";
4
+ import { OKX_SVG } from "../assets/okx.svg";
5
+ import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
3
6
  export function generateWalletsScene(wallets, onWalletSelected, onSignerSelected) {
7
+ const recommendedWallets = [
8
+ {
9
+ name: "MetaMask",
10
+ icon: METAMASK_SVG,
11
+ downloadLink: `https://metamask.app.link/dapp/${window.location.href}`,
12
+ },
13
+ {
14
+ name: "OKX Wallet",
15
+ icon: OKX_SVG,
16
+ downloadLink: "https://www.okx.com/zh-hans/download",
17
+ },
18
+ {
19
+ name: "UniSat",
20
+ icon: UNI_SAT_SVG,
21
+ downloadLink: "https://unisat.io/",
22
+ },
23
+ ];
24
+ const missingWallets = recommendedWallets.filter((recommendedWallet) => !wallets.some((wallet) => wallet.name === recommendedWallet.name));
25
+ const additionalButtons = missingWallets.map((wallet) => html `
26
+ <button
27
+ class="btn-primary mb-1"
28
+ @click=${() => {
29
+ window.open(wallet.downloadLink, "_blank");
30
+ }}
31
+ >
32
+ <img src=${wallet.icon} alt=${wallet.name} />
33
+ ${wallet.name}
34
+ </button>
35
+ `);
4
36
  return [
5
37
  "Connect Wallet",
6
- repeat(wallets, (wallet) => wallet.name, (wallet) => html `
7
- <button
8
- class="btn-primary mb-1"
9
- @click=${async () => {
38
+ html `
39
+ ${repeat(wallets, (wallet) => wallet.name, (wallet) => html `
40
+ <button
41
+ class="btn-primary mb-1"
42
+ @click=${async () => {
10
43
  if (wallet.signers.length === 1) {
11
44
  onSignerSelected(wallet, wallet.signers[0]);
12
45
  }
@@ -14,10 +47,12 @@ export function generateWalletsScene(wallets, onWalletSelected, onSignerSelected
14
47
  onWalletSelected(wallet);
15
48
  }
16
49
  }}
17
- >
18
- <img src=${wallet.icon} alt=${wallet.name} />
19
- ${wallet.name}
20
- </button>
21
- `),
50
+ >
51
+ <img src=${wallet.icon} alt=${wallet.name} />
52
+ ${wallet.name}
53
+ </button>
54
+ `)}
55
+ ${additionalButtons}
56
+ `,
22
57
  ];
23
58
  }