@ic-reactor/react 1.12.2 → 1.14.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.
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createActorContext = void 0;
17
+ exports.createActorContext = createActorContext;
18
18
  const react_1 = __importDefault(require("react"));
19
19
  const useActor_1 = require("../../hooks/useActor");
20
20
  const extractActorContext_1 = require("../../helpers/extractActorContext");
@@ -112,4 +112,3 @@ function createActorContext(contextConfig = {}) {
112
112
  return Object.assign({ ActorProvider,
113
113
  ActorHookProvider }, (0, extractActorContext_1.extractActorContext)(ActorContext));
114
114
  }
115
- exports.createActorContext = createActorContext;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useActorInterface = void 0;
3
+ exports.useActorInterface = useActorInterface;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  *
@@ -8,4 +8,3 @@ const __1 = require("..");
8
8
  function useActorInterface() {
9
9
  return __1.ActorHooks.useActorInterface();
10
10
  }
11
- exports.useActorInterface = useActorInterface;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMethod = void 0;
3
+ exports.useMethod = useMethod;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  * Hook for making dynamically update or query calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
@@ -32,4 +32,3 @@ const __1 = require("..");
32
32
  function useMethod(args) {
33
33
  return __1.ActorHooks.useMethod(args);
34
34
  }
35
- exports.useMethod = useMethod;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useQueryCall = void 0;
3
+ exports.useQueryCall = useQueryCall;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  * Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
@@ -31,4 +31,3 @@ const __1 = require("..");
31
31
  function useQueryCall(args) {
32
32
  return __1.ActorHooks.useQueryCall(args);
33
33
  }
34
- exports.useQueryCall = useQueryCall;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useUpdateCall = void 0;
3
+ exports.useUpdateCall = useUpdateCall;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  * Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
@@ -32,4 +32,3 @@ const __1 = require("..");
32
32
  function useUpdateCall(args) {
33
33
  return __1.ActorHooks.useUpdateCall(args);
34
34
  }
35
- exports.useUpdateCall = useUpdateCall;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useVisitMethod = void 0;
3
+ exports.useVisitMethod = useVisitMethod;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  * Memoizes and returns a visit service function for a specific actor method.
@@ -11,4 +11,3 @@ const __1 = require("..");
11
11
  function useVisitMethod(functionName) {
12
12
  return __1.ActorHooks.useVisitMethod(functionName);
13
13
  }
14
- exports.useVisitMethod = useVisitMethod;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useVisitService = void 0;
3
+ exports.useVisitService = useVisitService;
4
4
  const __1 = require("..");
5
5
  /**
6
6
  * Memoizes and returns a visit service function for a specific actor method.
@@ -11,4 +11,3 @@ const __1 = require("..");
11
11
  function useVisitService() {
12
12
  return __1.ActorHooks.useVisitService();
13
13
  }
14
- exports.useVisitService = useVisitService;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * `ActorProvider` is a React functional component that serves as a context provider for IC actor interactions within a React application.
4
3
  * It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided canister ID and configuration.
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { IDL, ActorHooksReturnType, BaseActor, ActorManagerParameters, CanisterId, InitializeActor } from "../../types";
3
2
  export interface CreateActorContextType<A = BaseActor> extends ActorHooksReturnType<A> {
4
3
  useInitializeActor?: () => InitializeActor;
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.createAdapterContext = void 0;
26
+ exports.createAdapterContext = createAdapterContext;
27
27
  const react_1 = __importDefault(require("react"));
28
28
  const agent_1 = require("../agent");
29
29
  const core_1 = require("@ic-reactor/core");
@@ -107,4 +107,3 @@ function createAdapterContext(config = {}) {
107
107
  useCandidAdapter,
108
108
  };
109
109
  }
110
- exports.createAdapterContext = createAdapterContext;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /** @ignore */
3
2
  export declare const AdapterHooks: import("./types").CreateCandidAdapterContextReturnType;
