@ic-reactor/react 1.0.5 → 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/README.md +7 -8
- package/dist/context/actor.d.ts +64 -0
- package/dist/context/actor.js +117 -0
- package/dist/context/agent.d.ts +74 -0
- package/dist/context/agent.js +128 -0
- 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 +14 -18
- package/dist/helpers/extractActorContext.js +0 -82
- package/dist/helpers/extractAgentContext.d.ts +1 -1
- package/dist/helpers/extractAgentContext.js +3 -81
- package/dist/helpers/types.d.ts +15 -15
- package/dist/hooks/actor/hooks.d.ts +1 -0
- package/dist/hooks/actor/hooks.js +5 -0
- package/dist/hooks/actor/index.d.ts +4 -0
- package/dist/{provider/types.js → hooks/actor/index.js} +4 -1
- package/dist/hooks/actor/useActorState.d.ts +21 -0
- package/dist/hooks/actor/useActorState.js +25 -0
- package/dist/hooks/actor/useQueryCall.d.ts +28 -0
- package/dist/hooks/actor/useQueryCall.js +34 -0
- package/dist/hooks/actor/useUpdateCall.d.ts +29 -0
- package/dist/hooks/actor/useUpdateCall.js +35 -0
- package/dist/hooks/actor/useVisitMethod.d.ts +8 -0
- package/dist/hooks/actor/useVisitMethod.js +14 -0
- package/dist/hooks/agent/hooks.d.ts +1 -0
- package/dist/hooks/agent/hooks.js +5 -0
- package/dist/hooks/agent/index.d.ts +6 -0
- package/dist/hooks/agent/index.js +22 -0
- package/dist/hooks/agent/useAgent.d.ts +14 -0
- package/dist/hooks/agent/useAgent.js +18 -0
- package/dist/hooks/agent/useAgentManager.d.ts +15 -0
- package/dist/hooks/agent/useAgentManager.js +18 -0
- package/dist/hooks/agent/useAgentState.d.ts +21 -0
- package/dist/hooks/agent/useAgentState.js +25 -0
- package/dist/hooks/agent/useAuth.d.ts +57 -0
- package/dist/hooks/agent/useAuth.js +61 -0
- package/dist/hooks/agent/useAuthState.d.ts +19 -0
- package/dist/hooks/agent/useAuthState.js +23 -0
- package/dist/hooks/agent/useUserPrincipal.d.ts +17 -0
- package/dist/hooks/agent/useUserPrincipal.js +21 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/{provider/hooks → hooks}/index.js +2 -0
- 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 +6 -4
- package/dist/{provider/hooks → hooks}/useActor.js +14 -16
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/provider/actor.d.ts +18 -56
- package/dist/provider/actor.js +19 -107
- package/dist/provider/agent.d.ts +20 -62
- package/dist/provider/agent.js +21 -113
- 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/ActorProvider.d.ts +0 -27
- package/dist/provider/ActorProvider.js +0 -30
- package/dist/provider/AgentProvider.d.ts +0 -30
- package/dist/provider/AgentProvider.js +0 -33
- package/dist/provider/hooks/index.d.ts +0 -1
- package/dist/provider/index.d.ts +0 -8
- package/dist/provider/index.js +0 -25
- /package/dist/{provider/hooks → context}/types.js +0 -0
package/dist/provider/agent.d.ts
CHANGED
|
@@ -1,71 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import type { CreateAgentContextReturnType } from "./types";
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
4
|
+
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
|
|
7
|
+
* create various hooks related to agent operations and authentication processes. These hooks are made available to all
|
|
8
|
+
* child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
|
|
8
9
|
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* @param children - Child components that can consume the context.
|
|
11
|
+
* @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
|
|
12
|
+
* will be created based on the provided options combined with default configuration.
|
|
13
|
+
* @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
|
|
14
|
+
* specified during the context creation and can include custom settings for the agent, such as identity,
|
|
15
|
+
* host URL, etc.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
|
-
*
|
|
18
|
-
* // agent.ts
|
|
19
|
-
* import { createAgentContext } from "@ic-reactor/react";
|
|
20
|
-
* import { CreateAgentParameters } from "@ic-reactor/react/dist/types";
|
|
21
|
-
*
|
|
22
|
-
* // Optional: Define custom agent configuration
|
|
23
|
-
* const agentConfig: CreateAgentParameters = {
|
|
24
|
-
* host: "https://localhost:8000",
|
|
25
|
-
* // or
|
|
26
|
-
* // isLocalEnv: true,
|
|
27
|
-
* // port: 8000,
|
|
28
|
-
* };
|
|
29
|
-
*
|
|
30
|
-
* export const {
|
|
31
|
-
* AgentProvider,
|
|
32
|
-
* useAgent,
|
|
33
|
-
* useAuthClient,
|
|
34
|
-
* useAuthState,
|
|
35
|
-
* useAgentState,
|
|
36
|
-
* useAgentManager,
|
|
37
|
-
* useUserPrincipal,
|
|
38
|
-
* } = createAgentContext(agentConfig);
|
|
39
|
-
*
|
|
40
|
-
* // Now you can use the returned hooks in your React components
|
|
41
|
-
*
|
|
42
|
-
* // App.tsx
|
|
43
|
-
* import React from 'react';
|
|
44
|
-
* import { AgentProvider } from './agent';
|
|
45
|
-
*
|
|
46
|
-
* const App = () => (
|
|
47
|
-
* <AgentProvider>
|
|
48
|
-
* <Login />
|
|
49
|
-
* <YourActor />
|
|
50
|
-
* </AgentProvider>
|
|
51
|
-
* );
|
|
52
|
-
*
|
|
53
|
-
* const Login = () => {
|
|
54
|
-
* const { login } = useAuthClient()
|
|
55
|
-
* const principal = useUserPrincipal()
|
|
56
|
-
*
|
|
57
|
-
* return (
|
|
58
|
-
* <div>
|
|
59
|
-
* <button onClick={() => login()}>Login</button>
|
|
60
|
-
* <p>User: {principal?.toText()}</p>
|
|
61
|
-
* </div>
|
|
62
|
-
* )
|
|
63
|
-
* };
|
|
18
|
+
* Wrap your component tree with `AgentProvider` to provide all child components access to IC agent and authentication hooks.
|
|
64
19
|
*
|
|
20
|
+
* ```jsx
|
|
21
|
+
* <AgentProvider>
|
|
22
|
+
* <YourComponent />
|
|
23
|
+
* </AgentProvider>
|
|
65
24
|
* ```
|
|
66
25
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* with the Internet Computer blockchain.
|
|
26
|
+
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
27
|
+
* manage authentication, and perform other agent-related tasks.
|
|
70
28
|
*/
|
|
71
|
-
export declare const
|
|
29
|
+
export declare const AgentProvider: import("react").FC<import("../types").AgentProviderProps>;
|
package/dist/provider/agent.js
CHANGED
|
@@ -1,124 +1,32 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.
|
|
38
|
-
const
|
|
39
|
-
const core_1 = require("@ic-reactor/core");
|
|
40
|
-
const agentHooks_1 = require("../helpers/agentHooks");
|
|
41
|
-
const authHooks_1 = require("../helpers/authHooks");
|
|
42
|
-
const extractAgentContext_1 = require("../helpers/extractAgentContext");
|
|
3
|
+
exports.AgentProvider = void 0;
|
|
4
|
+
const hooks_1 = require("../hooks/agent/hooks");
|
|
43
5
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
6
|
+
* `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
7
|
+
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
46
8
|
*
|
|
47
|
-
*
|
|
9
|
+
* The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
|
|
10
|
+
* create various hooks related to agent operations and authentication processes. These hooks are made available to all
|
|
11
|
+
* child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
|
|
48
12
|
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
13
|
+
* @param children - Child components that can consume the context.
|
|
14
|
+
* @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
|
|
15
|
+
* will be created based on the provided options combined with default configuration.
|
|
16
|
+
* @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
|
|
17
|
+
* specified during the context creation and can include custom settings for the agent, such as identity,
|
|
18
|
+
* host URL, etc.
|
|
55
19
|
*
|
|
56
20
|
* @example
|
|
57
|
-
*
|
|
58
|
-
* // agent.ts
|
|
59
|
-
* import { createAgentContext } from "@ic-reactor/react";
|
|
60
|
-
* import { CreateAgentParameters } from "@ic-reactor/react/dist/types";
|
|
61
|
-
*
|
|
62
|
-
* // Optional: Define custom agent configuration
|
|
63
|
-
* const agentConfig: CreateAgentParameters = {
|
|
64
|
-
* host: "https://localhost:8000",
|
|
65
|
-
* // or
|
|
66
|
-
* // isLocalEnv: true,
|
|
67
|
-
* // port: 8000,
|
|
68
|
-
* };
|
|
69
|
-
*
|
|
70
|
-
* export const {
|
|
71
|
-
* AgentProvider,
|
|
72
|
-
* useAgent,
|
|
73
|
-
* useAuthClient,
|
|
74
|
-
* useAuthState,
|
|
75
|
-
* useAgentState,
|
|
76
|
-
* useAgentManager,
|
|
77
|
-
* useUserPrincipal,
|
|
78
|
-
* } = createAgentContext(agentConfig);
|
|
79
|
-
*
|
|
80
|
-
* // Now you can use the returned hooks in your React components
|
|
81
|
-
*
|
|
82
|
-
* // App.tsx
|
|
83
|
-
* import React from 'react';
|
|
84
|
-
* import { AgentProvider } from './agent';
|
|
85
|
-
*
|
|
86
|
-
* const App = () => (
|
|
87
|
-
* <AgentProvider>
|
|
88
|
-
* <Login />
|
|
89
|
-
* <YourActor />
|
|
90
|
-
* </AgentProvider>
|
|
91
|
-
* );
|
|
92
|
-
*
|
|
93
|
-
* const Login = () => {
|
|
94
|
-
* const { login } = useAuthClient()
|
|
95
|
-
* const principal = useUserPrincipal()
|
|
96
|
-
*
|
|
97
|
-
* return (
|
|
98
|
-
* <div>
|
|
99
|
-
* <button onClick={() => login()}>Login</button>
|
|
100
|
-
* <p>User: {principal?.toText()}</p>
|
|
101
|
-
* </div>
|
|
102
|
-
* )
|
|
103
|
-
* };
|
|
21
|
+
* Wrap your component tree with `AgentProvider` to provide all child components access to IC agent and authentication hooks.
|
|
104
22
|
*
|
|
23
|
+
* ```jsx
|
|
24
|
+
* <AgentProvider>
|
|
25
|
+
* <YourComponent />
|
|
26
|
+
* </AgentProvider>
|
|
105
27
|
* ```
|
|
106
28
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* with the Internet Computer blockchain.
|
|
29
|
+
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
30
|
+
* manage authentication, and perform other agent-related tasks.
|
|
110
31
|
*/
|
|
111
|
-
|
|
112
|
-
const AgentContext = (0, react_1.createContext)(null);
|
|
113
|
-
const AgentProvider = (_a) => {
|
|
114
|
-
var { children, agentManager: mybeAgentManager } = _a, options = __rest(_a, ["children", "agentManager"]);
|
|
115
|
-
const hooks = (0, react_1.useMemo)(() => {
|
|
116
|
-
const agentManager = mybeAgentManager !== null && mybeAgentManager !== void 0 ? mybeAgentManager : (0, core_1.createAgentManager)(Object.assign(Object.assign({}, options), config));
|
|
117
|
-
return Object.assign(Object.assign(Object.assign({}, (0, agentHooks_1.agentHooks)(agentManager)), (0, authHooks_1.authHooks)(agentManager)), { agentManager });
|
|
118
|
-
}, [options]);
|
|
119
|
-
return (react_1.default.createElement(AgentContext.Provider, { value: hooks }, children));
|
|
120
|
-
};
|
|
121
|
-
AgentProvider.displayName = "AgentProvider";
|
|
122
|
-
return Object.assign({ AgentProvider }, (0, extractAgentContext_1.extractAgentContext)(AgentContext));
|
|
123
|
-
};
|
|
124
|
-
exports.createAgentContext = createAgentContext;
|
|
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 { useAuthClient, 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 { useAuthClient, 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,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const ActorHooks: import("./types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
|
|
3
|
-
/**
|
|
4
|
-
* `ActorProvider` is a React functional component that serves as a context provider for IC actor interactions within a React application.
|
|
5
|
-
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided canister ID and configuration.
|
|
6
|
-
*
|
|
7
|
-
* Props:
|
|
8
|
-
* - `children`: React Node - The child components that will have access to the actor context.
|
|
9
|
-
* - `canisterId` (optional): string - The Canister ID for actor interactions. If not provided, the default from `createActorContext` is used.
|
|
10
|
-
* - `loadingComponent` (optional): React Node - A component displayed during the loading/fetching state. Defaults to a simple message.
|
|
11
|
-
* - `...restConfig`: Additional configuration options that will be merged with the default configuration provided during context creation.
|
|
12
|
-
*
|
|
13
|
-
* Behavior:
|
|
14
|
-
* - Validates the presence of a `canisterId`. Throws an error if it is missing, ensuring that a valid canister ID is always used for actor operations.
|
|
15
|
-
* - Utilizes `useMemo` to combine the default configuration with the props provided to the `ActorProvider`, optimizing for performance by avoiding unnecessary recalculations.
|
|
16
|
-
* - Employs the `useActor` hook to initiate actor interactions based on the combined configuration, managing states such as `fetching`, `fetchError`, and the actor `hooks`.
|
|
17
|
-
* - Conditionally renders the `loadingComponent` or `fetchError` based on the actor fetching state. Once the actor is ready and no errors are present, it renders the child components, effectively providing them access to the actor context.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```jsx
|
|
21
|
-
* <ActorProvider canisterId="your-canister-id">
|
|
22
|
-
* <YourComponent />
|
|
23
|
-
* </ActorProvider>
|
|
24
|
-
* ```
|
|
25
|
-
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
26
|
-
*/
|
|
27
|
-
export declare const ActorProvider: import("react").FC<import("./types").ActorProviderProps>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActorProvider = exports.ActorHooks = void 0;
|
|
4
|
-
const actor_1 = require("./actor");
|
|
5
|
-
exports.ActorHooks = (0, actor_1.createActorContext)();
|
|
6
|
-
/**
|
|
7
|
-
* `ActorProvider` is a React functional component that serves as a context provider for IC actor interactions within a React application.
|
|
8
|
-
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided canister ID and configuration.
|
|
9
|
-
*
|
|
10
|
-
* Props:
|
|
11
|
-
* - `children`: React Node - The child components that will have access to the actor context.
|
|
12
|
-
* - `canisterId` (optional): string - The Canister ID for actor interactions. If not provided, the default from `createActorContext` is used.
|
|
13
|
-
* - `loadingComponent` (optional): React Node - A component displayed during the loading/fetching state. Defaults to a simple message.
|
|
14
|
-
* - `...restConfig`: Additional configuration options that will be merged with the default configuration provided during context creation.
|
|
15
|
-
*
|
|
16
|
-
* Behavior:
|
|
17
|
-
* - Validates the presence of a `canisterId`. Throws an error if it is missing, ensuring that a valid canister ID is always used for actor operations.
|
|
18
|
-
* - Utilizes `useMemo` to combine the default configuration with the props provided to the `ActorProvider`, optimizing for performance by avoiding unnecessary recalculations.
|
|
19
|
-
* - Employs the `useActor` hook to initiate actor interactions based on the combined configuration, managing states such as `fetching`, `fetchError`, and the actor `hooks`.
|
|
20
|
-
* - Conditionally renders the `loadingComponent` or `fetchError` based on the actor fetching state. Once the actor is ready and no errors are present, it renders the child components, effectively providing them access to the actor context.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```jsx
|
|
24
|
-
* <ActorProvider canisterId="your-canister-id">
|
|
25
|
-
* <YourComponent />
|
|
26
|
-
* </ActorProvider>
|
|
27
|
-
* ```
|
|
28
|
-
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
29
|
-
*/
|
|
30
|
-
exports.ActorProvider = exports.ActorHooks.ActorProvider;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const AgentHooks: import("./types").CreateAgentContextReturnType;
|
|
3
|
-
/**
|
|
4
|
-
* `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
5
|
-
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
6
|
-
*
|
|
7
|
-
* The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
|
|
8
|
-
* create various hooks related to agent operations and authentication processes. These hooks are made available to all
|
|
9
|
-
* child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
|
|
10
|
-
*
|
|
11
|
-
* @param children - Child components that can consume the context.
|
|
12
|
-
* @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
|
|
13
|
-
* will be created based on the provided options combined with default configuration.
|
|
14
|
-
* @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
|
|
15
|
-
* specified during the context creation and can include custom settings for the agent, such as identity,
|
|
16
|
-
* host URL, etc.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* Wrap your component tree with `AgentProvider` to provide all child components access to IC agent and authentication hooks.
|
|
20
|
-
*
|
|
21
|
-
* ```jsx
|
|
22
|
-
* <AgentProvider>
|
|
23
|
-
* <YourComponent />
|
|
24
|
-
* </AgentProvider>
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
28
|
-
* manage authentication, and perform other agent-related tasks.
|
|
29
|
-
*/
|
|
30
|
-
export declare const AgentProvider: import("react").FC<import("./types").AgentProviderProps>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentProvider = exports.AgentHooks = void 0;
|
|
4
|
-
const agent_1 = require("./agent");
|
|
5
|
-
exports.AgentHooks = (0, agent_1.createAgentContext)();
|
|
6
|
-
/**
|
|
7
|
-
* `AgentProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
8
|
-
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
9
|
-
*
|
|
10
|
-
* The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
|
|
11
|
-
* create various hooks related to agent operations and authentication processes. These hooks are made available to all
|
|
12
|
-
* child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
|
|
13
|
-
*
|
|
14
|
-
* @param children - Child components that can consume the context.
|
|
15
|
-
* @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
|
|
16
|
-
* will be created based on the provided options combined with default configuration.
|
|
17
|
-
* @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
|
|
18
|
-
* specified during the context creation and can include custom settings for the agent, such as identity,
|
|
19
|
-
* host URL, etc.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* Wrap your component tree with `AgentProvider` to provide all child components access to IC agent and authentication hooks.
|
|
23
|
-
*
|
|
24
|
-
* ```jsx
|
|
25
|
-
* <AgentProvider>
|
|
26
|
-
* <YourComponent />
|
|
27
|
-
* </AgentProvider>
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
31
|
-
* manage authentication, and perform other agent-related tasks.
|
|
32
|
-
*/
|
|
33
|
-
exports.AgentProvider = exports.AgentHooks.AgentProvider;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./useActor";
|
package/dist/provider/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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 };
|
|
8
|
-
export * from "./hooks";
|
package/dist/provider/index.js
DELETED
|
@@ -1,25 +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
|
-
var _a, _b;
|
|
17
|
-
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");
|
|
20
|
-
Object.defineProperty(exports, "createActorContext", { enumerable: true, get: function () { return actor_1.createActorContext; } });
|
|
21
|
-
const agent_1 = require("./agent");
|
|
22
|
-
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
|
-
__exportStar(require("./hooks"), exports);
|
|
File without changes
|