@ckb-ccc/connector-react 0.0.5-alpha.0 → 0.0.5-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.
@@ -2,5 +2,6 @@ import { ccc } from "@ckb-ccc/connector";
2
2
  import { EventName } from "@lit/react";
3
3
  export declare const Connector: import("@lit/react").ReactWebComponent<ccc.WebComponentConnector, {
4
4
  onWillUpdate: EventName<ccc.WillUpdateEvent>;
5
+ onClosed: EventName<ccc.ClosedEvent>;
5
6
  }>;
6
7
  //# 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,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAGxD,eAAO,MAAM,SAAS;;EAOpB,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;;;EAQpB,CAAC"}
@@ -8,5 +8,6 @@ export const Connector = createComponent({
8
8
  react: React,
9
9
  events: {
10
10
  onWillUpdate: "willUpdate",
11
+ onClosed: "closed",
11
12
  },
12
13
  });
@@ -1,8 +1,12 @@
1
1
  import { ccc } from "@ckb-ccc/connector";
2
2
  import React from "react";
3
- export declare function Provider({ children, connectorProps, }: {
3
+ export declare function Provider({ children, connectorProps, name, icon, signerFilter, client: clientArg, }: {
4
4
  children: React.ReactNode;
5
5
  connectorProps?: React.HTMLAttributes<{}>;
6
+ name?: string;
7
+ icon?: string;
8
+ signerFilter?: (signerInfo: ccc.SignerInfo, wallet: ccc.Wallet) => Promise<boolean>;
9
+ client?: ccc.Client;
6
10
  }): React.JSX.Element;
7
11
  export declare function useCcc(): {
8
12
  open: () => unknown;
@@ -1 +1 @@
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
+ {"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,EACd,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,MAAM,EAAE,SAAS,GAClB,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,CACb,UAAU,EAAE,GAAG,CAAC,UAAU,EAC1B,MAAM,EAAE,GAAG,CAAC,MAAM,KACf,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;CACrB,qBAgEA;AAED,wBAAgB,MAAM;;;;;;;EAQrB"}
@@ -2,11 +2,15 @@ import { ccc } from "@ckb-ccc/connector";
2
2
  import React, { createContext, useCallback, useMemo, useState } from "react";
3
3
  import { Connector } from "../components";
4
4
  const CCC_CONTEXT = createContext(undefined);
5
- export function Provider({ children, connectorProps, }) {
5
+ export function Provider({ children, connectorProps, name, icon, signerFilter, client: clientArg, }) {
6
6
  const [ref, setRef] = useState(null);
7
+ const [isOpen, setIsOpen] = useState(false);
7
8
  const [_, setFlag] = useState(0);
8
9
  const client = useMemo(() => ref?.client ?? new ccc.ClientPublicTestnet(), [ref?.client]);
9
- const open = useCallback(() => ref?.setIsOpen(true), [ref, ref?.setIsOpen]);
10
+ const open = useCallback(() => {
11
+ setIsOpen(true);
12
+ ref?.requestUpdate();
13
+ }, [setIsOpen, ref, ref?.requestUpdate]);
10
14
  const disconnect = useMemo(() => ref?.disconnect.bind(ref) ?? (() => { }), [ref, ref?.disconnect]);
11
15
  const setClient = useMemo(() => ref?.setClient.bind(ref) ?? (() => { }), [ref, ref?.setClient]);
12
16
  return (React.createElement(CCC_CONTEXT.Provider, { value: {
@@ -17,11 +21,23 @@ export function Provider({ children, connectorProps, }) {
17
21
  wallet: ref?.wallet,
18
22
  signerInfo: ref?.signer,
19
23
  } },
20
- React.createElement(Connector, { ref: setRef, onWillUpdate: () => setFlag((f) => f + 1), ...connectorProps,
24
+ React.createElement(Connector, { name: name, icon: icon, signerFilter: signerFilter, ref: setRef, onWillUpdate: () => setFlag((f) => f + 1), onClosed: () => setIsOpen(false), ...connectorProps,
21
25
  style: {
22
26
  ...connectorProps?.style,
23
27
  zIndex: connectorProps?.style?.zIndex ?? 999,
24
- } }),
28
+ ...(isOpen ? {} : { display: "none" }),
29
+ ...{
30
+ "--background": "#fff",
31
+ "--divider": "#eee",
32
+ "--btn-primary": "#f8f8f8",
33
+ "--btn-primary-hover": "#efeeee",
34
+ "--btn-secondary": "#ddd",
35
+ "--btn-secondary-hover": "#ccc",
36
+ color: "#1e1e1e",
37
+ "--tip-color": "#666",
38
+ },
39
+ },
40
+ ...(clientArg ? { client: clientArg } : {}) }),
25
41
  children));
26
42
  }
27
43
  export function useCcc() {
@@ -1,2 +1,3 @@
1
- export declare function useSigner(): import("@ckb-ccc/core").Signer | undefined;
1
+ import { ccc } from "..";
2
+ export declare function useSigner(): ccc.Signer | undefined;
2
3
  //# sourceMappingURL=useSigner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useSigner.tsx"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,+CAExB"}
1
+ {"version":3,"file":"useSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useSigner.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AAGzB,wBAAgB,SAAS,IAAI,GAAG,CAAC,MAAM,GAAG,SAAS,CAElD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/connector-react",
3
- "version": "0.0.5-alpha.0",
3
+ "version": "0.0.5-alpha.10",
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.5-alpha.0",
41
+ "@ckb-ccc/connector": "0.0.5-alpha.10",
42
42
  "@lit/react": "^1.0.5",
43
43
  "react": "^18"
44
44
  },
45
- "gitHead": "8a927f901a8f2fe7dfe2f6bf78a44689d6503949"
45
+ "gitHead": "91ea3a92b02117905449ce4d2afef88bd3ffcc60"
46
46
  }
@@ -10,5 +10,6 @@ export const Connector = createComponent({
10
10
  react: React,
11
11
  events: {
12
12
  onWillUpdate: "willUpdate" as EventName<ccc.WillUpdateEvent>,
13
+ onClosed: "closed" as EventName<ccc.ClosedEvent>,
13
14
  },
14
15
  });
@@ -17,18 +17,33 @@ const CCC_CONTEXT = createContext<
17
17
  export function Provider({
18
18
  children,
19
19
  connectorProps,
20
+ name,
21
+ icon,
22
+ signerFilter,
23
+ client: clientArg,
20
24
  }: {
21
25
  children: React.ReactNode;
22
26
  connectorProps?: React.HTMLAttributes<{}>;
27
+ name?: string;
28
+ icon?: string;
29
+ signerFilter?: (
30
+ signerInfo: ccc.SignerInfo,
31
+ wallet: ccc.Wallet,
32
+ ) => Promise<boolean>;
33
+ client?: ccc.Client;
23
34
  }) {
24
35
  const [ref, setRef] = useState<WebComponentConnector | null>(null);
36
+ const [isOpen, setIsOpen] = useState(false);
25
37
  const [_, setFlag] = useState(0);
26
38
 
27
39
  const client = useMemo(
28
40
  () => ref?.client ?? new ccc.ClientPublicTestnet(),
29
41
  [ref?.client],
30
42
  );
31
- const open = useCallback(() => ref?.setIsOpen(true), [ref, ref?.setIsOpen]);
43
+ const open = useCallback(() => {
44
+ setIsOpen(true);
45
+ ref?.requestUpdate();
46
+ }, [setIsOpen, ref, ref?.requestUpdate]);
32
47
  const disconnect = useMemo(
33
48
  () => ref?.disconnect.bind(ref) ?? (() => {}),
34
49
  [ref, ref?.disconnect],
@@ -51,14 +66,30 @@ export function Provider({
51
66
  }}
52
67
  >
53
68
  <Connector
69
+ name={name}
70
+ icon={icon}
71
+ signerFilter={signerFilter}
54
72
  ref={setRef}
55
73
  onWillUpdate={() => setFlag((f) => f + 1)}
74
+ onClosed={() => setIsOpen(false)}
56
75
  {...{
57
76
  ...connectorProps,
58
77
  style: {
59
78
  ...connectorProps?.style,
60
79
  zIndex: connectorProps?.style?.zIndex ?? 999,
80
+ ...(isOpen ? {} : { display: "none" }),
81
+ ...({
82
+ "--background": "#fff",
83
+ "--divider": "#eee",
84
+ "--btn-primary": "#f8f8f8",
85
+ "--btn-primary-hover": "#efeeee",
86
+ "--btn-secondary": "#ddd",
87
+ "--btn-secondary-hover": "#ccc",
88
+ color: "#1e1e1e",
89
+ "--tip-color": "#666",
90
+ } as React.CSSProperties),
61
91
  },
92
+ ...(clientArg ? { client: clientArg } : {}),
62
93
  }}
63
94
  />
64
95
  {children}
@@ -1,5 +1,6 @@
1
+ import { ccc } from "..";
1
2
  import { useCcc } from "./useCcc";
2
3
 
3
- export function useSigner() {
4
+ export function useSigner(): ccc.Signer | undefined {
4
5
  return useCcc().signerInfo?.signer;
5
6
  }