@ckb-ccc/connector-react 0.0.3-alpha.1 → 0.0.4-alpha.0
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/components/index.d.ts +5 -4
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -3
- package/dist/hooks/useCcc.d.ts +4 -2
- package/dist/hooks/useCcc.d.ts.map +1 -1
- package/dist/hooks/useCcc.js +30 -4
- package/package.json +3 -3
- package/src/components/index.ts +5 -8
- package/src/hooks/useCcc.tsx +41 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ccc } from "@ckb-ccc/connector";
|
|
2
2
|
import { type EventName } from "@lit/react";
|
|
3
|
-
export declare const Connector: import("@lit/react").ReactWebComponent<WebComponentConnector, {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare const Connector: import("@lit/react").ReactWebComponent<ccc.WebComponentConnector, {
|
|
4
|
+
onSignerChanged: EventName<ccc.SignerChangedEvent>;
|
|
5
|
+
onStatusChanged: EventName<ccc.StatusChangedEvent>;
|
|
6
|
+
onClose: EventName<ccc.CloseEvent>;
|
|
6
7
|
}>;
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAG7D,eAAO,MAAM,SAAS;;;;EASpB,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { ccc } from "@ckb-ccc/connector";
|
|
3
3
|
import { createComponent } from "@lit/react";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
export const Connector = createComponent({
|
|
6
6
|
tagName: "ccc-connector",
|
|
7
|
-
elementClass: WebComponentConnector,
|
|
7
|
+
elementClass: ccc.WebComponentConnector,
|
|
8
8
|
react: React,
|
|
9
9
|
events: {
|
|
10
|
-
|
|
10
|
+
onSignerChanged: "signerChanged",
|
|
11
|
+
onStatusChanged: "statusChanged",
|
|
11
12
|
onClose: "close",
|
|
12
13
|
},
|
|
13
14
|
});
|
package/dist/hooks/useCcc.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ccc } from "@ckb-ccc/connector";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
export declare function Provider({ children }: {
|
|
@@ -7,6 +7,8 @@ export declare function Provider({ children }: {
|
|
|
7
7
|
export declare function useCcc(): {
|
|
8
8
|
open: () => unknown;
|
|
9
9
|
disconnect: () => unknown;
|
|
10
|
-
|
|
10
|
+
wallet?: ccc.Wallet | undefined;
|
|
11
|
+
signerInfo?: ccc.SignerInfo | undefined;
|
|
12
|
+
status: ccc.ConnectorStatus;
|
|
11
13
|
};
|
|
12
14
|
//# sourceMappingURL=useCcc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCcc.d.ts","sourceRoot":"","sources":["../../src/hooks/useCcc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useCcc.d.ts","sourceRoot":"","sources":["../../src/hooks/useCcc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAA2B,MAAM,OAAO,CAAC;AAe3D,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,qBAgD7D;AAED,wBAAgB,MAAM;;;;;;EAErB"}
|
package/dist/hooks/useCcc.js
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/connector";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import { createContext, useState } from "react";
|
|
3
4
|
import { Connector } from "../components";
|
|
4
|
-
const CCC_CONTEXT = createContext({
|
|
5
|
+
const CCC_CONTEXT = createContext({
|
|
6
|
+
open: () => { },
|
|
7
|
+
disconnect: () => { },
|
|
8
|
+
status: ccc.ConnectorStatus.SelectingSigner,
|
|
9
|
+
});
|
|
5
10
|
export function Provider({ children }) {
|
|
6
11
|
const [isOpen, setIsOpen] = useState(false);
|
|
12
|
+
const [wallet, setWallet] = useState();
|
|
7
13
|
const [signerInfo, setSignerInfo] = useState();
|
|
14
|
+
const [status, setStatus] = useState(ccc.ConnectorStatus.SelectingSigner);
|
|
8
15
|
return (React.createElement(CCC_CONTEXT.Provider, { value: {
|
|
9
16
|
open: () => setIsOpen(true),
|
|
10
|
-
disconnect: () =>
|
|
11
|
-
|
|
17
|
+
disconnect: () => {
|
|
18
|
+
setWallet(undefined);
|
|
19
|
+
setSignerInfo(undefined);
|
|
20
|
+
setStatus(ccc.ConnectorStatus.SelectingSigner);
|
|
21
|
+
},
|
|
22
|
+
...([
|
|
23
|
+
ccc.ConnectorStatus.SelectingSigner,
|
|
24
|
+
ccc.ConnectorStatus.Connecting,
|
|
25
|
+
].includes(status)
|
|
26
|
+
? {
|
|
27
|
+
wallet: undefined,
|
|
28
|
+
signerInfo: undefined,
|
|
29
|
+
}
|
|
30
|
+
: {
|
|
31
|
+
wallet,
|
|
32
|
+
signerInfo,
|
|
33
|
+
}),
|
|
34
|
+
status,
|
|
12
35
|
} },
|
|
13
|
-
React.createElement(Connector, { isOpen: isOpen, onClose: () => setIsOpen(false),
|
|
36
|
+
React.createElement(Connector, { isOpen: isOpen, wallet: wallet, signer: signerInfo, status: status, onClose: () => setIsOpen(false), onSignerChanged: ({ wallet, signerInfo }) => {
|
|
37
|
+
setWallet(wallet);
|
|
38
|
+
setSignerInfo(signerInfo);
|
|
39
|
+
}, onStatusChanged: ({ status }) => setStatus(status) }),
|
|
14
40
|
children));
|
|
15
41
|
}
|
|
16
42
|
export function useCcc() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/connector-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-alpha.0",
|
|
4
4
|
"description": "Common Chains Connector UI Component for React",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@ckb-ccc/connector": "0.0.
|
|
41
|
+
"@ckb-ccc/connector": "0.0.4-alpha.0",
|
|
42
42
|
"@lit/react": "^1.0.5",
|
|
43
43
|
"react": "^18"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e49045ed4b2778c92d6f49b79c17125245141a21"
|
|
46
46
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
CloseEvent,
|
|
5
|
-
ConnectedEvent,
|
|
6
|
-
WebComponentConnector,
|
|
7
|
-
} from "@ckb-ccc/connector";
|
|
3
|
+
import { ccc } from "@ckb-ccc/connector";
|
|
8
4
|
import { createComponent, type EventName } from "@lit/react";
|
|
9
5
|
import * as React from "react";
|
|
10
6
|
|
|
11
7
|
export const Connector = createComponent({
|
|
12
8
|
tagName: "ccc-connector",
|
|
13
|
-
elementClass: WebComponentConnector,
|
|
9
|
+
elementClass: ccc.WebComponentConnector,
|
|
14
10
|
react: React,
|
|
15
11
|
events: {
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
onSignerChanged: "signerChanged" as EventName<ccc.SignerChangedEvent>,
|
|
13
|
+
onStatusChanged: "statusChanged" as EventName<ccc.StatusChangedEvent>,
|
|
14
|
+
onClose: "close" as EventName<ccc.CloseEvent>,
|
|
18
15
|
},
|
|
19
16
|
});
|
package/src/hooks/useCcc.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ccc } from "@ckb-ccc/connector";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { ReactNode, createContext, useState } from "react";
|
|
4
4
|
import { Connector } from "../components";
|
|
@@ -6,25 +6,59 @@ import { Connector } from "../components";
|
|
|
6
6
|
const CCC_CONTEXT = createContext<{
|
|
7
7
|
open: () => unknown;
|
|
8
8
|
disconnect: () => unknown;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
wallet?: ccc.Wallet;
|
|
10
|
+
signerInfo?: ccc.SignerInfo;
|
|
11
|
+
status: ccc.ConnectorStatus;
|
|
12
|
+
}>({
|
|
13
|
+
open: () => {},
|
|
14
|
+
disconnect: () => {},
|
|
15
|
+
status: ccc.ConnectorStatus.SelectingSigner,
|
|
16
|
+
});
|
|
11
17
|
|
|
12
18
|
export function Provider({ children }: { children: ReactNode }) {
|
|
13
19
|
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
-
const [
|
|
20
|
+
const [wallet, setWallet] = useState<ccc.Wallet | undefined>();
|
|
21
|
+
const [signerInfo, setSignerInfo] = useState<ccc.SignerInfo | undefined>();
|
|
22
|
+
const [status, setStatus] = useState<ccc.ConnectorStatus>(
|
|
23
|
+
ccc.ConnectorStatus.SelectingSigner,
|
|
24
|
+
);
|
|
15
25
|
|
|
16
26
|
return (
|
|
17
27
|
<CCC_CONTEXT.Provider
|
|
18
28
|
value={{
|
|
19
29
|
open: () => setIsOpen(true),
|
|
20
|
-
disconnect: () =>
|
|
21
|
-
|
|
30
|
+
disconnect: () => {
|
|
31
|
+
setWallet(undefined);
|
|
32
|
+
setSignerInfo(undefined);
|
|
33
|
+
setStatus(ccc.ConnectorStatus.SelectingSigner);
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
...([
|
|
37
|
+
ccc.ConnectorStatus.SelectingSigner,
|
|
38
|
+
ccc.ConnectorStatus.Connecting,
|
|
39
|
+
].includes(status)
|
|
40
|
+
? {
|
|
41
|
+
wallet: undefined,
|
|
42
|
+
signerInfo: undefined,
|
|
43
|
+
}
|
|
44
|
+
: {
|
|
45
|
+
wallet,
|
|
46
|
+
signerInfo,
|
|
47
|
+
}),
|
|
48
|
+
status,
|
|
22
49
|
}}
|
|
23
50
|
>
|
|
24
51
|
<Connector
|
|
25
52
|
isOpen={isOpen}
|
|
53
|
+
wallet={wallet}
|
|
54
|
+
signer={signerInfo}
|
|
55
|
+
status={status}
|
|
26
56
|
onClose={() => setIsOpen(false)}
|
|
27
|
-
|
|
57
|
+
onSignerChanged={({ wallet, signerInfo }) => {
|
|
58
|
+
setWallet(wallet);
|
|
59
|
+
setSignerInfo(signerInfo);
|
|
60
|
+
}}
|
|
61
|
+
onStatusChanged={({ status }) => setStatus(status)}
|
|
28
62
|
/>
|
|
29
63
|
{children}
|
|
30
64
|
</CCC_CONTEXT.Provider>
|