@ckb-ccc/connector 0.0.5-alpha.0 → 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.
@@ -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>');
@@ -1,10 +1,13 @@
1
1
  import { ccc } from "@ckb-ccc/ccc";
2
2
  import { LitElement, PropertyValues } from "lit";
3
+ import { Ref } from "lit/directives/ref.js";
3
4
  export declare class WebComponentConnector extends LitElement {
4
5
  private wallets;
5
6
  private resetListeners;
6
7
  isOpen: boolean;
7
8
  setIsOpen(isOpen: boolean): void;
9
+ name?: string;
10
+ icon?: string;
8
11
  client: ccc.Client;
9
12
  setClient(client: ccc.Client): void;
10
13
  private scene;
@@ -22,7 +25,11 @@ export declare class WebComponentConnector extends LitElement {
22
25
  willUpdate(changedProperties: PropertyValues): void;
23
26
  private reloadSigners;
24
27
  private addSigner;
28
+ mainRef: Ref<HTMLDivElement>;
29
+ headerRef: Ref<HTMLDivElement>;
30
+ bodyRef: Ref<HTMLDivElement>;
25
31
  render(): import("lit").TemplateResult<1>;
32
+ updated(): void;
26
33
  private closedHandler;
27
34
  private signerSelectedHandler;
28
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;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,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;IAyDrB,OAAO,CAAC,SAAS;IA+BjB,MAAM;IAwDN,OAAO,CAAC,aAAa,CAanB;IAEF,OAAO,CAAC,qBAAqB,CAkB3B;IAEF,MAAM,CAAC,MAAM,0BAiIX;CACH"}
1
+ {"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IAUP,OAAO,CAAC,aAAa,CAanB;IAEF,OAAO,CAAC,qBAAqB,CAkB3B;IAEF,MAAM,CAAC,MAAM,0BA4IX;CACH"}
@@ -7,8 +7,10 @@ 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";
11
12
  import { JOY_ID_SVG } from "../assets/joy-id.svg";
13
+ import { LEFT_SVG } from "../assets/left.svg";
12
14
  import { OKX_SVG } from "../assets/okx.svg";
13
15
  import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
14
16
  import { WillUpdateEvent } from "../events";
@@ -28,6 +30,9 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
28
30
  this.isOpen = false;
29
31
  this.client = new ccc.ClientPublicTestnet();
30
32
  this.scene = Scene.SelectingWallets;
33
+ this.mainRef = createRef();
34
+ this.headerRef = createRef();
35
+ this.bodyRef = createRef();
31
36
  this.closedHandler = () => {
32
37
  if ([
33
38
  Scene.SelectingSigners,
@@ -127,7 +132,11 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
127
132
  })();
128
133
  this.resetListeners.forEach((listener) => listener());
129
134
  this.resetListeners = [];
130
- ccc.JoyId.getJoyIdSigners(this.client).forEach(({ signer, type, name }) => {
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 }) => {
131
140
  this.addSigner("JoyID", name, JOY_ID_SVG, type, signer);
132
141
  });
133
142
  const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
@@ -177,6 +186,7 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
177
186
  }
178
187
  return generateConnectingScene(this.selectedWallet, this.selectedSigner, this.signerSelectedHandler);
179
188
  })();
189
+ const canBack = [Scene.SelectingSigners, Scene.Connecting].includes(this.scene);
180
190
  return html `<style>
181
191
  :host {
182
192
  ${this.isOpen ? "" : "display: none;"}
@@ -197,16 +207,38 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
197
207
  }
198
208
  }}
199
209
  >
200
- <div class="main">
201
- <div class="header text-bold fs-big">
202
- <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
+ />
203
224
  ${title}
204
- <img class="close" src=${CLOSE_SVG} @click=${this.closedHandler} />
225
+ <img
226
+ class="close active"
227
+ src=${CLOSE_SVG}
228
+ @click=${this.closedHandler}
229
+ />
205
230
  </div>
206
- <div class="body">${body}</div>
231
+ <div class="body" ${ref(this.bodyRef)}>${body}</div>
207
232
  </div>
208
233
  </div>`;
209
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
+ }
210
242
  };
211
243
  WebComponentConnector.styles = css `
212
244
  :host {
@@ -265,6 +297,8 @@ WebComponentConnector.styles = css `
265
297
  transform: translate(-50%, -50%);
266
298
  background: var(--background);
267
299
  border-radius: 1.2rem;
300
+ overflow: hidden;
301
+ transition: height 0.15s ease-out;
268
302
  }
269
303
 
