@ic-reactor/react 1.0.5 → 1.0.6

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.
Files changed (51) hide show
  1. package/README.md +7 -8
  2. package/dist/helpers/authHooks.js +11 -15
  3. package/dist/helpers/extractActorContext.js +0 -82
  4. package/dist/helpers/extractAgentContext.d.ts +1 -1
  5. package/dist/helpers/extractAgentContext.js +3 -81
  6. package/dist/helpers/types.d.ts +15 -15
  7. package/dist/main.d.ts +1 -1
  8. package/dist/main.js +1 -1
  9. package/dist/provider/ActorProvider.d.ts +0 -1
  10. package/dist/provider/ActorProvider.js +3 -4
  11. package/dist/provider/AgentProvider.d.ts +0 -1
  12. package/dist/provider/AgentProvider.js +3 -4
  13. package/dist/provider/actorHooks.d.ts +1 -0
  14. package/dist/provider/actorHooks.js +5 -0
  15. package/dist/provider/agentHooks.d.ts +1 -0
  16. package/dist/provider/agentHooks.js +5 -0
  17. package/dist/provider/{actor.d.ts → context/actor.d.ts} +2 -2
  18. package/dist/provider/{actor.js → context/actor.js} +2 -2
  19. package/dist/provider/{agent.d.ts → context/agent.d.ts} +5 -5
  20. package/dist/provider/{agent.js → context/agent.js} +6 -6
  21. package/dist/provider/hooks/actor/index.d.ts +4 -0
  22. package/dist/provider/hooks/actor/index.js +20 -0
  23. package/dist/provider/hooks/actor/useActorState.d.ts +21 -0
  24. package/dist/provider/hooks/actor/useActorState.js +25 -0
  25. package/dist/provider/hooks/actor/useQueryCall.d.ts +28 -0
  26. package/dist/provider/hooks/actor/useQueryCall.js +34 -0
  27. package/dist/provider/hooks/actor/useUpdateCall.d.ts +29 -0
  28. package/dist/provider/hooks/actor/useUpdateCall.js +35 -0
  29. package/dist/provider/hooks/actor/useVisitMethod.d.ts +8 -0
  30. package/dist/provider/hooks/actor/useVisitMethod.js +14 -0
  31. package/dist/provider/hooks/agent/index.d.ts +6 -0
  32. package/dist/provider/hooks/agent/index.js +22 -0
  33. package/dist/provider/hooks/agent/useAgent.d.ts +14 -0
  34. package/dist/provider/hooks/agent/useAgent.js +18 -0
  35. package/dist/provider/hooks/agent/useAgentManager.d.ts +15 -0
  36. package/dist/provider/hooks/agent/useAgentManager.js +18 -0
  37. package/dist/provider/hooks/agent/useAgentState.d.ts +21 -0
  38. package/dist/provider/hooks/agent/useAgentState.js +25 -0
  39. package/dist/provider/hooks/agent/useAuth.d.ts +57 -0
  40. package/dist/provider/hooks/agent/useAuth.js +61 -0
  41. package/dist/provider/hooks/agent/useAuthState.d.ts +19 -0
  42. package/dist/provider/hooks/agent/useAuthState.js +23 -0
  43. package/dist/provider/hooks/agent/useUserPrincipal.d.ts +17 -0
  44. package/dist/provider/hooks/agent/useUserPrincipal.js +21 -0
  45. package/dist/provider/hooks/index.d.ts +2 -0
  46. package/dist/provider/hooks/index.js +2 -0
  47. package/dist/provider/hooks/useActor.d.ts +5 -3
  48. package/dist/provider/hooks/useActor.js +7 -5
  49. package/dist/provider/index.d.ts +4 -7
  50. package/dist/provider/index.js +5 -6
  51. package/package.json +3 -3
