@ckb-ccc/connector-react 0.0.4-alpha.9 → 0.0.4
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 +2 -4
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -3
- package/dist/hooks/useCcc.d.ts +2 -1
- package/dist/hooks/useCcc.d.ts.map +1 -1
- package/dist/hooks/useCcc.js +20 -34
- package/package.json +3 -3
- package/src/components/index.ts +2 -4
- package/src/hooks/useCcc.tsx +43 -48
- package/tsconfig.base.json +22 -0
- package/tsconfig.commonjs.json +8 -0
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/connector";
|
|
2
|
-
import {
|
|
2
|
+
import { EventName } from "@lit/react";
|
|
3
3
|
export declare const Connector: import("@lit/react").ReactWebComponent<ccc.WebComponentConnector, {
|
|
4
|
-
|
|
5
|
-
onStatusChanged: EventName<ccc.StatusChangedEvent>;
|
|
6
|
-
onClose: EventName<ccc.CloseEvent>;
|
|
4
|
+
onWillUpdate: EventName<ccc.WillUpdateEvent>;
|
|
7
5
|
}>;
|
|
8
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAGxD,eAAO,MAAM,SAAS;;EAOpB,CAAC"}
|
package/dist/components/index.js
CHANGED
package/dist/hooks/useCcc.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export declare function Provider({ children, connectorProps, }: {
|
|
|
7
7
|
export declare function useCcc(): {
|
|
8
8
|
open: () => unknown;
|
|
9
9
|
disconnect: () => unknown;
|
|
10
|
+
setClient: (client: ccc.Client) => unknown;
|
|
11
|
+
client: ccc.Client;
|
|
10
12
|
wallet?: ccc.Wallet | undefined;
|
|
11
13
|
signerInfo?: ccc.SignerInfo | undefined;
|
|
12
|
-
status: ccc.ConnectorStatus;
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=useCcc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCcc.d.ts","sourceRoot":"","sources":["../../src/hooks/useCcc.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useCcc.d.ts","sourceRoot":"","sources":["../../src/hooks/useCcc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyB,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAwD,MAAM,OAAO,CAAC;AAe7E,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EACR,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;CAC3C,qBA4CA;AAED,wBAAgB,MAAM;;;;;;;EAQrB"}
|
package/dist/hooks/useCcc.js
CHANGED
|
@@ -1,41 +1,23 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/connector";
|
|
2
|
-
import React, { createContext, useState } from "react";
|
|
2
|
+
import React, { createContext, useCallback, useMemo, useState } from "react";
|
|
3
3
|
import { Connector } from "../components";
|
|
4
|
-
const CCC_CONTEXT = createContext(
|
|
5
|
-
open: () => { },
|
|
6
|
-
disconnect: () => { },
|
|
7
|
-
status: ccc.ConnectorStatus.SelectingSigner,
|
|
8
|
-
});
|
|
4
|
+
const CCC_CONTEXT = createContext(undefined);
|
|
9
5
|
export function Provider({ children, connectorProps, }) {
|
|
10
|
-
const [
|
|
11
|
-
const [
|
|
12
|
-
const
|
|
13
|
-
const
|
|
6
|
+
const [ref, setRef] = useState(null);
|
|
7
|
+
const [_, setFlag] = useState(0);
|
|
8
|
+
const client = useMemo(() => ref?.client ?? new ccc.ClientPublicTestnet(), [ref?.client]);
|
|
9
|
+
const open = useCallback(() => ref?.setIsOpen(true), [ref, ref?.setIsOpen]);
|
|
10
|
+
const disconnect = useMemo(() => ref?.disconnect.bind(ref) ?? (() => { }), [ref, ref?.disconnect]);
|
|
11
|
+
const setClient = useMemo(() => ref?.setClient.bind(ref) ?? (() => { }), [ref, ref?.setClient]);
|
|
14
12
|
return (React.createElement(CCC_CONTEXT.Provider, { value: {
|
|
15
|
-
open
|
|
16
|
-
disconnect
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
...([
|
|
22
|
-
ccc.ConnectorStatus.SelectingSigner,
|
|
23
|
-
ccc.ConnectorStatus.Connecting,
|
|
24
|
-
].includes(status)
|
|
25
|
-
? {
|
|
26
|
-
wallet: undefined,
|
|
27
|
-
signerInfo: undefined,
|
|
28
|
-
}
|
|
29
|
-
: {
|
|
30
|
-
wallet,
|
|
31
|
-
signerInfo,
|
|
32
|
-
}),
|
|
33
|
-
status,
|
|
13
|
+
open,
|
|
14
|
+
disconnect,
|
|
15
|
+
setClient,
|
|
16
|
+
client,
|
|
17
|
+
wallet: ref?.wallet,
|
|
18
|
+
signerInfo: ref?.signer,
|
|
34
19
|
} },
|
|
35
|
-
React.createElement(Connector, {
|
|
36
|
-
setWallet(wallet);
|
|
37
|
-
setSignerInfo(signerInfo);
|
|
38
|
-
}, onStatusChanged: ({ status }) => setStatus(status), ...connectorProps,
|
|
20
|
+
React.createElement(Connector, { ref: setRef, onWillUpdate: () => setFlag((f) => f + 1), ...connectorProps,
|
|
39
21
|
style: {
|
|
40
22
|
...connectorProps?.style,
|
|
41
23
|
zIndex: connectorProps?.style?.zIndex ?? 999,
|
|
@@ -43,5 +25,9 @@ export function Provider({ children, connectorProps, }) {
|
|
|
43
25
|
children));
|
|
44
26
|
}
|
|
45
27
|
export function useCcc() {
|
|
46
|
-
|
|
28
|
+
const context = React.useContext(CCC_CONTEXT);
|
|
29
|
+
if (!context) {
|
|
30
|
+
throw Error("The component which invokes the useCcc hook should be placed in a ccc.Provider.");
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
47
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/connector-react",
|
|
3
|
-
"version": "0.0.4
|
|
3
|
+
"version": "0.0.4",
|
|
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.4
|
|
41
|
+
"@ckb-ccc/connector": "0.0.4",
|
|
42
42
|
"@lit/react": "^1.0.5",
|
|
43
43
|
"react": "^18"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "76485b6b76ce3c97d5acebd42decbafd546aa433"
|
|
46
46
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { ccc } from "@ckb-ccc/connector";
|
|
4
|
-
import {
|
|
4
|
+
import { EventName, createComponent } from "@lit/react";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
|
|
7
7
|
export const Connector = createComponent({
|
|
@@ -9,8 +9,6 @@ export const Connector = createComponent({
|
|
|
9
9
|
elementClass: ccc.WebComponentConnector,
|
|
10
10
|
react: React,
|
|
11
11
|
events: {
|
|
12
|
-
|
|
13
|
-
onStatusChanged: "statusChanged" as EventName<ccc.StatusChangedEvent>,
|
|
14
|
-
onClose: "close" as EventName<ccc.CloseEvent>,
|
|
12
|
+
onWillUpdate: "willUpdate" as EventName<ccc.WillUpdateEvent>,
|
|
15
13
|
},
|
|
16
14
|
});
|
package/src/hooks/useCcc.tsx
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/connector";
|
|
2
|
-
import React, { createContext, useState } from "react";
|
|
1
|
+
import { WebComponentConnector, ccc } from "@ckb-ccc/connector";
|
|
2
|
+
import React, { createContext, useCallback, useMemo, useState } from "react";
|
|
3
3
|
import { Connector } from "../components";
|
|
4
4
|
|
|
5
|
-
const CCC_CONTEXT = createContext<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const CCC_CONTEXT = createContext<
|
|
6
|
+
| {
|
|
7
|
+
open: () => unknown;
|
|
8
|
+
disconnect: () => unknown;
|
|
9
|
+
setClient: (client: ccc.Client) => unknown;
|
|
10
|
+
client: ccc.Client;
|
|
11
|
+
wallet?: ccc.Wallet;
|
|
12
|
+
signerInfo?: ccc.SignerInfo;
|
|
13
|
+
}
|
|
14
|
+
| undefined
|
|
15
|
+
>(undefined);
|
|
16
16
|
|
|
17
17
|
export function Provider({
|
|
18
18
|
children,
|
|
@@ -21,49 +21,38 @@ export function Provider({
|
|
|
21
21
|
children: React.ReactNode;
|
|
22
22
|
connectorProps?: React.HTMLAttributes<{}>;
|
|
23
23
|
}) {
|
|
24
|
-
const [
|
|
25
|
-
const [
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
ccc.
|
|
24
|
+
const [ref, setRef] = useState<WebComponentConnector | null>(null);
|
|
25
|
+
const [_, setFlag] = useState(0);
|
|
26
|
+
|
|
27
|
+
const client = useMemo(
|
|
28
|
+
() => ref?.client ?? new ccc.ClientPublicTestnet(),
|
|
29
|
+
[ref?.client],
|
|
30
|
+
);
|
|
31
|
+
const open = useCallback(() => ref?.setIsOpen(true), [ref, ref?.setIsOpen]);
|
|
32
|
+
const disconnect = useMemo(
|
|
33
|
+
() => ref?.disconnect.bind(ref) ?? (() => {}),
|
|
34
|
+
[ref, ref?.disconnect],
|
|
35
|
+
);
|
|
36
|
+
const setClient = useMemo(
|
|
37
|
+
() => ref?.setClient.bind(ref) ?? (() => {}),
|
|
38
|
+
[ref, ref?.setClient],
|
|
29
39
|
);
|
|
30
40
|
|
|
31
41
|
return (
|
|
32
42
|
<CCC_CONTEXT.Provider
|
|
33
43
|
value={{
|
|
34
|
-
open
|
|
35
|
-
disconnect
|
|
36
|
-
|
|
37
|
-
setSignerInfo(undefined);
|
|
38
|
-
setStatus(ccc.ConnectorStatus.SelectingSigner);
|
|
39
|
-
},
|
|
44
|
+
open,
|
|
45
|
+
disconnect,
|
|
46
|
+
setClient,
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
].includes(status)
|
|
45
|
-
? {
|
|
46
|
-
wallet: undefined,
|
|
47
|
-
signerInfo: undefined,
|
|
48
|
-
}
|
|
49
|
-
: {
|
|
50
|
-
wallet,
|
|
51
|
-
signerInfo,
|
|
52
|
-
}),
|
|
53
|
-
status,
|
|
48
|
+
client,
|
|
49
|
+
wallet: ref?.wallet,
|
|
50
|
+
signerInfo: ref?.signer,
|
|
54
51
|
}}
|
|
55
52
|
>
|
|
56
53
|
<Connector
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
signer={signerInfo}
|
|
60
|
-
status={status}
|
|
61
|
-
onClose={() => setIsOpen(false)}
|
|
62
|
-
onSignerChanged={({ wallet, signerInfo }) => {
|
|
63
|
-
setWallet(wallet);
|
|
64
|
-
setSignerInfo(signerInfo);
|
|
65
|
-
}}
|
|
66
|
-
onStatusChanged={({ status }) => setStatus(status)}
|
|
54
|
+
ref={setRef}
|
|
55
|
+
onWillUpdate={() => setFlag((f) => f + 1)}
|
|
67
56
|
{...{
|
|
68
57
|
...connectorProps,
|
|
69
58
|
style: {
|
|
@@ -78,5 +67,11 @@ export function Provider({
|
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
export function useCcc() {
|
|
81
|
-
|
|
70
|
+
const context = React.useContext(CCC_CONTEXT);
|
|
71
|
+
if (!context) {
|
|
72
|
+
throw Error(
|
|
73
|
+
"The component which invokes the useCcc hook should be placed in a ccc.Provider.",
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return context;
|
|
82
77
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"jsx": "react",
|
|
5
|
+
"incremental": true,
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"importHelpers": false,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"useDefineForClassFields": false,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noImplicitAny": true,
|
|
15
|
+
"strictBindCallApply": true,
|
|
16
|
+
"strictNullChecks": true,
|
|
17
|
+
"alwaysStrict": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true,
|
|
19
|
+
"forceConsistentCasingInFileNames": true
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/**/*"]
|
|
22
|
+
}
|