@ckb-ccc/connector-react 0.0.4-alpha.8 → 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.
@@ -1,8 +1,6 @@
1
1
  import { ccc } from "@ckb-ccc/connector";
2
- import { type EventName } from "@lit/react";
2
+ import { EventName } from "@lit/react";
3
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>;
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,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAG7D,eAAO,MAAM,SAAS;;;;EASpB,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,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAGxD,eAAO,MAAM,SAAS;;EAOpB,CAAC"}
@@ -7,8 +7,6 @@ export const Connector = createComponent({
7
7
  elementClass: ccc.WebComponentConnector,
8
8
  react: React,
9
9
  events: {
10
- onSignerChanged: "signerChanged",
11
- onStatusChanged: "statusChanged",
12
- onClose: "close",
10
+ onWillUpdate: "willUpdate",
13
11
  },
14
12
  });
@@ -1,14 +1,15 @@
1
1
  import { ccc } from "@ckb-ccc/connector";
2
- import * as React from "react";
3
- import { ReactNode } from "react";
4
- export declare function Provider({ children }: {
5
- children: ReactNode;
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
- 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,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
+ {"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"}
@@ -1,44 +1,33 @@
1
1
  import { ccc } from "@ckb-ccc/connector";
2
- import * as React from "react";
3
- import { createContext, useState } from "react";
2
+ import React, { createContext, useCallback, useMemo, useState } from "react";
4
3
  import { Connector } from "../components";
5
- const CCC_CONTEXT = createContext({
6
- open: () => { },
7
- disconnect: () => { },
8
- status: ccc.ConnectorStatus.SelectingSigner,
9
- });
10
- export function Provider({ children }) {
11
- const [isOpen, setIsOpen] = useState(false);
12
- const [wallet, setWallet] = useState();
13
- const [signerInfo, setSignerInfo] = useState();
14
- const [status, setStatus] = useState(ccc.ConnectorStatus.SelectingSigner);
4
+ const CCC_CONTEXT = createContext(undefined);
5
+ export function Provider({ children, connectorProps, }) {
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]);
15
12
  return (React.createElement(CCC_CONTEXT.Provider, { value: {
16
- open: () => setIsOpen(true),
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,
13
+ open,
14
+ disconnect,
15
+ setClient,
16
+ client,
17
+ wallet: ref?.wallet,
18
+ signerInfo: ref?.signer,
35
19
  } },
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) }),
20
+ React.createElement(Connector, { ref: setRef, onWillUpdate: () => setFlag((f) => f + 1), ...connectorProps,
21
+ style: {
22
+ ...connectorProps?.style,
23
+ zIndex: connectorProps?.style?.zIndex ?? 999,
24
+ } }),
40
25
  children));
41
26
  }
42
27
  export function useCcc() {
43
- return React.useContext(CCC_CONTEXT);
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;
44
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/connector-react",
3
- "version": "0.0.4-alpha.8",
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-alpha.8",
41
+ "@ckb-ccc/connector": "0.0.4",
42
42
  "@lit/react": "^1.0.5",
43
43
  "react": "^18"
44
44
  },
45
- "gitHead": "98556e415832a41aeedb467e8a72b8861fe6a32d"
45
+ "gitHead": "76485b6b76ce3c97d5acebd42decbafd546aa433"
46
46
  }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { ccc } from "@ckb-ccc/connector";
4
- import { createComponent, type EventName } from "@lit/react";
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
- onSignerChanged: "signerChanged" as EventName<ccc.SignerChangedEvent>,
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
  });
@@ -1,64 +1,65 @@
1
- import { ccc } from "@ckb-ccc/connector";
2
- import * as React from "react";
3
- import { ReactNode, createContext, useState } from "react";
1
+ import { WebComponentConnector, ccc } from "@ckb-ccc/connector";
2
+ import React, { createContext, useCallback, useMemo, useState } from "react";
4
3
  import { Connector } from "../components";
5
4
 
6
- const CCC_CONTEXT = createContext<{
7
- open: () => unknown;
8
- disconnect: () => unknown;
9
- wallet?: ccc.Wallet;
10
- signerInfo?: ccc.SignerInfo;
11
- status: ccc.ConnectorStatus;
12
- }>({
13
- open: () => {},
14
- disconnect: () => {},
15
- status: ccc.ConnectorStatus.SelectingSigner,
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
+ }
14
+ | undefined
15
+ >(undefined);
17
16
 
18
- export function Provider({ children }: { children: ReactNode }) {
19
- const [isOpen, setIsOpen] = useState(false);
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,
17
+ export function Provider({
18
+ children,
19
+ connectorProps,
20
+ }: {
21
+ children: React.ReactNode;
22
+ connectorProps?: React.HTMLAttributes<{}>;
23
+ }) {
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],
24
39
  );
25
40
 
26
41
  return (
27
42
  <CCC_CONTEXT.Provider
28
43
  value={{
29
- open: () => setIsOpen(true),
30
- disconnect: () => {
31
- setWallet(undefined);
32
- setSignerInfo(undefined);
33
- setStatus(ccc.ConnectorStatus.SelectingSigner);
34
- },
44
+ open,
45
+ disconnect,
46
+ setClient,
35
47
 
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,
48
+ client,
49
+ wallet: ref?.wallet,
50
+ signerInfo: ref?.signer,
49
51
  }}
50
52
  >
51
53
  <Connector
52
- isOpen={isOpen}
53
- wallet={wallet}
54
- signer={signerInfo}
55
- status={status}
56
- onClose={() => setIsOpen(false)}
57
- onSignerChanged={({ wallet, signerInfo }) => {
58
- setWallet(wallet);
59
- setSignerInfo(signerInfo);
54
+ ref={setRef}
55
+ onWillUpdate={() => setFlag((f) => f + 1)}
56
+ {...{
57
+ ...connectorProps,
58
+ style: {
59
+ ...connectorProps?.style,
60
+ zIndex: connectorProps?.style?.zIndex ?? 999,
61
+ },
60
62
  }}
61
- onStatusChanged={({ status }) => setStatus(status)}
62
63
  />
63
64
  {children}
64
65
  </CCC_CONTEXT.Provider>
@@ -66,5 +67,11 @@ export function Provider({ children }: { children: ReactNode }) {
66
67
  }
67
68
 
68
69
  export function useCcc() {
69
- return React.useContext(CCC_CONTEXT);
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;
70
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
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "./dist.commonjs"
7
+ }
8
+ }