@ckb-ccc/connector-react 0.0.3 → 0.0.4-alpha.1

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 ADDED
@@ -0,0 +1,32 @@
1
+ <h1 align="center" style="font-size: 64px;">
2
+ CCC
3
+ </h1>
4
+
5
+ <p align="center">
6
+ <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc">
7
+ <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master">
8
+ <img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production">
9
+ <img alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fckbccc-demo.vercel.app%2F&label=Demo">
10
+ </p>
11
+
12
+ <p align="center">
13
+ "Common Chains Connector" is where CCC begins.
14
+ <br />
15
+ CCC helps you to interoperate wallets from different chain ecosystems with CKB,
16
+ <br />
17
+ fully enabling CKB's cryptographic freedom power.
18
+ </p>
19
+
20
+ ## Preview
21
+
22
+ <p align="center">
23
+ <a href="https://ckbccc-demo.vercel.app/">
24
+ <img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="30%" />
25
+ </a>
26
+ </p>
27
+
28
+ 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/).
29
+
30
+ <h3 align="center">
31
+ Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
32
+ </h3>
@@ -1,7 +1,8 @@
1
- import { CloseEvent, ConnectedEvent, WebComponentConnector } from "@ckb-ccc/connector";
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
- onConnected: EventName<ConnectedEvent>;
5
- onClose: EventName<CloseEvent>;
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,EACL,UAAU,EACV,cAAc,EACd,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAG7D,eAAO,MAAM,SAAS;;;EAQpB,CAAC"}
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"}
@@ -1,13 +1,14 @@
1
1
  "use client";
2
- import { WebComponentConnector, } from "@ckb-ccc/connector";
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
- onConnected: "connected",
10
+ onSignerChanged: "signerChanged",
11
+ onStatusChanged: "statusChanged",
11
12
  onClose: "close",
12
13
  },
13
14
  });
@@ -1,4 +1,4 @@
1
- import { SignerInfo } from "@ckb-ccc/connector";
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
- signerInfo?: SignerInfo | undefined;
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,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAA2B,MAAM,OAAO,CAAC;AAS3D,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,qBAoB7D;AAED,wBAAgB,MAAM;;;;EAErB"}
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"}
@@ -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({ open: () => { }, disconnect: () => { } });
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: () => setSignerInfo(undefined),
11
- signerInfo,
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), onConnected: ({ signerInfo }) => setSignerInfo(signerInfo) }),
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,14 +1,14 @@
1
1
  {
2
2
  "name": "@ckb-ccc/connector-react",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-alpha.1",
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/Hanssen0/ccc",
8
+ "homepage": "https://github.com/ckb-ecofund/ccc",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git://github.com/Hanssen0/ccc.git"
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.3",
41
+ "@ckb-ccc/connector": "0.0.4-alpha.1",
42
42
  "@lit/react": "^1.0.5",
43
43
  "react": "^18"
44
44
  },
45
- "gitHead": "9df1bbe0007136568914d8a73fe39f898d636a12"
45
+ "gitHead": "7dab1a1d6e3e380b26f43d0d0308bd4da1617029"
46
46
  }
@@ -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
- onConnected: "connected" as EventName<ConnectedEvent>,
17
- onClose: "close" as EventName<CloseEvent>,
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
  });
@@ -1,4 +1,4 @@
1
- import { SignerInfo } from "@ckb-ccc/connector";
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
- signerInfo?: SignerInfo;
10
- }>({ open: () => {}, disconnect: () => {} });
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 [signerInfo, setSignerInfo] = useState<SignerInfo | undefined>();
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: () => setSignerInfo(undefined),
21
- signerInfo,
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
- onConnected={({ signerInfo }) => setSignerInfo(signerInfo)}
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>