@@ -0,0 +1,28 @@
1
+ import { FunctionName, UseQueryCallParameters } from "../../../types";
2
+ /**
3
+ * Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
4
+ *
5
+ * @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
6
+ * @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
7
+ * @example
8
+ * ```tsx
9
+ * function QueryCallComponent() {
10
+ * const { call, data, loading } = useQueryCall({
11
+ * functionName: 'getUserProfile',
12
+ * args: ['123'],
13
+ * refetchOnMount: true,
14
+ * refetchInterval: 5000, // refetch every 5 seconds
15
+ * });
16
+ *
17
+ * if (loading) return <p>Loading profile...</p>;
18
+ *
19
+ * return (
20
+ * <div>
21
+ * <p>User Profile: {JSON.stringify(data)}</p>
22
+ * <button onClick={call}>Refetch</button>
23
+ * </div>
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function useQueryCall<A, M extends FunctionName<A> = FunctionName<A>>(args: UseQueryCallParameters<A, M>): import("../../../types").UseMethodCallReturnType<A, M>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useQueryCall = void 0;
4
+ const actorHooks_1 = require("../../actorHooks");
5
+ /**
6
+ * Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
7
+ *
8
+ * @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
9
+ * @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
10
+ * @example
11
+ * ```tsx
12
+ * function QueryCallComponent() {
13
+ * const { call, data, loading } = useQueryCall({
14
+ * functionName: 'getUserProfile',
15
+ * args: ['123'],
16
+ * refetchOnMount: true,
17
+ * refetchInterval: 5000, // refetch every 5 seconds
18
+ * });
19
+ *
20
+ * if (loading) return <p>Loading profile...</p>;
21
+ *
22
+ * return (
23
+ * <div>
24
+ * <p>User Profile: {JSON.stringify(data)}</p>
25
+ * <button onClick={call}>Refetch</button>
26
+ * </div>
27
+ * );
28
+ * }
29
+ * ```
30
+ */
31
+ function useQueryCall(args) {
32
+ return actorHooks_1.ActorHooks.useQueryCall(args);
33
+ }
34
+ exports.useQueryCall = useQueryCall;
@@ -0,0 +1,29 @@
1
+ import { BaseActor, FunctionName, UseUpdateCallParameters } from "../../../types";
2
+ /**
3
+ * Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
4
+ *
5
+ * @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
6
+ * @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
7
+ * @example
8
+ * ```tsx
9
+ * function UpdateCallComponent() {
10
+ * const { call, data, loading } = useUpdateCall({
11
+ * functionName: 'updateUserProfile',
12
+ * args: ['123', { name: 'John Doe' }],
13
+ * onLoading: (loading) => console.log('Loading:', loading),
14
+ * onError: (error) => console.error('Error:', error),
15
+ * onSuccess: (data) => console.log('Success:', data),
16
+ * });
17
+ *
18
+ * if (loading) return <p>Updating profile...</p>;
19
+ *
20
+ * return (
21
+ * <div>
22
+ * <p>Updated Profile: {JSON.stringify(data)}</p>
23
+ * <button onClick={call}>Update</button>
24
+ * </div>
25
+ * );
26
+ * }
27
+ * ```
28
+ */
29
+ export declare function useUpdateCall<A = BaseActor, M extends FunctionName<A> = FunctionName<A>>(args: UseUpdateCallParameters<A, M>): import("../../../types").UseMethodCallReturnType<A, M>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUpdateCall = void 0;
4
+ const actorHooks_1 = require("../../actorHooks");
5
+ /**
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.
7
+ *
8
+ * @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
9
+ * @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
10
+ * @example
11
+ * ```tsx
12
+ * function UpdateCallComponent() {
13
+ * const { call, data, loading } = useUpdateCall({
14
+ * functionName: 'updateUserProfile',
15
+ * args: ['123', { name: 'John Doe' }],
16
+ * onLoading: (loading) => console.log('Loading:', loading),
17
+ * onError: (error) => console.error('Error:', error),
18
+ * onSuccess: (data) => console.log('Success:', data),
19
+ * });
20
+ *
21
+ * if (loading) return <p>Updating profile...</p>;
22
+ *
23
+ * return (
24
+ * <div>
25
+ * <p>Updated Profile: {JSON.stringify(data)}</p>
26
+ * <button onClick={call}>Update</button>
27
+ * </div>
28
+ * );
29
+ * }
30
+ * ```
31
+ */
32
+ function useUpdateCall(args) {
33
+ return actorHooks_1.ActorHooks.useUpdateCall(args);
34
+ }
35
+ exports.useUpdateCall = useUpdateCall;
@@ -0,0 +1,8 @@
1
+ import { BaseActor, FunctionName } from "../../../types";
2
+ /**
3
+ * Memoizes and returns a visit service function for a specific actor method.
4
+ *
5
+ * @param functionName The name of the actor method to visit.
6
+ * @returns The visit service function for the specified method.
7
+ */
8
+ export declare function useVisitMethod<A = BaseActor>(functionName: FunctionName<A>): <V extends import("@dfinity/candid/lib/cjs/idl").Visitor<unknown, unknown>>(extractorClass: V, data?: import("@ic-reactor/core/dist/classes/actor/types").VisitorType<V>["data"] | undefined) => ReturnType<V["visitFunc"]>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useVisitMethod = void 0;
4
+ const actorHooks_1 = require("../../actorHooks");
5
+ /**
6
+ * Memoizes and returns a visit service function for a specific actor method.
7
+ *
8
+ * @param functionName The name of the actor method to visit.
9
+ * @returns The visit service function for the specified method.
10
+ */
11
+ function useVisitMethod(functionName) {
12
+ return actorHooks_1.ActorHooks.useVisitMethod(functionName);
13
+ }
14
+ exports.useVisitMethod = useVisitMethod;
@@ -0,0 +1,6 @@
1
+ export * from "./useAgent";
2
+ export * from "./useAgentState";
3
+ export * from "./useAgentManager";
4
+ export * from "./useAuth";
5
+ export * from "./useAuthState";
6
+ export * from "./useUserPrincipal";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./useAgent"), exports);
18
+ __exportStar(require("./useAgentState"), exports);
19
+ __exportStar(require("./useAgentManager"), exports);
20
+ __exportStar(require("./useAuth"), exports);
21
+ __exportStar(require("./useAuthState"), exports);
22
+ __exportStar(require("./useUserPrincipal"), exports);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Accesses the current agent instance.
3
+ *
4
+ * @example
5
+ *```jsx
6
+ * function AgentComponent() {
7
+ * const agent = useAgent();
8
+ *
9
+ * // Use agent for interacting with the Internet Computer.
10
+ * return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
11
+ * }
12
+ *```
13
+ */
14
+ export declare const useAgent: () => import("@dfinity/agent").HttpAgent | undefined;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAgent = void 0;
4
+ const agentHooks_1 = require("../../agentHooks");
5
+ /**
6
+ * Accesses the current agent instance.
7
+ *
8
+ * @example
9
+ *```jsx
10
+ * function AgentComponent() {
11
+ * const agent = useAgent();
12
+ *
13
+ * // Use agent for interacting with the Internet Computer.
14
+ * return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
15
+ * }
16
+ *```
17
+ */
18
+ exports.useAgent = agentHooks_1.AgentHooks.useAgent;
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Accesses the `AgentManager` instance for managing agent configurations and state.
4
+ *
5
+ * @example
6
+ *```jsx
7
+ * function AgentManagerComponent() {
8
+ * const agentManager = useAgentManager();
9
+ *
10
+ * // Use agentManager for managing agent configurations, etc.
11
+ * return <div>Agent Manager ready.</div>;
12
+ * }
13
+ *```
14
+ */
15
+ export declare const useAgentManager: (agentContext?: import("react").Context<import("../../types").AgentContext | null> | undefined) => import("@ic-reactor/core/dist/types").AgentManager;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAgentManager = void 0;
4
+ const agentHooks_1 = require("../../agentHooks");
5
+ /**
6
+ * Accesses the `AgentManager` instance for managing agent configurations and state.
7
+ *
8
+ * @example
9
+ *```jsx
10
+ * function AgentManagerComponent() {
11
+ * const agentManager = useAgentManager();
12
+ *
13
+ * // Use agentManager for managing agent configurations, etc.
14
+ * return <div>Agent Manager ready.</div>;
15
+ * }
16
+ *```
17
+ */
18
+ exports.useAgentManager = agentHooks_1.AgentHooks.useAgentManager;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Accesses the current state of the agent.
3
+ *
4
+ * @example
5
+ * ```jsx
6
+ * function AgentStateComponent() {
7
+ * const { initialized, initializing } = useAgentState();
8
+ *
9
+ * return (
10
+ * <div>
11
+ * {initialized
12
+ * ? 'Agent is initialized.'
13
+ * : initializing
14
+ * ? 'Agent is initializing...'
15
+ * : 'Agent is not initialized.'}
16
+ * </div>
17
+ * );
18
+ * }
19
+ * ```
20
+ */
21
+ export declare const useAgentState: () => import("@ic-reactor/core/dist/types").AgentState;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAgentState = void 0;
4
+ const agentHooks_1 = require("../../agentHooks");
5
+ /**
6
+ * Accesses the current state of the agent.
7
+ *
8
+ * @example
9
+ * ```jsx
10
+ * function AgentStateComponent() {
11
+ * const { initialized, initializing } = useAgentState();
12
+ *
13
+ * return (
14
+ * <div>
15
+ * {initialized
16
+ * ? 'Agent is initialized.'
17
+ * : initializing
18
+ * ? 'Agent is initializing...'
19
+ * : 'Agent is not initialized.'}
20
+ * </div>
21
+ * );
22
+ * }
23
+ * ```
24
+ */
25
+ exports.useAgentState = agentHooks_1.AgentHooks.useAgentState;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
3
+ * It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
4
+ *
5
+ * @param options - An optional object containing the following properties:
6
+ * - `onAuthentication`: Callback function triggered before authentication starts.
7
+ * - `onAuthenticationSuccess`: Callback function triggered on successful authentication, receives the authenticated `Identity`.
8
+ * - `onAuthenticationFailure`: Callback function triggered on authentication failure, receives the error.
9
+ * - `onLogin`: Callback function triggered before the login process starts.
10
+ * - `onLoginSuccess`: Callback function triggered on successful login, receives the user's `Principal`.
11
+ * - `onLoginError`: Callback function triggered on login error, receives the error.
12
+ * - `onLoggedOut`: Callback function triggered after logging out.
13
+ *
14
+ * @returns An object containing the following properties:
15
+ * - `authenticated`: Boolean indicating if the user is currently authenticated.
16
+ * - `authenticating`: Boolean indicating if an authentication process is currently underway.
17
+ * - `identity`: The authenticated user's `Identity`, if available.
18
+ * - `error`: Any error that occurred during the authentication process.
19
+ * - `login`: Function to initiate the login process, optionally accepting `LoginParameters`.
20
+ * - `logout`: Function to log the user out, optionally accepting `LogoutParameters`.
21
+ * - `authenticate`: Function to authenticate the user, internally used by `login` and `logout`.
22
+ * - `loginLoading`: Boolean indicating if a login operation is in progress.
23
+ * - `loginError`: Error object if an error occurred during the login process.
24
+ *
25
+ * Usage:
26
+ * This hook can be used to add authentication functionality to your IC application components, handling user login, logout, and authentication state management seamlessly.
27
+ *
28
+ * Example:
29
+ * ```jsx
30
+ * const YourComponent = () => {
31
+ * const { login, logout, authenticated, identity, loginError } = useAuth({
32
+ * onLoginSuccess: (principal) => console.log(`Logged in as ${principal}`),
33
+ * onLoginError: (error) => console.error(`Login failed: ${error.message}`),
34
+ * });
35
+ *
36
+ * if (loginError) {
37
+ * return <div>Error logging in: {loginError.message}</div>;
38
+ * }
39
+ *
40
+ * return (
41
+ * <div>
42
+ * {authenticated ? (
43
+ * <>
44
+ * <div>Authenticated as {identity.getPrincipal().toText()}</div>
45
+ * <button onClick={() => logout()}>Logout</button>
46
+ * </>
47
+ * ) : (
48
+ * <button onClick={() => login()}>Login</button>
49
+ * )}
50
+ * </div>
51
+ * );
52
+ * };
53
+ * ```
54
+ *
55
+ * This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
56
+ */
57
+ export declare const useAuth: (options?: import("../../../types").UseAuthParameters | undefined) => import("../../../types").UseAuthReturnType;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuth = void 0;
4
+ const agentHooks_1 = require("../../agentHooks");
5
+ /**
6
+ * `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
7
+ * It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
8
+ *
9
+ * @param options - An optional object containing the following properties:
10
+ * - `onAuthentication`: Callback function triggered before authentication starts.
11
+ * - `onAuthenticationSuccess`: Callback function triggered on successful authentication, receives the authenticated `Identity`.
12
+ * - `onAuthenticationFailure`: Callback function triggered on authentication failure, receives the error.
13
+ * - `onLogin`: Callback function triggered before the login process starts.
14
+ * - `onLoginSuccess`: Callback function triggered on successful login, receives the user's `Principal`.
15
+ * - `onLoginError`: Callback function triggered on login error, receives the error.
16
+ * - `onLoggedOut`: Callback function triggered after logging out.
17
+ *
18
+ * @returns An object containing the following properties:
19
+ * - `authenticated`: Boolean indicating if the user is currently authenticated.
20
+ * - `authenticating`: Boolean indicating if an authentication process is currently underway.
21
+ * - `identity`: The authenticated user's `Identity`, if available.
22
+ * - `error`: Any error that occurred during the authentication process.
23
+ * - `login`: Function to initiate the login process, optionally accepting `LoginParameters`.
24
+ * - `logout`: Function to log the user out, optionally accepting `LogoutParameters`.
25
+ * - `authenticate`: Function to authenticate the user, internally used by `login` and `logout`.
26
+ * - `loginLoading`: Boolean indicating if a login operation is in progress.
27
+ * - `loginError`: Error object if an error occurred during the login process.
28
+ *
29
+ * Usage:
30
+ * This hook can be used to add authentication functionality to your IC application components, handling user login, logout, and authentication state management seamlessly.
31
+ *
32
+ * Example:
33
+ * ```jsx
34
+ * const YourComponent = () => {
35
+ * const { login, logout, authenticated, identity, loginError } = useAuth({
36
+ * onLoginSuccess: (principal) => console.log(`Logged in as ${principal}`),
37
+ * onLoginError: (error) => console.error(`Login failed: ${error.message}`),
38
+ * });
39
+ *
40
+ * if (loginError) {
41
+ * return <div>Error logging in: {loginError.message}</div>;
42
+ * }
43
+ *
44
+ * return (
45
+ * <div>
46
+ * {authenticated ? (
47
+ * <>
48
+ * <div>Authenticated as {identity.getPrincipal().toText()}</div>
49
+ * <button onClick={() => logout()}>Logout</button>
50
+ * </>
51
+ * ) : (
52
+ * <button onClick={() => login()}>Login</button>
53
+ * )}
54
+ * </div>
55
+ * );
56
+ * };
57
+ * ```
58
+ *
59
+ * This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
60
+ */
61
+ exports.useAuth = agentHooks_1.AgentHooks.useAuth;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Accesses the current authentication state.
3
+ *
4
+ * @example
5
+ * ```jsx
6
+ * function AuthStateComponent() {
7
+ * const { isAuthenticated, authenticating, identity, error } = useAuthState();
8
+ *
9
+ * return (
10
+ * <div>
11
+ * {authenticating ? 'Authenticating...' : ''}
12
+ * {error ? `Error: ${error.message}` : ''}
13
+ * {isAuthenticated ? `User ${identity?.getPrincipal()} is authenticated.` : 'User is not authenticated.'}
14
+ * </div>
15
+ * );
16
+ * }
17
+ * ```
18
+ */
19
+ export declare const useAuthState: () => import("@ic-reactor/core/dist/types").AuthState;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuthState = void 0;
4
+ const agentHooks_1 = require("../../agentHooks");
5
+ /**
6
+ * Accesses the current authentication state.
7
+ *
8
+ * @example
9
+ * ```jsx
10
+ * function AuthStateComponent() {
11
+ * const { isAuthenticated, authenticating, identity, error } = useAuthState();
12
+ *
13
+ * return (
14
+ * <div>
15
+ * {authenticating ? 'Authenticating...' : ''}
16
+ * {error ? `Error: ${error.message}` : ''}
17
+ * {isAuthenticated ? `User ${identity?.getPrincipal()} is authenticated.` : 'User is not authenticated.'}
18
+ * </div>
19
+ * );
20
+ * }
21
+ * ```
22
+ */
23
+ exports.useAuthState = agentHooks_1.AgentHooks.useAuthState;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Accesses the user's principal.
3
+ *
4
+ * @example
5
+ * ```jsx
6
+ * function UserPrincipalComponent() {
7
+ * const userPrincipal = useUserPrincipal();
8
+ *
9
+ * return (
10
+ * <div>
11
+ * {userPrincipal ? `User principal: ${userPrincipal}` : 'User principal not found.'}
12
+ * </div>
13
+ * );
14
+ * }
15
+ * ```
16
+ */
17
+ export declare const useUserPrincipal: () => import("@dfinity/principal").Principal | undefined;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUserPrincipal = void 0;
4
+ const agentHooks_1 = require("../../agentHooks");
5
+ /**
6
+ * Accesses the user's principal.
7
+ *
8
+ * @example
9
+ * ```jsx
10
+ * function UserPrincipalComponent() {
11
+ * const userPrincipal = useUserPrincipal();
12
+ *
13
+ * return (
14
+ * <div>
15
+ * {userPrincipal ? `User principal: ${userPrincipal}` : 'User principal not found.'}
16
+ * </div>
17
+ * );
18
+ * }
19
+ * ```
20
+ */
21
+ exports.useUserPrincipal = agentHooks_1.AgentHooks.useUserPrincipal;
@@ -1 +1,3 @@
1
+ export * from "./actor";
2
+ export * from "./agent";
1
3
  export * from "./useActor";