270
304
  .header {
@@ -279,6 +313,13 @@ WebComponentConnector.styles = css `
279
313
  .back {
280
314
  width: 0.8rem;
281
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;
282
323
  cursor: pointer;
283
324
  }
284
325
 
@@ -298,13 +339,14 @@ WebComponentConnector.styles = css `
298
339
  padding: 0.75rem 1rem;
299
340
  background: var(--btn-primary);
300
341
  border-radius: 0.4rem;
301
- transition: background 0.3s ease-in-out;
342
+ transition: background 0.15s ease-in-out;
302
343
  }
303
344
 
304
345
  .btn-primary img {
305
346
  width: 2rem;
306
347
  height: 2rem;
307
348
  margin-right: 1rem;
349
+ border-radius: 0.4rem;
308
350
  }
309
351
 
310
352
  .btn-primary:hover {
@@ -317,7 +359,7 @@ WebComponentConnector.styles = css `
317
359
  padding: 0.25rem 1rem;
318
360
  background: var(--btn-secondary);
319
361
  border-radius: 9999px;
320
- transition: background 0.3s ease-in-out;
362
+ transition: background 0.15s ease-in-out;
321
363
  }
322
364
 
323
365
  .btn-secondary img {
@@ -330,6 +372,7 @@ WebComponentConnector.styles = css `
330
372
  width: 4rem;
331
373
  height: 4rem;
332
374
  margin-bottom: 0.5rem;
375
+ border-radius: 0.8rem;
333
376
  }
334
377
 
