@ic-reactor/react 1.4.3 → 1.4.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.
@@ -8,7 +8,7 @@ export interface CreateAgentCotextParameters extends AgentManagerParameters {
8
8
  disableAuthenticateOnMount?: boolean;
9
9
  }
10
10
  export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
11
- useAgentManager: (agentContext?: React.Context<AgentContext | null>) => AgentManager;
11
+ useAgentManager: () => AgentManager;
12
12
  AgentProvider: React.FC<AgentProviderProps>;
13
13
  }
14
14
  export interface AgentProviderProps extends PropsWithChildren, CreateAgentCotextParameters {
@@ -25,7 +25,6 @@ export interface ActorProviderProps extends CreateActorContextParameters {
25
25
  export interface CreateActorContextParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
26
26
  didjsId?: string;
27
27
  canisterId?: string;
28
- agentContext?: React.Context<AgentContext | null>;
29
28
  idlFactory?: IDL.InterfaceFactory;
30
29
  loadingComponent?: React.ReactNode;
31
30
  }
@@ -18,6 +18,7 @@ const authHooks = (agentManager) => {
18
18
  const useAuthState = () => (0, zustand_1.useStore)(authStore);
19
19
  const useUserPrincipal = () => { var _a, _b; return (_b = (_a = useAuthState()) === null || _a === void 0 ? void 0 : _a.identity) === null || _b === void 0 ? void 0 : _b.getPrincipal(); };
20
20
  const useAuth = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
21
+ const network = React.useRef("ic");
21
22
  const [loginState, setLoginState] = React.useState({
22
23
  loading: false,
23
24
  error: undefined,
@@ -94,12 +95,12 @@ const authHooks = (agentManager) => {
94
95
  yield authenticate();
95
96
  onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
96
97
  }), [onLoggedOut]);
97
- React.useEffect(() => {
98
- const authClient = getAuth();
99
- if (!authClient && !authenticating) {
98
+ React.useEffect(() => agentManager.subscribeAgentState((state) => {
99
+ if (network.current !== state.network) {
100
+ network.current = state.network;
100
101
  authenticate();
101
102
  }
102
- }, [authenticating]);
103
+ }), []);
103
104
  return {
104
105
  authenticated,
105
106
  authenticating,
@@ -31,15 +31,15 @@ const react_1 = __importDefault(require("react"));
31
31
  * This context provides the necessary agent functionalities and state management capabilities required by the hooks.
32
32
  */
33
33
  const extractAgentContext = (agentContext) => {
34
- const useAgentContext = (mybeAgentContext) => {
35
- const context = react_1.default.useContext(mybeAgentContext || agentContext);
34
+ const useAgentContext = () => {
35
+ const context = react_1.default.useContext(agentContext);
36
36
  if (!context) {
37
37
  throw new Error("Agent hooks must be used within a AgentProvider");
38
38
  }
39
39
  return context;
40
40
  };
41
- const useAgentManager = (agentContext) => {
42
- const context = useAgentContext(agentContext);
41
+ const useAgentManager = () => {
42
+ const context = useAgentContext();
43
43
  return context.agentManager;
44
44
  };
45
45
  const useAgent = () => useAgentContext().useAgent();
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * Accesses the `AgentManager` instance for managing agent configurations and state.
4
3
  *
@@ -12,4 +11,4 @@
12
11
  * }
13
12
  *```
14
13
  */
15
- export declare const useAgentManager: (agentContext?: import("react").Context<import("../../types").AgentContext | null> | undefined) => import("@ic-reactor/core/dist/types").AgentManager;
14
+ export declare const useAgentManager: () => import("@ic-reactor/core/dist/types").AgentManager;
@@ -1,8 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { CandidAdapter } from "@ic-reactor/core/dist/classes";
3
- import { AgentContext } from "../../types";
4
2
  export interface UseCandidAdapterParams {
5
- agentContext?: React.Context<AgentContext | null>;
6
3
  didjsCanisterId?: string;
7
4
  }
8
5
  /**
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCandidAdapter = void 0;
4
- const useAgentManager_1 = require("./useAgentManager");
5
4
  const react_1 = require("react");
6
5
  const core_1 = require("@ic-reactor/core");
6
+ const useAgent_1 = require("./useAgent");
7
7
  /**
8
8
  * Accesses the `CandidAdapter` to download the actor's Candid interface.
9
9
  *
@@ -28,9 +28,8 @@ const core_1 = require("@ic-reactor/core");
28
28
  */
29
29
  const useCandidAdapter = (config) => {
30
30
  const [candidAdapter, setCandidAdapter] = (0, react_1.useState)();
31
- const agentManager = (0, useAgentManager_1.useAgentManager)(config.agentContext);
31
+ const agent = (0, useAgent_1.useAgent)();
32
32
  (0, react_1.useEffect)(() => {
33
- const agent = agentManager.getAgent();
34
33
  try {
35
34
  const candidManager = (0, core_1.createCandidAdapter)({
36
35
  agent,
@@ -42,7 +41,7 @@ const useCandidAdapter = (config) => {
42
41
  // eslint-disable-next-line no-console
43
42
  console.error("Error creating CandidAdapter", error);
44
43
  }
45
- }, [agentManager, config.didjsCanisterId]);
44
+ }, [agent, config.didjsCanisterId]);
46
45
  return candidAdapter;
47
46
  };
48
47
  exports.useCandidAdapter = useCandidAdapter;
@@ -1,11 +1,8 @@
1
- /// <reference types="react" />
2
1
  import type { IDL } from "@dfinity/candid";
3
- import { AgentContext } from "../context/types";
4
2
  import { ActorHooksReturnType, ActorManagerParameters, BaseActor } from "../types";
5
3
  export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
6
4
  canisterId: string;
7
5
  idlFactory?: IDL.InterfaceFactory;
8
- agentContext?: React.Context<AgentContext | null>;
9
6
  didjsCanisterId?: string;
10
7
  }
11
8
  export interface UseActorReturn<A = BaseActor> {
@@ -90,7 +90,7 @@ const useCandidAdapter_1 = require("./agent/useCandidAdapter");
90
90
  * ```
91
91
  */
92
92
  const useActor = (config) => {
93
- const { canisterId, idlFactory: maybeIdlFactory, agentContext, didjsCanisterId } = config, actorConfig = __rest(config, ["canisterId", "idlFactory", "agentContext", "didjsCanisterId"]);
93
+ const { canisterId, idlFactory: maybeIdlFactory, didjsCanisterId } = config, actorConfig = __rest(config, ["canisterId", "idlFactory", "didjsCanisterId"]);
94
94
  if (!canisterId) {
95
95
  throw new Error("canisterId is required");
96
96
  }
@@ -106,7 +106,6 @@ const useActor = (config) => {
106
106
  fetchError: null,
107
107
  });
108
108
  const candidAdapter = (0, useCandidAdapter_1.useCandidAdapter)({
109
- agentContext,
110
109
  didjsCanisterId,
111
110
  });
112
111
  const authenticating = (0, agent_1.useAuthState)().authenticating;
@@ -134,7 +133,7 @@ const useActor = (config) => {
134
133
  });
135
134
  }
136
135
  }), [canisterId, candidAdapter, authenticating, didjsCanisterId]);
137
- const agentManager = (0, useAgentManager_1.useAgentManager)(agentContext);
136
+ const agentManager = (0, useAgentManager_1.useAgentManager)();
138
137
  const initialActorManager = (0, react_1.useCallback)((idlFactory) => {
139
138
  if (authenticating)
140
139
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
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,7 +35,7 @@
35
35
  "node": ">=10"
36
36
  },
37
37
  "dependencies": {
38
- "@ic-reactor/core": "^1.4.1",
38
+ "@ic-reactor/core": "^1.4.2",
39
39
  "zustand-utils": "^1.3"
40
40
  },
41
41
  "peerDependencies": {
@@ -47,5 +47,5 @@
47
47
  "react": ">=16.8",
48
48
  "zustand": "4.5"
49
49
  },
50
- "gitHead": "86cb46dd7015edaed6b82601ff83e07ed8f43c99"
50
+ "gitHead": "89bab92f75cbbe39c9bdd6a0ac60344c6844ce5d"
51
51
  }