@@ -14,4 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./actor"), exports);
18
+ __exportStar(require("./agent"), exports);
17
19
  __exportStar(require("./useActor"), exports);
@@ -22,7 +22,7 @@ import type { UseActorParameters, UseActorReturn } from "./types";
22
22
  *
23
23
  * export const { useQueryCall, useUpdateCall } = extractActorHooks(ActorContext)
24
24
  *
25
- * const LedgerActor = () => {
25
+ * const LedgerActor = ({ children }) => {
26
26
  * const { hooks, fetching, fetchError } = useActor<Ledger>({
27
27
  * canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai", // ICP Ledger canister
28
28
  * })
@@ -32,7 +32,7 @@ import type { UseActorParameters, UseActorReturn } from "./types";
32
32
  * <h2>IC Canister Interaction</h2>
33
33
  * {fetching && <p>Loading Candid interface...</p>}
34
34
  * {fetchError && <p>Error: {fetchError}</p>}
35
- * {hooks && <CanisterName />}
35
+ * {hooks && children}
36
36
  * </ActorContext.Provider>
37
37
  * )
38
38
  * }
@@ -52,7 +52,9 @@ import type { UseActorParameters, UseActorReturn } from "./types";
52
52
  *
53
53
  * const App = () => (
54
54
  * <AgentProvider withDevtools>
55
- * <LedgerActor />
55
+ * <LedgerActor>
56
+ * <CanisterName />
57
+ * </LedgerActor>
56
58
  * </AgentProvider>
57
59
  * )
