@ckb-ccc/connector 0.0.5-alpha.0 → 0.0.5-alpha.10
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/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/left.svg.d.ts +2 -0
- package/dist/assets/left.svg.d.ts.map +1 -0
- package/dist/assets/left.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 +13 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +318 -77
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +5 -0
- 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/connecting.d.ts +1 -1
- package/dist/scenes/connecting.d.ts.map +1 -1
- package/dist/scenes/connecting.js +9 -3
- 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/package.json +3 -3
- 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/left.svg.ts +5 -0
- package/src/assets/swap.svg.ts +5 -0
- package/src/connector/index.ts +373 -95
- package/src/events/index.ts +6 -0
- package/src/scenes/connected.ts +87 -0
- package/src/scenes/connecting.ts +9 -2
- package/src/scenes/networks.ts +47 -0
- package/src/scenes/signers.ts +5 -2
- package/src/scenes/wallets.ts +20 -63
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
package/src/connector/index.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
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";
|
|
8
|
+
import { METAMASK_SVG } from "../assets/metamask.svg";
|
|
6
9
|
import { OKX_SVG } from "../assets/okx.svg";
|
|
7
10
|
import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
|
|
8
|
-
import { WillUpdateEvent } from "../events";
|
|
11
|
+
import { ClosedEvent, WillUpdateEvent } from "../events";
|
|
9
12
|
import {
|
|
10
13
|
generateConnectingScene,
|
|
11
14
|
generateSignersScene,
|
|
12
15
|
generateWalletsScene,
|
|
13
16
|
} from "../scenes";
|
|
17
|
+
import { generateConnectedScene } from "../scenes/connected";
|
|
18
|
+
import { generateNetworksScene } from "../scenes/networks";
|
|
14
19
|
import { WalletWithSigners } from "../types";
|
|
15
20
|
|
|
16
21
|
enum Scene {
|
|
@@ -18,20 +23,25 @@ enum Scene {
|
|
|
18
23
|
SelectingSigners = "SelectingSigners",
|
|
19
24
|
Connecting = "Connecting",
|
|
20
25
|
Connected = "Connected",
|
|
26
|
+
SwitchingNetworks = "SwitchingNetworks",
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
@customElement("ccc-connector")
|
|
24
30
|
export class WebComponentConnector extends LitElement {
|
|
25
31
|
@state()
|
|
26
32
|
private wallets: WalletWithSigners[] = [];
|
|
33
|
+
@property()
|
|
34
|
+
public signerFilter?: (
|
|
35
|
+
signerInfo: ccc.SignerInfo,
|
|
36
|
+
wallet: ccc.Wallet,
|
|
37
|
+
) => Promise<boolean>;
|
|
27
38
|
|
|
28
39
|
private resetListeners: (() => void)[] = [];
|
|
29
40
|
|
|
30
|
-
@
|
|
31
|
-
public
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
41
|
+
@property()
|
|
42
|
+
public name?: string;
|
|
43
|
+
@property()
|
|
44
|
+
public icon?: string;
|
|
35
45
|
|
|
36
46
|
@property()
|
|
37
47
|
public client: ccc.Client = new ccc.ClientPublicTestnet();
|
|
@@ -45,6 +55,8 @@ export class WebComponentConnector extends LitElement {
|
|
|
45
55
|
private selectedWallet?: WalletWithSigners;
|
|
46
56
|
@state()
|
|
47
57
|
private selectedSigner?: ccc.SignerInfo;
|
|
58
|
+
@state()
|
|
59
|
+
private connectingError?: string;
|
|
48
60
|
|
|
49
61
|
@state()
|
|
50
62
|
private walletName?: string;
|
|
@@ -54,17 +66,34 @@ export class WebComponentConnector extends LitElement {
|
|
|
54
66
|
public wallet?: ccc.Wallet;
|
|
55
67
|
@state()
|
|
56
68
|
public signer?: ccc.SignerInfo;
|
|
57
|
-
private prepareSigner() {
|
|
58
|
-
(async () => {
|
|
59
|
-
if (this.signer && (await this.signer.signer.isConnected())) {
|
|
60
|
-
this.scene = Scene.Connected;
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
@state()
|
|
71
|
+
private recommendAddress?: string;
|
|
72
|
+
@state()
|
|
73
|
+
private internalAddress?: string;
|
|
74
|
+
@state()
|
|
75
|
+
private balance?: ccc.Num;
|
|
76
|
+
|
|
77
|
+
private async updateSignerInfo() {
|
|
78
|
+
const signer = this.signer?.signer;
|
|
79
|
+
if (!signer) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.recommendAddress = await signer.getRecommendedAddress();
|
|
83
|
+
this.internalAddress = await signer.getInternalAddress();
|
|
84
|
+
this.balance = await signer.getBalance();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async prepareSigner() {
|
|
88
|
+
if (this.signer && (await this.signer.signer.isConnected())) {
|
|
89
|
+
await this.updateSignerInfo();
|
|
90
|
+
this.scene = Scene.Connected;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.wallet = undefined;
|
|
95
|
+
this.signer = undefined;
|
|
96
|
+
this.scene = Scene.SelectingWallets;
|
|
68
97
|
}
|
|
69
98
|
|
|
70
99
|
public disconnect() {
|
|
@@ -72,6 +101,7 @@ export class WebComponentConnector extends LitElement {
|
|
|
72
101
|
this.walletName = undefined;
|
|
73
102
|
this.signerName = undefined;
|
|
74
103
|
this.saveConnection();
|
|
104
|
+
this.closedHandler();
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
private loadConnection() {
|
|
@@ -103,23 +133,33 @@ export class WebComponentConnector extends LitElement {
|
|
|
103
133
|
}
|
|
104
134
|
|
|
105
135
|
willUpdate(changedProperties: PropertyValues): void {
|
|
106
|
-
if (changedProperties.has("client")) {
|
|
107
|
-
this.reloadSigners();
|
|
108
|
-
}
|
|
109
136
|
if (
|
|
110
|
-
changedProperties.has("
|
|
111
|
-
changedProperties.has("
|
|
137
|
+
changedProperties.has("client") ||
|
|
138
|
+
changedProperties.has("signerFilter")
|
|
112
139
|
) {
|
|
113
|
-
this.
|
|
140
|
+
this.reloadSigners();
|
|
114
141
|
}
|
|
115
142
|
if (
|
|
116
|
-
changedProperties.has("
|
|
117
|
-
changedProperties.has("
|
|
143
|
+
(changedProperties.has("scene") && this.scene === Scene.Connected) ||
|
|
144
|
+
changedProperties.has("wallets") ||
|
|
145
|
+
changedProperties.has("walletName") ||
|
|
146
|
+
changedProperties.has("signerName")
|
|
118
147
|
) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
(async () => {
|
|
149
|
+
const wallet = this.wallets.find(
|
|
150
|
+
({ name }) => name === this.walletName,
|
|
151
|
+
);
|
|
152
|
+
const signer = wallet?.signers.find(
|
|
153
|
+
({ name }) => name === this.signerName,
|
|
154
|
+
);
|
|
155
|
+
if (signer && (await signer.signer.isConnected())) {
|
|
156
|
+
this.wallet = wallet;
|
|
157
|
+
this.signer = signer;
|
|
158
|
+
} else {
|
|
159
|
+
this.wallet = undefined;
|
|
160
|
+
this.signer = undefined;
|
|
161
|
+
}
|
|
162
|
+
})();
|
|
123
163
|
}
|
|
124
164
|
if (changedProperties.has("signer")) {
|
|
125
165
|
this.prepareSigner();
|
|
@@ -132,43 +172,41 @@ export class WebComponentConnector extends LitElement {
|
|
|
132
172
|
this.wallets = [];
|
|
133
173
|
|
|
134
174
|
(async () => {
|
|
135
|
-
|
|
175
|
+
const signer = this.signer;
|
|
176
|
+
if (!signer) {
|
|
136
177
|
return;
|
|
137
178
|
}
|
|
138
179
|
|
|
180
|
+
await signer.signer.replaceClient(this.client);
|
|
181
|
+
|
|
139
182
|
this.signer = {
|
|
140
|
-
...
|
|
141
|
-
signer: await this.signer.signer.replaceClient(this.client),
|
|
183
|
+
...signer,
|
|
142
184
|
};
|
|
143
185
|
})();
|
|
144
186
|
|
|
145
187
|
this.resetListeners.forEach((listener) => listener());
|
|
146
188
|
this.resetListeners = [];
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
189
|
+
const name =
|
|
190
|
+
this.name ??
|
|
191
|
+
(document.querySelector("head title") as HTMLTitleElement).text;
|
|
192
|
+
const icon =
|
|
193
|
+
this.icon ??
|
|
194
|
+
(document.querySelector('link[rel="icon"]') as HTMLLinkElement).href;
|
|
195
|
+
|
|
196
|
+
ccc.JoyId.getJoyIdSigners(this.client, name, icon).forEach(
|
|
197
|
+
({ signer, name }) => {
|
|
198
|
+
this.addSigner("JoyID", name, JOY_ID_SVG, signer);
|
|
199
|
+
},
|
|
200
|
+
);
|
|
151
201
|
|
|
152
202
|
const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
|
|
153
203
|
if (uniSatSigner) {
|
|
154
|
-
this.addSigner(
|
|
155
|
-
"UniSat",
|
|
156
|
-
"BTC",
|
|
157
|
-
UNI_SAT_SVG,
|
|
158
|
-
ccc.SignerType.BTC,
|
|
159
|
-
uniSatSigner,
|
|
160
|
-
);
|
|
204
|
+
this.addSigner("UniSat", "BTC", UNI_SAT_SVG, uniSatSigner);
|
|
161
205
|
}
|
|
162
206
|
|
|
163
207
|
const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
|
|
164
208
|
if (okxBitcoinSigner) {
|
|
165
|
-
this.addSigner(
|
|
166
|
-
"OKX Wallet",
|
|
167
|
-
"BTC",
|
|
168
|
-
OKX_SVG,
|
|
169
|
-
ccc.SignerType.BTC,
|
|
170
|
-
okxBitcoinSigner,
|
|
171
|
-
);
|
|
209
|
+
this.addSigner("OKX Wallet", "BTC", OKX_SVG, okxBitcoinSigner);
|
|
172
210
|
}
|
|
173
211
|
|
|
174
212
|
const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
|
|
@@ -178,20 +216,64 @@ export class WebComponentConnector extends LitElement {
|
|
|
178
216
|
`${signer.detail.info.name}`,
|
|
179
217
|
"EVM",
|
|
180
218
|
signer.detail.info.icon,
|
|
181
|
-
ccc.SignerType.EVM,
|
|
182
219
|
signer,
|
|
183
220
|
);
|
|
184
221
|
}),
|
|
185
222
|
);
|
|
223
|
+
|
|
224
|
+
// === Dummy signers ===
|
|
225
|
+
this.addSigner(
|
|
226
|
+
"MetaMask",
|
|
227
|
+
"EVM",
|
|
228
|
+
METAMASK_SVG,
|
|
229
|
+
new ccc.SignerOpenLink(
|
|
230
|
+
this.client,
|
|
231
|
+
ccc.SignerType.EVM,
|
|
232
|
+
`https://metamask.app.link/dapp/${window.location.href}`,
|
|
233
|
+
),
|
|
234
|
+
);
|
|
235
|
+
[ccc.SignerType.EVM, ccc.SignerType.BTC].forEach((type) => {
|
|
236
|
+
this.addSigner(
|
|
237
|
+
"OKX Wallet",
|
|
238
|
+
type,
|
|
239
|
+
OKX_SVG,
|
|
240
|
+
new ccc.SignerOpenLink(
|
|
241
|
+
this.client,
|
|
242
|
+
type,
|
|
243
|
+
"https://www.okx.com/download?deeplink=" +
|
|
244
|
+
encodeURIComponent(
|
|
245
|
+
"okx://wallet/dapp/url?dappUrl=" +
|
|
246
|
+
encodeURIComponent(window.location.href),
|
|
247
|
+
),
|
|
248
|
+
),
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
this.addSigner(
|
|
252
|
+
"UniSat",
|
|
253
|
+
ccc.SignerType.BTC,
|
|
254
|
+
UNI_SAT_SVG,
|
|
255
|
+
new ccc.SignerOpenLink(
|
|
256
|
+
this.client,
|
|
257
|
+
ccc.SignerType.BTC,
|
|
258
|
+
"https://unisat.io/download",
|
|
259
|
+
),
|
|
260
|
+
);
|
|
261
|
+
// ===
|
|
186
262
|
}
|
|
187
263
|
|
|
188
|
-
private addSigner(
|
|
264
|
+
private async addSigner(
|
|
189
265
|
walletName: string,
|
|
190
266
|
signerName: string,
|
|
191
267
|
icon: string,
|
|
192
|
-
type: ccc.SignerType,
|
|
193
268
|
signer: ccc.Signer,
|
|
194
269
|
) {
|
|
270
|
+
const signerInfo = { name: signerName, signer };
|
|
271
|
+
if (
|
|
272
|
+
this.signerFilter &&
|
|
273
|
+
!(await this.signerFilter(signerInfo, { name: walletName, icon }))
|
|
274
|
+
) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
195
277
|
let updated = false;
|
|
196
278
|
const wallets = this.wallets.map((wallet) => {
|
|
197
279
|
if (wallet.name !== walletName) {
|
|
@@ -199,9 +281,13 @@ export class WebComponentConnector extends LitElement {
|
|
|
199
281
|
}
|
|
200
282
|
|
|
201
283
|
updated = true;
|
|
284
|
+
const allSigners = [...wallet.signers, signerInfo];
|
|
285
|
+
const signers = allSigners.filter(
|
|
286
|
+
({ signer }) => !(signer instanceof ccc.SignerDummy),
|
|
287
|
+
);
|
|
202
288
|
return {
|
|
203
289
|
...wallet,
|
|
204
|
-
signers:
|
|
290
|
+
signers: signers.length !== 0 ? signers : [signerInfo],
|
|
205
291
|
};
|
|
206
292
|
});
|
|
207
293
|
|
|
@@ -209,15 +295,38 @@ export class WebComponentConnector extends LitElement {
|
|
|
209
295
|
wallets.push({
|
|
210
296
|
name: walletName,
|
|
211
297
|
icon,
|
|
212
|
-
signers: [
|
|
298
|
+
signers: [signerInfo],
|
|
213
299
|
});
|
|
214
300
|
}
|
|
215
301
|
|
|
216
302
|
this.wallets = wallets;
|
|
217
303
|
}
|
|
218
304
|
|
|
305
|
+
mainRef: Ref<HTMLDivElement> = createRef();
|
|
306
|
+
headerRef: Ref<HTMLDivElement> = createRef();
|
|
307
|
+
bodyRef: Ref<HTMLDivElement> = createRef();
|
|
308
|
+
|
|
219
309
|
render() {
|
|
220
310
|
const [title, body] = (() => {
|
|
311
|
+
if (this.scene === Scene.Connected && this.wallet && this.signer) {
|
|
312
|
+
return generateConnectedScene(
|
|
313
|
+
this.wallet,
|
|
314
|
+
this.signer,
|
|
315
|
+
this.recommendAddress,
|
|
316
|
+
this.internalAddress,
|
|
317
|
+
this.balance,
|
|
318
|
+
this.disconnect.bind(this),
|
|
319
|
+
() => {
|
|
320
|
+
this.scene = Scene.SwitchingNetworks;
|
|
321
|
+
},
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
if (this.scene === Scene.SwitchingNetworks) {
|
|
325
|
+
return generateNetworksScene(this.client, (client) => {
|
|
326
|
+
this.setClient(client);
|
|
327
|
+
this.closedHandler();
|
|
328
|
+
});
|
|
329
|
+
}
|
|
221
330
|
if (this.scene === Scene.SelectingWallets || !this.selectedWallet) {
|
|
222
331
|
return generateWalletsScene(
|
|
223
332
|
this.wallets,
|
|
@@ -237,39 +346,69 @@ export class WebComponentConnector extends LitElement {
|
|
|
237
346
|
return generateConnectingScene(
|
|
238
347
|
this.selectedWallet,
|
|
239
348
|
this.selectedSigner,
|
|
349
|
+
this.connectingError,
|
|
240
350
|
this.signerSelectedHandler,
|
|
241
351
|
);
|
|
242
352
|
})();
|
|
243
353
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
354
|
+
const canBack = [
|
|
355
|
+
Scene.SelectingSigners,
|
|
356
|
+
Scene.Connecting,
|
|
357
|
+
Scene.SwitchingNetworks,
|
|
358
|
+
].includes(this.scene);
|
|
359
|
+
|
|
360
|
+
return html` <div
|
|
361
|
+
class="background"
|
|
362
|
+
@click=${(event: Event) => {
|
|
363
|
+
if (event.target === event.currentTarget) {
|
|
364
|
+
this.closedHandler();
|
|
254
365
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
366
|
+
}}
|
|
367
|
+
>
|
|
368
|
+
<div class="main" ${ref(this.mainRef)}>
|
|
369
|
+
<div
|
|
370
|
+
class="header text-bold fs-lg ${title == null
|
|
371
|
+
? ""
|
|
372
|
+
: "header-divider"}"
|
|
373
|
+
${ref(this.headerRef)}
|
|
374
|
+
>
|
|
375
|
+
<img
|
|
376
|
+
class="back ${canBack ? "active" : ""}"
|
|
377
|
+
src=${LEFT_SVG}
|
|
378
|
+
@click=${() => {
|
|
379
|
+
if (this.scene === Scene.Connecting) {
|
|
380
|
+
if ((this.selectedWallet?.signers.length ?? 0) <= 1) {
|
|
381
|
+
this.scene = Scene.SelectingWallets;
|
|
382
|
+
} else {
|
|
383
|
+
this.scene = Scene.SelectingSigners;
|
|
384
|
+
}
|
|
385
|
+
} else if (this.scene === Scene.SelectingSigners) {
|
|
386
|
+
this.scene = Scene.SelectingWallets;
|
|
387
|
+
} else if (this.scene === Scene.SwitchingNetworks) {
|
|
388
|
+
this.scene = Scene.Connected;
|
|
389
|
+
}
|
|
390
|
+
}}
|
|
391
|
+
/>
|
|
392
|
+
${title}
|
|
393
|
+
<img
|
|
394
|
+
class="close active"
|
|
395
|
+
src=${CLOSE_SVG}
|
|
396
|
+
@click=${this.closedHandler}
|
|
397
|
+
/>
|
|
271
398
|
</div>
|
|
272
|
-
|
|
399
|
+
<div class="body" ${ref(this.bodyRef)}>${body}</div>
|
|
400
|
+
</div>
|
|
401
|
+
</div>`;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
updated() {
|
|
405
|
+
if (!this.mainRef.value) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
this.mainRef.value.style.height = `${
|
|
409
|
+
(this.bodyRef.value?.clientHeight ?? 0) +
|
|
410
|
+
(this.headerRef.value?.clientHeight ?? 0)
|
|
411
|
+
}px`;
|
|
273
412
|
}
|
|
274
413
|
|
|
275
414
|
private closedHandler = () => {
|
|
@@ -283,27 +422,49 @@ export class WebComponentConnector extends LitElement {
|
|
|
283
422
|
this.scene = Scene.SelectingWallets;
|
|
284
423
|
this.selectedSigner = undefined;
|
|
285
424
|
this.selectedWallet = undefined;
|
|
425
|
+
} else if ([Scene.SwitchingNetworks].includes(this.scene)) {
|
|
426
|
+
this.scene = Scene.Connected;
|
|
286
427
|
}
|
|
287
|
-
|
|
428
|
+
|
|
429
|
+
this.dispatchEvent(new ClosedEvent());
|
|
288
430
|
};
|
|
289
431
|
|
|
290
432
|
private signerSelectedHandler = (
|
|
291
433
|
wallet: WalletWithSigners,
|
|
292
|
-
|
|
434
|
+
signerInfo: ccc.SignerInfo,
|
|
293
435
|
) => {
|
|
294
436
|
this.scene = Scene.Connecting;
|
|
437
|
+
this.connectingError = undefined;
|
|
295
438
|
this.selectedWallet = wallet;
|
|
296
|
-
this.selectedSigner =
|
|
439
|
+
this.selectedSigner = signerInfo;
|
|
297
440
|
(async () => {
|
|
298
|
-
|
|
299
|
-
|
|
441
|
+
const { signer } = signerInfo;
|
|
442
|
+
try {
|
|
443
|
+
await signer.connect();
|
|
444
|
+
} catch (error) {
|
|
445
|
+
if (typeof error === "object") {
|
|
446
|
+
const message = (error as { message: unknown })?.message;
|
|
447
|
+
if (typeof message === "string") {
|
|
448
|
+
this.connectingError = message;
|
|
449
|
+
} else {
|
|
450
|
+
this.connectingError = JSON.stringify(message);
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
this.connectingError = JSON.stringify(error);
|
|
456
|
+
}
|
|
457
|
+
if (!(await signer.isConnected())) {
|
|
300
458
|
return;
|
|
301
459
|
}
|
|
302
460
|
this.scene = Scene.Connected;
|
|
303
461
|
this.walletName = wallet.name;
|
|
304
|
-
this.signerName =
|
|
462
|
+
this.signerName = signerInfo.name;
|
|
305
463
|
this.saveConnection();
|
|
306
464
|
this.closedHandler();
|
|
465
|
+
this.internalAddress = await signer.getInternalAddress();
|
|
466
|
+
this.recommendAddress = await signer.getRecommendedAddress();
|
|
467
|
+
this.balance = await signer.getBalance();
|
|
307
468
|
})();
|
|
308
469
|
};
|
|
309
470
|
|
|
@@ -334,9 +495,18 @@ export class WebComponentConnector extends LitElement {
|
|
|
334
495
|
color: var(--tip-color);
|
|
335
496
|
}
|
|
336
497
|
|
|
337
|
-
.fs-
|
|
498
|
+
.fs-sm {
|
|
499
|
+
font-size: 0.8rem;
|
|
500
|
+
}
|
|
501
|
+
.fs-md {
|
|
502
|
+
font-size: 1rem;
|
|
503
|
+
}
|
|
504
|
+
.fs-lg {
|
|
338
505
|
font-size: 1.2rem;
|
|
339
506
|
}
|
|
507
|
+
.fs-xl {
|
|
508
|
+
font-size: 1.5rem;
|
|
509
|
+
}
|
|
340
510
|
|
|
341
511
|
.mb-1 {
|
|
342
512
|
margin-bottom: 0.7rem;
|
|
@@ -350,6 +520,18 @@ export class WebComponentConnector extends LitElement {
|
|
|
350
520
|
.mt-2 {
|
|
351
521
|
margin-top: 1rem;
|
|
352
522
|
}
|
|
523
|
+
.ml-1 {
|
|
524
|
+
margin-left: 0.7rem;
|
|
525
|
+
}
|
|
526
|
+
.ml-2 {
|
|
527
|
+
margin-left: 1em;
|
|
528
|
+
}
|
|
529
|
+
.mr-1 {
|
|
530
|
+
margin-right: 0.7rem;
|
|
531
|
+
}
|
|
532
|
+
.mr-2 {
|
|
533
|
+
margin-right: 1rem;
|
|
534
|
+
}
|
|
353
535
|
|
|
354
536
|
.background {
|
|
355
537
|
width: 100%;
|
|
@@ -364,25 +546,39 @@ export class WebComponentConnector extends LitElement {
|
|
|
364
546
|
transform: translate(-50%, -50%);
|
|
365
547
|
background: var(--background);
|
|
366
548
|
border-radius: 1.2rem;
|
|
549
|
+
overflow: hidden;
|
|
550
|
+
transition: height 0.15s ease-out;
|
|
367
551
|
}
|
|
368
552
|
|
|
369
553
|
.header {
|
|
370
554
|
display: flex;
|
|
371
555
|
justify-content: space-between;
|
|
372
556
|
align-items: center;
|
|
373
|
-
padding: 1rem 1.3rem;
|
|
557
|
+
padding: 1rem 1.3rem 0.5rem;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
.header-divider {
|
|
561
|
+
padding-bottom: 1rem;
|
|
374
562
|
border-bottom: 1px solid var(--divider);
|
|
563
|
+
margin-bottom: 1rem;
|
|
375
564
|
}
|
|
376
565
|
|
|
377
566
|
.close,
|
|
378
567
|
.back {
|
|
379
568
|
width: 0.8rem;
|
|
380
569
|
height: 0.8rem;
|
|
570
|
+
opacity: 0;
|
|
571
|
+
transition: opacity 0.15s ease-in-out;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.close.active,
|
|
575
|
+
.back.active {
|
|
576
|
+
opacity: 1;
|
|
381
577
|
cursor: pointer;
|
|
382
578
|
}
|
|
383
579
|
|
|
384
580
|
.body {
|
|
385
|
-
padding: 1.
|
|
581
|
+
padding: 0 1.3rem 1.4rem;
|
|
386
582
|
min-width: 20rem;
|
|
387
583
|
display: flex;
|
|
388
584
|
flex-direction: column;
|
|
@@ -397,18 +593,23 @@ export class WebComponentConnector extends LitElement {
|
|
|
397
593
|
padding: 0.75rem 1rem;
|
|
398
594
|
background: var(--btn-primary);
|
|
399
595
|
border-radius: 0.4rem;
|
|
400
|
-
transition: background 0.
|
|
596
|
+
transition: background 0.15s ease-in-out;
|
|
401
597
|
}
|
|
402
|
-
|
|
403
598
|
.btn-primary img {
|
|
404
599
|
width: 2rem;
|
|
405
600
|
height: 2rem;
|
|
406
601
|
margin-right: 1rem;
|
|
602
|
+
border-radius: 0.4rem;
|
|
407
603
|
}
|
|
408
|
-
|
|
409
604
|
.btn-primary:hover {
|
|
410
605
|
background: var(--btn-primary-hover);
|
|
411
606
|
}
|
|
607
|
+
.btn-primary:disabled {
|
|
608
|
+
cursor: not-allowed;
|
|
609
|
+
}
|
|
610
|
+
.btn-primary:disabled:hover {
|
|
611
|
+
background: var(--btn-primary);
|
|
612
|
+
}
|
|
412
613
|
|
|
413
614
|
.btn-secondary {
|
|
414
615
|
display: flex;
|
|
@@ -416,19 +617,28 @@ export class WebComponentConnector extends LitElement {
|
|
|
416
617
|
padding: 0.25rem 1rem;
|
|
417
618
|
background: var(--btn-secondary);
|
|
418
619
|
border-radius: 9999px;
|
|
419
|
-
transition: background 0.
|
|
620
|
+
transition: background 0.15s ease-in-out;
|
|
420
621
|
}
|
|
421
|
-
|
|
422
622
|
.btn-secondary img {
|
|
423
623
|
width: 0.8rem;
|
|
424
624
|
height: 0.8rem;
|
|
425
625
|
margin-right: 0.5rem;
|
|
426
626
|
}
|
|
627
|
+
.btn-secondary:hover {
|
|
628
|
+
background: var(--btn-secondary-hover);
|
|
629
|
+
}
|
|
630
|
+
.btn-secondary:disabled {
|
|
631
|
+
cursor: not-allowed;
|
|
632
|
+
}
|
|
633
|
+
.btn-secondary:disabled:hover {
|
|
634
|
+
background: var(--btn-secondary);
|
|
635
|
+
}
|
|
427
636
|
|
|
428
637
|
.wallet-icon {
|
|
429
638
|
width: 4rem;
|
|
430
639
|
height: 4rem;
|
|
431
640
|
margin-bottom: 0.5rem;
|
|
641
|
+
border-radius: 0.8rem;
|
|
432
642
|
}
|
|
433
643
|
|
|
434
644
|
.connecting-wallet-icon {
|
|
@@ -436,5 +646,73 @@ export class WebComponentConnector extends LitElement {
|
|
|
436
646
|
height: 5rem;
|
|
437
647
|
border-radius: 1rem;
|
|
438
648
|
}
|
|
649
|
+
|
|
650
|
+
.position-relative {
|
|
651
|
+
position: relative;
|
|
652
|
+
}
|
|
653
|
+
.position-absolute {
|
|
654
|
+
position: absolute;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
.connected-type-icon {
|
|
658
|
+
position: absolute;
|
|
659
|
+
width: 1.5rem;
|
|
660
|
+
height: 1.5rem;
|
|
661
|
+
right: -0.5rem;
|
|
662
|
+
bottom: -0.5rem;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
.text-center {
|
|
666
|
+
text-align: center;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
.cursor-pointer {
|
|
670
|
+
cursor: pointer;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
.flex {
|
|
674
|
+
display: flex;
|
|
675
|
+
}
|
|
676
|
+
.justify-center {
|
|
677
|
+
justify-content: center;
|
|
678
|
+
}
|
|
679
|
+
.justify-between {
|
|
680
|
+
justify-content: space-between;
|
|
681
|
+
}
|
|
682
|
+
.align-center {
|
|
683
|
+
align-items: center;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
.switch-btn-container {
|
|
687
|
+
width: 100%;
|
|
688
|
+
padding: 1rem;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
.switch-line {
|
|
692
|
+
flex: 1;
|
|
693
|
+
height: 1px;
|
|
694
|
+
background-color: var(--divider);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
.switching-status-dot {
|
|
698
|
+
width: 0.5rem;
|
|
699
|
+
height: 0.5rem;
|
|
700
|
+
background: #0f0;
|
|
701
|
+
border-radius: 50%;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
.copy-btn {
|
|
705
|
+
width: 1.5rem;
|
|
706
|
+
height: 1.5rem;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
.copy-btn-sm {
|
|
710
|
+
width: 1rem;
|
|
711
|
+
height: 1rem;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
.sm-chain-logo {
|
|
715
|
+
width: 1.125rem;
|
|
716
|
+
}
|
|
439
717
|
`;
|
|
440
718
|
}
|