335
378
  .connecting-wallet-icon {
@@ -344,6 +387,12 @@ __decorate([
344
387
  __decorate([
345
388
  state()
346
389
  ], WebComponentConnector.prototype, "isOpen", void 0);
390
+ __decorate([
391
+ property()
392
+ ], WebComponentConnector.prototype, "name", void 0);
393
+ __decorate([
394
+ property()
395
+ ], WebComponentConnector.prototype, "icon", void 0);
347
396
  __decorate([
348
397
  property()
349
398
  ], WebComponentConnector.prototype, "client", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/connector",
3
- "version": "0.0.5-alpha.0",
3
+ "version": "0.0.5-alpha.1",
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.5-alpha.0",
40
+ "@ckb-ccc/ccc": "0.0.5-alpha.1",
41
41
  "lit": "^3.1.3"
42
42
  },
43
- "gitHead": "8a927f901a8f2fe7dfe2f6bf78a44689d6503949"
43
+ "gitHead": "98d6d902fff0cc3d65f536cb85b32c867045d15d"
44
44
  }
@@ -0,0 +1,5 @@
1
+ import { encodeSvgToImgSrc } from "./utils";
2
+
3
+ export const LEFT_SVG = encodeSvgToImgSrc(
4
+ '<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>',
5
+ );
@@ -1,8 +1,10 @@
1
1
  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
+ import { Ref, createRef, ref } from "lit/directives/ref.js";
4
5
  import { CLOSE_SVG } from "../assets/close.svg";
5
6
  import { JOY_ID_SVG } from "../assets/joy-id.svg";
7
+ import { LEFT_SVG } from "../assets/left.svg";
6
8
  import { OKX_SVG } from "../assets/okx.svg";
7
9
  import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
8
10
  import { WillUpdateEvent } from "../events";
@@ -33,6 +35,11 @@ export class WebComponentConnector extends LitElement {
33
35
  this.isOpen = isOpen;
34
36
  }
35
37
 
38
+ @property()
39
+ public name?: string;
40
+ @property()
41
+ public icon?: string;
42
+
36
43
  @property()
37
44
  public client: ccc.Client = new ccc.ClientPublicTestnet();
38
45
  public setClient(client: ccc.Client) {
@@ -144,10 +151,18 @@ export class WebComponentConnector extends LitElement {
144
151
 
145
152
  this.resetListeners.forEach((listener) => listener());
146
153
  this.resetListeners = [];
147
-
148
- ccc.JoyId.getJoyIdSigners(this.client).forEach(({ signer, type, name }) => {
149
- this.addSigner("JoyID", name, JOY_ID_SVG, type, signer);
150
- });
154
+ const name =
155
+ this.name ??
156
+ (document.querySelector("head title") as HTMLTitleElement).text;
157
+ const icon =
158
+ this.icon ??
159
+ (document.querySelector('link[rel="icon"]') as HTMLLinkElement).href;
160
+
161
+ ccc.JoyId.getJoyIdSigners(this.client, name, icon).forEach(
162
+ ({ signer, type, name }) => {
163
+ this.addSigner("JoyID", name, JOY_ID_SVG, type, signer);
164
+ },
165
+ );
151
166
 
152
167
  const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
153
168
  if (uniSatSigner) {
@@ -216,6 +231,10 @@ export class WebComponentConnector extends LitElement {
216
231
  this.wallets = wallets;
217
232
  }
218
233
 
234
+ mainRef: Ref<HTMLDivElement> = createRef();
235
+ headerRef: Ref<HTMLDivElement> = createRef();
236
+ bodyRef: Ref<HTMLDivElement> = createRef();
237
+
219
238
  render() {
220
239
  const [title, body] = (() => {
221
240
  if (this.scene === Scene.SelectingWallets || !this.selectedWallet) {
@@ -241,6 +260,10 @@ export class WebComponentConnector extends LitElement {
241
260
  );
242
261
  })();
243
262
 
263
+ const canBack = [Scene.SelectingSigners, Scene.Connecting].includes(
264
+ this.scene,
265
+ );
266
+
244
267
  return html`<style>
245
268
  :host {
246
269
  ${this.isOpen ? "" : "display: none;"}
@@ -261,17 +284,41 @@ export class WebComponentConnector extends LitElement {
261
284
  }
262
285
  }}
263
286
  >
264
- <div class="main">
265
- <div class="header text-bold fs-big">
266
- <div class="back"></div>
287
+ <div class="main" ${ref(this.mainRef)}>
288
+ <div class="header text-bold fs-big" ${ref(this.headerRef)}>
289
+ <img
290
+ class="back ${canBack ? "active" : ""}"
291
+ src=${LEFT_SVG}
292
+ @click=${() => {
293
+ if (this.scene === Scene.Connecting) {
294
+ this.scene = Scene.SelectingSigners;
295
+ } else if (this.scene === Scene.SelectingSigners) {
296
+ this.scene = Scene.SelectingWallets;
297
+ }
298
+ }}
299
+ />
267
300
  ${title}
268
- <img class="close" src=${CLOSE_SVG} @click=${this.closedHandler} />
301
+ <img
302
+ class="close active"
303
+ src=${CLOSE_SVG}
304
+ @click=${this.closedHandler}
305
+ />
269
306
  </div>
270
- <div class="body">${body}</div>
307
+ <div class="body" ${ref(this.bodyRef)}>${body}</div>
271
308
  </div>
272
309
  </div>`;
273
310
  }
274
311
 
312
+ updated() {
313
+ if (!this.mainRef.value) {
314
+ return;
315
+ }
316
+ this.mainRef.value.style.height = `${
317
+ (this.bodyRef.value?.clientHeight ?? 0) +
318
+ (this.headerRef.value?.clientHeight ?? 0)
319
+ }px`;
320
+ }
321
+
275
322
  private closedHandler = () => {
276
323
  if (
277
324
  [
@@ -364,6 +411,8 @@ export class WebComponentConnector extends LitElement {
364
411
  transform: translate(-50%, -50%);
365
412
  background: var(--background);
366
413
  border-radius: 1.2rem;
414
+ overflow: hidden;
415
+ transition: height 0.15s ease-out;
367
416
  }
368
417
 
369
418
  .header {
@@ -378,6 +427,13 @@ export class WebComponentConnector extends LitElement {
378
427
  .back {
379
428
  width: 0.8rem;
380
429
  height: 0.8rem;
430
+ opacity: 0;
431
+ transition: opacity 0.15s ease-in-out;
432
+ }
433
+
434
+ .close.active,
435
+ .back.active {
436
+ opacity: 1;
381
437
  cursor: pointer;
382
438
  }
383
439
 
@@ -397,13 +453,14 @@ export class WebComponentConnector extends LitElement {
397
453
  padding: 0.75rem 1rem;
398
454
  background: var(--btn-primary);
399
455
  border-radius: 0.4rem;
400
- transition: background 0.3s ease-in-out;
456
+ transition: background 0.15s ease-in-out;
401
457
  }
402
458
 
403
459
  .btn-primary img {
404
460
  width: 2rem;
405
461
  height: 2rem;
406
462
  margin-right: 1rem;
463
+ border-radius: 0.4rem;
407
464
  }
408
465
 
409
466
  .btn-primary:hover {
@@ -416,7 +473,7 @@ export class WebComponentConnector extends LitElement {
416
473
  padding: 0.25rem 1rem;
417
474
  background: var(--btn-secondary);
418
475
  border-radius: 9999px;
419
- transition: background 0.3s ease-in-out;
476
+ transition: background 0.15s ease-in-out;
420
477
  }
421
478
 
422
479
  .btn-secondary img {
@@ -429,6 +486,7 @@ export class WebComponentConnector extends LitElement {
429
486
  width: 4rem;
430
487
  height: 4rem;
431
488
  margin-bottom: 0.5rem;
489
+ border-radius: 0.8rem;
432
490
  }
433
491
 
434
492
  .connecting-wallet-icon {