@kheopskit/react 0.0.1-alpha.1 → 0.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @kheopskit/react
2
2
 
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e1cebed`](https://github.com/kheopskit/kheopskit/commit/e1cebed92d303f041070e0ae146ee34d9eb717bd) Thanks [@0xKheops](https://github.com/0xKheops)! - refactor property names
8
+
9
+ - [`e1cebed`](https://github.com/kheopskit/kheopskit/commit/e1cebed92d303f041070e0ae146ee34d9eb717bd) Thanks [@0xKheops](https://github.com/0xKheops)! - initial alpha release
10
+
11
+ - Updated dependencies [[`e1cebed`](https://github.com/kheopskit/kheopskit/commit/e1cebed92d303f041070e0ae146ee34d9eb717bd), [`e1cebed`](https://github.com/kheopskit/kheopskit/commit/e1cebed92d303f041070e0ae146ee34d9eb717bd)]:
12
+ - @kheopskit/core@0.0.1
13
+
3
14
  ## 0.0.1-alpha.1
4
15
 
5
16
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,21 +1,11 @@
1
- import { FC, PropsWithChildren } from 'react';
2
1
  import * as _kheopskit_core from '@kheopskit/core';
3
2
  import { KheopskitConfig } from '@kheopskit/core';
3
+ import { FC, PropsWithChildren } from 'react';
4
4
 
5
- declare const SuspenseMonitorInner: FC<{
6
- label: string;
7
- }>;
8
- declare const SuspenseMonitor: FC<{
9
- label: string;
10
- }>;
11
-
12
- declare const useWallets: () => {
13
- wallets: _kheopskit_core.Wallet[];
14
- accounts: _kheopskit_core.WalletAccount[];
15
- };
5
+ declare const useWallets: () => _kheopskit_core.KheopskitState;
16
6
 
17
7
  declare const KheopskitProvider: FC<PropsWithChildren & {
18
- config: KheopskitConfig;
8
+ config?: Partial<KheopskitConfig>;
19
9
  }>;
20
10
 
21
- export { KheopskitProvider, SuspenseMonitor, SuspenseMonitorInner, useWallets };
11
+ export { KheopskitProvider, useWallets };
package/dist/index.d.ts CHANGED
@@ -1,21 +1,11 @@
1
- import { FC, PropsWithChildren } from 'react';
2
1
  import * as _kheopskit_core from '@kheopskit/core';
3
2
  import { KheopskitConfig } from '@kheopskit/core';
3
+ import { FC, PropsWithChildren } from 'react';
4
4
 
5
- declare const SuspenseMonitorInner: FC<{
6
- label: string;
7
- }>;
8
- declare const SuspenseMonitor: FC<{
9
- label: string;
10
- }>;
11
-
12
- declare const useWallets: () => {
13
- wallets: _kheopskit_core.Wallet[];
14
- accounts: _kheopskit_core.WalletAccount[];
15
- };
5
+ declare const useWallets: () => _kheopskit_core.KheopskitState;
16
6
 
17
7
  declare const KheopskitProvider: FC<PropsWithChildren & {
18
- config: KheopskitConfig;
8
+ config?: Partial<KheopskitConfig>;
19
9
  }>;
20
10
 
21
- export { KheopskitProvider, SuspenseMonitor, SuspenseMonitorInner, useWallets };
11
+ export { KheopskitProvider, useWallets };
package/dist/index.js CHANGED
@@ -21,74 +21,75 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  KheopskitProvider: () => KheopskitProvider,
24
- SuspenseMonitor: () => SuspenseMonitor,
25
- SuspenseMonitorInner: () => SuspenseMonitorInner,
26
24
  useWallets: () => useWallets
27
25
  });
28
26
  module.exports = __toCommonJS(index_exports);
29
27
 
30
- // src/SuspenseMonitor.tsx
28
+ // src/useWallets.ts
29
+ var import_react2 = require("react");
30
+
31
+ // src/context.ts
31
32
  var import_react = require("react");
32
- var import_jsx_runtime = require("react/jsx-runtime");
33
- var SHOULD_LOG = true;
34
- var SuspenseMonitorInner = ({ label }) => {
35
- const refStart = (0, import_react.useRef)(performance.now());
36
- (0, import_react.useEffect)(() => {
37
- const timeout = setTimeout(() => {
38
- console.warn(`[Suspense] ${label} is hanging`);
39
- }, 500);
40
- return () => {
41
- console.debug(
42
- "[Suspense] %s : %s ms",
43
- label,
44
- (performance.now() - refStart.current).toFixed(2)
45
- );
46
- clearTimeout(timeout);
47
- };
48
- }, [label]);
49
- return null;
33
+ var KheopskitContext = (0, import_react.createContext)(null);
34
+
35
+ // src/useWallets.ts
36
+ var useWallets = () => {
37
+ const ctx = (0, import_react2.useContext)(KheopskitContext);
38
+ if (!ctx)
39
+ throw new Error("useWallets can't be used without a KheopskitProvider");
40
+ return ctx.state;
50
41
  };
51
- var SuspenseMonitor = ({ label }) => SHOULD_LOG ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SuspenseMonitorInner, { label }) : null;
52
42
 
53
- // src/useKheopskit.ts
43
+ // src/KheopskitProvider.tsx
54
44
  var import_core = require("@kheopskit/core");
55
- var import_core2 = require("@react-rxjs/core");
56
45
  var import_react3 = require("react");
57
46
 
58
- // src/context.ts
59
- var import_react2 = require("react");
60
- var KheopskitContext = (0, import_react2.createContext)(null);
61
-
62
- // src/useKheopskit.ts
63
- var DEFAULT_VALUE = {
64
- wallets: [],
65
- accounts: []
66
- };
67
- var [useKheopskit] = (0, import_core2.bind)(
68
- (config) => (0, import_core.getKheopskit$)(config),
69
- DEFAULT_VALUE
70
- );
71
- var useWallets = () => {
72
- const ctx = (0, import_react3.useContext)(KheopskitContext);
73
- if (!ctx)
74
- throw new Error("useWallets must be used within a KheopskitProvider");
75
- return useKheopskit(ctx.config);
47
+ // src/createStore.ts
48
+ var import_rxjs = require("rxjs");
49
+ var createStore = (observable$, initialValue) => {
50
+ const subject = new import_rxjs.BehaviorSubject(initialValue);
51
+ const sub = observable$.subscribe((value) => {
52
+ subject.next(value);
53
+ });
54
+ const getSnapshot = () => subject.getValue();
55
+ const subscribe = (callback) => {
56
+ const sub2 = subject.subscribe(callback);
57
+ return () => {
58
+ sub2.unsubscribe();
59
+ };
60
+ };
61
+ const destroy = () => {
62
+ sub.unsubscribe();
63
+ };
64
+ return {
65
+ getSnapshot,
66
+ subscribe,
67
+ destroy
68
+ };
76
69
  };
77
70
 
78
71
  // src/KheopskitProvider.tsx
79
- var import_core3 = require("@react-rxjs/core");
80
- var import_jsx_runtime2 = require("react/jsx-runtime");
72
+ var import_jsx_runtime = require("react/jsx-runtime");
81
73
  var KheopskitProvider = ({ children, config }) => {
82
- return (
83
- // TODO set source
84
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(KheopskitContext.Provider, { value: { config }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core3.Subscribe, { fallback: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SuspenseMonitor, { label: "KheopskitProvider" }), children }) })
74
+ const defaultValue = (0, import_react3.useMemo)(
75
+ () => ({
76
+ wallets: [],
77
+ accounts: [],
78
+ config: (0, import_core.resolveConfig)(config)
79
+ }),
80
+ [config]
81
+ );
82
+ const store = (0, import_react3.useMemo)(
83
+ () => createStore((0, import_core.getKheopskit$)(config), defaultValue),
84
+ [config, defaultValue]
85
85
  );
86
+ const state = (0, import_react3.useSyncExternalStore)(store.subscribe, store.getSnapshot);
87
+ const value = (0, import_react3.useMemo)(() => ({ state }), [state]);
88
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KheopskitContext.Provider, { value, children });
86
89
  };
87
90
  // Annotate the CommonJS export names for ESM import in node:
88
91
  0 && (module.exports = {
89
92
  KheopskitProvider,
90
- SuspenseMonitor,
91
- SuspenseMonitorInner,
92
93
  useWallets
93
94
  });
94
95
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/SuspenseMonitor.tsx","../src/useKheopskit.ts","../src/context.ts","../src/KheopskitProvider.tsx"],"sourcesContent":["export * from \"./SuspenseMonitor\";\nexport * from \"./useKheopskit\";\nexport * from \"./KheopskitProvider\";\n","import { type FC, useEffect, useRef } from \"react\";\n\nconst SHOULD_LOG = true; // TODO only DEV\n\nexport const SuspenseMonitorInner: FC<{ label: string }> = ({ label }) => {\n const refStart = useRef(performance.now());\n\n useEffect(() => {\n const timeout = setTimeout(() => {\n console.warn(`[Suspense] ${label} is hanging`);\n }, 500);\n\n return () => {\n console.debug(\n \"[Suspense] %s : %s ms\",\n label,\n (performance.now() - refStart.current).toFixed(2)\n );\n clearTimeout(timeout);\n };\n }, [label]);\n\n return null;\n};\n\nexport const SuspenseMonitor: FC<{ label: string }> = ({ label }) =>\n SHOULD_LOG ? <SuspenseMonitorInner label={label} /> : null;\n","import { getKheopskit$, type KheopskitConfig } from \"@kheopskit/core\";\nimport { bind } from \"@react-rxjs/core\";\nimport { useContext } from \"react\";\nimport { KheopskitContext } from \"./context\";\n\nconst DEFAULT_VALUE = {\n wallets: [],\n accounts: [],\n};\n\nconst [useKheopskit] = bind(\n (config: KheopskitConfig) => getKheopskit$(config),\n DEFAULT_VALUE\n);\n\nexport const useWallets = () => {\n const ctx = useContext(KheopskitContext);\n if (!ctx)\n throw new Error(\"useWallets must be used within a KheopskitProvider\");\n\n return useKheopskit(ctx.config);\n};\n","import type { KheopskitConfig } from \"@kheopskit/core\";\nimport { createContext } from \"react\";\n\nexport const KheopskitContext = createContext<{\n config: KheopskitConfig;\n} | null>(null);\n","import type { KheopskitConfig } from \"@kheopskit/core\";\nimport { Subscribe } from \"@react-rxjs/core\";\nimport type { FC, PropsWithChildren } from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { SuspenseMonitor } from \"./SuspenseMonitor\";\n\nexport const KheopskitProvider: FC<\n PropsWithChildren & { config: KheopskitConfig }\n> = ({ children, config }) => {\n return (\n // TODO set source\n <KheopskitContext.Provider value={{ config }}>\n <Subscribe fallback={<SuspenseMonitor label=\"KheopskitProvider\" />}>\n {children}\n </Subscribe>\n </KheopskitContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA2C;AA0B5B;AAxBf,IAAM,aAAa;AAEZ,IAAM,uBAA8C,CAAC,EAAE,MAAM,MAAM;AACxE,QAAM,eAAW,qBAAO,YAAY,IAAI,CAAC;AAEzC,8BAAU,MAAM;AACd,UAAM,UAAU,WAAW,MAAM;AAC/B,cAAQ,KAAK,cAAc,KAAK,aAAa;AAAA,IAC/C,GAAG,GAAG;AAEN,WAAO,MAAM;AACX,cAAQ;AAAA,QACN;AAAA,QACA;AAAA,SACC,YAAY,IAAI,IAAI,SAAS,SAAS,QAAQ,CAAC;AAAA,MAClD;AACA,mBAAa,OAAO;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;AAEO,IAAM,kBAAyC,CAAC,EAAE,MAAM,MAC7D,aAAa,4CAAC,wBAAqB,OAAc,IAAK;;;AC1BxD,kBAAoD;AACpD,IAAAA,eAAqB;AACrB,IAAAC,gBAA2B;;;ACD3B,IAAAC,gBAA8B;AAEvB,IAAM,uBAAmB,6BAEtB,IAAI;;;ADAd,IAAM,gBAAgB;AAAA,EACpB,SAAS,CAAC;AAAA,EACV,UAAU,CAAC;AACb;AAEA,IAAM,CAAC,YAAY,QAAI;AAAA,EACrB,CAAC,eAA4B,2BAAc,MAAM;AAAA,EACjD;AACF;AAEO,IAAM,aAAa,MAAM;AAC9B,QAAM,UAAM,0BAAW,gBAAgB;AACvC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,oDAAoD;AAEtE,SAAO,aAAa,IAAI,MAAM;AAChC;;;AEpBA,IAAAC,eAA0B;AAWC,IAAAC,sBAAA;AANpB,IAAM,oBAET,CAAC,EAAE,UAAU,OAAO,MAAM;AAC5B;AAAA;AAAA,IAEE,6CAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,OAAO,GACzC,uDAAC,0BAAU,UAAU,6CAAC,mBAAgB,OAAM,qBAAoB,GAC7D,UACH,GACF;AAAA;AAEJ;","names":["import_core","import_react","import_react","import_core","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/useWallets.ts","../src/context.ts","../src/KheopskitProvider.tsx","../src/createStore.ts"],"sourcesContent":["export * from \"./useWallets\";\nexport * from \"./KheopskitProvider\";\n","import { useContext } from \"react\";\nimport { KheopskitContext } from \"./context\";\n\nexport const useWallets = () => {\n const ctx = useContext(KheopskitContext);\n\n // useEffect(() => {\n // console.debug(\n // \"useWallets wallets:%s accounts:%s\",\n // ctx?.state.wallets.length ?? 0,\n // ctx?.state.accounts.length ?? 0,\n // );\n // }, [ctx?.state]);\n\n if (!ctx)\n throw new Error(\"useWallets can't be used without a KheopskitProvider\");\n\n return ctx.state;\n};\n","import type { KheopskitState } from \"@kheopskit/core\";\nimport { createContext } from \"react\";\n\nexport const KheopskitContext = createContext<{\n state: KheopskitState;\n} | null>(null);\n","import {\n type KheopskitConfig,\n type KheopskitState,\n getKheopskit$,\n resolveConfig,\n} from \"@kheopskit/core\";\nimport {\n type FC,\n type PropsWithChildren,\n useMemo,\n useSyncExternalStore,\n} from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { createStore } from \"./createStore\";\n\nexport const KheopskitProvider: FC<\n PropsWithChildren & { config?: Partial<KheopskitConfig> }\n> = ({ children, config }) => {\n const defaultValue = useMemo<KheopskitState>(\n () => ({\n wallets: [],\n accounts: [],\n config: resolveConfig(config),\n }),\n [config],\n );\n\n const store = useMemo(\n () => createStore(getKheopskit$(config), defaultValue),\n [config, defaultValue],\n );\n\n const state = useSyncExternalStore(store.subscribe, store.getSnapshot);\n\n const value = useMemo(() => ({ state }), [state]);\n\n return (\n <KheopskitContext.Provider value={value}>\n {children}\n </KheopskitContext.Provider>\n );\n};\n","import { BehaviorSubject, type Observable } from \"rxjs\";\n\nexport const createStore = <T>(observable$: Observable<T>, initialValue: T) => {\n const subject = new BehaviorSubject<T>(initialValue);\n\n const sub = observable$.subscribe((value) => {\n subject.next(value);\n });\n\n const getSnapshot = () => subject.getValue();\n\n const subscribe = (callback: (value: T) => void) => {\n const sub = subject.subscribe(callback);\n\n return () => {\n sub.unsubscribe();\n };\n };\n\n const destroy = () => {\n sub.unsubscribe();\n };\n\n return {\n getSn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,OAAO,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC;AAEhD,SACE,4CAAC,iBAAiB,UAAjB,EAA0B,OACxB,UACH;AAEJ;","names":["import_react","import_react","sub"]}
package/dist/index.mjs CHANGED
@@ -1,64 +1,73 @@
1
- // src/SuspenseMonitor.tsx
2
- import { useEffect, useRef } from "react";
3
- import { jsx } from "react/jsx-runtime";
4
- var SHOULD_LOG = true;
5
- var SuspenseMonitorInner = ({ label }) => {
6
- const refStart = useRef(performance.now());
7
- useEffect(() => {
8
- const timeout = setTimeout(() => {
9
- console.warn(`[Suspense] ${label} is hanging`);
10
- }, 500);
11
- return () => {
12
- console.debug(
13
- "[Suspense] %s : %s ms",
14
- label,
15
- (performance.now() - refStart.current).toFixed(2)
16
- );
17
- clearTimeout(timeout);
18
- };
19
- }, [label]);
20
- return null;
21
- };
22
- var SuspenseMonitor = ({ label }) => SHOULD_LOG ? /* @__PURE__ */ jsx(SuspenseMonitorInner, { label }) : null;
23
-
24
- // src/useKheopskit.ts
25
- import { getKheopskit$ } from "@kheopskit/core";
26
- import { bind } from "@react-rxjs/core";
1
+ // src/useWallets.ts
27
2
  import { useContext } from "react";
28
3
 
29
4
  // src/context.ts
30
5
  import { createContext } from "react";
31
6
  var KheopskitContext = createContext(null);
32
7
 
33
- // src/useKheopskit.ts
34
- var DEFAULT_VALUE = {
35
- wallets: [],
36
- accounts: []
37
- };
38
- var [useKheopskit] = bind(
39
- (config) => getKheopskit$(config),
40
- DEFAULT_VALUE
41
- );
8
+ // src/useWallets.ts
42
9
  var useWallets = () => {
43
10
  const ctx = useContext(KheopskitContext);
44
11
  if (!ctx)
45
- throw new Error("useWallets must be used within a KheopskitProvider");
46
- return useKheopskit(ctx.config);
12
+ throw new Error("useWallets can't be used without a KheopskitProvider");
13
+ return ctx.state;
14
+ };
15
+
16
+ // src/KheopskitProvider.tsx
17
+ import {
18
+ getKheopskit$,
19
+ resolveConfig
20
+ } from "@kheopskit/core";
21
+ import {
22
+ useMemo,
23
+ useSyncExternalStore
24
+ } from "react";
25
+
26
+ // src/createStore.ts
27
+ import { BehaviorSubject } from "rxjs";
28
+ var createStore = (observable$, initialValue) => {
29
+ const subject = new BehaviorSubject(initialValue);
30
+ const sub = observable$.subscribe((value) => {
31
+ subject.next(value);
32
+ });
33
+ const getSnapshot = () => subject.getValue();
34
+ const subscribe = (callback) => {
35
+ const sub2 = subject.subscribe(callback);
36
+ return () => {
37
+ sub2.unsubscribe();
38
+ };
39
+ };
40
+ const destroy = () => {
41
+ sub.unsubscribe();
42
+ };
43
+ return {
44
+ getSnapshot,
45
+ subscribe,
46
+ destroy
47
+ };
47
48
  };
48
49
 
49
50
  // src/KheopskitProvider.tsx
50
- import { Subscribe } from "@react-rxjs/core";
51
- import { jsx as jsx2 } from "react/jsx-runtime";
51
+ import { jsx } from "react/jsx-runtime";
52
52
  var KheopskitProvider = ({ children, config }) => {
53
- return (
54
- // TODO set source
55
- /* @__PURE__ */ jsx2(KheopskitContext.Provider, { value: { config }, children: /* @__PURE__ */ jsx2(Subscribe, { fallback: /* @__PURE__ */ jsx2(SuspenseMonitor, { label: "KheopskitProvider" }), children }) })
53
+ const defaultValue = useMemo(
54
+ () => ({
55
+ wallets: [],
56
+ accounts: [],
57
+ config: resolveConfig(config)
58
+ }),
59
+ [config]
60
+ );
61
+ const store = useMemo(
62
+ () => createStore(getKheopskit$(config), defaultValue),
63
+ [config, defaultValue]
56
64
  );
65
+ const state = useSyncExternalStore(store.subscribe, store.getSnapshot);
66
+ const value = useMemo(() => ({ state }), [state]);
67
+ return /* @__PURE__ */ jsx(KheopskitContext.Provider, { value, children });
57
68
  };
58
69
  export {
59
70
  KheopskitProvider,
60
- SuspenseMonitor,
61
- SuspenseMonitorInner,
62
71
  useWallets
63
72
  };
64
73
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/SuspenseMonitor.tsx","../src/useKheopskit.ts","../src/context.ts","../src/KheopskitProvider.tsx"],"sourcesContent":["import { type FC, useEffect, useRef } from \"react\";\n\nconst SHOULD_LOG = true; // TODO only DEV\n\nexport const SuspenseMonitorInner: FC<{ label: string }> = ({ label }) => {\n const refStart = useRef(performance.now());\n\n useEffect(() => {\n const timeout = setTimeout(() => {\n console.warn(`[Suspense] ${label} is hanging`);\n }, 500);\n\n return () => {\n console.debug(\n \"[Suspense] %s : %s ms\",\n label,\n (performance.now() - refStart.current).toFixed(2)\n );\n clearTimeout(timeout);\n };\n }, [label]);\n\n return null;\n};\n\nexport const SuspenseMonitor: FC<{ label: string }> = ({ label }) =>\n SHOULD_LOG ? <SuspenseMonitorInner label={label} /> : null;\n","import { getKheopskit$, type KheopskitConfig } from \"@kheopskit/core\";\nimport { bind } from \"@react-rxjs/core\";\nimport { useContext } from \"react\";\nimport { KheopskitContext } from \"./context\";\n\nconst DEFAULT_VALUE = {\n wallets: [],\n accounts: [],\n};\n\nconst [useKheopskit] = bind(\n (config: KheopskitConfig) => getKheopskit$(config),\n DEFAULT_VALUE\n);\n\nexport const useWallets = () => {\n const ctx = useContext(KheopskitContext);\n if (!ctx)\n throw new Error(\"useWallets must be used within a KheopskitProvider\");\n\n return useKheopskit(ctx.config);\n};\n","import type { KheopskitConfig } from \"@kheopskit/core\";\nimport { createContext } from \"react\";\n\nexport const KheopskitContext = createContext<{\n config: KheopskitConfig;\n} | null>(null);\n","import type { KheopskitConfig } from \"@kheopskit/core\";\nimport { Subscribe } from \"@react-rxjs/core\";\nimport type { FC, PropsWithChildren } from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { SuspenseMonitor } from \"./SuspenseMonitor\";\n\nexport const KheopskitProvider: FC<\n PropsWithChildren & { config: KheopskitConfig }\n> = ({ children, config }) => {\n return (\n // TODO set source\n <KheopskitContext.Provider value={{ config }}>\n <Subscribe fallback={<SuspenseMonitor label=\"KheopskitProvider\" />}>\n {children}\n </Subscribe>\n </KheopskitContext.Provider>\n );\n};\n"],"mappings":";AAAA,SAAkB,WAAW,cAAc;AA0B5B;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useWallets.ts","../src/context.ts","../src/KheopskitProvider.tsx","../src/createStore.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { KheopskitContext } from \"./context\";\n\nexport const useWallets = () => {\n const ctx = useContext(KheopskitContext);\n\n // useEffect(() => {\n // console.debug(\n // \"useWallets wallets:%s accounts:%s\",\n // ctx?.state.wallets.length ?? 0,\n // ctx?.state.accounts.length ?? 0,\n // );\n // }, [ctx?.state]);\n\n if (!ctx)\n throw new Error(\"useWallets can't be used without a KheopskitProvider\");\n\n return ctx.state;\n};\n","import type { KheopskitState } from \"@kheopskit/core\";\nimport { createContext } from \"react\";\n\nexport const KheopskitContext = createContext<{\n state: KheopskitState;\n} | null>(null);\n","import {\n type KheopskitConfig,\n type KheopskitState,\n getKheopskit$,\n resolveConfig,\n} from \"@kheopskit/core\";\nimport {\n type FC,\n type PropsWithChildren,\n useMemo,\n useSyncExternalStore,\n} from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { createStore } from \"./createStore\";\n\nexport const KheopskitProvider: FC<\n PropsWithChildren & { config?: Partial<KheopskitConfig> }\n> = ({ children, config }) => {\n const defaultValue = useMemo<KheopskitState>(\n () => ({\n wallets: [],\n accounts: [],\n config: resolveConfig(config),\n }),\n [config],\n );\n\n const store = useMemo(\n () => createStore(getKheopskit$(config), defaultValue),\n [config, defaultValue],\n );\n\n const state = useSyncExternalStore(store.subscribe, store.getSnapshot);\n\n const value = useMemo(() => ({ state }), [state]);\n\n return (\n <KheopskitContext.Provider value={value}>\n {children}\n </KheopskitContext.Provider>\n );\n};\n","import { BehaviorSubject, type Observable } from \"rxjs\";\n\nexport const createStore = <T>(observable$: Observable<T>, initialValue: T) => {\n const subject = new BehaviorSubject<T>(initialValue);\n\n const sub = observable$.subscribe((value) => {\n subject.next(value);\n });\n\n const getSnapshot = () => subject.getValue();\n\n const subscribe = (callback: (value: T) => void) => {\n const sub = subject.subscribe(callback);\n\n return () => {\n sub.unsubscribe();\n };\n };\n\n const destroy = () => {\n sub.un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AQ,QAAQ,OAAO,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC;AAEhD,SACE,oBAAC,iBAAiB,UAAjB,EAA0B,OACxB,UACH;AAEJ;","names":["sub"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kheopskit/react",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,24 +16,28 @@
16
16
  }
17
17
  },
18
18
  "keywords": [],
19
- "author": "",
19
+ "author": "Kheops (https://github.com/0xKheops)",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/kheopskit/kheopskit.git"
23
+ },
20
24
  "license": "ISC",
21
25
  "peerDependencies": {
22
- "rxjs": ">=7.8.0",
26
+ "polkadot-api": ">=1.10.0",
23
27
  "react": "^19.0.0",
24
28
  "react-dom": "^19.0.0",
25
- "polkadot-api": ">=1.10.0"
29
+ "rxjs": ">=7.8.0"
26
30
  },
27
31
  "dependencies": {
28
- "@react-rxjs/core": "^0.10.8",
29
- "@kheopskit/core": "0.0.1-alpha.1"
32
+ "@kheopskit/core": "0.0.1"
30
33
  },
31
34
  "devDependencies": {
32
- "react": "^19.0.0",
33
- "react-dom": "^19.0.0",
34
- "@types/react": "^19.0.10",
35
- "@types/react-dom": "^19.0.4",
36
- "polkadot-api": "^1.10.0"
35
+ "@types/react": "^19.1.5",
36
+ "@types/react-dom": "^19.1.5",
37
+ "polkadot-api": "^1.12.0",
38
+ "react": "^19.1.0",
39
+ "react-dom": "^19.1.0",
40
+ "rxjs": "^7.8.2"
37
41
  },
38
42
  "tsup": {
39
43
  "entry": [
@@ -53,6 +57,6 @@
53
57
  "test": "echo \"Error: no test specified\" && exit 1",
54
58
  "dev": "tsup --watch",
55
59
  "build": "tsup",
56
- "clean": "rm -rf dist"
60
+ "clean": "rm -rf ./dist && rm -rf ./node_modules"
57
61
  }
58
62
  }
@@ -1,18 +1,42 @@
1
- import type { KheopskitConfig } from "@kheopskit/core";
2
- import { Subscribe } from "@react-rxjs/core";
3
- import type { FC, PropsWithChildren } from "react";
1
+ import {
2
+ type KheopskitConfig,
3
+ type KheopskitState,
4
+ getKheopskit$,
5
+ resolveConfig,
6
+ } from "@kheopskit/core";
7
+ import {
8
+ type FC,
9
+ type PropsWithChildren,
10
+ useMemo,
11
+ useSyncExternalStore,
12
+ } from "react";
4
13
  import { KheopskitContext } from "./context";
5
- import { SuspenseMonitor } from "./SuspenseMonitor";
14
+ import { createStore } from "./createStore";
6
15
 
7
16
  export const KheopskitProvider: FC<
8
- PropsWithChildren & { config: KheopskitConfig }
17
+ PropsWithChildren & { config?: Partial<KheopskitConfig> }
9
18
  > = ({ children, config }) => {
19
+ const defaultValue = useMemo<KheopskitState>(
20
+ () => ({
21
+ wallets: [],
22
+ accounts: [],
23
+ config: resolveConfig(config),
24
+ }),
25
+ [config],
26
+ );
27
+
28
+ const store = useMemo(
29
+ () => createStore(getKheopskit$(config), defaultValue),
30
+ [config, defaultValue],
31
+ );
32
+
33
+ const state = useSyncExternalStore(store.subscribe, store.getSnapshot);
34
+
35
+ const value = useMemo(() => ({ state }), [state]);
36
+
10
37
  return (
11
- // TODO set source
12
- <KheopskitContext.Provider value={{ config }}>
13
- <Subscribe fallback={<SuspenseMonitor label="KheopskitProvider" />}>
14
- {children}
15
- </Subscribe>
38
+ <KheopskitContext.Provider value={value}>
39
+ {children}
16
40
  </KheopskitContext.Provider>
17
41
  );
18
42
  };
package/src/context.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { KheopskitConfig } from "@kheopskit/core";
1
+ import type { KheopskitState } from "@kheopskit/core";
2
2
  import { createContext } from "react";
3
3
 
4
4
  export const KheopskitContext = createContext<{
5
- config: KheopskitConfig;
5
+ state: KheopskitState;
6
6
  } | null>(null);
@@ -0,0 +1,29 @@
1
+ import { BehaviorSubject, type Observable } from "rxjs";
2
+
3
+ export const createStore = <T>(observable$: Observable<T>, initialValue: T) => {
4
+ const subject = new BehaviorSubject<T>(initialValue);
5
+
6
+ const sub = observable$.subscribe((value) => {
7
+ subject.next(value);
8
+ });
9
+
10
+ const getSnapshot = () => subject.getValue();
11
+
12
+ const subscribe = (callback: (value: T) => void) => {
13
+ const sub = subject.subscribe(callback);
14
+
15
+ return () => {
16
+ sub.unsubscribe();
17
+ };
18
+ };
19
+
20
+ const destroy = () => {
21
+ sub.unsubscribe();
22
+ };
23
+
24
+ return {
25
+ getSnapshot,
26
+ subscribe,
27
+ destroy,
28
+ };
29
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from "./SuspenseMonitor";
2
- export * from "./useKheopskit";
1
+ export * from "./useWallets";
3
2
  export * from "./KheopskitProvider";
@@ -0,0 +1,19 @@
1
+ import { useContext } from "react";
2
+ import { KheopskitContext } from "./context";
3
+
4
+ export const useWallets = () => {
5
+ const ctx = useContext(KheopskitContext);
6
+
7
+ // useEffect(() => {
8
+ // console.debug(
9
+ // "useWallets wallets:%s accounts:%s",
10
+ // ctx?.state.wallets.length ?? 0,
11
+ // ctx?.state.accounts.length ?? 0,
12
+ // );
13
+ // }, [ctx?.state]);
14
+
15
+ if (!ctx)
16
+ throw new Error("useWallets can't be used without a KheopskitProvider");
17
+
18
+ return ctx.state;
19
+ };
@@ -1,27 +0,0 @@
1
- import { type FC, useEffect, useRef } from "react";
2
-
3
- const SHOULD_LOG = true; // TODO only DEV
4
-
5
- export const SuspenseMonitorInner: FC<{ label: string }> = ({ label }) => {
6
- const refStart = useRef(performance.now());
7
-
8
- useEffect(() => {
9
- const timeout = setTimeout(() => {
10
- console.warn(`[Suspense] ${label} is hanging`);
11
- }, 500);
12
-
13
- return () => {
14
- console.debug(
15
- "[Suspense] %s : %s ms",
16
- label,
17
- (performance.now() - refStart.current).toFixed(2)
18
- );
19
- clearTimeout(timeout);
20
- };
21
- }, [label]);
22
-
23
- return null;
24
- };
25
-
26
- export const SuspenseMonitor: FC<{ label: string }> = ({ label }) =>
27
- SHOULD_LOG ? <SuspenseMonitorInner label={label} /> : null;
@@ -1,22 +0,0 @@
1
- import { getKheopskit$, type KheopskitConfig } from "@kheopskit/core";
2
- import { bind } from "@react-rxjs/core";
3
- import { useContext } from "react";
4
- import { KheopskitContext } from "./context";
5
-
6
- const DEFAULT_VALUE = {
7
- wallets: [],
8
- accounts: [],
9
- };
10
-
11
- const [useKheopskit] = bind(
12
- (config: KheopskitConfig) => getKheopskit$(config),
13
- DEFAULT_VALUE
14
- );
15
-
16
- export const useWallets = () => {
17
- const ctx = useContext(KheopskitContext);
18
- if (!ctx)
19
- throw new Error("useWallets must be used within a KheopskitProvider");
20
-
21
- return useKheopskit(ctx.config);
22
- };