@ic-reactor/react 1.8.0 → 1.8.2

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.
@@ -82,7 +82,7 @@ function createActorContext(contextConfig = {}) {
82
82
  const { canisterId: defaultCanisterId } = contextConfig, defaultConfig = __rest(contextConfig, ["canisterId"]);
83
83
  const ActorContext = react_1.default.createContext(null);
84
84
  const ActorProvider = (_a) => {
85
- var { children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Fetching canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "fetchingComponent", "canisterId", "errorComponent", "loadingComponent", "authenticatingComponent"]);
85
+ var { children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Loading canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "fetchingComponent", "canisterId", "errorComponent", "loadingComponent", "authenticatingComponent"]);
86
86
  if (!canisterId) {
87
87
  throw new Error("canisterId is required");
88
88
  }
@@ -91,15 +91,19 @@ function createActorContext(contextConfig = {}) {
91
91
  const useInitializeActor = react_1.default.useCallback(() => {
92
92
  return initializeActor;
93
93
  }, [initializeActor]);
94
+ const ActorChildren = ({ useActorState }) => {
95
+ const { initializing, initialized, error } = useActorState();
96
+ return initializing
97
+ ? loadingComponent
98
+ : initialized
99
+ ? children
100
+ : error
101
+ ? errorComponent(error.message)
102
+ : null;
103
+ };
94
104
  return (react_1.default.createElement(ActorContext.Provider, { value: Object.assign(Object.assign({}, hooks), { useInitializeActor }) },
95
105
  fetchingComponent,
96
- hooks === null
97
- ? fetchError
98
- ? errorComponent(fetchError)
99
- : authenticating
100
- ? authenticatingComponent
101
- : loadingComponent
102
- : children));
106
+ hooks === null ? (fetchError ? (errorComponent(fetchError)) : authenticating ? (authenticatingComponent) : (loadingComponent)) : (react_1.default.createElement(ActorChildren, { useActorState: hooks.useActorState }, children))));
103
107
  };
104
108
  ActorProvider.displayName = "ActorProvider";
105
109
  const ActorHookProvider = ({ hooks, children, }) => {
@@ -26,3 +26,6 @@ export interface CreateActorContextParameters extends Omit<ActorManagerParameter
26
26
  idlFactory?: IDL.InterfaceFactory;
27
27
  disableAutoFetch?: boolean;
28
28
  }
29
+ export interface ActorChildrenProps extends React.PropsWithChildren {
30
+ useActorState: ActorHooksReturnType["useActorState"];
31
+ }
@@ -52,8 +52,6 @@ function createAdapterContext(config = {}) {
52
52
  return candidAdapter.validateIDL(candidString);
53
53
  }
54
54
  catch (err) {
55
- // eslint-disable-next-line no-console
56
- console.error(err);
57
55
  setState({
58
56
  fetchError: `Error validating Candid definition, ${err}`,
59
57
  fetching: false,
@@ -68,13 +66,15 @@ function createAdapterContext(config = {}) {
68
66
  try {
69
67
  const definition = yield candidAdapter.dynamicEvalJs(candidString);
70
68
  if (typeof (definition === null || definition === void 0 ? void 0 : definition.idlFactory) !== "function") {
71
- throw new Error("Error evaluating Candid definition");
69
+ throw new Error("No Function found in Candid definition!");
72
70
  }
71
+ setState({
72
+ fetchError: null,
73
+ fetching: false,
74
+ });
73
75
  return definition.idlFactory;
74
76
  }
75
77
  catch (err) {
76
- // eslint-disable-next-line no-console
77
- console.error(err);
78
78
  setState({
79
79
  fetchError: `Error evaluating Candid definition, ${err}`,
80
80
  fetching: false,
@@ -1,5 +1,6 @@
1
1
  import { IDL, ActorHooksReturnType, ActorManagerParameters, BaseActor, CanisterId } from "../types";
2
- export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
2
+ export type ActorReConfigParameters = Omit<ActorManagerParameters, "idlFactory" | "canisterId" | "agentManager">;
3
+ export interface UseActorParameters extends ActorReConfigParameters {
3
4
  candidString?: string;
4
5
  canisterId: CanisterId;
5
6
  idlFactory?: IDL.InterfaceFactory;
@@ -12,4 +13,4 @@ export interface UseActorReturn<A = BaseActor> {
12
13
  authenticating: boolean;
13
14
  initializeActor: InitializeActor;
14
15
  }
15
- export type InitializeActor = (idlFactory: IDL.InterfaceFactory, actorReConfig?: UseActorParameters) => void;
16
+ export type InitializeActor = (idlFactory: IDL.InterfaceFactory, actorReConfig?: ActorReConfigParameters) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "A React library for interacting with Internet Computer canisters",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "react": ">=16.8",
48
48
  "zustand": "4.5"
49
49
  },
50
- "gitHead": "35908ed17cea4c78169b00b9c4707393381041e1"
50
+ "gitHead": "2f9795480903113c771e2d0dbbf4d7cb87a0591e"
51
51
  }