@ckb-ccc/connector 0.0.5-alpha.1 → 0.0.5-alpha.3
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/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +1 -0
- package/dist/assets/chains/ckb.sm.svg.d.ts +2 -0
- package/dist/assets/chains/ckb.sm.svg.d.ts.map +1 -0
- package/dist/assets/chains/ckb.sm.svg.js +2 -0
- package/dist/assets/copy.svg.d.ts +2 -0
- package/dist/assets/copy.svg.d.ts.map +1 -0
- package/dist/assets/copy.svg.js +2 -0
- package/dist/assets/diconnect.svg.d.ts +2 -0
- package/dist/assets/diconnect.svg.d.ts.map +1 -0
- package/dist/assets/diconnect.svg.js +2 -0
- package/dist/assets/swap.svg.d.ts +2 -0
- package/dist/assets/swap.svg.d.ts.map +1 -0
- package/dist/assets/swap.svg.js +2 -0
- package/dist/connector/index.d.ts +5 -0
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +225 -34
- package/dist/scenes/connected.d.ts +4 -0
- package/dist/scenes/connected.d.ts.map +1 -0
- package/dist/scenes/connected.js +71 -0
- package/dist/scenes/networks.d.ts +3 -0
- package/dist/scenes/networks.d.ts.map +1 -0
- package/dist/scenes/networks.js +38 -0
- package/dist/scenes/signers.d.ts.map +1 -1
- package/dist/scenes/signers.js +5 -2
- package/dist/scenes/wallets.d.ts +1 -1
- package/dist/scenes/wallets.d.ts.map +1 -1
- package/dist/scenes/wallets.js +9 -44
- package/dist/signerOpenLink/index.d.ts +13 -0
- package/dist/signerOpenLink/index.d.ts.map +1 -0
- package/dist/signerOpenLink/index.js +26 -0
- package/package.json +3 -3
- package/src/advancedBarrel.ts +1 -0
- package/src/assets/chains/ckb.sm.svg.ts +5 -0
- package/src/assets/copy.svg.ts +5 -0
- package/src/assets/diconnect.svg.ts +5 -0
- package/src/assets/swap.svg.ts +5 -0
- package/src/connector/index.ts +270 -52
- package/src/scenes/connected.ts +87 -0
- package/src/scenes/networks.ts +47 -0
- package/src/scenes/signers.ts +5 -2
- package/src/scenes/wallets.ts +20 -63
- package/src/signerOpenLink/index.ts +35 -0
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
package/src/connector/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Ref, createRef, ref } from "lit/directives/ref.js";
|
|
|
5
5
|
import { CLOSE_SVG } from "../assets/close.svg";
|
|
6
6
|
import { JOY_ID_SVG } from "../assets/joy-id.svg";
|
|
7
7
|
import { LEFT_SVG } from "../assets/left.svg";
|
|
8
|
+
import { METAMASK_SVG } from "../assets/metamask.svg";
|
|
8
9
|
import { OKX_SVG } from "../assets/okx.svg";
|
|
9
10
|
import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
|
|
10
11
|
import { WillUpdateEvent } from "../events";
|
|
@@ -13,6 +14,9 @@ import {
|
|
|
13
14
|
generateSignersScene,
|
|
14
15
|
generateWalletsScene,
|
|
15
16
|
} from "../scenes";
|
|
17
|
+
import { generateConnectedScene } from "../scenes/connected";
|
|
18
|
+
import { generateNetworksScene } from "../scenes/networks";
|
|
19
|
+
import { SignerOpenLink } from "../signerOpenLink";
|
|
16
20
|
import { WalletWithSigners } from "../types";
|
|
17
21
|
|
|
18
22
|
enum Scene {
|
|
@@ -20,12 +24,18 @@ enum Scene {
|
|
|
20
24
|
SelectingSigners = "SelectingSigners",
|
|
21
25
|
Connecting = "Connecting",
|
|
22
26
|
Connected = "Connected",
|
|
27
|
+
SwitchingNetworks = "SwitchingNetworks",
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
@customElement("ccc-connector")
|
|
26
31
|
export class WebComponentConnector extends LitElement {
|
|
27
32
|
@state()
|
|
28
33
|
private wallets: WalletWithSigners[] = [];
|
|
34
|
+
@property()
|
|
35
|
+
public signerFilter?: (
|
|
36
|
+
signerInfo: ccc.SignerInfo,
|
|
37
|
+
wallet: ccc.Wallet,
|
|
38
|
+
) => Promise<boolean>;
|
|
29
39
|
|
|
30
40
|
private resetListeners: (() => void)[] = [];
|
|
31
41
|
|
|
@@ -61,17 +71,33 @@ export class WebComponentConnector extends LitElement {
|
|
|
61
71
|
public wallet?: ccc.Wallet;
|
|
62
72
|
@state()
|
|
63
73
|
public signer?: ccc.SignerInfo;
|
|
64
|
-
private prepareSigner() {
|
|
65
|
-
(async () => {
|
|
66
|
-
if (this.signer && (await this.signer.signer.isConnected())) {
|
|
67
|
-
this.scene = Scene.Connected;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
@state()
|
|
76
|
+
private recommendAddress?: string;
|
|
77
|
+
@state()
|
|
78
|
+
private internalAddress?: string;
|
|
79
|
+
@state()
|
|
80
|
+
private balance?: ccc.Num;
|
|
81
|
+
|
|
82
|
+
private async updateSignerInfo() {
|
|
83
|
+
if (!this.signer) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.recommendAddress = await this.signer.signer.getRecommendedAddress();
|
|
87
|
+
this.balance = await this.signer.signer.getBalance();
|
|
88
|
+
this.internalAddress = await this.signer.signer.getInternalAddress();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private async prepareSigner() {
|
|
92
|
+
if (this.signer && (await this.signer.signer.isConnected())) {
|
|
93
|
+
await this.updateSignerInfo();
|
|
94
|
+
this.scene = Scene.Connected;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.wallet = undefined;
|
|
99
|
+
this.signer = undefined;
|
|
100
|
+
this.scene = Scene.SelectingWallets;
|
|
75
101
|
}
|
|
76
102
|
|
|
77
103
|
public disconnect() {
|
|
@@ -79,6 +105,7 @@ export class WebComponentConnector extends LitElement {
|
|
|
79
105
|
this.walletName = undefined;
|
|
80
106
|
this.signerName = undefined;
|
|
81
107
|
this.saveConnection();
|
|
108
|
+
this.closedHandler();
|
|
82
109
|
}
|
|
83
110
|
|
|
84
111
|
private loadConnection() {
|
|
@@ -110,23 +137,33 @@ export class WebComponentConnector extends LitElement {
|
|
|
110
137
|
}
|
|
111
138
|
|
|
112
139
|
willUpdate(changedProperties: PropertyValues): void {
|
|
113
|
-
if (changedProperties.has("client")) {
|
|
114
|
-
this.reloadSigners();
|
|
115
|
-
}
|
|
116
140
|
if (
|
|
117
|
-
changedProperties.has("
|
|
118
|
-
changedProperties.has("
|
|
141
|
+
changedProperties.has("client") ||
|
|
142
|
+
changedProperties.has("signerFilter")
|
|
119
143
|
) {
|
|
120
|
-
this.
|
|
144
|
+
this.reloadSigners();
|
|
121
145
|
}
|
|
122
146
|
if (
|
|
147
|
+
changedProperties.has("walletName") ||
|
|
148
|
+
changedProperties.has("wallets") ||
|
|
123
149
|
changedProperties.has("signerName") ||
|
|
124
150
|
changedProperties.has("wallet")
|
|
125
151
|
) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
152
|
+
(async () => {
|
|
153
|
+
const wallet = this.wallets.find(
|
|
154
|
+
({ name }) => name === this.walletName,
|
|
155
|
+
);
|
|
156
|
+
const signer = wallet?.signers.find(
|
|
157
|
+
({ name }) => name === this.signerName,
|
|
158
|
+
);
|
|
159
|
+
if (signer && (await signer.signer.isConnected())) {
|
|
160
|
+
this.wallet = wallet;
|
|
161
|
+
this.signer = signer;
|
|
162
|
+
} else {
|
|
163
|
+
this.wallet = undefined;
|
|
164
|
+
this.signer = undefined;
|
|
165
|
+
}
|
|
166
|
+
})();
|
|
130
167
|
}
|
|
131
168
|
if (changedProperties.has("signer")) {
|
|
132
169
|
this.prepareSigner();
|
|
@@ -159,31 +196,19 @@ export class WebComponentConnector extends LitElement {
|
|
|
159
196
|
(document.querySelector('link[rel="icon"]') as HTMLLinkElement).href;
|
|
160
197
|
|
|
161
198
|
ccc.JoyId.getJoyIdSigners(this.client, name, icon).forEach(
|
|
162
|
-
({ signer,
|
|
163
|
-
this.addSigner("JoyID", name, JOY_ID_SVG,
|
|
199
|
+
({ signer, name }) => {
|
|
200
|
+
this.addSigner("JoyID", name, JOY_ID_SVG, signer);
|
|
164
201
|
},
|
|
165
202
|
);
|
|
166
203
|
|
|
167
204
|
const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
|
|
168
205
|
if (uniSatSigner) {
|
|
169
|
-
this.addSigner(
|
|
170
|
-
"UniSat",
|
|
171
|
-
"BTC",
|
|
172
|
-
UNI_SAT_SVG,
|
|
173
|
-
ccc.SignerType.BTC,
|
|
174
|
-
uniSatSigner,
|
|
175
|
-
);
|
|
206
|
+
this.addSigner("UniSat", "BTC", UNI_SAT_SVG, uniSatSigner);
|
|
176
207
|
}
|
|
177
208
|
|
|
178
209
|
const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
|
|
179
210
|
if (okxBitcoinSigner) {
|
|
180
|
-
this.addSigner(
|
|
181
|
-
"OKX Wallet",
|
|
182
|
-
"BTC",
|
|
183
|
-
OKX_SVG,
|
|
184
|
-
ccc.SignerType.BTC,
|
|
185
|
-
okxBitcoinSigner,
|
|
186
|
-
);
|
|
211
|
+
this.addSigner("OKX Wallet", "BTC", OKX_SVG, okxBitcoinSigner);
|
|
187
212
|
}
|
|
188
213
|
|
|
189
214
|
const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
|
|
@@ -193,20 +218,64 @@ export class WebComponentConnector extends LitElement {
|
|
|
193
218
|
`${signer.detail.info.name}`,
|
|
194
219
|
"EVM",
|
|
195
220
|
signer.detail.info.icon,
|
|
196
|
-
ccc.SignerType.EVM,
|
|
197
221
|
signer,
|
|
198
222
|
);
|
|
199
223
|
}),
|
|
200
224
|
);
|
|
225
|
+
|
|
226
|
+
// === Dummy signers ===
|
|
227
|
+
this.addSigner(
|
|
228
|
+
"MetaMask",
|
|
229
|
+
"EVM",
|
|
230
|
+
METAMASK_SVG,
|
|
231
|
+
new SignerOpenLink(
|
|
232
|
+
this.client,
|
|
233
|
+
`https://metamask.app.link/dapp/${window.location.href}`,
|
|
234
|
+
ccc.SignerType.EVM,
|
|
235
|
+
),
|
|
236
|
+
);
|
|
237
|
+
[ccc.SignerType.EVM, ccc.SignerType.BTC].forEach((type) => {
|
|
238
|
+
this.addSigner(
|
|
239
|
+
"OKX Wallet",
|
|
240
|
+
type,
|
|
241
|
+
OKX_SVG,
|
|
242
|
+
new SignerOpenLink(
|
|
243
|
+
this.client,
|
|
244
|
+
"https://www.okx.com/download?deeplink=" +
|
|
245
|
+
encodeURIComponent(
|
|
246
|
+
"okx://wallet/dapp/url?dappUrl=" +
|
|
247
|
+
encodeURIComponent(window.location.href),
|
|
248
|
+
),
|
|
249
|
+
type,
|
|
250
|
+
),
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
this.addSigner(
|
|
254
|
+
"UniSat",
|
|
255
|
+
ccc.SignerType.BTC,
|
|
256
|
+
UNI_SAT_SVG,
|
|
257
|
+
new SignerOpenLink(
|
|
258
|
+
this.client,
|
|
259
|
+
"https://unisat.io/download",
|
|
260
|
+
ccc.SignerType.BTC,
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
// ===
|
|
201
264
|
}
|
|
202
265
|
|
|
203
|
-
private addSigner(
|
|
266
|
+
private async addSigner(
|
|
204
267
|
walletName: string,
|
|
205
268
|
signerName: string,
|
|
206
269
|
icon: string,
|
|
207
|
-
type: ccc.SignerType,
|
|
208
270
|
signer: ccc.Signer,
|
|
209
271
|
) {
|
|
272
|
+
const signerInfo = { name: signerName, signer };
|
|
273
|
+
if (
|
|
274
|
+
this.signerFilter &&
|
|
275
|
+
!(await this.signerFilter(signerInfo, { name: walletName, icon }))
|
|
276
|
+
) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
210
279
|
let updated = false;
|
|
211
280
|
const wallets = this.wallets.map((wallet) => {
|
|
212
281
|
if (wallet.name !== walletName) {
|
|
@@ -214,9 +283,13 @@ export class WebComponentConnector extends LitElement {
|
|
|
214
283
|
}
|
|
215
284
|
|
|
216
285
|
updated = true;
|
|
286
|
+
const allSigners = [...wallet.signers, signerInfo];
|
|
287
|
+
const signers = allSigners.filter(
|
|
288
|
+
({ signer }) => !(signer instanceof SignerOpenLink),
|
|
289
|
+
);
|
|
217
290
|
return {
|
|
218
291
|
...wallet,
|
|
219
|
-
signers:
|
|
292
|
+
signers: signers.length !== 0 ? signers : [signerInfo],
|
|
220
293
|
};
|
|
221
294
|
});
|
|
222
295
|
|
|
@@ -224,7 +297,7 @@ export class WebComponentConnector extends LitElement {
|
|
|
224
297
|
wallets.push({
|
|
225
298
|
name: walletName,
|
|
226
299
|
icon,
|
|
227
|
-
signers: [
|
|
300
|
+
signers: [signerInfo],
|
|
228
301
|
});
|
|
229
302
|
}
|
|
230
303
|
|
|
@@ -237,6 +310,25 @@ export class WebComponentConnector extends LitElement {
|
|
|
237
310
|
|
|
238
311
|
render() {
|
|
239
312
|
const [title, body] = (() => {
|
|
313
|
+
if (this.scene === Scene.Connected && this.wallet && this.signer) {
|
|
314
|
+
return generateConnectedScene(
|
|
315
|
+
this.wallet,
|
|
316
|
+
this.signer,
|
|
317
|
+
this.recommendAddress,
|
|
318
|
+
this.internalAddress,
|
|
319
|
+
this.balance,
|
|
320
|
+
this.disconnect.bind(this),
|
|
321
|
+
() => {
|
|
322
|
+
this.scene = Scene.SwitchingNetworks;
|
|
323
|
+
},
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
if (this.scene === Scene.SwitchingNetworks) {
|
|
327
|
+
return generateNetworksScene(this.client, (client) => {
|
|
328
|
+
this.setClient(client);
|
|
329
|
+
this.closedHandler();
|
|
330
|
+
});
|
|
331
|
+
}
|
|
240
332
|
if (this.scene === Scene.SelectingWallets || !this.selectedWallet) {
|
|
241
333
|
return generateWalletsScene(
|
|
242
334
|
this.wallets,
|
|
@@ -260,9 +352,11 @@ export class WebComponentConnector extends LitElement {
|
|
|
260
352
|
);
|
|
261
353
|
})();
|
|
262
354
|
|
|
263
|
-
const canBack = [
|
|
264
|
-
|
|
265
|
-
|
|
355
|
+
const canBack = [
|
|
356
|
+
Scene.SelectingSigners,
|
|
357
|
+
Scene.Connecting,
|
|
358
|
+
Scene.SwitchingNetworks,
|
|
359
|
+
].includes(this.scene);
|
|
266
360
|
|
|
267
361
|
return html`<style>
|
|
268
362
|
:host {
|
|
@@ -272,6 +366,7 @@ export class WebComponentConnector extends LitElement {
|
|
|
272
366
|
--btn-primary: #f8f8f8;
|
|
273
367
|
--btn-primary-hover: #efeeee;
|
|
274
368
|
--btn-secondary: #ddd;
|
|
369
|
+
--btn-secondary-hover: #ccc;
|
|
275
370
|
color: #1e1e1e;
|
|
276
371
|
--tip-color: #666;
|
|
277
372
|
}
|
|
@@ -285,15 +380,26 @@ export class WebComponentConnector extends LitElement {
|
|
|
285
380
|
}}
|
|
286
381
|
>
|
|
287
382
|
<div class="main" ${ref(this.mainRef)}>
|
|
288
|
-
<div
|
|
383
|
+
<div
|
|
384
|
+
class="header text-bold fs-lg ${title == null
|
|
385
|
+
? ""
|
|
386
|
+
: "header-divider"}"
|
|
387
|
+
${ref(this.headerRef)}
|
|
388
|
+
>
|
|
289
389
|
<img
|
|
290
390
|
class="back ${canBack ? "active" : ""}"
|
|
291
391
|
src=${LEFT_SVG}
|
|
292
392
|
@click=${() => {
|
|
293
393
|
if (this.scene === Scene.Connecting) {
|
|
294
|
-
this.
|
|
394
|
+
if ((this.selectedWallet?.signers.length ?? 0) <= 1) {
|
|
395
|
+
this.scene = Scene.SelectingWallets;
|
|
396
|
+
} else {
|
|
397
|
+
this.scene = Scene.SelectingSigners;
|
|
398
|
+
}
|
|
295
399
|
} else if (this.scene === Scene.SelectingSigners) {
|
|
296
400
|
this.scene = Scene.SelectingWallets;
|
|
401
|
+
} else if (this.scene === Scene.SwitchingNetworks) {
|
|
402
|
+
this.scene = Scene.Connected;
|
|
297
403
|
}
|
|
298
404
|
}}
|
|
299
405
|
/>
|
|
@@ -330,7 +436,10 @@ export class WebComponentConnector extends LitElement {
|
|
|
330
436
|
this.scene = Scene.SelectingWallets;
|
|
331
437
|
this.selectedSigner = undefined;
|
|
332
438
|
this.selectedWallet = undefined;
|
|
439
|
+
} else if ([Scene.SwitchingNetworks].includes(this.scene)) {
|
|
440
|
+
this.scene = Scene.Connected;
|
|
333
441
|
}
|
|
442
|
+
|
|
334
443
|
this.isOpen = false;
|
|
335
444
|
};
|
|
336
445
|
|
|
@@ -351,6 +460,9 @@ export class WebComponentConnector extends LitElement {
|
|
|
351
460
|
this.signerName = signer.name;
|
|
352
461
|
this.saveConnection();
|
|
353
462
|
this.closedHandler();
|
|
463
|
+
this.internalAddress = await signer.signer.getInternalAddress();
|
|
464
|
+
this.recommendAddress = await signer.signer.getRecommendedAddress();
|
|
465
|
+
this.balance = await signer.signer.getBalance();
|
|
354
466
|
})();
|
|
355
467
|
};
|
|
356
468
|
|
|
@@ -381,9 +493,18 @@ export class WebComponentConnector extends LitElement {
|
|
|
381
493
|
color: var(--tip-color);
|
|
382
494
|
}
|
|
383
495
|
|
|
384
|
-
.fs-
|
|
496
|
+
.fs-sm {
|
|
497
|
+
font-size: 0.8rem;
|
|
498
|
+
}
|
|
499
|
+
.fs-md {
|
|
500
|
+
font-size: 1rem;
|
|
501
|
+
}
|
|
502
|
+
.fs-lg {
|
|
385
503
|
font-size: 1.2rem;
|
|
386
504
|
}
|
|
505
|
+
.fs-xl {
|
|
506
|
+
font-size: 1.5rem;
|
|
507
|
+
}
|
|
387
508
|
|
|
388
509
|
.mb-1 {
|
|
389
510
|
margin-bottom: 0.7rem;
|
|
@@ -397,6 +518,18 @@ export class WebComponentConnector extends LitElement {
|
|
|
397
518
|
.mt-2 {
|
|
398
519
|
margin-top: 1rem;
|
|
399
520
|
}
|
|
521
|
+
.ml-1 {
|
|
522
|
+
margin-left: 0.7rem;
|
|
523
|
+
}
|
|
524
|
+
.ml-2 {
|
|
525
|
+
margin-left: 1em;
|
|
526
|
+
}
|
|
527
|
+
.mr-1 {
|
|
528
|
+
margin-right: 0.7rem;
|
|
529
|
+
}
|
|
530
|
+
.mr-2 {
|
|
531
|
+
margin-right: 1rem;
|
|
532
|
+
}
|
|
400
533
|
|
|
401
534
|
.background {
|
|
402
535
|
width: 100%;
|
|
@@ -419,8 +552,13 @@ export class WebComponentConnector extends LitElement {
|
|
|
419
552
|
display: flex;
|
|
420
553
|
justify-content: space-between;
|
|
421
554
|
align-items: center;
|
|
422
|
-
padding: 1rem 1.3rem;
|
|
555
|
+
padding: 1rem 1.3rem 0.5rem;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.header-divider {
|
|
559
|
+
padding-bottom: 1rem;
|
|
423
560
|
border-bottom: 1px solid var(--divider);
|
|
561
|
+
margin-bottom: 1rem;
|
|
424
562
|
}
|
|
425
563
|
|
|
426
564
|
.close,
|
|
@@ -438,7 +576,7 @@ export class WebComponentConnector extends LitElement {
|
|
|
438
576
|
}
|
|
439
577
|
|
|
440
578
|
.body {
|
|
441
|
-
padding: 1.
|
|
579
|
+
padding: 0 1.3rem 1.4rem;
|
|
442
580
|
min-width: 20rem;
|
|
443
581
|
display: flex;
|
|
444
582
|
flex-direction: column;
|
|
@@ -455,17 +593,21 @@ export class WebComponentConnector extends LitElement {
|
|
|
455
593
|
border-radius: 0.4rem;
|
|
456
594
|
transition: background 0.15s ease-in-out;
|
|
457
595
|
}
|
|
458
|
-
|
|
459
596
|
.btn-primary img {
|
|
460
597
|
width: 2rem;
|
|
461
598
|
height: 2rem;
|
|
462
599
|
margin-right: 1rem;
|
|
463
600
|
border-radius: 0.4rem;
|
|
464
601
|
}
|
|
465
|
-
|
|
466
602
|
.btn-primary:hover {
|
|
467
603
|
background: var(--btn-primary-hover);
|
|
468
604
|
}
|
|
605
|
+
.btn-primary:disabled {
|
|
606
|
+
cursor: not-allowed;
|
|
607
|
+
}
|
|
608
|
+
.btn-primary:disabled:hover {
|
|
609
|
+
background: var(--btn-primary);
|
|
610
|
+
}
|
|
469
611
|
|
|
470
612
|
.btn-secondary {
|
|
471
613
|
display: flex;
|
|
@@ -475,12 +617,20 @@ export class WebComponentConnector extends LitElement {
|
|
|
475
617
|
border-radius: 9999px;
|
|
476
618
|
transition: background 0.15s ease-in-out;
|
|
477
619
|
}
|
|
478
|
-
|
|
479
620
|
.btn-secondary img {
|
|
480
621
|
width: 0.8rem;
|
|
481
622
|
height: 0.8rem;
|
|
482
623
|
margin-right: 0.5rem;
|
|
483
624
|
}
|
|
625
|
+
.btn-secondary:hover {
|
|
626
|
+
background: var(--btn-secondary-hover);
|
|
627
|
+
}
|
|
628
|
+
.btn-secondary:disabled {
|
|
629
|
+
cursor: not-allowed;
|
|
630
|
+
}
|
|
631
|
+
.btn-secondary:disabled:hover {
|
|
632
|
+
background: var(--btn-secondary);
|
|
633
|
+
}
|
|
484
634
|
|
|
485
635
|
.wallet-icon {
|
|
486
636
|
width: 4rem;
|
|
@@ -494,5 +644,73 @@ export class WebComponentConnector extends LitElement {
|
|
|
494
644
|
height: 5rem;
|
|
495
645
|
border-radius: 1rem;
|
|
496
646
|
}
|
|
647
|
+
|
|
648
|
+
.position-relative {
|
|
649
|
+
position: relative;
|
|
650
|
+
}
|
|
651
|
+
.position-absolute {
|
|
652
|
+
position: absolute;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
.connected-type-icon {
|
|
656
|
+
position: absolute;
|
|
657
|
+
width: 1.5rem;
|
|
658
|
+
height: 1.5rem;
|
|
659
|
+
right: -0.5rem;
|
|
660
|
+
bottom: -0.5rem;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
.text-center {
|
|
664
|
+
text-align: center;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
.cursor-pointer {
|
|
668
|
+
cursor: pointer;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
.flex {
|
|
672
|
+
display: flex;
|
|
673
|
+
}
|
|
674
|
+
.justify-center {
|
|
675
|
+
justify-content: center;
|
|
676
|
+
}
|
|
677
|
+
.justify-between {
|
|
678
|
+
justify-content: space-between;
|
|
679
|
+
}
|
|
680
|
+
.align-center {
|
|
681
|
+
align-items: center;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
.switch-btn-container {
|
|
685
|
+
width: 100%;
|
|
686
|
+
padding: 1rem;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.switch-line {
|
|
690
|
+
flex: 1;
|
|
691
|
+
height: 1px;
|
|
692
|
+
background-color: var(--divider);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
.switching-status-dot {
|
|
696
|
+
width: 0.5rem;
|
|
697
|
+
height: 0.5rem;
|
|
698
|
+
background: #0f0;
|
|
699
|
+
border-radius: 50%;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
.copy-btn {
|
|
703
|
+
width: 1.5rem;
|
|
704
|
+
height: 1.5rem;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
.copy-btn-sm {
|
|
708
|
+
width: 1rem;
|
|
709
|
+
height: 1rem;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
.sm-chain-logo {
|
|
713
|
+
width: 1.125rem;
|
|
714
|
+
}
|
|
497
715
|
`;
|
|
498
716
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/ccc";
|
|
2
|
+
import { html } from "lit";
|
|
3
|
+
import { CKB_SVG } from "../assets/chains";
|
|
4
|
+
import { COPY_SVG } from "../assets/copy.svg";
|
|
5
|
+
import { DISCONNECT_SVG } from "../assets/diconnect.svg";
|
|
6
|
+
import { SWAP_SVG } from "../assets/swap.svg";
|
|
7
|
+
import { signerTypeToIcon } from "./signers";
|
|
8
|
+
|
|
9
|
+
function copyAddress(address?: string) {
|
|
10
|
+
if (!address) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return window.navigator.clipboard.writeText(address);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function formatString(
|
|
18
|
+
str: string | undefined,
|
|
19
|
+
l = 7,
|
|
20
|
+
r = 5,
|
|
21
|
+
): string | undefined {
|
|
22
|
+
if (str && str.length > l + r + 3) {
|
|
23
|
+
return `${str.slice(0, l)}...${str.slice(-r)}`;
|
|
24
|
+
}
|
|
25
|
+
return str;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function generateConnectedScene(
|
|
29
|
+
wallet: ccc.Wallet,
|
|
30
|
+
signer: ccc.SignerInfo,
|
|
31
|
+
recommendedAddress: string | undefined,
|
|
32
|
+
internalAddress: string | undefined,
|
|
33
|
+
balance: ccc.Num | undefined,
|
|
34
|
+
disconnect: () => void,
|
|
35
|
+
handleSwitchClick: () => void,
|
|
36
|
+
) {
|
|
37
|
+
return [
|
|
38
|
+
undefined,
|
|
39
|
+
html`
|
|
40
|
+
<div class="position-relative">
|
|
41
|
+
<img
|
|
42
|
+
class="connecting-wallet-icon"
|
|
43
|
+
src=${wallet.icon}
|
|
44
|
+
alt=${wallet.name}
|
|
45
|
+
/>
|
|
46
|
+
<img
|
|
47
|
+
class="connected-type-icon"
|
|
48
|
+
src=${signerTypeToIcon(signer.signer.type)}
|
|
49
|
+
alt=${signer.signer.type}
|
|
50
|
+
>
|
|
51
|
+
</img>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div class="flex align-center mt-2">
|
|
55
|
+
<span class="text-bold fs-xl">${formatString(internalAddress)}</span>
|
|
56
|
+
<img class="cursor-pointer copy-btn" src=${COPY_SVG} alt="copy" @click=${() => copyAddress(internalAddress)}/>
|
|
57
|
+
</div>
|
|
58
|
+
<div class="text-bold fs-md">${ccc.fixedPointToString(balance ?? ccc.Zero)} CKB</div>
|
|
59
|
+
<div class="flex align-center">
|
|
60
|
+
<span class="text-bold text-tip fs-md">${formatString(recommendedAddress, 13, 7)}</span>
|
|
61
|
+
<img class="cursor-pointer copy-btn-sm" src=${COPY_SVG} alt="copy" @click=${() => copyAddress(recommendedAddress)}/>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<button
|
|
65
|
+
class="btn-primary mt-2"
|
|
66
|
+
@click=${disconnect}
|
|
67
|
+
>
|
|
68
|
+
<img
|
|
69
|
+
src=${DISCONNECT_SVG}
|
|
70
|
+
alt="disconnect"
|
|
71
|
+
/>
|
|
72
|
+
Disconnect
|
|
73
|
+
</button>
|
|
74
|
+
|
|
75
|
+
<div class="switch-btn-container align-center flex justify-center mt-1">
|
|
76
|
+
<div class="switch-line"></div>
|
|
77
|
+
<div class="switch-content flex align-center cursor-pointer ml-2 mr-2 fs-sm" @click=${handleSwitchClick}>
|
|
78
|
+
<img class="mr-1 sm-chain-logo" src=${CKB_SVG} alt="Nervos Network">
|
|
79
|
+
${signer.signer.client.addressPrefix === "ckb" ? "Mainnet" : "Testnet"}
|
|
80
|
+
${["ckb", "ckt"].includes(signer.signer.client.addressPrefix) ? "" : ` ${signer.signer.client.addressPrefix}`}
|
|
81
|
+
<img class="ml-1" src=${SWAP_SVG} alt="Nervos Network">
|
|
82
|
+
</div>
|
|
83
|
+
<div class="switch-line"></div>
|
|
84
|
+
</div>
|
|
85
|
+
`,
|
|
86
|
+
];
|
|
87
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
3
|
+
import { ccc } from "..";
|
|
4
|
+
import { CKB_SVG } from "../assets/chains";
|
|
5
|
+
|
|
6
|
+
export function generateNetworksScene(
|
|
7
|
+
client: ccc.Client,
|
|
8
|
+
handleSwapClick: (client: ccc.Client) => unknown,
|
|
9
|
+
) {
|
|
10
|
+
const isMainnet = client.addressPrefix === "ckb";
|
|
11
|
+
|
|
12
|
+
return [
|
|
13
|
+
"Switch Network",
|
|
14
|
+
repeat(
|
|
15
|
+
[
|
|
16
|
+
{
|
|
17
|
+
activated: isMainnet,
|
|
18
|
+
name: "Mainnet",
|
|
19
|
+
onClick: () => handleSwapClick(new ccc.ClientPublicMainnet()),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
activated: !isMainnet,
|
|
23
|
+
name: "Testnet",
|
|
24
|
+
onClick: () => handleSwapClick(new ccc.ClientPublicTestnet()),
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
({ name }) => name,
|
|
28
|
+
({ activated, name, onClick }) => html`
|
|
29
|
+
<button
|
|
30
|
+
class="btn-primary flex justify-between mb-1 ${activated
|
|
31
|
+
? "switching-active"
|
|
32
|
+
: ""}"
|
|
33
|
+
?disabled=${activated}
|
|
34
|
+
@click=${onClick}
|
|
35
|
+
>
|
|
36
|
+
<div class="flex align-center">
|
|
37
|
+
<img src=${CKB_SVG} alt="Nervos Network" />
|
|
38
|
+
<span>${name}</span>
|
|
39
|
+
</div>
|
|
40
|
+
<div class="flex align-center">
|
|
41
|
+
${activated ? html`<div class="switching-status-dot"></div>` : ""}
|
|
42
|
+
</div>
|
|
43
|
+
</button>
|
|
44
|
+
`,
|
|
45
|
+
),
|
|
46
|
+
];
|
|
47
|
+
}
|
package/src/scenes/signers.ts
CHANGED
|
@@ -27,7 +27,7 @@ export function generateSignersScene(
|
|
|
27
27
|
<span class="mb-2">${wallet.name}</span>
|
|
28
28
|
${repeat(
|
|
29
29
|
wallet.signers,
|
|
30
|
-
(signer) => signer.
|
|
30
|
+
(signer) => signer.name,
|
|
31
31
|
(signer) => html`
|
|
32
32
|
<button
|
|
33
33
|
class="btn-primary mb-1"
|
|
@@ -35,7 +35,10 @@ export function generateSignersScene(
|
|
|
35
35
|
onSignerSelected(wallet, signer);
|
|
36
36
|
}}
|
|
37
37
|
>
|
|
38
|
-
<img
|
|
38
|
+
<img
|
|
39
|
+
src=${signerTypeToIcon(signer.signer.type)}
|
|
40
|
+
alt=${signer.signer.type}
|
|
41
|
+
/>
|
|
39
42
|
${signer.name}
|
|
40
43
|
</button>
|
|
41
44
|
`,
|