@ckb-ccc/connector 0.0.5-alpha.1 → 0.0.5-alpha.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.
- 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 +224 -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 +269 -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/dist/advancedBarrel.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC"}
|
package/dist/advancedBarrel.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ckb.sm.svg.d.ts","sourceRoot":"","sources":["../../../src/assets/chains/ckb.sm.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAEtB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { encodeSvgToImgSrc } from "../utils";
|
|
2
|
+
export const CKB_SM_SVG = encodeSvgToImgSrc('<svg width="19" height="18" viewBox="0 0 19 18" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_221_415)"><path d="M0.666992 9C0.666992 11.3869 1.6152 13.6761 3.30303 15.364C4.99086 17.0518 7.28004 18 9.66699 18C12.0539 18 14.3431 17.0518 16.031 15.364C17.7188 13.6761 18.667 11.3869 18.667 9C18.667 6.61305 17.7188 4.32387 16.031 2.63604C14.3431 0.948212 12.0539 0 9.66699 0C7.28004 0 4.99086 0.948212 3.30303 2.63604C1.6152 4.32387 0.666992 6.61305 0.666992 9Z" fill="#333333"/><path d="M5.51318 4.84619V12.9231H7.60395V8.52235H9.20549L5.51318 4.84619Z" fill="white"/><path d="M11.73 4.84619V9.24696H10.1284L13.8207 12.9231V4.84619H11.73Z" fill="white"/></g><defs><clipPath id="clip0_221_415"><rect width="18" height="18" fill="white" transform="translate(0.666992)"/></clipPath></defs></svg>');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.svg.d.ts","sourceRoot":"","sources":["../../src/assets/copy.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,QAEpB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { encodeSvgToImgSrc } from "./utils";
|
|
2
|
+
export const COPY_SVG = encodeSvgToImgSrc('<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 13.5657V6.10526C19 5.49737 18.5091 5 17.9091 5H10.5454C9.94543 5 9.45452 5.49737 9.45452 6.10526V13.5657C9.45452 14.1736 9.94543 14.671 10.5454 14.671H17.9091C18.5091 14.671 19 14.1736 19 13.5657Z" fill="#999999"/><path d="M14.5455 15.8684H9.18183C8.58183 15.8684 8.09092 15.3711 8.09092 14.7632V9.329H6.09091C5.49091 9.329 5 9.82637 5 10.4343V17.8947C5 18.5026 5.49091 19 6.09091 19H13.4546C14.0546 19 14.5455 18.5026 14.5455 17.8947V15.8684Z" fill="#999999"/></svg>');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diconnect.svg.d.ts","sourceRoot":"","sources":["../../src/assets/diconnect.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,QAE1B,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { encodeSvgToImgSrc } from "./utils";
|
|
2
|
+
export const DISCONNECT_SVG = encodeSvgToImgSrc('<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect width="32" height="32" rx="8" fill="#DDDDDD"/><path d="M20.375 16.875H14.25V15.125H20.375L19.5 13.375H21.25L23 16L21.25 18.625H19.5L20.375 16.875ZM20.9509 11.051L19.7128 12.2886C19.226 11.8 18.6473 11.4125 18.0101 11.1484C17.3729 10.8844 16.6897 10.749 16 10.75C13.1006 10.75 10.75 13.1006 10.75 16C10.75 18.8994 13.1006 21.25 16 21.25C17.4107 21.25 18.7309 20.6923 19.71 19.7147L20.9462 20.9532C20.297 21.6031 19.5259 22.1184 18.6771 22.4696C17.8283 22.8209 16.9186 23.0011 16 23C12.1341 23 9 19.8659 9 16C9 12.1341 12.1341 9 16 9C17.8816 9 19.647 9.74667 20.9509 11.051Z" fill="#666666"/></svg>');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.svg.d.ts","sourceRoot":"","sources":["../../src/assets/swap.svg.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,QAEpB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { encodeSvgToImgSrc } from "./utils";
|
|
2
|
+
export const SWAP_SVG = encodeSvgToImgSrc('<svg width="13" height="12" viewBox="0 0 13 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9.30688 5.22537L11.1669 3.36536L9.30688 1.50537" stroke="#666666" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/><path d="M2.16699 3.36523H11.167" stroke="#666666" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/><path d="M4.02698 6.77539L2.16699 8.63541L4.02698 10.4954" stroke="#666666" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/><path d="M11.167 8.63525H2.16699" stroke="#666666" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/></svg>');
|
|
@@ -3,6 +3,7 @@ import { LitElement, PropertyValues } from "lit";
|
|
|
3
3
|
import { Ref } from "lit/directives/ref.js";
|
|
4
4
|
export declare class WebComponentConnector extends LitElement {
|
|
5
5
|
private wallets;
|
|
6
|
+
signerFilter?: (signerInfo: ccc.SignerInfo, wallet: ccc.Wallet) => Promise<boolean>;
|
|
6
7
|
private resetListeners;
|
|
7
8
|
isOpen: boolean;
|
|
8
9
|
setIsOpen(isOpen: boolean): void;
|
|
@@ -17,6 +18,10 @@ export declare class WebComponentConnector extends LitElement {
|
|
|
17
18
|
private signerName?;
|
|
18
19
|
wallet?: ccc.Wallet;
|
|
19
20
|
signer?: ccc.SignerInfo;
|
|
21
|
+
private recommendAddress?;
|
|
22
|
+
private internalAddress?;
|
|
23
|
+
private balance?;
|
|
24
|
+
private updateSignerInfo;
|
|
20
25
|
private prepareSigner;
|
|
21
26
|
disconnect(): void;
|
|
22
27
|
private loadConnection;
|
|
@@ -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;AAE5D,OAAO,EAAE,GAAG,EAAkB,MAAM,uBAAuB,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;AAE5D,OAAO,EAAE,GAAG,EAAkB,MAAM,uBAAuB,CAAC;AA0B5D,qBACa,qBAAsB,SAAQ,UAAU;IAEnD,OAAO,CAAC,OAAO,CAA2B;IAEnC,YAAY,CAAC,EAAE,CACpB,UAAU,EAAE,GAAG,CAAC,UAAU,EAC1B,MAAM,EAAE,GAAG,CAAC,MAAM,KACf,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtB,OAAO,CAAC,cAAc,CAAsB;IAGrC,MAAM,EAAE,OAAO,CAAS;IACxB,SAAS,CAAC,MAAM,EAAE,OAAO;IAKzB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,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;IAG/B,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAElC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC,OAAO,CAAC,OAAO,CAAC,CAAU;YAEZ,gBAAgB;YAShB,aAAa;IAYpB,UAAU;IAQjB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAUtB,iBAAiB,IAAI,IAAI;IAMzB,UAAU,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI;IAoCnD,OAAO,CAAC,aAAa;YA2FP,SAAS;IAyCvB,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAC3C,SAAS,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAC7C,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAe;IAE3C,MAAM;IA2GN,OAAO;IAUP,OAAO,CAAC,aAAa,CAgBnB;IAEF,OAAO,CAAC,qBAAqB,CAoB3B;IAEF,MAAM,CAAC,MAAM,0BAsPX;CACH"}
|
package/dist/connector/index.js
CHANGED
|
@@ -11,16 +11,21 @@ import { createRef, ref } from "lit/directives/ref.js";
|
|
|
11
11
|
import { CLOSE_SVG } from "../assets/close.svg";
|
|
12
12
|
import { JOY_ID_SVG } from "../assets/joy-id.svg";
|
|
13
13
|
import { LEFT_SVG } from "../assets/left.svg";
|
|
14
|
+
import { METAMASK_SVG } from "../assets/metamask.svg";
|
|
14
15
|
import { OKX_SVG } from "../assets/okx.svg";
|
|
15
16
|
import { UNI_SAT_SVG } from "../assets/uni-sat.svg";
|
|
16
17
|
import { WillUpdateEvent } from "../events";
|
|
17
18
|
import { generateConnectingScene, generateSignersScene, generateWalletsScene, } from "../scenes";
|
|
19
|
+
import { generateConnectedScene } from "../scenes/connected";
|
|
20
|
+
import { generateNetworksScene } from "../scenes/networks";
|
|
21
|
+
import { SignerOpenLink } from "../signerOpenLink";
|
|
18
22
|
var Scene;
|
|
19
23
|
(function (Scene) {
|
|
20
24
|
Scene["SelectingWallets"] = "SelectingWallets";
|
|
21
25
|
Scene["SelectingSigners"] = "SelectingSigners";
|
|
22
26
|
Scene["Connecting"] = "Connecting";
|
|
23
27
|
Scene["Connected"] = "Connected";
|
|
28
|
+
Scene["SwitchingNetworks"] = "SwitchingNetworks";
|
|
24
29
|
})(Scene || (Scene = {}));
|
|
25
30
|
let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
26
31
|
constructor() {
|
|
@@ -43,6 +48,9 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
43
48
|
this.selectedSigner = undefined;
|
|
44
49
|
this.selectedWallet = undefined;
|
|
45
50
|
}
|
|
51
|
+
else if ([Scene.SwitchingNetworks].includes(this.scene)) {
|
|
52
|
+
this.scene = Scene.Connected;
|
|
53
|
+
}
|
|
46
54
|
this.isOpen = false;
|
|
47
55
|
};
|
|
48
56
|
this.signerSelectedHandler = (wallet, signer) => {
|
|
@@ -54,6 +62,8 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
54
62
|
if (!(await signer.signer.isConnected())) {
|
|
55
63
|
return;
|
|
56
64
|
}
|
|
65
|
+
this.recommendAddress = await signer.signer.getRecommendedAddress();
|
|
66
|
+
this.balance = await signer.signer.getBalance();
|
|
57
67
|
this.scene = Scene.Connected;
|
|
58
68
|
this.walletName = wallet.name;
|
|
59
69
|
this.signerName = signer.name;
|
|
@@ -68,22 +78,30 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
68
78
|
setClient(client) {
|
|
69
79
|
this.client = client;
|
|
70
80
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
async updateSignerInfo() {
|
|
82
|
+
if (!this.signer) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.recommendAddress = await this.signer.signer.getRecommendedAddress();
|
|
86
|
+
this.balance = await this.signer.signer.getBalance();
|
|
87
|
+
this.internalAddress = await this.signer.signer.getInternalAddress();
|
|
88
|
+
}
|
|
89
|
+
async prepareSigner() {
|
|
90
|
+
if (this.signer && (await this.signer.signer.isConnected())) {
|
|
91
|
+
await this.updateSignerInfo();
|
|
92
|
+
this.scene = Scene.Connected;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.wallet = undefined;
|
|
96
|
+
this.signer = undefined;
|
|
97
|
+
this.scene = Scene.SelectingWallets;
|
|
81
98
|
}
|
|
82
99
|
disconnect() {
|
|
83
100
|
this.signer?.signer?.disconnect();
|
|
84
101
|
this.walletName = undefined;
|
|
85
102
|
this.signerName = undefined;
|
|
86
103
|
this.saveConnection();
|
|
104
|
+
this.closedHandler();
|
|
87
105
|
}
|
|
88
106
|
loadConnection() {
|
|
89
107
|
const { signerName, walletName, } = JSON.parse(window.localStorage.getItem("ccc-connection-info") ?? "{}");
|
|
@@ -102,17 +120,26 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
102
120
|
this.reloadSigners();
|
|
103
121
|
}
|
|
104
122
|
willUpdate(changedProperties) {
|
|
105
|
-
if (changedProperties.has("client")
|
|
123
|
+
if (changedProperties.has("client") ||
|
|
124
|
+
changedProperties.has("signerFilter")) {
|
|
106
125
|
this.reloadSigners();
|
|
107
126
|
}
|
|
108
127
|
if (changedProperties.has("walletName") ||
|
|
109
|
-
changedProperties.has("wallets")
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
if (changedProperties.has("signerName") ||
|
|
128
|
+
changedProperties.has("wallets") ||
|
|
129
|
+
changedProperties.has("signerName") ||
|
|
113
130
|
changedProperties.has("wallet")) {
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
(async () => {
|
|
132
|
+
const wallet = this.wallets.find(({ name }) => name === this.walletName);
|
|
133
|
+
const signer = wallet?.signers.find(({ name }) => name === this.signerName);
|
|
134
|
+
if (signer && (await signer.signer.isConnected())) {
|
|
135
|
+
this.wallet = wallet;
|
|
136
|
+
this.signer = signer;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.wallet = undefined;
|
|
140
|
+
this.signer = undefined;
|
|
141
|
+
}
|
|
142
|
+
})();
|
|
116
143
|
}
|
|
117
144
|
if (changedProperties.has("signer")) {
|
|
118
145
|
this.prepareSigner();
|
|
@@ -136,45 +163,72 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
136
163
|
document.querySelector("head title").text;
|
|
137
164
|
const icon = this.icon ??
|
|
138
165
|
document.querySelector('link[rel="icon"]').href;
|
|
139
|
-
ccc.JoyId.getJoyIdSigners(this.client, name, icon).forEach(({ signer,
|
|
140
|
-
this.addSigner("JoyID", name, JOY_ID_SVG,
|
|
166
|
+
ccc.JoyId.getJoyIdSigners(this.client, name, icon).forEach(({ signer, name }) => {
|
|
167
|
+
this.addSigner("JoyID", name, JOY_ID_SVG, signer);
|
|
141
168
|
});
|
|
142
169
|
const uniSatSigner = ccc.UniSat.getUniSatSigner(this.client);
|
|
143
170
|
if (uniSatSigner) {
|
|
144
|
-
this.addSigner("UniSat", "BTC", UNI_SAT_SVG,
|
|
171
|
+
this.addSigner("UniSat", "BTC", UNI_SAT_SVG, uniSatSigner);
|
|
145
172
|
}
|
|
146
173
|
const okxBitcoinSigner = ccc.Okx.getOKXBitcoinSigner(this.client);
|
|
147
174
|
if (okxBitcoinSigner) {
|
|
148
|
-
this.addSigner("OKX Wallet", "BTC", OKX_SVG,
|
|
175
|
+
this.addSigner("OKX Wallet", "BTC", OKX_SVG, okxBitcoinSigner);
|
|
149
176
|
}
|
|
150
177
|
const eip6963Manager = new ccc.Eip6963.SignerFactory(this.client);
|
|
151
178
|
this.resetListeners.push(eip6963Manager.subscribeSigners((signer) => {
|
|
152
|
-
this.addSigner(`${signer.detail.info.name}`, "EVM", signer.detail.info.icon,
|
|
179
|
+
this.addSigner(`${signer.detail.info.name}`, "EVM", signer.detail.info.icon, signer);
|
|
153
180
|
}));
|
|
181
|
+
// === Dummy signers ===
|
|
182
|
+
this.addSigner("MetaMask", "EVM", METAMASK_SVG, new SignerOpenLink(this.client, `https://metamask.app.link/dapp/${window.location.href}`, ccc.SignerType.EVM));
|
|
183
|
+
[ccc.SignerType.EVM, ccc.SignerType.BTC].forEach((type) => {
|
|
184
|
+
this.addSigner("OKX Wallet", type, OKX_SVG, new SignerOpenLink(this.client, "https://www.okx.com/download?deeplink=" +
|
|
185
|
+
encodeURIComponent("okx://wallet/dapp/url?dappUrl=" +
|
|
186
|
+
encodeURIComponent(window.location.href)), type));
|
|
187
|
+
});
|
|
188
|
+
this.addSigner("UniSat", ccc.SignerType.BTC, UNI_SAT_SVG, new SignerOpenLink(this.client, "https://unisat.io/download", ccc.SignerType.BTC));
|
|
189
|
+
// ===
|
|
154
190
|
}
|
|
155
|
-
addSigner(walletName, signerName, icon,
|
|
191
|
+
async addSigner(walletName, signerName, icon, signer) {
|
|
192
|
+
const signerInfo = { name: signerName, signer };
|
|
193
|
+
if (this.signerFilter &&
|
|
194
|
+
!(await this.signerFilter(signerInfo, { name: walletName, icon }))) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
156
197
|
let updated = false;
|
|
157
198
|
const wallets = this.wallets.map((wallet) => {
|
|
158
199
|
if (wallet.name !== walletName) {
|
|
159
200
|
return wallet;
|
|
160
201
|
}
|
|
161
202
|
updated = true;
|
|
203
|
+
const allSigners = [...wallet.signers, signerInfo];
|
|
204
|
+
const signers = allSigners.filter(({ signer }) => !(signer instanceof SignerOpenLink));
|
|
162
205
|
return {
|
|
163
206
|
...wallet,
|
|
164
|
-
signers:
|
|
207
|
+
signers: signers.length !== 0 ? signers : [signerInfo],
|
|
165
208
|
};
|
|
166
209
|
});
|
|
167
210
|
if (!updated) {
|
|
168
211
|
wallets.push({
|
|
169
212
|
name: walletName,
|
|
170
213
|
icon,
|
|
171
|
-
signers: [
|
|
214
|
+
signers: [signerInfo],
|
|
172
215
|
});
|
|
173
216
|
}
|
|
174
217
|
this.wallets = wallets;
|
|
175
218
|
}
|
|
176
219
|
render() {
|
|
177
220
|
const [title, body] = (() => {
|
|
221
|
+
if (this.scene === Scene.Connected && this.wallet && this.signer) {
|
|
222
|
+
return generateConnectedScene(this.wallet, this.signer, this.recommendAddress, this.internalAddress, this.balance, this.disconnect.bind(this), () => {
|
|
223
|
+
this.scene = Scene.SwitchingNetworks;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (this.scene === Scene.SwitchingNetworks) {
|
|
227
|
+
return generateNetworksScene(this.client, (client) => {
|
|
228
|
+
this.setClient(client);
|
|
229
|
+
this.closedHandler();
|
|
230
|
+
});
|
|
231
|
+
}
|
|
178
232
|
if (this.scene === Scene.SelectingWallets || !this.selectedWallet) {
|
|
179
233
|
return generateWalletsScene(this.wallets, (wallet) => {
|
|
180
234
|
this.selectedWallet = wallet;
|
|
@@ -186,7 +240,11 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
186
240
|
}
|
|
187
241
|
return generateConnectingScene(this.selectedWallet, this.selectedSigner, this.signerSelectedHandler);
|
|
188
242
|
})();
|
|
189
|
-
const canBack = [
|
|
243
|
+
const canBack = [
|
|
244
|
+
Scene.SelectingSigners,
|
|
245
|
+
Scene.Connecting,
|
|
246
|
+
Scene.SwitchingNetworks,
|
|
247
|
+
].includes(this.scene);
|
|
190
248
|
return html `<style>
|
|
191
249
|
:host {
|
|
192
250
|
${this.isOpen ? "" : "display: none;"}
|
|
@@ -195,6 +253,7 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
195
253
|
--btn-primary: #f8f8f8;
|
|
196
254
|
--btn-primary-hover: #efeeee;
|
|
197
255
|
--btn-secondary: #ddd;
|
|
256
|
+
--btn-secondary-hover: #ccc;
|
|
198
257
|
color: #1e1e1e;
|
|
199
258
|
--tip-color: #666;
|
|
200
259
|
}
|
|
@@ -208,17 +267,30 @@ let WebComponentConnector = class WebComponentConnector extends LitElement {
|
|
|
208
267
|
}}
|
|
209
268
|
>
|
|
210
269
|
<div class="main" ${ref(this.mainRef)}>
|
|
211
|
-
<div
|
|
270
|
+
<div
|
|
271
|
+
class="header text-bold fs-lg ${title == null
|
|
272
|
+
? ""
|
|
273
|
+
: "header-divider"}"
|
|
274
|
+
${ref(this.headerRef)}
|
|
275
|
+
>
|
|
212
276
|
<img
|
|
213
277
|
class="back ${canBack ? "active" : ""}"
|
|
214
278
|
src=${LEFT_SVG}
|
|
215
279
|
@click=${() => {
|
|
216
280
|
if (this.scene === Scene.Connecting) {
|
|
217
|
-
this.
|
|
281
|
+
if ((this.selectedWallet?.signers.length ?? 0) <= 1) {
|
|
282
|
+
this.scene = Scene.SelectingWallets;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
this.scene = Scene.SelectingSigners;
|
|
286
|
+
}
|
|
218
287
|
}
|
|
219
288
|
else if (this.scene === Scene.SelectingSigners) {
|
|
220
289
|
this.scene = Scene.SelectingWallets;
|
|
221
290
|
}
|
|
291
|
+
else if (this.scene === Scene.SwitchingNetworks) {
|
|
292
|
+
this.scene = Scene.Connected;
|
|
293
|
+
}
|
|
222
294
|
}}
|
|
223
295
|
/>
|
|
224
296
|
${title}
|
|
@@ -267,9 +339,18 @@ WebComponentConnector.styles = css `
|
|
|
267
339
|
color: var(--tip-color);
|
|
268
340
|
}
|
|
269
341
|
|
|
270
|
-
.fs-
|
|
342
|
+
.fs-sm {
|
|
343
|
+
font-size: 0.8rem;
|
|
344
|
+
}
|
|
345
|
+
.fs-md {
|
|
346
|
+
font-size: 1rem;
|
|
347
|
+
}
|
|
348
|
+
.fs-lg {
|
|
271
349
|
font-size: 1.2rem;
|
|
272
350
|
}
|
|
351
|
+
.fs-xl {
|
|
352
|
+
font-size: 1.5rem;
|
|
353
|
+
}
|
|
273
354
|
|
|
274
355
|
.mb-1 {
|
|
275
356
|
margin-bottom: 0.7rem;
|
|
@@ -283,6 +364,18 @@ WebComponentConnector.styles = css `
|
|
|
283
364
|
.mt-2 {
|
|
284
365
|
margin-top: 1rem;
|
|
285
366
|
}
|
|
367
|
+
.ml-1 {
|
|
368
|
+
margin-left: 0.7rem;
|
|
369
|
+
}
|
|
370
|
+
.ml-2 {
|
|
371
|
+
margin-left: 1em;
|
|
372
|
+
}
|
|
373
|
+
.mr-1 {
|
|
374
|
+
margin-right: 0.7rem;
|
|
375
|
+
}
|
|
376
|
+
.mr-2 {
|
|
377
|
+
margin-right: 1rem;
|
|
378
|
+
}
|
|
286
379
|
|
|
287
380
|
.background {
|
|
288
381
|
width: 100%;
|
|
@@ -305,8 +398,13 @@ WebComponentConnector.styles = css `
|
|
|
305
398
|
display: flex;
|
|
306
399
|
justify-content: space-between;
|
|
307
400
|
align-items: center;
|
|
308
|
-
padding: 1rem 1.3rem;
|
|
401
|
+
padding: 1rem 1.3rem 0.5rem;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.header-divider {
|
|
405
|
+
padding-bottom: 1rem;
|
|
309
406
|
border-bottom: 1px solid var(--divider);
|
|
407
|
+
margin-bottom: 1rem;
|
|
310
408
|
}
|
|
311
409
|
|
|
312
410
|
.close,
|
|
@@ -324,7 +422,7 @@ WebComponentConnector.styles = css `
|
|
|
324
422
|
}
|
|
325
423
|
|
|
326
424
|
.body {
|
|
327
|
-
padding: 1.
|
|
425
|
+
padding: 0 1.3rem 1.4rem;
|
|
328
426
|
min-width: 20rem;
|
|
329
427
|
display: flex;
|
|
330
428
|
flex-direction: column;
|
|
@@ -341,17 +439,21 @@ WebComponentConnector.styles = css `
|
|
|
341
439
|
border-radius: 0.4rem;
|
|
342
440
|
transition: background 0.15s ease-in-out;
|
|
343
441
|
}
|
|
344
|
-
|
|
345
442
|
.btn-primary img {
|
|
346
443
|
width: 2rem;
|
|
347
444
|
height: 2rem;
|
|
348
445
|
margin-right: 1rem;
|
|
349
446
|
border-radius: 0.4rem;
|
|
350
447
|
}
|
|
351
|
-
|
|
352
448
|
.btn-primary:hover {
|
|
353
449
|
background: var(--btn-primary-hover);
|
|
354
450
|
}
|
|
451
|
+
.btn-primary:disabled {
|
|
452
|
+
cursor: not-allowed;
|
|
453
|
+
}
|
|
454
|
+
.btn-primary:disabled:hover {
|
|
455
|
+
background: var(--btn-primary);
|
|
456
|
+
}
|
|
355
457
|
|
|
356
458
|
.btn-secondary {
|
|
357
459
|
display: flex;
|
|
@@ -361,12 +463,20 @@ WebComponentConnector.styles = css `
|
|
|
361
463
|
border-radius: 9999px;
|
|
362
464
|
transition: background 0.15s ease-in-out;
|
|
363
465
|
}
|
|
364
|
-
|
|
365
466
|
.btn-secondary img {
|
|
366
467
|
width: 0.8rem;
|
|
367
468
|
height: 0.8rem;
|
|
368
469
|
margin-right: 0.5rem;
|
|
369
470
|
}
|
|
471
|
+
.btn-secondary:hover {
|
|
472
|
+
background: var(--btn-secondary-hover);
|
|
473
|
+
}
|
|
474
|
+
.btn-secondary:disabled {
|
|
475
|
+
cursor: not-allowed;
|
|
476
|
+
}
|
|
477
|
+
.btn-secondary:disabled:hover {
|
|
478
|
+
background: var(--btn-secondary);
|
|
479
|
+
}
|
|
370
480
|
|
|
371
481
|
.wallet-icon {
|
|
372
482
|
width: 4rem;
|
|
@@ -380,10 +490,81 @@ WebComponentConnector.styles = css `
|
|
|
380
490
|
height: 5rem;
|
|
381
491
|
border-radius: 1rem;
|
|
382
492
|
}
|
|
493
|
+
|
|
494
|
+
.position-relative {
|
|
495
|
+
position: relative;
|
|
496
|
+
}
|
|
497
|
+
.position-absolute {
|
|
498
|
+
position: absolute;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.connected-type-icon {
|
|
502
|
+
position: absolute;
|
|
503
|
+
width: 1.5rem;
|
|
504
|
+
height: 1.5rem;
|
|
505
|
+
right: -0.5rem;
|
|
506
|
+
bottom: -0.5rem;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.text-center {
|
|
510
|
+
text-align: center;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
.cursor-pointer {
|
|
514
|
+
cursor: pointer;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
.flex {
|
|
518
|
+
display: flex;
|
|
519
|
+
}
|
|
520
|
+
.justify-center {
|
|
521
|
+
justify-content: center;
|
|
522
|
+
}
|
|
523
|
+
.justify-between {
|
|
524
|
+
justify-content: space-between;
|
|
525
|
+
}
|
|
526
|
+
.align-center {
|
|
527
|
+
align-items: center;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.switch-btn-container {
|
|
531
|
+
width: 100%;
|
|
532
|
+
padding: 1rem;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
.switch-line {
|
|
536
|
+
flex: 1;
|
|
537
|
+
height: 1px;
|
|
538
|
+
background-color: var(--divider);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
.switching-status-dot {
|
|
542
|
+
width: 0.5rem;
|
|
543
|
+
height: 0.5rem;
|
|
544
|
+
background: #0f0;
|
|
545
|
+
border-radius: 50%;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
.copy-btn {
|
|
549
|
+
width: 1.5rem;
|
|
550
|
+
height: 1.5rem;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
.copy-btn-sm {
|
|
554
|
+
width: 1rem;
|
|
555
|
+
height: 1rem;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.sm-chain-logo {
|
|
559
|
+
width: 1.125rem;
|
|
560
|
+
}
|
|
383
561
|
`;
|
|
384
562
|
__decorate([
|
|
385
563
|
state()
|
|
386
564
|
], WebComponentConnector.prototype, "wallets", void 0);
|
|
565
|
+
__decorate([
|
|
566
|
+
property()
|
|
567
|
+
], WebComponentConnector.prototype, "signerFilter", void 0);
|
|
387
568
|
__decorate([
|
|
388
569
|
state()
|
|
389
570
|
], WebComponentConnector.prototype, "isOpen", void 0);
|
|
@@ -417,6 +598,15 @@ __decorate([
|
|
|
417
598
|
__decorate([
|
|
418
599
|
state()
|
|
419
600
|
], WebComponentConnector.prototype, "signer", void 0);
|
|
601
|
+
__decorate([
|
|
602
|
+
state()
|
|
603
|
+
], WebComponentConnector.prototype, "recommendAddress", void 0);
|
|
604
|
+
__decorate([
|
|
605
|
+
state()
|
|
606
|
+
], WebComponentConnector.prototype, "internalAddress", void 0);
|
|
607
|
+
__decorate([
|
|
608
|
+
state()
|
|
609
|
+
], WebComponentConnector.prototype, "balance", void 0);
|
|
420
610
|
WebComponentConnector = __decorate([
|
|
421
611
|
customElement("ccc-connector")
|
|
422
612
|
], WebComponentConnector);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/ccc";
|
|
2
|
+
export declare function formatString(str: string | undefined, l?: number, r?: number): string | undefined;
|
|
3
|
+
export declare function generateConnectedScene(wallet: ccc.Wallet, signer: ccc.SignerInfo, recommendedAddress: string | undefined, internalAddress: string | undefined, balance: ccc.Num | undefined, disconnect: () => void, handleSwitchClick: () => void): (import("lit").TemplateResult<1> | undefined)[];
|
|
4
|
+
//# sourceMappingURL=connected.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../../src/scenes/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAgBnC,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,CAAC,SAAI,EACL,CAAC,SAAI,GACJ,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,MAAM,EAAE,GAAG,CAAC,UAAU,EACtB,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,OAAO,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,EAC5B,UAAU,EAAE,MAAM,IAAI,EACtB,iBAAiB,EAAE,MAAM,IAAI,mDAoD9B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
function copyAddress(address) {
|
|
9
|
+
if (!address) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return window.navigator.clipboard.writeText(address);
|
|
13
|
+
}
|
|
14
|
+
export function formatString(str, l = 7, r = 5) {
|
|
15
|
+
if (str && str.length > l + r + 3) {
|
|
16
|
+
return `${str.slice(0, l)}...${str.slice(-r)}`;
|
|
17
|
+
}
|
|
18
|
+
return str;
|
|
19
|
+
}
|
|
20
|
+
export function generateConnectedScene(wallet, signer, recommendedAddress, internalAddress, balance, disconnect, handleSwitchClick) {
|
|
21
|
+
return [
|
|
22
|
+
undefined,
|
|
23
|
+
html `
|
|
24
|
+
<div class="position-relative">
|
|
25
|
+
<img
|
|
26
|
+
class="connecting-wallet-icon"
|
|
27
|
+
src=${wallet.icon}
|
|
28
|
+
alt=${wallet.name}
|
|
29
|
+
/>
|
|
30
|
+
<img
|
|
31
|
+
class="connected-type-icon"
|
|
32
|
+
src=${signerTypeToIcon(signer.signer.type)}
|
|
33
|
+
alt=${signer.signer.type}
|
|
34
|
+
>
|
|
35
|
+
</img>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div class="flex align-center mt-2">
|
|
39
|
+
<span class="text-bold fs-xl">${formatString(internalAddress)}</span>
|
|
40
|
+
<img class="cursor-pointer copy-btn" src=${COPY_SVG} alt="copy" @click=${() => copyAddress(internalAddress)}/>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="text-bold fs-md">${ccc.fixedPointToString(balance ?? ccc.Zero)} CKB</div>
|
|
43
|
+
<div class="flex align-center">
|
|
44
|
+
<span class="text-bold text-tip fs-md">${formatString(recommendedAddress, 13, 7)}</span>
|
|
45
|
+
<img class="cursor-pointer copy-btn-sm" src=${COPY_SVG} alt="copy" @click=${() => copyAddress(recommendedAddress)}/>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<button
|
|
49
|
+
class="btn-primary mt-2"
|
|
50
|
+
@click=${disconnect}
|
|
51
|
+
>
|
|
52
|
+
<img
|
|
53
|
+
src=${DISCONNECT_SVG}
|
|
54
|
+
alt="disconnect"
|
|
55
|
+
/>
|
|
56
|
+
Disconnect
|
|
57
|
+
</button>
|
|
58
|
+
|
|
59
|
+
<div class="switch-btn-container align-center flex justify-center mt-1">
|
|
60
|
+
<div class="switch-line"></div>
|
|
61
|
+
<div class="switch-content flex align-center cursor-pointer ml-2 mr-2 fs-sm" @click=${handleSwitchClick}>
|
|
62
|
+
<img class="mr-1 sm-chain-logo" src=${CKB_SVG} alt="Nervos Network">
|
|
63
|
+
${signer.signer.client.addressPrefix === "ckb" ? "Mainnet" : "Testnet"}
|
|
64
|
+
${["ckb", "ckt"].includes(signer.signer.client.addressPrefix) ? "" : ` ${signer.signer.client.addressPrefix}`}
|
|
65
|
+
<img class="ml-1" src=${SWAP_SVG} alt="Nervos Network">
|
|
66
|
+
</div>
|
|
67
|
+
<div class="switch-line"></div>
|
|
68
|
+
</div>
|
|
69
|
+
`,
|
|
70
|
+
];
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../src/scenes/networks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AAGzB,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,eAAe,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,OAAO,aAuCjD"}
|