@ckb-ccc/connector 0.0.14 → 0.0.15
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/CHANGELOG.md +6 -0
- package/dist/components/dialog.d.ts.map +1 -1
- package/dist/components/dialog.js +2 -1
- package/dist/connector/index.d.ts +1 -0
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +22 -7
- package/dist/events/index.d.ts +15 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +19 -0
- package/dist/scenes/connected.d.ts +0 -4
- package/dist/scenes/connected.d.ts.map +1 -1
- package/dist/scenes/connected.js +1 -6
- package/dist/scenes/selecting/connecting.d.ts.map +1 -1
- package/dist/scenes/selecting/connecting.js +1 -3
- package/dist/scenes/selecting/index.d.ts +0 -5
- package/dist/scenes/selecting/index.d.ts.map +1 -1
- package/dist/scenes/selecting/index.js +4 -12
- package/package.json +1 -1
- package/src/components/dialog.ts +2 -3
- package/src/connector/index.ts +28 -11
- package/src/events/index.ts +22 -0
- package/src/scenes/connected.ts +1 -6
- package/src/scenes/selecting/connecting.ts +1 -3
- package/src/scenes/selecting/index.ts +6 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ckb-ccc/connector
|
|
2
2
|
|
|
3
|
+
## 0.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2483637`](https://github.com/ckb-ecofund/ccc/commit/2483637c89a2e012ed6408d8cabc123b8a45faa9) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(connector): animation
|
|
8
|
+
|
|
3
9
|
## 0.0.14
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/components/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/components/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAM5C,qBACa,MAAO,SAAQ,UAAU;IAE7B,OAAO,EAAE,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC;IAEhC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEvB,MAAM;IA6BN,MAAM,CAAC,MAAM,0BA0DX;CACH"}
|
|
@@ -8,6 +8,7 @@ import { css, html, LitElement } from "lit";
|
|
|
8
8
|
import { customElement, property } from "lit/decorators.js";
|
|
9
9
|
import { CLOSE_SVG } from "../assets/close.svg.js";
|
|
10
10
|
import { LEFT_SVG } from "../assets/left.svg.js";
|
|
11
|
+
import { CloseEvent } from "../events/index.js";
|
|
11
12
|
let Dialog = class Dialog extends LitElement {
|
|
12
13
|
render() {
|
|
13
14
|
return html `
|
|
@@ -26,7 +27,7 @@ let Dialog = class Dialog extends LitElement {
|
|
|
26
27
|
<span
|
|
27
28
|
class="close active"
|
|
28
29
|
@click=${() => {
|
|
29
|
-
this.dispatchEvent(new
|
|
30
|
+
this.dispatchEvent(new CloseEvent());
|
|
30
31
|
}}
|
|
31
32
|
>
|
|
32
33
|
${CLOSE_SVG}
|
|
@@ -28,6 +28,7 @@ export declare class WebComponentConnector extends LitElement {
|
|
|
28
28
|
private readonly mainRef;
|
|
29
29
|
private readonly bodyRef;
|
|
30
30
|
render(): import("lit").TemplateResult<1>;
|
|
31
|
+
onClose(onClosed?: () => void): void;
|
|
31
32
|
updated(): void;
|
|
32
33
|
static styles: import("lit").CSSResult;
|
|
33
34
|
}
|
|
@@ -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;
|
|
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;AAU5D,qBACa,qBAAsB,SAAQ,UAAU;IAE5C,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,CAAC;IAE5C,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC;IAE1C,aAAa,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAGtE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAiC;IACnD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM;IAInC,OAAO,CAAC,sBAAsB,CAA+B;IAG7D,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;IAE/B,OAAO,CAAC,wBAAwB,CAAC,CAAa;IAEvC,UAAU;IASjB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAUtB,iBAAiB,IAAI,IAAI;IAKzB,UAAU,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI;IAoBnD,aAAa;IAQP,YAAY,CAChB,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,EAC9B,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,SAAS;IAsBxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CACV;IAEd,MAAM;IA2CN,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI;IAY7B,OAAO;IASP,MAAM,CAAC,MAAM,0BAyBX;CACH"}
|
package/dist/connector/index.js
CHANGED
|
@@ -8,6 +8,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
10
|
import { createRef, ref } from "lit/directives/ref.js";
|
|
11
|
+
import { CloseEvent, } from "../events/index.js";
|
|
11
12
|
import { SignersController } from "../signers/index.js";
|
|
12
13
|
let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
13
14
|
constructor() {
|
|
@@ -21,11 +22,12 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
21
22
|
this.client = client;
|
|
22
23
|
}
|
|
23
24
|
disconnect() {
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
this.onClose(() => {
|
|
26
|
+
this.walletName = undefined;
|
|
27
|
+
this.signerName = undefined;
|
|
28
|
+
this.saveConnection();
|
|
29
|
+
this.signer?.signer.disconnect();
|
|
30
|
+
});
|
|
29
31
|
}
|
|
30
32
|
loadConnection() {
|
|
31
33
|
const { signerName, walletName, } = JSON.parse(window.localStorage.getItem("ccc-connection-info") ?? "{}");
|
|
@@ -85,10 +87,13 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
85
87
|
class="background"
|
|
86
88
|
@click=${(event) => {
|
|
87
89
|
if (event.target === event.currentTarget) {
|
|
88
|
-
this.
|
|
89
|
-
this.bodyRef.value?.onClose?.();
|
|
90
|
+
this.onClose();
|
|
90
91
|
}
|
|
91
92
|
}}
|
|
93
|
+
@close=${(event) => {
|
|
94
|
+
event.stopPropagation();
|
|
95
|
+
this.onClose(event.callback);
|
|
96
|
+
}}
|
|
92
97
|
@updated=${() => this.updated()}
|
|
93
98
|
>
|
|
94
99
|
<div class="main" ${ref(this.mainRef)}>
|
|
@@ -118,6 +123,16 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
118
123
|
</div>
|
|
119
124
|
</div>`;
|
|
120
125
|
}
|
|
126
|
+
onClose(onClosed) {
|
|
127
|
+
if (this.mainRef.value) {
|
|
128
|
+
this.mainRef.value.style.height = "0";
|
|
129
|
+
}
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
this.dispatchEvent(new CloseEvent());
|
|
132
|
+
this.bodyRef.value?.onClose?.();
|
|
133
|
+
onClosed?.();
|
|
134
|
+
}, 150);
|
|
135
|
+
}
|
|
121
136
|
updated() {
|
|
122
137
|
if (!this.mainRef.value) {
|
|
123
138
|
return;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/ccc";
|
|
2
|
+
export declare class SelectClientEvent extends Event {
|
|
3
|
+
client: ccc.Client;
|
|
4
|
+
constructor(client: ccc.Client);
|
|
5
|
+
}
|
|
6
|
+
export declare class ConnectedEvent extends Event {
|
|
7
|
+
readonly walletName: string;
|
|
8
|
+
readonly signerName: string;
|
|
9
|
+
constructor(walletName: string, signerName: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class CloseEvent extends Event {
|
|
12
|
+
callback?: (() => void) | undefined;
|
|
13
|
+
constructor(callback?: (() => void) | undefined);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,qBAAa,iBAAkB,SAAQ,KAAK;IACvB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAAlB,MAAM,EAAE,GAAG,CAAC,MAAM;CAGtC;AAED,qBAAa,cAAe,SAAQ,KAAK;aAErB,UAAU,EAAE,MAAM;aAClB,UAAU,EAAE,MAAM;gBADlB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM;CAIrC;AAED,qBAAa,UAAW,SAAQ,KAAK;IAChB,QAAQ,CAAC,SAAQ,IAAI;gBAArB,QAAQ,CAAC,SAAQ,IAAI,aAAA;CAGzC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class SelectClientEvent extends Event {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
super("select-client");
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class ConnectedEvent extends Event {
|
|
8
|
+
constructor(walletName, signerName) {
|
|
9
|
+
super("connected");
|
|
10
|
+
this.walletName = walletName;
|
|
11
|
+
this.signerName = signerName;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class CloseEvent extends Event {
|
|
15
|
+
constructor(callback) {
|
|
16
|
+
super("close", { bubbles: true, composed: true });
|
|
17
|
+
this.callback = callback;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/ccc";
|
|
2
2
|
import { LitElement, PropertyValues } from "lit";
|
|
3
|
-
export declare class SelectClientEvent extends Event {
|
|
4
|
-
client: ccc.Client;
|
|
5
|
-
constructor(client: ccc.Client);
|
|
6
|
-
}
|
|
7
3
|
export declare function formatString(str: string | undefined, l?: number, r?: number): string | undefined;
|
|
8
4
|
export declare class ConnectedScene extends LitElement {
|
|
9
5
|
wallet?: ccc.Wallet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../../src/scenes/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAa,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../../src/scenes/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAa,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAU5D,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,CAAC,SAAI,EACL,CAAC,SAAI,GACJ,MAAM,GAAG,SAAS,CAKpB;AAED,qBACa,cAAe,SAAQ,UAAU;IAErC,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAEpB,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAEpB,aAAa,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAG7E,OAAO,CAAC,kBAAkB,CAAC,CAAS;IAEpC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC,OAAO,CAAC,OAAO,CAAC,CAAU;IAE1B,OAAO,CAAC,eAAe,CAAS;IAEhC,UAAU,CAAC,iBAAiB,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IAgBzD,MAAM;IAoGN,MAAM,CAAC,MAAM,0BAmHX;IAEF,OAAO;CAGR"}
|
package/dist/scenes/connected.js
CHANGED
|
@@ -12,13 +12,8 @@ import { CKB_SVG } from "../assets/chains/index.js";
|
|
|
12
12
|
import { DISCONNECT_SVG } from "../assets/diconnect.svg.js";
|
|
13
13
|
import { SWAP_SVG } from "../assets/swap.svg.js";
|
|
14
14
|
import { USER_SVG } from "../assets/user.svg.js";
|
|
15
|
+
import { SelectClientEvent } from "../events/index.js";
|
|
15
16
|
import { signerTypeToIcon } from "./selecting/signers.js";
|
|
16
|
-
export class SelectClientEvent extends Event {
|
|
17
|
-
constructor(client) {
|
|
18
|
-
super("select-client");
|
|
19
|
-
this.client = client;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
17
|
export function formatString(str, l = 9, r = 6) {
|
|
23
18
|
if (str && str.length > l + r + 3) {
|
|
24
19
|
return `${str.slice(0, l)}...${str.slice(-r)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connecting.d.ts","sourceRoot":"","sources":["../../../src/scenes/selecting/connecting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,CAAC,iBAAiB,EAC7B,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,gBAAgB,EAAE,CAChB,MAAM,EAAE,GAAG,CAAC,iBAAiB,EAC7B,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,
|
|
1
|
+
{"version":3,"file":"connecting.d.ts","sourceRoot":"","sources":["../../../src/scenes/selecting/connecting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,CAAC,iBAAiB,EAC7B,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,gBAAgB,EAAE,CAChB,MAAM,EAAE,GAAG,CAAC,iBAAiB,EAC7B,MAAM,EAAE,GAAG,CAAC,UAAU,KACnB,OAAO,gDA0Bb"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/ccc";
|
|
2
2
|
import { LitElement } from "lit";
|
|
3
|
-
export declare class ConnectedEvent extends Event {
|
|
4
|
-
readonly walletName: string;
|
|
5
|
-
readonly signerName: string;
|
|
6
|
-
constructor(walletName: string, signerName: string);
|
|
7
|
-
}
|
|
8
3
|
export declare class SelectingScene extends LitElement {
|
|
9
4
|
wallets?: ccc.WalletWithSigners[];
|
|
10
5
|
private selectedWallet?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scenes/selecting/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scenes/selecting/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAO5C,qBACa,cAAe,SAAQ,UAAU;IAErC,OAAO,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,CAAC;IAGzC,OAAO,CAAC,cAAc,CAAC,CAAwB;IAE/C,OAAO,CAAC,cAAc,CAAC,CAAiB;IAExC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC,MAAM;IA4CC,OAAO;IAMd,OAAO,CAAC,qBAAqB,CA2C3B;IAEF,MAAM,CAAC,MAAM,0BA0DX;IAEF,OAAO;CAGR"}
|
|
@@ -6,16 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { css, html, LitElement } from "lit";
|
|
8
8
|
import { customElement, property, state } from "lit/decorators.js";
|
|
9
|
+
import { CloseEvent, ConnectedEvent } from "../../events/index.js";
|
|
9
10
|
import { generateConnectingScene } from "./connecting.js";
|
|
10
11
|
import { generateSignersScene } from "./signers.js";
|
|
11
12
|
import { generateWalletsScene } from "./wallets.js";
|
|
12
|
-
export class ConnectedEvent extends Event {
|
|
13
|
-
constructor(walletName, signerName) {
|
|
14
|
-
super("connected");
|
|
15
|
-
this.walletName = walletName;
|
|
16
|
-
this.signerName = signerName;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
13
|
let SelectingScene = class SelectingScene extends LitElement {
|
|
20
14
|
constructor() {
|
|
21
15
|
super(...arguments);
|
|
@@ -49,8 +43,9 @@ let SelectingScene = class SelectingScene extends LitElement {
|
|
|
49
43
|
this.connectingError = JSON.stringify(message);
|
|
50
44
|
return;
|
|
51
45
|
}
|
|
52
|
-
this.dispatchEvent(new
|
|
53
|
-
|
|
46
|
+
this.dispatchEvent(new CloseEvent(() => {
|
|
47
|
+
this.dispatchEvent(new ConnectedEvent(wallet.name, signerInfo.name));
|
|
48
|
+
}));
|
|
54
49
|
})();
|
|
55
50
|
};
|
|
56
51
|
}
|
|
@@ -69,9 +64,6 @@ let SelectingScene = class SelectingScene extends LitElement {
|
|
|
69
64
|
return html `<ccc-dialog
|
|
70
65
|
header=${title}
|
|
71
66
|
?canBack=${this.selectedSigner || this.selectedWallet}
|
|
72
|
-
@close=${() => {
|
|
73
|
-
this.onClose();
|
|
74
|
-
}}
|
|
75
67
|
@back=${() => {
|
|
76
68
|
if (!this.selectedSigner ||
|
|
77
69
|
(this.selectedWallet && this.selectedWallet.signers.length <= 1)) {
|
package/package.json
CHANGED
package/src/components/dialog.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { css, html, LitElement } from "lit";
|
|
|
2
2
|
import { customElement, property } from "lit/decorators.js";
|
|
3
3
|
import { CLOSE_SVG } from "../assets/close.svg.js";
|
|
4
4
|
import { LEFT_SVG } from "../assets/left.svg.js";
|
|
5
|
+
import { CloseEvent } from "../events/index.js";
|
|
5
6
|
|
|
6
7
|
@customElement("ccc-dialog")
|
|
7
8
|
export class Dialog extends LitElement {
|
|
@@ -27,9 +28,7 @@ export class Dialog extends LitElement {
|
|
|
27
28
|
<span
|
|
28
29
|
class="close active"
|
|
29
30
|
@click=${() => {
|
|
30
|
-
this.dispatchEvent(
|
|
31
|
-
new Event("close", { bubbles: true, composed: true }),
|
|
32
|
-
);
|
|
31
|
+
this.dispatchEvent(new CloseEvent());
|
|
33
32
|
}}
|
|
34
33
|
>
|
|
35
34
|
${CLOSE_SVG}
|
package/src/connector/index.ts
CHANGED
|
@@ -2,8 +2,11 @@ import { ccc } from "@ckb-ccc/ccc";
|
|
|
2
2
|
import { LitElement, PropertyValues, css, html } from "lit";
|
|
3
3
|
import { customElement, property, state } from "lit/decorators.js";
|
|
4
4
|
import { Ref, createRef, ref } from "lit/directives/ref.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
CloseEvent,
|
|
7
|
+
ConnectedEvent,
|
|
8
|
+
SelectClientEvent,
|
|
9
|
+
} from "../events/index.js";
|
|
7
10
|
import { SignersController } from "../signers/index.js";
|
|
8
11
|
|
|
9
12
|
@customElement("ccc-connector")
|
|
@@ -39,11 +42,12 @@ export class WebComponentConnector extends LitElement {
|
|
|
39
42
|
private unregisterSignerReplacer?: () => void;
|
|
40
43
|
|
|
41
44
|
public disconnect() {
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
this.onClose(() => {
|
|
46
|
+
this.walletName = undefined;
|
|
47
|
+
this.signerName = undefined;
|
|
48
|
+
this.saveConnection();
|
|
49
|
+
this.signer?.signer.disconnect();
|
|
50
|
+
});
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
private loadConnection() {
|
|
@@ -134,12 +138,13 @@ export class WebComponentConnector extends LitElement {
|
|
|
134
138
|
class="background"
|
|
135
139
|
@click=${(event: Event) => {
|
|
136
140
|
if (event.target === event.currentTarget) {
|
|
137
|
-
this.
|
|
138
|
-
new Event("close", { bubbles: true, composed: true }),
|
|
139
|
-
);
|
|
140
|
-
this.bodyRef.value?.onClose?.();
|
|
141
|
+
this.onClose();
|
|
141
142
|
}
|
|
142
143
|
}}
|
|
144
|
+
@close=${(event: CloseEvent) => {
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
this.onClose(event.callback);
|
|
147
|
+
}}
|
|
143
148
|
@updated=${() => this.updated()}
|
|
144
149
|
>
|
|
145
150
|
<div class="main" ${ref(this.mainRef)}>
|
|
@@ -171,6 +176,18 @@ export class WebComponentConnector extends LitElement {
|
|
|
171
176
|
</div>`;
|
|
172
177
|
}
|
|
173
178
|
|
|
179
|
+
onClose(onClosed?: () => void) {
|
|
180
|
+
if (this.mainRef.value) {
|
|
181
|
+
this.mainRef.value.style.height = "0";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
this.dispatchEvent(new CloseEvent());
|
|
186
|
+
this.bodyRef.value?.onClose?.();
|
|
187
|
+
onClosed?.();
|
|
188
|
+
}, 150);
|
|
189
|
+
}
|
|
190
|
+
|
|
174
191
|
updated() {
|
|
175
192
|
if (!this.mainRef.value) {
|
|
176
193
|
return;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/ccc";
|
|
2
|
+
|
|
3
|
+
export class SelectClientEvent extends Event {
|
|
4
|
+
constructor(public client: ccc.Client) {
|
|
5
|
+
super("select-client");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ConnectedEvent extends Event {
|
|
10
|
+
constructor(
|
|
11
|
+
public readonly walletName: string,
|
|
12
|
+
public readonly signerName: string,
|
|
13
|
+
) {
|
|
14
|
+
super("connected");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class CloseEvent extends Event {
|
|
19
|
+
constructor(public callback?: () => void) {
|
|
20
|
+
super("close", { bubbles: true, composed: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/scenes/connected.ts
CHANGED
|
@@ -6,14 +6,9 @@ import { CKB_SVG } from "../assets/chains/index.js";
|
|
|
6
6
|
import { DISCONNECT_SVG } from "../assets/diconnect.svg.js";
|
|
7
7
|
import { SWAP_SVG } from "../assets/swap.svg.js";
|
|
8
8
|
import { USER_SVG } from "../assets/user.svg.js";
|
|
9
|
+
import { SelectClientEvent } from "../events/index.js";
|
|
9
10
|
import { signerTypeToIcon } from "./selecting/signers.js";
|
|
10
11
|
|
|
11
|
-
export class SelectClientEvent extends Event {
|
|
12
|
-
constructor(public client: ccc.Client) {
|
|
13
|
-
super("select-client");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
12
|
export function formatString(
|
|
18
13
|
str: string | undefined,
|
|
19
14
|
l = 9,
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/ccc";
|
|
2
2
|
import { css, html, LitElement } from "lit";
|
|
3
3
|
import { customElement, property, state } from "lit/decorators.js";
|
|
4
|
+
import { CloseEvent, ConnectedEvent } from "../../events/index.js";
|
|
4
5
|
import { generateConnectingScene } from "./connecting.js";
|
|
5
6
|
import { generateSignersScene } from "./signers.js";
|
|
6
7
|
import { generateWalletsScene } from "./wallets.js";
|
|
7
8
|
|
|
8
|
-
export class ConnectedEvent extends Event {
|
|
9
|
-
constructor(
|
|
10
|
-
public readonly walletName: string,
|
|
11
|
-
public readonly signerName: string,
|
|
12
|
-
) {
|
|
13
|
-
super("connected");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
9
|
@customElement("ccc-selecting-scene")
|
|
18
10
|
export class SelectingScene extends LitElement {
|
|
19
11
|
@property()
|
|
@@ -55,9 +47,6 @@ export class SelectingScene extends LitElement {
|
|
|
55
47
|
return html`<ccc-dialog
|
|
56
48
|
header=${title}
|
|
57
49
|
?canBack=${this.selectedSigner || this.selectedWallet}
|
|
58
|
-
@close=${() => {
|
|
59
|
-
this.onClose();
|
|
60
|
-
}}
|
|
61
50
|
@back=${() => {
|
|
62
51
|
if (
|
|
63
52
|
!this.selectedSigner ||
|
|
@@ -116,8 +105,11 @@ export class SelectingScene extends LitElement {
|
|
|
116
105
|
return;
|
|
117
106
|
}
|
|
118
107
|
|
|
119
|
-
this.dispatchEvent(
|
|
120
|
-
|
|
108
|
+
this.dispatchEvent(
|
|
109
|
+
new CloseEvent(() => {
|
|
110
|
+
this.dispatchEvent(new ConnectedEvent(wallet.name, signerInfo.name));
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
121
113
|
})();
|
|
122
114
|
};
|
|
123
115
|
|