@ckb-ccc/connector-react 0.0.4-alpha.0 → 0.0.4-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/README.md +37 -0
- package/dist/hooks/useCcc.d.ts +6 -4
- package/dist/hooks/useCcc.d.ts.map +1 -1
- package/dist/hooks/useCcc.js +17 -11
- package/package.json +5 -5
- package/src/hooks/useCcc.tsx +40 -15
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<h1 align="center" style="font-size: 48px;">
|
|
2
|
+
CCC Connector for React
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@ckb-ccc/connector-react"><img
|
|
7
|
+
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fconnector-react"
|
|
8
|
+
/></a>
|
|
9
|
+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
|
|
10
|
+
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
|
|
11
|
+
<img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production" />
|
|
12
|
+
<a href="https://ckbccc-demo.vercel.app/"><img
|
|
13
|
+
alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fckbccc-demo.vercel.app%2F&label=Demo"
|
|
14
|
+
/></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
"Common Chains Connector" is where CCC begins.
|
|
19
|
+
<br />
|
|
20
|
+
CCC helps you to interoperate wallets from different chain ecosystems with CKB,
|
|
21
|
+
<br />
|
|
22
|
+
fully enabling CKB's cryptographic freedom power.
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
## Preview
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<a href="https://ckbccc-demo.vercel.app/">
|
|
29
|
+
<img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="30%" />
|
|
30
|
+
</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
|
|
34
|
+
|
|
35
|
+
<h3 align="center">
|
|
36
|
+
Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
|
|
37
|
+
</h3>
|
package/dist/hooks/useCcc.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/connector";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare function Provider({ children, connectorProps, }: {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
connectorProps?: React.HTMLAttributes<{}>;
|
|
6
6
|
}): React.JSX.Element;
|
|
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
14
|
status: ccc.ConnectorStatus;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,KAAkC,MAAM,OAAO,CAAC;AAgBvD,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,qBA6DA;AAED,wBAAgB,MAAM;;;;;;;;EAQrB"}
|
package/dist/hooks/useCcc.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/connector";
|
|
2
|
-
import
|
|
3
|
-
import { createContext, useState } from "react";
|
|
2
|
+
import React, { createContext, useState } from "react";
|
|
4
3
|
import { Connector } from "../components";
|
|
5
|
-
const CCC_CONTEXT = createContext(
|
|
6
|
-
|
|
7
|
-
disconnect: () => { },
|
|
8
|
-
status: ccc.ConnectorStatus.SelectingSigner,
|
|
9
|
-
});
|
|
10
|
-
export function Provider({ children }) {
|
|
4
|
+
const CCC_CONTEXT = createContext(undefined);
|
|
5
|
+
export function Provider({ children, connectorProps, }) {
|
|
11
6
|
const [isOpen, setIsOpen] = useState(false);
|
|
7
|
+
const [client, setClient] = useState(() => new ccc.ClientPublicTestnet());
|
|
12
8
|
const [wallet, setWallet] = useState();
|
|
13
9
|
const [signerInfo, setSignerInfo] = useState();
|
|
14
10
|
const [status, setStatus] = useState(ccc.ConnectorStatus.SelectingSigner);
|
|
@@ -19,6 +15,8 @@ export function Provider({ children }) {
|
|
|
19
15
|
setSignerInfo(undefined);
|
|
20
16
|
setStatus(ccc.ConnectorStatus.SelectingSigner);
|
|
21
17
|
},
|
|
18
|
+
setClient,
|
|
19
|
+
client,
|
|
22
20
|
...([
|
|
23
21
|
ccc.ConnectorStatus.SelectingSigner,
|
|
24
22
|
ccc.ConnectorStatus.Connecting,
|
|
@@ -33,12 +31,20 @@ export function Provider({ children }) {
|
|
|
33
31
|
}),
|
|
34
32
|
status,
|
|
35
33
|
} },
|
|
36
|
-
React.createElement(Connector, { isOpen: isOpen, wallet: wallet, signer: signerInfo, status: status, onClose: () => setIsOpen(false), onSignerChanged: ({ wallet, signerInfo }) => {
|
|
34
|
+
React.createElement(Connector, { isOpen: isOpen, client: client, wallet: wallet, signer: signerInfo, status: status, onClose: () => setIsOpen(false), onSignerChanged: ({ wallet, signerInfo }) => {
|
|
37
35
|
setWallet(wallet);
|
|
38
36
|
setSignerInfo(signerInfo);
|
|
39
|
-
}, onStatusChanged: ({ status }) => setStatus(status)
|
|
37
|
+
}, onStatusChanged: ({ status }) => setStatus(status), ...connectorProps,
|
|
38
|
+
style: {
|
|
39
|
+
...connectorProps?.style,
|
|
40
|
+
zIndex: connectorProps?.style?.zIndex ?? 999,
|
|
41
|
+
} }),
|
|
40
42
|
children));
|
|
41
43
|
}
|
|
42
44
|
export function useCcc() {
|
|
43
|
-
|
|
45
|
+
const context = React.useContext(CCC_CONTEXT);
|
|
46
|
+
if (!context) {
|
|
47
|
+
throw Error("The component which invokes the useCcc hook should be placed in a ccc.Provider.");
|
|
48
|
+
}
|
|
49
|
+
return context;
|
|
44
50
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/connector-react",
|
|
3
|
-
"version": "0.0.4-alpha.
|
|
3
|
+
"version": "0.0.4-alpha.10",
|
|
4
4
|
"description": "Common Chains Connector UI Component for React",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
8
|
-
"homepage": "https://github.com/
|
|
8
|
+
"homepage": "https://github.com/ckb-ecofund/ccc",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git://github.com/
|
|
11
|
+
"url": "git://github.com/ckb-ecofund/ccc.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"exports": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@ckb-ccc/connector": "0.0.4-alpha.
|
|
41
|
+
"@ckb-ccc/connector": "0.0.4-alpha.10",
|
|
42
42
|
"@lit/react": "^1.0.5",
|
|
43
43
|
"react": "^18"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "dec13b260f57a1b244c69af5566e316a4c329e35"
|
|
46
46
|
}
|
package/src/hooks/useCcc.tsx
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/connector";
|
|
2
|
-
import
|
|
3
|
-
import { ReactNode, createContext, useState } from "react";
|
|
2
|
+
import React, { createContext, useState } from "react";
|
|
4
3
|
import { Connector } from "../components";
|
|
5
4
|
|
|
6
|
-
const CCC_CONTEXT = createContext<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
status: ccc.ConnectorStatus;
|
|
14
|
+
}
|
|
15
|
+
| undefined
|
|
16
|
+
>(undefined);
|
|
17
17
|
|
|
18
|
-
export function Provider({
|
|
18
|
+
export function Provider({
|
|
19
|
+
children,
|
|
20
|
+
connectorProps,
|
|
21
|
+
}: {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
connectorProps?: React.HTMLAttributes<{}>;
|
|
24
|
+
}) {
|
|
19
25
|
const [isOpen, setIsOpen] = useState(false);
|
|
26
|
+
const [client, setClient] = useState<ccc.Client>(
|
|
27
|
+
() => new ccc.ClientPublicTestnet(),
|
|
28
|
+
);
|
|
20
29
|
const [wallet, setWallet] = useState<ccc.Wallet | undefined>();
|
|
21
30
|
const [signerInfo, setSignerInfo] = useState<ccc.SignerInfo | undefined>();
|
|
22
31
|
const [status, setStatus] = useState<ccc.ConnectorStatus>(
|
|
@@ -32,7 +41,9 @@ export function Provider({ children }: { children: ReactNode }) {
|
|
|
32
41
|
setSignerInfo(undefined);
|
|
33
42
|
setStatus(ccc.ConnectorStatus.SelectingSigner);
|
|
34
43
|
},
|
|
44
|
+
setClient,
|
|
35
45
|
|
|
46
|
+
client,
|
|
36
47
|
...([
|
|
37
48
|
ccc.ConnectorStatus.SelectingSigner,
|
|
38
49
|
ccc.ConnectorStatus.Connecting,
|
|
@@ -50,6 +61,7 @@ export function Provider({ children }: { children: ReactNode }) {
|
|
|
50
61
|
>
|
|
51
62
|
<Connector
|
|
52
63
|
isOpen={isOpen}
|
|
64
|
+
client={client}
|
|
53
65
|
wallet={wallet}
|
|
54
66
|
signer={signerInfo}
|
|
55
67
|
status={status}
|
|
@@ -59,6 +71,13 @@ export function Provider({ children }: { children: ReactNode }) {
|
|
|
59
71
|
setSignerInfo(signerInfo);
|
|
60
72
|
}}
|
|
61
73
|
onStatusChanged={({ status }) => setStatus(status)}
|
|
74
|
+
{...{
|
|
75
|
+
...connectorProps,
|
|
76
|
+
style: {
|
|
77
|
+
...connectorProps?.style,
|
|
78
|
+
zIndex: connectorProps?.style?.zIndex ?? 999,
|
|
79
|
+
},
|
|
80
|
+
}}
|
|
62
81
|
/>
|
|
63
82
|
{children}
|
|
64
83
|
</CCC_CONTEXT.Provider>
|
|
@@ -66,5 +85,11 @@ export function Provider({ children }: { children: ReactNode }) {
|
|
|
66
85
|
}
|
|
67
86
|
|
|
68
87
|
export function useCcc() {
|
|
69
|
-
|
|
88
|
+
const context = React.useContext(CCC_CONTEXT);
|
|
89
|
+
if (!context) {
|
|
90
|
+
throw Error(
|
|
91
|
+
"The component which invokes the useCcc hook should be placed in a ccc.Provider.",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return context;
|
|
70
95
|
}
|