4
3
  export declare const CandidAdapterContext: import("react").Context<import("./types").CandidAdapterContextType | null>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * `CandidAdapterProvider` is a React component that provides the CandidAdapter to its children.
4
3
  * It initializes the CandidAdapter with the provided options and makes it available to all children.
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createAgentContext = void 0;
17
+ exports.createAgentContext = createAgentContext;
18
18
  const react_1 = __importDefault(require("react"));
19
19
  const core_1 = require("@ic-reactor/core");
20
20
  const agentHooks_1 = require("../../helpers/agentHooks");
@@ -109,4 +109,3 @@ function createAgentContext(config = {}) {
109
109
  AgentProvider.displayName = "AgentProvider";
110
110
  return Object.assign({ AgentContext, AgentProvider }, (0, extractAgentContext_1.extractAgentContext)(AgentContext));
111
111
  }
112
- exports.createAgentContext = createAgentContext;
@@ -54,4 +54,4 @@
54
54
  *
55
55
  * This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
56
56
  */
57
- export declare const useAuth: (options?: import("../../../types").UseAuthParameters | undefined) => import("../../../types").UseAuthReturnType;
57
+ export declare const useAuth: (options?: import("../../../types").UseAuthParameters) => import("../../../types").UseAuthReturnType;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { createAgentContext } from "./create";
3
2
  export { createAgentContext };
4
3
  /** @ignore */
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
4
3
  * It enables any child components to access and use the agent and authentication functionalities seamlessly.
@@ -114,7 +114,7 @@ const actorHooks = (actorManager) => {
114
114
  }, [functionName]);
115
115
  };
116
116
  const useSharedCall = (_a) => {
117
- var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess"]);
117
+ var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess, onSuccessResult } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess", "onSuccessResult"]);
118
118
  const requestKey = React.useMemo(() => (0, utils_1.generateRequestHash)(args), [args]);
119
119
  const [sharedState, setSharedState] = useMethodState(functionName, requestKey);
120
120
  const latestDataRef = React.useRef();
@@ -130,7 +130,8 @@ const actorHooks = (actorManager) => {
130
130
  const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
131
131
  latestDataRef.current = data;
132
132
  setSharedState({ data, error: undefined, loading: false });
133
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess((0, utils_1.createCompiledResult)(data));
133
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
134
+ onSuccessResult === null || onSuccessResult === void 0 ? void 0 : onSuccessResult((0, utils_1.createCompiledResult)(data));
134
135
  onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
135
136
  return data;
136
137
  }
@@ -147,7 +148,16 @@ const actorHooks = (actorManager) => {
147
148
  if (throwOnError)
148
149
  throw error;
149
150
  }
150
- }), [args, functionName, options, onError, onLoading, onSuccess, throwOnError]);
151
+ }), [
152
+ args,
153
+ functionName,
154
+ options,
155
+ onError,
156
+ onLoading,
157
+ onSuccess,
158
+ onSuccessResult,
159
+ throwOnError,
160
+ ]);
151
161
  const compileResult = () => {
152
162
  return (0, utils_1.createCompiledResult)(latestDataRef.current || (sharedState === null || sharedState === void 0 ? void 0 : sharedState.data));
153
163
  };
@@ -161,7 +171,7 @@ const actorHooks = (actorManager) => {
161
171
  const _b = useSharedCall(rest), { call, requestKey } = _b, state = __rest(_b, ["call", "requestKey"]);
162
172
  const intervalId = React.useRef();
163
173
  React.useEffect(() => {
164
- var _a;
174
+ var _a, _b;
165
175
  if (refetchInterval) {
166
176
  intervalId.current = setInterval(call, refetchInterval);
167
177
  }
@@ -169,7 +179,8 @@ const actorHooks = (actorManager) => {
169
179
  call();
170
180
  }
171
181
  else if (refetchOnMount && state.data !== undefined) {
172
- (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, (0, utils_1.createCompiledResult)(state.data));
182
+ (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, state.data);
183
+ (_b = rest.onSuccessResult) === null || _b === void 0 ? void 0 : _b.call(rest, (0, utils_1.createCompiledResult)(state.data));
173
184
  }
174
185
  return () => clearInterval(intervalId.current);
175
186
  }, [refetchInterval, refetchOnMount, requestKey]);
@@ -98,12 +98,17 @@ const authHooks = (agentManager) => {
98
98
  yield authenticate();
99
99
  onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
100
100
  }), [onLoggedOut]);
