@ckb-ccc/connector 0.0.2

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.
@@ -0,0 +1,12 @@
1
+ node_modules/
2
+
3
+ dist/
4
+
5
+ .npmignore
6
+ .prettierrc
7
+ tsconfig.json
8
+ eslint.config.mjs
9
+ .prettierrc
10
+
11
+ tsconfig.tsbuildinfo
12
+ .github/
@@ -0,0 +1,3 @@
1
+ export * from "./advancedBarrel";
2
+ export * as cccA from "./advancedBarrel";
3
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./advancedBarrel";
2
+ export * as cccA from "./advancedBarrel";
@@ -0,0 +1,2 @@
1
+ export * from "@ckb-ccc/ccc/advancedBarrel";
2
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "@ckb-ccc/ccc/advancedBarrel";
@@ -0,0 +1,5 @@
1
+ export * from "@ckb-ccc/ccc";
2
+ export * from "./connector";
3
+ export * from "./events";
4
+ export * from "./signers";
5
+ //# sourceMappingURL=barrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
package/dist/barrel.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "@ckb-ccc/ccc";
2
+ export * from "./connector";
3
+ export * from "./events";
4
+ export * from "./signers";
@@ -0,0 +1,9 @@
1
+ import { LitElement } from "lit";
2
+ export declare class WebComponentConnector extends LitElement {
3
+ private signers;
4
+ isOpen: boolean;
5
+ connectedCallback(): void;
6
+ static styles: import("lit").CSSResult;
7
+ render(): import("lit").TemplateResult<1>;
8
+ }
9
+ //# sourceMappingURL=connector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAM5C,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAAoB;IAG5B,MAAM,EAAE,OAAO,CAAS;IAE/B,iBAAiB,IAAI,IAAI;IAsBzB,MAAM,CAAC,MAAM,0BA+CX;IAEF,MAAM;CAoCP"}
@@ -0,0 +1,129 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { ClientPublicMainnet, Eip6963 } from "@ckb-ccc/ccc";
8
+ import { LitElement, css, html } from "lit";
9
+ import { customElement, property, state } from "lit/decorators.js";
10
+ import { repeat } from "lit/directives/repeat.js";
11
+ import { CloseEvent, ConnectedEvent } from "./events";
12
+ import { SignerType } from "./signers";
13
+ let WebComponentConnector = class WebComponentConnector extends LitElement {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.signers = [];
17
+ this.isOpen = false;
18
+ }
19
+ connectedCallback() {
20
+ super.connectedCallback();
21
+ const client = new ClientPublicMainnet();
22
+ const eip6963Manager = new Eip6963.SignerFactory(client);
23
+ eip6963Manager.subscribeSigners((signer) => {
24
+ if (this.signers.some((s) => s.id === signer.detail.info.uuid)) {
25
+ return;
26
+ }
27
+ this.signers = [
28
+ ...this.signers,
29
+ {
30
+ id: signer.detail.info.uuid,
31
+ name: signer.detail.info.name,
32
+ icon: signer.detail.info.icon,
33
+ type: SignerType.Eip6963,
34
+ signer,
35
+ },
36
+ ];
37
+ });
38
+ }
39
+ render() {
40
+ return html `<style>
41
+ :host {
42
+ ${this.isOpen ? "" : "display: none;"}
43
+ --background: rgba(0, 0, 0, 0.2);
44
+ }
45
+ </style>
46
+ <div
47
+ class="background"
48
+ @click=${(event) => {
49
+ if (event.target === event.currentTarget) {
50
+ this.dispatchEvent(new CloseEvent());
51
+ }
52
+ }}
53
+ >
54
+ <div class="main">
55
+ ${repeat(this.signers, (signer) => signer.id, (signer) => html `
56
+ <button
57
+ class="wallet-button"
58
+ @click=${async () => {
59
+ await signer.signer.connect();
60
+ this.dispatchEvent(new ConnectedEvent(signer));
61
+ this.dispatchEvent(new CloseEvent());
62
+ }}
63
+ >
64
+ <img src=${signer.icon} alt=${signer.name} />
65
+ Connect ${signer.name}
66
+ </button>
67
+ `)}
68
+ </div>
69
+ </div>`;
70
+ }
71
+ };
72
+ WebComponentConnector.styles = css `
73
+ :host {
74
+ width: 100vw;
75
+ height: 100vh;
76
+ position: fixed;
77
+ left: 0;
78
+ top: 0;
79
+ }
80
+
81
+ button {
82
+ background: none;
83
+ color: inherit;
84
+ border: none;
85
+ padding: 0;
86
+ font: inherit;
87
+ cursor: pointer;
88
+ outline: inherit;
89
+ }
90
+
91
+ .background {
92
+ width: 100%;
93
+ height: 100%;
94
+ background: var(--background);
95
+ }
96
+
97
+ .main {
98
+ position: fixed;
99
+ left: 50%;
100
+ top: 50%;
101
+ transform: translate(-50%, -50%);
102
+ }
103
+
104
+ .wallet-button {
105
+ display: flex;
106
+ align-items: center;
107
+ justify-content: center;
108
+ padding: 0.75rem 1.25rem;
109
+ color: #fff;
110
+ background: #000;
111
+ background-image: none;
112
+ border-radius: 9999px;
113
+ border: none;
114
+ }
115
+
116
+ .wallet-button img {
117
+ padding-right: 0.5rem;
118
+ }
119
+ `;
120
+ __decorate([
121
+ state()
122
+ ], WebComponentConnector.prototype, "signers", void 0);
123
+ __decorate([
124
+ property()
125
+ ], WebComponentConnector.prototype, "isOpen", void 0);
126
+ WebComponentConnector = __decorate([
127
+ customElement("ccc-connector")
128
+ ], WebComponentConnector);
129
+ export { WebComponentConnector };
@@ -0,0 +1,9 @@
1
+ import { SignerInfo } from "./signers";
2
+ export declare class ConnectedEvent extends Event {
3
+ readonly signerInfo: SignerInfo;
4
+ constructor(signerInfo: SignerInfo);
5
+ }
6
+ export declare class CloseEvent extends Event {
7
+ constructor();
8
+ }
9
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,qBAAa,cAAe,SAAQ,KAAK;aACX,UAAU,EAAE,UAAU;gBAAtB,UAAU,EAAE,UAAU;CAGnD;AAED,qBAAa,UAAW,SAAQ,KAAK;;CAIpC"}
package/dist/events.js ADDED
@@ -0,0 +1,11 @@
1
+ export class ConnectedEvent extends Event {
2
+ constructor(signerInfo) {
3
+ super("connected", { composed: true });
4
+ this.signerInfo = signerInfo;
5
+ }
6
+ }
7
+ export class CloseEvent extends Event {
8
+ constructor() {
9
+ super("close", { composed: true });
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./barrel";
2
+ export * as ccc from "./barrel";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./barrel";
2
+ export * as ccc from "./barrel";
@@ -0,0 +1,13 @@
1
+ import { Signer } from "@ckb-ccc/ccc";
2
+ export declare enum SignerType {
3
+ Eip6963 = "Eip6963"
4
+ }
5
+ export declare class SignerInfo {
6
+ type: SignerType;
7
+ id: string;
8
+ name: string;
9
+ icon: string;
10
+ signer: Signer;
11
+ constructor(type: SignerType, id: string, name: string, icon: string, signer: Signer);
12
+ }
13
+ //# sourceMappingURL=signers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signers.d.ts","sourceRoot":"","sources":["../src/signers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,oBAAY,UAAU;IACpB,OAAO,YAAY;CACpB;AAED,qBAAa,UAAU;IAEZ,IAAI,EAAE,UAAU;IAChB,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBAJd,IAAI,EAAE,UAAU,EAChB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAExB"}
@@ -0,0 +1,13 @@
1
+ export var SignerType;
2
+ (function (SignerType) {
3
+ SignerType["Eip6963"] = "Eip6963";
4
+ })(SignerType || (SignerType = {}));
5
+ export class SignerInfo {
6
+ constructor(type, id, name, icon, signer) {
7
+ this.type = type;
8
+ this.id = id;
9
+ this.name = name;
10
+ this.icon = icon;
11
+ this.signer = signer;
12
+ }
13
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@ckb-ccc/connector",
3
+ "version": "0.0.2",
4
+ "description": "Common Chains Connector UI",
5
+ "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "main": "dist/index.js",
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./barrel": "./dist/barrel.js",
12
+ "./advancedBarrel": "./dist/advancedBarrel.js",
13
+ "./advanced": "./dist/advanced.js"
14
+ },
15
+ "scripts": {
16
+ "build": "rimraf ./dist && tsc",
17
+ "lint": "eslint",
18
+ "format": "prettier --write . && eslint --fix"
19
+ },
20
+ "devDependencies": {
21
+ "@eslint/js": "^9.1.1",
22
+ "eslint": "^9.1.0",
23
+ "eslint-config-prettier": "^9.1.0",
24
+ "eslint-plugin-prettier": "^5.1.3",
25
+ "prettier": "^3.2.5",
26
+ "prettier-plugin-organize-imports": "^3.2.4",
27
+ "rimraf": "^5.0.5",
28
+ "typescript": "^5.4.5",
29
+ "typescript-eslint": "^7.7.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "@ckb-ccc/ccc": "0.0.2",
36
+ "lit": "^3.1.3"
37
+ },
38
+ "gitHead": "34b7f8d8443258188d47aad71246e787b544300b"
39
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./advancedBarrel";
2
+ export * as cccA from "./advancedBarrel";
@@ -0,0 +1 @@
1
+ export * from "@ckb-ccc/ccc/advancedBarrel";
package/src/barrel.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "@ckb-ccc/ccc";
2
+ export * from "./connector";
3
+ export * from "./events";
4
+ export * from "./signers";
@@ -0,0 +1,123 @@
1
+ import { ClientPublicMainnet, Eip6963 } from "@ckb-ccc/ccc";
2
+ import { LitElement, css, html } from "lit";
3
+ import { customElement, property, state } from "lit/decorators.js";
4
+ import { repeat } from "lit/directives/repeat.js";
5
+ import { CloseEvent, ConnectedEvent } from "./events";
6
+ import { SignerInfo, SignerType } from "./signers";
7
+
8
+ @customElement("ccc-connector")
9
+ export class WebComponentConnector extends LitElement {
10
+ @state()
11
+ private signers: SignerInfo[] = [];
12
+
13
+ @property()
14
+ public isOpen: boolean = false;
15
+
16
+ connectedCallback(): void {
17
+ super.connectedCallback();
18
+
19
+ const client = new ClientPublicMainnet();
20
+ const eip6963Manager = new Eip6963.SignerFactory(client);
21
+ eip6963Manager.subscribeSigners((signer) => {
22
+ if (this.signers.some((s) => s.id === signer.detail.info.uuid)) {
23
+ return;
24
+ }
25
+ this.signers = [
26
+ ...this.signers,
27
+ {
28
+ id: signer.detail.info.uuid,
29
+ name: signer.detail.info.name,
30
+ icon: signer.detail.info.icon,
31
+ type: SignerType.Eip6963,
32
+ signer,
33
+ },
34
+ ];
35
+ });
36
+ }
37
+
38
+ static styles = css`
39
+ :host {
40
+ width: 100vw;
41
+ height: 100vh;
42
+ position: fixed;
43
+ left: 0;
44
+ top: 0;
45
+ }
46
+
47
+ button {
48
+ background: none;
49
+ color: inherit;
50
+ border: none;
51
+ padding: 0;
52
+ font: inherit;
53
+ cursor: pointer;
54
+ outline: inherit;
55
+ }
56
+
57
+ .background {
58
+ width: 100%;
59
+ height: 100%;
60
+ background: var(--background);
61
+ }
62
+
63
+ .main {
64
+ position: fixed;
65
+ left: 50%;
66
+ top: 50%;
67
+ transform: translate(-50%, -50%);
68
+ }
69
+
70
+ .wallet-button {
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: center;
74
+ padding: 0.75rem 1.25rem;
75
+ color: #fff;
76
+ background: #000;
77
+ background-image: none;
78
+ border-radius: 9999px;
79
+ border: none;
80
+ }
81
+
82
+ .wallet-button img {
83
+ padding-right: 0.5rem;
84
+ }
85
+ `;
86
+
87
+ render() {
88
+ return html`<style>
89
+ :host {
90
+ ${this.isOpen ? "" : "display: none;"}
91
+ --background: rgba(0, 0, 0, 0.2);
92
+ }
93
+ </style>
94
+ <div
95
+ class="background"
96
+ @click=${(event: Event) => {
97
+ if (event.target === event.currentTarget) {
98
+ this.dispatchEvent(new CloseEvent());
99
+ }
100
+ }}
101
+ >
102
+ <div class="main">
103
+ ${repeat(
104
+ this.signers,
105
+ (signer) => signer.id,
106
+ (signer) => html`
107
+ <button
108
+ class="wallet-button"
109
+ @click=${async () => {
110
+ await signer.signer.connect();
111
+ this.dispatchEvent(new ConnectedEvent(signer));
112
+ this.dispatchEvent(new CloseEvent());
113
+ }}
114
+ >
115
+ <img src=${signer.icon} alt=${signer.name} />
116
+ Connect ${signer.name}
117
+ </button>
118
+ `,
119
+ )}
120
+ </div>
121
+ </div>`;
122
+ }
123
+ }
package/src/events.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { SignerInfo } from "./signers";
2
+
3
+ export class ConnectedEvent extends Event {
4
+ constructor(public readonly signerInfo: SignerInfo) {
5
+ super("connected", { composed: true });
6
+ }
7
+ }
8
+
9
+ export class CloseEvent extends Event {
10
+ constructor() {
11
+ super("close", { composed: true });
12
+ }
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./barrel";
2
+ export * as ccc from "./barrel";
package/src/signers.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Signer } from "@ckb-ccc/ccc";
2
+
3
+ export enum SignerType {
4
+ Eip6963 = "Eip6963",
5
+ }
6
+
7
+ export class SignerInfo {
8
+ constructor(
9
+ public type: SignerType,
10
+ public id: string,
11
+ public name: string,
12
+ public icon: string,
13
+ public signer: Signer,
14
+ ) {}
15
+ }