58
60
  *
@@ -23,7 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.useActor = void 0;
24
24
  const core_1 = require("@ic-reactor/core");
25
25
  const react_1 = require("react");
26
- const __1 = require("..");
26
+ const useAgentManager_1 = require("./agent/useAgentManager");
27
27
  const helpers_1 = require("../../helpers");
28
28
  /**
29
29
  * A comprehensive hook that manages both the fetching of Candid interfaces
@@ -47,7 +47,7 @@ const helpers_1 = require("../../helpers");
47
47
  *
48
48
  * export const { useQueryCall, useUpdateCall } = extractActorHooks(ActorContext)
49
49
  *
50
- * const LedgerActor = () => {
50
+ * const LedgerActor = ({ children }) => {
51
51
  * const { hooks, fetching, fetchError } = useActor<Ledger>({
52
52
  * canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai", // ICP Ledger canister
53
53
  * })
@@ -57,7 +57,7 @@ const helpers_1 = require("../../helpers");
57
57
  * <h2>IC Canister Interaction</h2>
58
58
  * {fetching && <p>Loading Candid interface...</p>}
59
59
  * {fetchError && <p>Error: {fetchError}</p>}
60
- * {hooks && <CanisterName />}
60
+ * {hooks && children}
61
61
  * </ActorContext.Provider>
62
62
  * )
63
63
  * }
@@ -77,7 +77,9 @@ const helpers_1 = require("../../helpers");
77
77
  *
78
78
  * const App = () => (
79
79
  * <AgentProvider withDevtools>
80
- * <LedgerActor />
80
+ * <LedgerActor>
81
+ * <CanisterName />
82
+ * </LedgerActor>
81
83
  * </AgentProvider>
82
84
  * )
83
85
  *
@@ -92,7 +94,7 @@ const useActor = (config) => {
92
94
  fetching: false,
93
95
  fetchError: null,
94
96
  });
95
- const agentManager = (0, __1.useAgentManager)(agentContext);
97
+ const agentManager = (0, useAgentManager_1.useAgentManager)(agentContext);
96
98
  const fetchCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
97
99
  if (!canisterId)
98
100
  return;
@@ -1,8 +1,5 @@
1
- /// <reference types="react" />
2
- import { createActorContext } from "./actor";
3
- import { createAgentContext } from "./agent";
4
- export declare const ActorProvider: import("react").FC<import("./types").ActorProviderProps>, useActorState: () => import("../types").UseActorState, useQueryCall: import("../types").UseQueryCall<import("@ic-reactor/core/dist/types").BaseActor>, useUpdateCall: import("../types").UseUpdateCall<import("@ic-reactor/core/dist/types").BaseActor>, useVisitMethod: <M extends string>(functionName: M) => <V extends import("@dfinity/candid/lib/cjs/idl").Visitor<unknown, unknown>>(extractorClass: V, data?: import("@ic-reactor/core/dist/types").VisitorType<V>["data"] | undefined) => ReturnType<V["visitFunc"]>;
5
- export { createActorContext };
6
- export declare const AgentProvider: import("react").FC<import("./types").AgentProviderProps>, useAgent: () => import("@dfinity/agent").HttpAgent | undefined, useAuthClient: (args?: import("../types").UseAuthClientParameters | undefined) => import("../types").UseAuthClientReturnType, useAuthState: () => import("@ic-reactor/core/dist/types").AuthState, useAgentState: () => import("@ic-reactor/core/dist/types").AgentState, useAgentManager: (agentContext?: import("react").Context<import("./types").AgentContext | null> | undefined) => import("@ic-reactor/core/dist/types").AgentManager, useUserPrincipal: () => import("@dfinity/principal").Principal | undefined;
7
- export { createAgentContext };
1
+ export { createActorContext } from "./context/actor";
2
+ export { createAgentContext } from "./context/agent";
8
3
  export * from "./hooks";
4
+ export * from "./ActorProvider";
5
+ export * from "./AgentProvider";
@@ -13,13 +13,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var _a, _b;
17
16
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createAgentContext = exports.useUserPrincipal = exports.useAgentManager = exports.useAgentState = exports.useAuthState = exports.useAuthClient = exports.useAgent = exports.AgentProvider = exports.createActorContext = exports.useVisitMethod = exports.useUpdateCall = exports.useQueryCall = exports.useActorState = exports.ActorProvider = void 0;
19
- const actor_1 = require("./actor");
17
+ exports.createAgentContext = exports.createActorContext = void 0;
18
+ var actor_1 = require("./context/actor");
20
19
  Object.defineProperty(exports, "createActorContext", { enumerable: true, get: function () { return actor_1.createActorContext; } });
21
- const agent_1 = require("./agent");
20
+ var agent_1 = require("./context/agent");
22
21
  Object.defineProperty(exports, "createAgentContext", { enumerable: true, get: function () { return agent_1.createAgentContext; } });
23
- _a = (0, actor_1.createActorContext)(), exports.ActorProvider = _a.ActorProvider, exports.useActorState = _a.useActorState, exports.useQueryCall = _a.useQueryCall, exports.useUpdateCall = _a.useUpdateCall, exports.useVisitMethod = _a.useVisitMethod;
24
- _b = (0, agent_1.createAgentContext)(), exports.AgentProvider = _b.AgentProvider, exports.useAgent = _b.useAgent, exports.useAuthClient = _b.useAuthClient, exports.useAuthState = _b.useAuthState, exports.useAgentState = _b.useAgentState, exports.useAgentManager = _b.useAgentManager, exports.useUserPrincipal = _b.useUserPrincipal;
25
22
  __exportStar(require("./hooks"), exports);
23
+ __exportStar(require("./ActorProvider"), exports);
24
+ __exportStar(require("./AgentProvider"), exports);