101
- react_1.default.useEffect(() => agentManager.subscribeAgentState((state) => {
102
- if (network.current !== state.network) {
103
- network.current = state.network;
104
- authenticate();
105
- }
106
- }), []);
101
+ react_1.default.useEffect(() => {
102
+ const unsubscribe = agentManager.subscribeAgent((agent) => {
103
+ const agentNetwork = (0, utils_1.getNetworkByHostname)(agent.host.hostname);
104
+ if (network.current !== agentNetwork) {
105
+ network.current = agentNetwork;
106
+ authenticate();
107
+ }
108
+ });
109
+ authenticate();
110
+ return unsubscribe;
111
+ }, []);
107
112
  return {
108
113
  authenticated,
109
114
  authenticating,
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractActorContext = void 0;
6
+ exports.extractActorContext = extractActorContext;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  function extractActorContext(actorContext) {
9
9
  const useActorContext = () => {
@@ -42,4 +42,3 @@ function extractActorContext(actorContext) {
42
42
  initialize,
43
43
  };
44
44
  }
45
- exports.extractActorContext = extractActorContext;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { CallConfig } from "@dfinity/agent";
3
2
  import type { IDL, ActorState, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService, AuthState, HttpAgent, AgentState, BaseActor, MethodAttributes, CompiledResult } from "../types";
4
3
  export interface AgentHooksReturnType {
@@ -52,7 +51,8 @@ export interface UseSharedCallParameters<A, M extends FunctionName<A>> extends C
52
51
  args?: ActorMethodParameters<A[M]>;
53
52
  onLoading?: (loading: boolean) => void;
54
53
  onError?: (error: Error | undefined) => void;
55
- onSuccess?: (data: CompiledResult<ActorMethodReturnType<A[M]>>) => void;
54
+ onSuccess?: (data: ActorMethodReturnType<A[M]>) => void;
55
+ onSuccessResult?: (result: CompiledResult<ActorMethodReturnType<A[M]>>) => void;
56
56
  throwOnError?: boolean;
57
57
  compileResult?: boolean;
58
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.12.2",
3
+ "version": "1.14.1",
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",
@@ -35,17 +35,18 @@
35
35
  "node": ">=10"
36
36
  },
37
37
  "dependencies": {
38
- "@ic-reactor/core": "^1.12.0",
38
+ "@ic-reactor/core": "^1.14.0",
39
+ "zustand": "4.5",
39
40
  "zustand-utils": "^1.3"
40
41
  },
41
42
  "peerDependencies": {
42
- "@dfinity/agent": ">=2.0.0",
43
- "@dfinity/auth-client": ">=2.0.0",
44
- "@dfinity/candid": ">=2.0.0",
45
- "@dfinity/identity": ">=2.0.0",
46
- "@dfinity/principal": ">=2.0.0",
43
+ "@dfinity/agent": ">=2.1",
44
+ "@dfinity/auth-client": ">=2.1",
45
+ "@dfinity/candid": ">=2.1",
46
+ "@dfinity/identity": ">=2.1",
47
+ "@dfinity/principal": ">=2.1",
47
48
  "react": ">=16.8",
48
49
  "zustand": "4.5"
49
50
  },
50
- "gitHead": "83eaedfd96a494e188b0b35366761800ea3be186"
51
+ "gitHead": "fee4b92574ba3fd295e28fb49105f0a07c6fdb61"
51
52
  }