@ic-reactor/react 1.0.6 → 1.0.7
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/dist/{provider/context → context}/actor.d.ts +2 -2
- package/dist/{provider/context → context}/actor.js +1 -1
- package/dist/{provider/context → context}/agent.d.ts +17 -14
- package/dist/{provider/context → context}/agent.js +18 -14
- package/dist/{provider → context}/types.d.ts +2 -1
- package/dist/createReactor.d.ts +49 -0
- package/dist/createReactor.js +64 -0
- package/dist/helpers/authHooks.js +3 -3
- package/dist/hooks/actor/hooks.d.ts +1 -0
- package/dist/{provider/actorHooks.js → hooks/actor/hooks.js} +1 -1
- package/dist/{provider/hooks → hooks}/actor/useActorState.d.ts +1 -1
- package/dist/{provider/hooks → hooks}/actor/useActorState.js +2 -2
- package/dist/{provider/hooks → hooks}/actor/useQueryCall.d.ts +2 -2
- package/dist/{provider/hooks → hooks}/actor/useQueryCall.js +2 -2
- package/dist/{provider/hooks → hooks}/actor/useUpdateCall.d.ts +2 -2
- package/dist/{provider/hooks → hooks}/actor/useUpdateCall.js +2 -2
- package/dist/{provider/hooks → hooks}/actor/useVisitMethod.d.ts +1 -1
- package/dist/{provider/hooks → hooks}/actor/useVisitMethod.js +2 -2
- package/dist/hooks/agent/hooks.d.ts +1 -0
- package/dist/{provider/agentHooks.js → hooks/agent/hooks.js} +1 -1
- package/dist/{provider/hooks → hooks}/agent/useAgent.js +2 -2
- package/dist/{provider/hooks → hooks}/agent/useAgentManager.js +2 -2
- package/dist/{provider/hooks → hooks}/agent/useAgentState.js +2 -2
- package/dist/{provider/hooks → hooks}/agent/useAuth.d.ts +1 -1
- package/dist/{provider/hooks → hooks}/agent/useAuth.js +2 -2
- package/dist/{provider/hooks → hooks}/agent/useAuthState.js +2 -2
- package/dist/{provider/hooks → hooks}/agent/useUserPrincipal.js +2 -2
- package/dist/{provider/hooks → hooks}/types.d.ts +2 -2
- package/dist/hooks/types.js +2 -0
- package/dist/{provider/hooks → hooks}/useActor.d.ts +1 -1
- package/dist/{provider/hooks → hooks}/useActor.js +7 -11
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/provider/{ActorProvider.d.ts → actor.d.ts} +1 -1
- package/dist/provider/{ActorProvider.js → actor.js} +2 -2
- package/dist/provider/{AgentProvider.d.ts → agent.d.ts} +1 -1
- package/dist/provider/{AgentProvider.js → agent.js} +2 -2
- package/dist/types.d.ts +2 -1
- package/dist/types.js +2 -1
- package/package.json +3 -3
- package/dist/main.d.ts +0 -38
- package/dist/main.js +0 -53
- package/dist/provider/actorHooks.d.ts +0 -1
- package/dist/provider/agentHooks.d.ts +0 -1
- package/dist/provider/index.d.ts +0 -5
- package/dist/provider/index.js +0 -24
- package/dist/provider/types.js +0 -17
- /package/dist/{provider/hooks → context}/types.js +0 -0
- /package/dist/{provider/hooks → hooks}/actor/index.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/actor/index.js +0 -0
- /package/dist/{provider/hooks → hooks}/agent/index.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/agent/index.js +0 -0
- /package/dist/{provider/hooks → hooks}/agent/useAgent.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/agent/useAgentManager.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/agent/useAgentState.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/agent/useAuthState.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/agent/useUserPrincipal.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/index.d.ts +0 -0
- /package/dist/{provider/hooks → hooks}/index.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseActor } from "
|
|
2
|
-
import { CreateActorContextParameters, CreateActorContextReturnType } from "
|
|
1
|
+
import { BaseActor } from "../types";
|
|
2
|
+
import { CreateActorContextParameters, CreateActorContextReturnType } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
|
|
5
5
|
* This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
|
|
@@ -37,7 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
exports.createActorContext = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const useActor_1 = require("../hooks/useActor");
|
|
40
|
-
const extractActorContext_1 = require("
|
|
40
|
+
const extractActorContext_1 = require("../helpers/extractActorContext");
|
|
41
41
|
/**
|
|
42
42
|
* Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
|
|
43
43
|
* This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CreateAgentContextReturnType } from "../types";
|
|
1
|
+
import type { CreateAgentContextReturnType, CreateAgentCotextParameters } from "./types";
|
|
3
2
|
/**
|
|
4
3
|
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
5
4
|
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
6
5
|
*
|
|
7
|
-
* @param
|
|
6
|
+
* @param config A partial configuration object {@link CreateAgentCotextParameters}, allowing customization of the agent's behavior.
|
|
8
7
|
*
|
|
9
|
-
* @returns
|
|
10
|
-
*
|
|
8
|
+
* @returns
|
|
9
|
+
* An object containing the {@link AgentProvider} component and various hooks for interacting with the agent and authentication state.
|
|
10
|
+
* The {@link AgentProvider} component is a React context provider that should wrap your app or components needing access to agent functionalities.
|
|
11
11
|
*
|
|
12
12
|
* Usage:
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
13
|
+
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
14
|
+
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
15
|
+
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
16
|
+
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
19
|
+
* agent.ts
|
|
17
20
|
* ```tsx
|
|
18
|
-
* // agent.ts
|
|
19
21
|
* import { createAgentContext } from "@ic-reactor/react";
|
|
20
|
-
* import {
|
|
22
|
+
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
21
23
|
*
|
|
22
24
|
* // Optional: Define custom agent configuration
|
|
23
|
-
* const agentConfig:
|
|
25
|
+
* const agentConfig: CreateAgentCotextParameters = {
|
|
24
26
|
* host: "https://localhost:8000",
|
|
25
27
|
* // or
|
|
26
28
|
* // isLocalEnv: true,
|
|
@@ -38,8 +40,9 @@ import type { CreateAgentContextReturnType } from "../types";
|
|
|
38
40
|
* } = createAgentContext(agentConfig);
|
|
39
41
|
*
|
|
40
42
|
* // Now you can use the returned hooks in your React components
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
+
*```
|
|
44
|
+
* App.tsx
|
|
45
|
+
* ```tsx
|
|
43
46
|
* import React from 'react';
|
|
44
47
|
* import { AgentProvider } from './agent';
|
|
45
48
|
*
|
|
@@ -65,7 +68,7 @@ import type { CreateAgentContextReturnType } from "../types";
|
|
|
65
68
|
* ```
|
|
66
69
|
*
|
|
67
70
|
* This setup allows you to use the agent and authentication hooks within
|
|
68
|
-
* the components wrapped by
|
|
71
|
+
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
69
72
|
* with the Internet Computer blockchain.
|
|
70
73
|
*/
|
|
71
|
-
export declare const createAgentContext: (config?:
|
|
74
|
+
export declare const createAgentContext: (config?: CreateAgentCotextParameters) => CreateAgentContextReturnType;
|
|
@@ -37,30 +37,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
exports.createAgentContext = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const core_1 = require("@ic-reactor/core");
|
|
40
|
-
const agentHooks_1 = require("
|
|
41
|
-
const authHooks_1 = require("
|
|
42
|
-
const extractAgentContext_1 = require("
|
|
40
|
+
const agentHooks_1 = require("../helpers/agentHooks");
|
|
41
|
+
const authHooks_1 = require("../helpers/authHooks");
|
|
42
|
+
const extractAgentContext_1 = require("../helpers/extractAgentContext");
|
|
43
43
|
/**
|
|
44
44
|
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
45
45
|
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
46
46
|
*
|
|
47
|
-
* @param
|
|
47
|
+
* @param config A partial configuration object {@link CreateAgentCotextParameters}, allowing customization of the agent's behavior.
|
|
48
48
|
*
|
|
49
|
-
* @returns
|
|
50
|
-
*
|
|
49
|
+
* @returns
|
|
50
|
+
* An object containing the {@link AgentProvider} component and various hooks for interacting with the agent and authentication state.
|
|
51
|
+
* The {@link AgentProvider} component is a React context provider that should wrap your app or components needing access to agent functionalities.
|
|
51
52
|
*
|
|
52
53
|
* Usage:
|
|
53
|
-
* -
|
|
54
|
-
* -
|
|
54
|
+
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
55
|
+
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
56
|
+
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
57
|
+
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
55
58
|
*
|
|
56
59
|
* @example
|
|
60
|
+
* agent.ts
|
|
57
61
|
* ```tsx
|
|
58
|
-
* // agent.ts
|
|
59
62
|
* import { createAgentContext } from "@ic-reactor/react";
|
|
60
|
-
* import {
|
|
63
|
+
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
61
64
|
*
|
|
62
65
|
* // Optional: Define custom agent configuration
|
|
63
|
-
* const agentConfig:
|
|
66
|
+
* const agentConfig: CreateAgentCotextParameters = {
|
|
64
67
|
* host: "https://localhost:8000",
|
|
65
68
|
* // or
|
|
66
69
|
* // isLocalEnv: true,
|
|
@@ -78,8 +81,9 @@ const extractAgentContext_1 = require("../../helpers/extractAgentContext");
|
|
|
78
81
|
* } = createAgentContext(agentConfig);
|
|
79
82
|
*
|
|
80
83
|
* // Now you can use the returned hooks in your React components
|
|
81
|
-
|
|
82
|
-
*
|
|
84
|
+
*```
|
|
85
|
+
* App.tsx
|
|
86
|
+
* ```tsx
|
|
83
87
|
* import React from 'react';
|
|
84
88
|
* import { AgentProvider } from './agent';
|
|
85
89
|
*
|
|
@@ -105,7 +109,7 @@ const extractAgentContext_1 = require("../../helpers/extractAgentContext");
|
|
|
105
109
|
* ```
|
|
106
110
|
*
|
|
107
111
|
* This setup allows you to use the agent and authentication hooks within
|
|
108
|
-
* the components wrapped by
|
|
112
|
+
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
109
113
|
* with the Internet Computer blockchain.
|
|
110
114
|
*/
|
|
111
115
|
const createAgentContext = (config = {}) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { IDL, ActorHooksReturnType, AgentHooksReturnType, AuthHooksReturnType, BaseActor, AgentManager, ActorManagerParameters, AgentManagerParameters } from "../types";
|
|
2
2
|
import type { PropsWithChildren } from "react";
|
|
3
|
-
export * from "./hooks/types";
|
|
4
3
|
export interface AgentContext extends AgentHooksReturnType, AuthHooksReturnType {
|
|
5
4
|
agentManager: AgentManager;
|
|
6
5
|
}
|
|
6
|
+
export interface CreateAgentCotextParameters extends AgentManagerParameters {
|
|
7
|
+
}
|
|
7
8
|
export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
|
|
8
9
|
useAgentManager: (agentContext?: React.Context<AgentContext | null>) => AgentManager;
|
|
9
10
|
AgentProvider: React.FC<AgentProviderProps>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BaseActor, CreateReactorParameters, CreateReactorReturnType } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application.
|
|
4
|
+
* It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.
|
|
5
|
+
*
|
|
6
|
+
* @param config Configuration {@link CreateReactorParameters} for the reactor, including:
|
|
7
|
+
* - `withProcessEnv` (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
|
|
8
|
+
* - `isLocalEnv` (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
|
|
9
|
+
* - `port` (optional): Port number for the local or development environment.
|
|
10
|
+
*
|
|
11
|
+
* @returns An object containing {@link CreateReactorReturnType} hooks and utilities:
|
|
12
|
+
* - {@link getAgent} - Returns the current agent instance.
|
|
13
|
+
* - {@link getVisitFunction} - Returns the visit function for the actor.
|
|
14
|
+
* - {@link useQueryCall} - A hook for querying actor methods.
|
|
15
|
+
* - {@link useUpdateCall} - A hook for updating actor methods.
|
|
16
|
+
* - {@link useAuth} - A hook for managing authentication and user principal.
|
|
17
|
+
* - {@link useActor} - A hook for managing actors and their methods.
|
|
18
|
+
* - {@link useActorManager} - A hook for managing actor manager and its methods.
|
|
19
|
+
* - {@link useAgentManager} - A hook for managing agent manager and its methods.
|
|
20
|
+
* - {@link initialize} - A function to initialize the actor manager if not initialized.
|
|
21
|
+
* - {@link useActorState} - A hook for managing actor state.
|
|
22
|
+
* - {@link useAgent} - A hook for managing agent and its methods.
|
|
23
|
+
* - {@link useAuthState} - A hook for managing authentication state.
|
|
24
|
+
* - {@link useAgentState} - A hook for managing agent state.
|
|
25
|
+
* - {@link useUserPrincipal} - A hook for managing user principal.
|
|
26
|
+
* - {@link useVisitMethod} - A hook for visiting actor methods.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { createReactor } from "@ic-reactor/react";
|
|
31
|
+
* import type { CreateReactorParameters } from "@ic-reactor/react/dist/types";
|
|
32
|
+
* import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"
|
|
33
|
+
*
|
|
34
|
+
* const config: CreateReactorParameters = {
|
|
35
|
+
* canisterId,
|
|
36
|
+
* idlFactory,
|
|
37
|
+
* host: "https://localhost:8000", // IC network host |
|
|
38
|
+
* isLocalEnv: true, // Set true for local network | one of these
|
|
39
|
+
* withProcessEnv: true, // Use process.env to determine host |
|
|
40
|
+
* port: 8000, // Port number for local network |
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* export type YourActor = typeof yourActor;
|
|
44
|
+
*
|
|
45
|
+
* export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
|
|
46
|
+
* // Now you can use the returned hooks in your React components
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const createReactor: <A = BaseActor>(config: CreateReactorParameters) => CreateReactorReturnType<A>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createReactor = void 0;
|
|
4
|
+
const core_1 = require("@ic-reactor/core");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application.
|
|
8
|
+
* It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.
|
|
9
|
+
*
|
|
10
|
+
* @param config Configuration {@link CreateReactorParameters} for the reactor, including:
|
|
11
|
+
* - `withProcessEnv` (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
|
|
12
|
+
* - `isLocalEnv` (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
|
|
13
|
+
* - `port` (optional): Port number for the local or development environment.
|
|
14
|
+
*
|
|
15
|
+
* @returns An object containing {@link CreateReactorReturnType} hooks and utilities:
|
|
16
|
+
* - {@link getAgent} - Returns the current agent instance.
|
|
17
|
+
* - {@link getVisitFunction} - Returns the visit function for the actor.
|
|
18
|
+
* - {@link useQueryCall} - A hook for querying actor methods.
|
|
19
|
+
* - {@link useUpdateCall} - A hook for updating actor methods.
|
|
20
|
+
* - {@link useAuth} - A hook for managing authentication and user principal.
|
|
21
|
+
* - {@link useActor} - A hook for managing actors and their methods.
|
|
22
|
+
* - {@link useActorManager} - A hook for managing actor manager and its methods.
|
|
23
|
+
* - {@link useAgentManager} - A hook for managing agent manager and its methods.
|
|
24
|
+
* - {@link initialize} - A function to initialize the actor manager if not initialized.
|
|
25
|
+
* - {@link useActorState} - A hook for managing actor state.
|
|
26
|
+
* - {@link useAgent} - A hook for managing agent and its methods.
|
|
27
|
+
* - {@link useAuthState} - A hook for managing authentication state.
|
|
28
|
+
* - {@link useAgentState} - A hook for managing agent state.
|
|
29
|
+
* - {@link useUserPrincipal} - A hook for managing user principal.
|
|
30
|
+
* - {@link useVisitMethod} - A hook for visiting actor methods.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createReactor } from "@ic-reactor/react";
|
|
35
|
+
* import type { CreateReactorParameters } from "@ic-reactor/react/dist/types";
|
|
36
|
+
* import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"
|
|
37
|
+
*
|
|
38
|
+
* const config: CreateReactorParameters = {
|
|
39
|
+
* canisterId,
|
|
40
|
+
* idlFactory,
|
|
41
|
+
* host: "https://localhost:8000", // IC network host |
|
|
42
|
+
* isLocalEnv: true, // Set true for local network | one of these
|
|
43
|
+
* withProcessEnv: true, // Use process.env to determine host |
|
|
44
|
+
* port: 8000, // Port number for local network |
|
|
45
|
+
* };
|
|
46
|
+
*
|
|
47
|
+
* export type YourActor = typeof yourActor;
|
|
48
|
+
*
|
|
49
|
+
* export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
|
|
50
|
+
* // Now you can use the returned hooks in your React components
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const createReactor = (config) => {
|
|
54
|
+
const actorManager = (0, core_1.createReactorStore)(config);
|
|
55
|
+
const getVisitFunction = () => {
|
|
56
|
+
return actorManager.visitFunction;
|
|
57
|
+
};
|
|
58
|
+
const getAgent = () => {
|
|
59
|
+
return actorManager.agentManager.getAgent();
|
|
60
|
+
};
|
|
61
|
+
return Object.assign(Object.assign(Object.assign({ getAgent,
|
|
62
|
+
getVisitFunction }, (0, helpers_1.actorHooks)(actorManager)), (0, helpers_1.authHooks)(actorManager.agentManager)), (0, helpers_1.agentHooks)(actorManager.agentManager));
|
|
63
|
+
};
|
|
64
|
+
exports.createReactor = createReactor;
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.authHooks = void 0;
|
|
13
13
|
const zustand_1 = require("zustand");
|
|
14
14
|
const react_1 = require("react");
|
|
15
|
-
const
|
|
15
|
+
const utils_1 = require("@ic-reactor/core/dist/utils");
|
|
16
16
|
const authHooks = (agentManager) => {
|
|
17
17
|
const { authenticate: authenticator, getAuth, authStore, isLocalEnv, } = agentManager;
|
|
18
18
|
const useAuthState = () => (0, zustand_1.useStore)(authStore);
|
|
@@ -52,8 +52,8 @@ const authHooks = (agentManager) => {
|
|
|
52
52
|
throw new Error("Auth client not initialized");
|
|
53
53
|
}
|
|
54
54
|
authClient.login(Object.assign(Object.assign({ identityProvider: isLocalEnv
|
|
55
|
-
?
|
|
56
|
-
:
|
|
55
|
+
? utils_1.LOCAL_INTERNET_IDENTITY_PROVIDER
|
|
56
|
+
: utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: () => {
|
|
57
57
|
authenticate()
|
|
58
58
|
.then((identity) => {
|
|
59
59
|
var _a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ActorHooks: import("../../types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useActorState = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Hook for accessing the current state of the actor, including the canister ID.
|
|
7
7
|
*
|
|
@@ -22,4 +22,4 @@ const actorHooks_1 = require("../../actorHooks");
|
|
|
22
22
|
* }
|
|
23
23
|
*```
|
|
24
24
|
*/
|
|
25
|
-
exports.useActorState =
|
|
25
|
+
exports.useActorState = hooks_1.ActorHooks.useActorState;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionName, UseQueryCallParameters } from "
|
|
1
|
+
import { FunctionName, UseQueryCallParameters } from "../../types";
|
|
2
2
|
/**
|
|
3
3
|
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
4
4
|
*
|
|
@@ -25,4 +25,4 @@ import { FunctionName, UseQueryCallParameters } from "../../../types";
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare function useQueryCall<A, M extends FunctionName<A> = FunctionName<A>>(args: UseQueryCallParameters<A, M>): import("
|
|
28
|
+
export declare function useQueryCall<A, M extends FunctionName<A> = FunctionName<A>>(args: UseQueryCallParameters<A, M>): import("../../types").UseMethodCallReturnType<A, M>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useQueryCall = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
7
7
|
*
|
|
@@ -29,6 +29,6 @@ const actorHooks_1 = require("../../actorHooks");
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
function useQueryCall(args) {
|
|
32
|
-
return
|
|
32
|
+
return hooks_1.ActorHooks.useQueryCall(args);
|
|
33
33
|
}
|
|
34
34
|
exports.useQueryCall = useQueryCall;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseActor, FunctionName, UseUpdateCallParameters } from "
|
|
1
|
+
import { BaseActor, FunctionName, UseUpdateCallParameters } from "../../types";
|
|
2
2
|
/**
|
|
3
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
4
|
*
|
|
@@ -26,4 +26,4 @@ import { BaseActor, FunctionName, UseUpdateCallParameters } from "../../../types
|
|
|
26
26
|
* }
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export declare function useUpdateCall<A = BaseActor, M extends FunctionName<A> = FunctionName<A>>(args: UseUpdateCallParameters<A, M>): import("
|
|
29
|
+
export declare function useUpdateCall<A = BaseActor, M extends FunctionName<A> = FunctionName<A>>(args: UseUpdateCallParameters<A, M>): import("../../types").UseMethodCallReturnType<A, M>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useUpdateCall = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
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.
|
|
7
7
|
*
|
|
@@ -30,6 +30,6 @@ const actorHooks_1 = require("../../actorHooks");
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
function useUpdateCall(args) {
|
|
33
|
-
return
|
|
33
|
+
return hooks_1.ActorHooks.useUpdateCall(args);
|
|
34
34
|
}
|
|
35
35
|
exports.useUpdateCall = useUpdateCall;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useVisitMethod = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Memoizes and returns a visit service function for a specific actor method.
|
|
7
7
|
*
|
|
@@ -9,6 +9,6 @@ const actorHooks_1 = require("../../actorHooks");
|
|
|
9
9
|
* @returns The visit service function for the specified method.
|
|
10
10
|
*/
|
|
11
11
|
function useVisitMethod(functionName) {
|
|
12
|
-
return
|
|
12
|
+
return hooks_1.ActorHooks.useVisitMethod(functionName);
|
|
13
13
|
}
|
|
14
14
|
exports.useVisitMethod = useVisitMethod;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AgentHooks: import("../../types").CreateAgentContextReturnType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAgent = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Accesses the current agent instance.
|
|
7
7
|
*
|
|
@@ -15,4 +15,4 @@ const agentHooks_1 = require("../../agentHooks");
|
|
|
15
15
|
* }
|
|
16
16
|
*```
|
|
17
17
|
*/
|
|
18
|
-
exports.useAgent =
|
|
18
|
+
exports.useAgent = hooks_1.AgentHooks.useAgent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAgentManager = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
7
7
|
*
|
|
@@ -15,4 +15,4 @@ const agentHooks_1 = require("../../agentHooks");
|
|
|
15
15
|
* }
|
|
16
16
|
*```
|
|
17
17
|
*/
|
|
18
|
-
exports.useAgentManager =
|
|
18
|
+
exports.useAgentManager = hooks_1.AgentHooks.useAgentManager;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAgentState = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Accesses the current state of the agent.
|
|
7
7
|
*
|
|
@@ -22,4 +22,4 @@ const agentHooks_1 = require("../../agentHooks");
|
|
|
22
22
|
* }
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
exports.useAgentState =
|
|
25
|
+
exports.useAgentState = hooks_1.AgentHooks.useAgentState;
|
|
@@ -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("
|
|
57
|
+
export declare const useAuth: (options?: import("../../types").UseAuthParameters | undefined) => import("../../types").UseAuthReturnType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAuth = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
|
|
7
7
|
* It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
|
|
@@ -58,4 +58,4 @@ const agentHooks_1 = require("../../agentHooks");
|
|
|
58
58
|
*
|
|
59
59
|
* This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
|
|
60
60
|
*/
|
|
61
|
-
exports.useAuth =
|
|
61
|
+
exports.useAuth = hooks_1.AgentHooks.useAuth;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAuthState = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Accesses the current authentication state.
|
|
7
7
|
*
|
|
@@ -20,4 +20,4 @@ const agentHooks_1 = require("../../agentHooks");
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
exports.useAuthState =
|
|
23
|
+
exports.useAuthState = hooks_1.AgentHooks.useAuthState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useUserPrincipal = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
5
|
/**
|
|
6
6
|
* Accesses the user's principal.
|
|
7
7
|
*
|
|
@@ -18,4 +18,4 @@ const agentHooks_1 = require("../../agentHooks");
|
|
|
18
18
|
* }
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
exports.useUserPrincipal =
|
|
21
|
+
exports.useUserPrincipal = hooks_1.AgentHooks.useUserPrincipal;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { IDL } from "@dfinity/candid";
|
|
3
|
-
import { AgentContext } from "../types";
|
|
4
|
-
import { ActorHooksReturnType, ActorManagerParameters, BaseActor } from "
|
|
3
|
+
import { AgentContext } from "../context/types";
|
|
4
|
+
import { ActorHooksReturnType, ActorManagerParameters, BaseActor } from "../types";
|
|
5
5
|
export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
6
6
|
canisterId: string;
|
|
7
7
|
idlFactory?: IDL.InterfaceFactory;
|
|
@@ -24,7 +24,7 @@ exports.useActor = void 0;
|
|
|
24
24
|
const core_1 = require("@ic-reactor/core");
|
|
25
25
|
const react_1 = require("react");
|
|
26
26
|
const useAgentManager_1 = require("./agent/useAgentManager");
|
|
27
|
-
const helpers_1 = require("
|
|
27
|
+
const helpers_1 = require("../helpers");
|
|
28
28
|
/**
|
|
29
29
|
* A comprehensive hook that manages both the fetching of Candid interfaces
|
|
30
30
|
* and the initialization of actor stores for Internet Computer (IC) canisters.
|
|
@@ -95,8 +95,8 @@ const useActor = (config) => {
|
|
|
95
95
|
fetchError: null,
|
|
96
96
|
});
|
|
97
97
|
const agentManager = (0, useAgentManager_1.useAgentManager)(agentContext);
|
|
98
|
-
const fetchCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
if (!canisterId)
|
|
98
|
+
const fetchCandid = (0, react_1.useCallback)((agent) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
if (!canisterId || fetching)
|
|
100
100
|
return;
|
|
101
101
|
setState({
|
|
102
102
|
idlFactory: undefined,
|
|
@@ -105,7 +105,7 @@ const useActor = (config) => {
|
|
|
105
105
|
});
|
|
106
106
|
try {
|
|
107
107
|
const candidManager = (0, core_1.createCandidAdapter)({
|
|
108
|
-
|
|
108
|
+
agent,
|
|
109
109
|
didjsCanisterId,
|
|
110
110
|
});
|
|
111
111
|
const { idlFactory } = yield candidManager.getCandidDefinition(canisterId);
|
|
@@ -125,13 +125,9 @@ const useActor = (config) => {
|
|
|
125
125
|
fetching: false,
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
}), [canisterId, didjsCanisterId
|
|
128
|
+
}), [canisterId, didjsCanisterId]);
|
|
129
129
|
// Automatically fetch Candid if not already fetched or provided.
|
|
130
|
-
(0, react_1.useEffect)(() =>
|
|
131
|
-
if (!fetching && !idlFactory) {
|
|
132
|
-
fetchCandid();
|
|
133
|
-
}
|
|
134
|
-
}, [fetchCandid]);
|
|
130
|
+
(0, react_1.useEffect)(() => agentManager.subscribeAgent(fetchCandid, !maybeIdlFactory), [fetchCandid, agentManager]);
|
|
135
131
|
const hooks = (0, react_1.useMemo)(() => {
|
|
136
132
|
if (!idlFactory)
|
|
137
133
|
return null;
|
|
@@ -139,7 +135,7 @@ const useActor = (config) => {
|
|
|
139
135
|
idlFactory,
|
|
140
136
|
canisterId }, actorConfig));
|
|
141
137
|
return (0, helpers_1.actorHooks)(actorManager);
|
|
142
|
-
}, [idlFactory]);
|
|
138
|
+
}, [canisterId, idlFactory]);
|
|
143
139
|
return { hooks, fetching, fetchError };
|
|
144
140
|
};
|
|
145
141
|
exports.useActor = useActor;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./createReactor";
|
|
2
|
+
export * from "./context/actor";
|
|
3
|
+
export * from "./context/agent";
|
|
4
|
+
export * from "./provider/actor";
|
|
5
|
+
export * from "./provider/agent";
|
|
6
|
+
export * from "./hooks";
|
|
3
7
|
export * as helpers from "./helpers";
|
|
4
8
|
export * as types from "./types";
|
|
5
9
|
export * as core from "./core";
|
package/dist/index.js
CHANGED
|
@@ -27,8 +27,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.core = exports.types = exports.helpers = void 0;
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
__exportStar(require("./
|
|
30
|
+
__exportStar(require("./createReactor"), exports);
|
|
31
|
+
__exportStar(require("./context/actor"), exports);
|
|
32
|
+
__exportStar(require("./context/agent"), exports);
|
|
33
|
+
__exportStar(require("./provider/actor"), exports);
|
|
34
|
+
__exportStar(require("./provider/agent"), exports);
|
|
35
|
+
__exportStar(require("./hooks"), exports);
|
|
32
36
|
exports.helpers = __importStar(require("./helpers"));
|
|
33
37
|
exports.types = __importStar(require("./types"));
|
|
34
38
|
exports.core = __importStar(require("./core"));
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
25
25
|
*/
|
|
26
|
-
export declare const ActorProvider: import("react").FC<import("
|
|
26
|
+
export declare const ActorProvider: import("react").FC<import("../types").ActorProviderProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActorProvider = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("../hooks/actor/hooks");
|
|
5
5
|
/**
|
|
6
6
|
* `ActorProvider` is a React functional component that serves as a context provider for IC actor interactions within a React application.
|
|
7
7
|
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided canister ID and configuration.
|
|
@@ -26,4 +26,4 @@ const actorHooks_1 = require("./actorHooks");
|
|
|
26
26
|
* ```
|
|
27
27
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
28
28
|
*/
|
|
29
|
-
exports.ActorProvider =
|
|
29
|
+
exports.ActorProvider = hooks_1.ActorHooks.ActorProvider;
|
|
@@ -26,4 +26,4 @@
|
|
|
26
26
|
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
27
27
|
* manage authentication, and perform other agent-related tasks.
|
|
28
28
|
*/
|
|
29
|
-
export declare const AgentProvider: import("react").FC<import("
|
|
29
|
+
export declare const AgentProvider: import("react").FC<import("../types").AgentProviderProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentProvider = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hooks_1 = require("../hooks/agent/hooks");
|
|
5
5
|
/**
|
|
6
6
|
* `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
7
7
|
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
@@ -29,4 +29,4 @@ const agentHooks_1 = require("./agentHooks");
|
|
|
29
29
|
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
30
30
|
* manage authentication, and perform other agent-related tasks.
|
|
31
31
|
*/
|
|
32
|
-
exports.AgentProvider =
|
|
32
|
+
exports.AgentProvider = hooks_1.AgentHooks.AgentProvider;
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface CreateReactorReturnType<A> extends ActorHooksReturnType<A>, Aut
|
|
|
6
6
|
getAgent: () => HttpAgent;
|
|
7
7
|
getVisitFunction: () => VisitService<A>;
|
|
8
8
|
}
|
|
9
|
-
export * from "./
|
|
9
|
+
export * from "./context/types";
|
|
10
10
|
export * from "./helpers/types";
|
|
11
|
+
export * from "./hooks/types";
|
|
11
12
|
export * from "@ic-reactor/core/dist/types";
|
package/dist/types.js
CHANGED
|
@@ -14,6 +14,7 @@ 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("./
|
|
17
|
+
__exportStar(require("./context/types"), exports);
|
|
18
18
|
__exportStar(require("./helpers/types"), exports);
|
|
19
|
+
__exportStar(require("./hooks/types"), exports);
|
|
19
20
|
__exportStar(require("@ic-reactor/core/dist/types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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.0.
|
|
38
|
+
"@ic-reactor/core": "^1.0.6",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": ">=16.8",
|
|
49
49
|
"zustand": "4.5"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "bf69ae06def96cd40814a72535325f7c7a8a6b5a"
|
|
52
52
|
}
|
package/dist/main.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { BaseActor, CreateReactorParameters, CreateReactorReturnType } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application.
|
|
4
|
-
* It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.
|
|
5
|
-
*
|
|
6
|
-
* @param config Configuration config for the reactor, including:
|
|
7
|
-
* - withProcessEnv (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
|
|
8
|
-
* - isLocalEnv (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
|
|
9
|
-
* - port (optional): Port number for the local or development environment.
|
|
10
|
-
* Extends `CreateReactorStoreParameters` which includes HTTP agent config, actor manager config (excluding `agentManager`), and an optional custom agent manager.
|
|
11
|
-
*
|
|
12
|
-
* @returns An object containing various hooks and utilities:
|
|
13
|
-
* - getAgent: Function to retrieve the configured IC agent.
|
|
14
|
-
* - getVisitFunction: Function to access the visit function from the actor manager, used for visitor pattern implementations.
|
|
15
|
-
* - Includes actor, auth, and agent hooks for state management, authentication, and agent operations.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { createReactor } from "@ic-reactor/react";
|
|
20
|
-
* import type { CreateReactorCoreParameters } from "@ic-reactor/react/dist/types";
|
|
21
|
-
* import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"
|
|
22
|
-
*
|
|
23
|
-
* const config: CreateReactorCoreParameters = {
|
|
24
|
-
* canisterId,
|
|
25
|
-
* idlFactory,
|
|
26
|
-
* host: "https://localhost:8000", // IC network host |
|
|
27
|
-
* isLocalEnv: true, // Set true for local network | one of these
|
|
28
|
-
* withProcessEnv: true, // Use process.env to determine host |
|
|
29
|
-
* port: 8000, // Port number for local network |
|
|
30
|
-
* };
|
|
31
|
-
*
|
|
32
|
-
* export type YourActor = typeof yourActor;
|
|
33
|
-
*
|
|
34
|
-
* export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
|
|
35
|
-
* // Now you can use the returned hooks in your React components
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare const createReactor: <A = BaseActor>(config: CreateReactorParameters) => CreateReactorReturnType<A>;
|
package/dist/main.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createReactor = void 0;
|
|
4
|
-
const core_1 = require("@ic-reactor/core");
|
|
5
|
-
const helpers_1 = require("./helpers");
|
|
6
|
-
/**
|
|
7
|
-
* Initializes and configures the reactor environment for interacting with the Internet Computer (IC) blockchain within a React application.
|
|
8
|
-
* It encapsulates the creation of actors, authentication, and agent management, offering a streamlined interface for blockchain interactions.
|
|
9
|
-
*
|
|
10
|
-
* @param config Configuration config for the reactor, including:
|
|
11
|
-
* - withProcessEnv (optional): Specifies whether to use process environment variables to determine if the environment is local or development. Defaults to false.
|
|
12
|
-
* - isLocalEnv (optional): Indicates if the current environment is local or development, influencing the agent and actor behavior. Useful for testing or development.
|
|
13
|
-
* - port (optional): Port number for the local or development environment.
|
|
14
|
-
* Extends `CreateReactorStoreParameters` which includes HTTP agent config, actor manager config (excluding `agentManager`), and an optional custom agent manager.
|
|
15
|
-
*
|
|
16
|
-
* @returns An object containing various hooks and utilities:
|
|
17
|
-
* - getAgent: Function to retrieve the configured IC agent.
|
|
18
|
-
* - getVisitFunction: Function to access the visit function from the actor manager, used for visitor pattern implementations.
|
|
19
|
-
* - Includes actor, auth, and agent hooks for state management, authentication, and agent operations.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* import { createReactor } from "@ic-reactor/react";
|
|
24
|
-
* import type { CreateReactorCoreParameters } from "@ic-reactor/react/dist/types";
|
|
25
|
-
* import { canisterId, idlFactory, yourActor } from "./declaration/yourActor"
|
|
26
|
-
*
|
|
27
|
-
* const config: CreateReactorCoreParameters = {
|
|
28
|
-
* canisterId,
|
|
29
|
-
* idlFactory,
|
|
30
|
-
* host: "https://localhost:8000", // IC network host |
|
|
31
|
-
* isLocalEnv: true, // Set true for local network | one of these
|
|
32
|
-
* withProcessEnv: true, // Use process.env to determine host |
|
|
33
|
-
* port: 8000, // Port number for local network |
|
|
34
|
-
* };
|
|
35
|
-
*
|
|
36
|
-
* export type YourActor = typeof yourActor;
|
|
37
|
-
*
|
|
38
|
-
* export const { useAuth, useQueryCall, useUpdateCall } = createReactor<YourActor>(config);
|
|
39
|
-
* // Now you can use the returned hooks in your React components
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const createReactor = (config) => {
|
|
43
|
-
const actorManager = (0, core_1.createReactorStore)(config);
|
|
44
|
-
const getVisitFunction = () => {
|
|
45
|
-
return actorManager.visitFunction;
|
|
46
|
-
};
|
|
47
|
-
const getAgent = () => {
|
|
48
|
-
return actorManager.agentManager.getAgent();
|
|
49
|
-
};
|
|
50
|
-
return Object.assign(Object.assign(Object.assign({ getAgent,
|
|
51
|
-
getVisitFunction }, (0, helpers_1.actorHooks)(actorManager)), (0, helpers_1.authHooks)(actorManager.agentManager)), (0, helpers_1.agentHooks)(actorManager.agentManager));
|
|
52
|
-
};
|
|
53
|
-
exports.createReactor = createReactor;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const ActorHooks: import("./types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const AgentHooks: import("./types").CreateAgentContextReturnType;
|
package/dist/provider/index.d.ts
DELETED
package/dist/provider/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
exports.createAgentContext = exports.createActorContext = void 0;
|
|
18
|
-
var actor_1 = require("./context/actor");
|
|
19
|
-
Object.defineProperty(exports, "createActorContext", { enumerable: true, get: function () { return actor_1.createActorContext; } });
|
|
20
|
-
var agent_1 = require("./context/agent");
|
|
21
|
-
Object.defineProperty(exports, "createAgentContext", { enumerable: true, get: function () { return agent_1.createAgentContext; } });
|
|
22
|
-
__exportStar(require("./hooks"), exports);
|
|
23
|
-
__exportStar(require("./ActorProvider"), exports);
|
|
24
|
-
__exportStar(require("./AgentProvider"), exports);
|
package/dist/provider/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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("./hooks/types"), exports);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|