@ic-reactor/react 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/types.d.ts +1 -2
- package/dist/helpers/authHooks.js +5 -4
- package/dist/helpers/extractAgentContext.js +4 -4
- package/dist/hooks/actor/useMethod.d.ts +3 -3
- package/dist/hooks/actor/useMethod.js +3 -3
- package/dist/hooks/agent/useAgentManager.d.ts +1 -2
- package/dist/hooks/agent/useCandidAdapter.d.ts +0 -3
- package/dist/hooks/agent/useCandidAdapter.js +3 -4
- package/dist/hooks/types.d.ts +0 -3
- package/dist/hooks/useActor.js +2 -3
- package/package.json +3 -3
package/dist/context/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface CreateAgentCotextParameters extends AgentManagerParameters {
|
|
|
8
8
|
disableAuthenticateOnMount?: boolean;
|
|
9
9
|
}
|
|
10
10
|
export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
|
|
11
|
-
useAgentManager: (
|
|
11
|
+
useAgentManager: () => AgentManager;
|
|
12
12
|
AgentProvider: React.FC<AgentProviderProps>;
|
|
13
13
|
}
|
|
14
14
|
export interface AgentProviderProps extends PropsWithChildren, CreateAgentCotextParameters {
|
|
@@ -25,7 +25,6 @@ export interface ActorProviderProps extends CreateActorContextParameters {
|
|
|
25
25
|
export interface CreateActorContextParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
26
26
|
didjsId?: string;
|
|
27
27
|
canisterId?: string;
|
|
28
|
-
agentContext?: React.Context<AgentContext | null>;
|
|
29
28
|
idlFactory?: IDL.InterfaceFactory;
|
|
30
29
|
loadingComponent?: React.ReactNode;
|
|
31
30
|
}
|
|
@@ -18,6 +18,7 @@ const authHooks = (agentManager) => {
|
|
|
18
18
|
const useAuthState = () => (0, zustand_1.useStore)(authStore);
|
|
19
19
|
const useUserPrincipal = () => { var _a, _b; return (_b = (_a = useAuthState()) === null || _a === void 0 ? void 0 : _a.identity) === null || _b === void 0 ? void 0 : _b.getPrincipal(); };
|
|
20
20
|
const useAuth = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
|
|
21
|
+
const network = React.useRef("ic");
|
|
21
22
|
const [loginState, setLoginState] = React.useState({
|
|
22
23
|
loading: false,
|
|
23
24
|
error: undefined,
|
|
@@ -94,12 +95,12 @@ const authHooks = (agentManager) => {
|
|
|
94
95
|
yield authenticate();
|
|
95
96
|
onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
|
|
96
97
|
}), [onLoggedOut]);
|
|
97
|
-
React.useEffect(() => {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
React.useEffect(() => agentManager.subscribeAgentState((state) => {
|
|
99
|
+
if (network.current !== state.network) {
|
|
100
|
+
network.current = state.network;
|
|
100
101
|
authenticate();
|
|
101
102
|
}
|
|
102
|
-
}, [
|
|
103
|
+
}), []);
|
|
103
104
|
return {
|
|
104
105
|
authenticated,
|
|
105
106
|
authenticating,
|
|
@@ -31,15 +31,15 @@ const react_1 = __importDefault(require("react"));
|
|
|
31
31
|
* This context provides the necessary agent functionalities and state management capabilities required by the hooks.
|
|
32
32
|
*/
|
|
33
33
|
const extractAgentContext = (agentContext) => {
|
|
34
|
-
const useAgentContext = (
|
|
35
|
-
const context = react_1.default.useContext(
|
|
34
|
+
const useAgentContext = () => {
|
|
35
|
+
const context = react_1.default.useContext(agentContext);
|
|
36
36
|
if (!context) {
|
|
37
37
|
throw new Error("Agent hooks must be used within a AgentProvider");
|
|
38
38
|
}
|
|
39
39
|
return context;
|
|
40
40
|
};
|
|
41
|
-
const useAgentManager = (
|
|
42
|
-
const context = useAgentContext(
|
|
41
|
+
const useAgentManager = () => {
|
|
42
|
+
const context = useAgentContext();
|
|
43
43
|
return context.agentManager;
|
|
44
44
|
};
|
|
45
45
|
const useAgent = () => useAgentContext().useAgent();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
2
|
+
* Hook for making dynamically update or query calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
3
3
|
*
|
|
4
4
|
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
5
5
|
* @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).
|
|
6
6
|
* @example
|
|
7
7
|
* ```tsx
|
|
8
|
-
* function
|
|
9
|
-
* const { call, data, loading } =
|
|
8
|
+
* function MethodCallComponent() {
|
|
9
|
+
* const { call, data, loading } = useMethod({
|
|
10
10
|
* functionName: 'updateUserProfile',
|
|
11
11
|
* args: ['123', { name: 'John Doe' }],
|
|
12
12
|
* onLoading: (loading) => console.log('Loading:', loading),
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useMethod = void 0;
|
|
4
4
|
const hooks_1 = require("./hooks");
|
|
5
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.
|
|
6
|
+
* Hook for making dynamically update or query calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
7
7
|
*
|
|
8
8
|
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
9
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
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
|
-
* function
|
|
13
|
-
* const { call, data, loading } =
|
|
12
|
+
* function MethodCallComponent() {
|
|
13
|
+
* const { call, data, loading } = useMethod({
|
|
14
14
|
* functionName: 'updateUserProfile',
|
|
15
15
|
* args: ['123', { name: 'John Doe' }],
|
|
16
16
|
* onLoading: (loading) => console.log('Loading:', loading),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/**
|
|
3
2
|
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
4
3
|
*
|
|
@@ -12,4 +11,4 @@
|
|
|
12
11
|
* }
|
|
13
12
|
*```
|
|
14
13
|
*/
|
|
15
|
-
export declare const useAgentManager: (
|
|
14
|
+
export declare const useAgentManager: () => import("@ic-reactor/core/dist/types").AgentManager;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { CandidAdapter } from "@ic-reactor/core/dist/classes";
|
|
3
|
-
import { AgentContext } from "../../types";
|
|
4
2
|
export interface UseCandidAdapterParams {
|
|
5
|
-
agentContext?: React.Context<AgentContext | null>;
|
|
6
3
|
didjsCanisterId?: string;
|
|
7
4
|
}
|
|
8
5
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCandidAdapter = void 0;
|
|
4
|
-
const useAgentManager_1 = require("./useAgentManager");
|
|
5
4
|
const react_1 = require("react");
|
|
6
5
|
const core_1 = require("@ic-reactor/core");
|
|
6
|
+
const useAgent_1 = require("./useAgent");
|
|
7
7
|
/**
|
|
8
8
|
* Accesses the `CandidAdapter` to download the actor's Candid interface.
|
|
9
9
|
*
|
|
@@ -28,9 +28,8 @@ const core_1 = require("@ic-reactor/core");
|
|
|
28
28
|
*/
|
|
29
29
|
const useCandidAdapter = (config) => {
|
|
30
30
|
const [candidAdapter, setCandidAdapter] = (0, react_1.useState)();
|
|
31
|
-
const
|
|
31
|
+
const agent = (0, useAgent_1.useAgent)();
|
|
32
32
|
(0, react_1.useEffect)(() => {
|
|
33
|
-
const agent = agentManager.getAgent();
|
|
34
33
|
try {
|
|
35
34
|
const candidManager = (0, core_1.createCandidAdapter)({
|
|
36
35
|
agent,
|
|
@@ -42,7 +41,7 @@ const useCandidAdapter = (config) => {
|
|
|
42
41
|
// eslint-disable-next-line no-console
|
|
43
42
|
console.error("Error creating CandidAdapter", error);
|
|
44
43
|
}
|
|
45
|
-
}, [
|
|
44
|
+
}, [agent, config.didjsCanisterId]);
|
|
46
45
|
return candidAdapter;
|
|
47
46
|
};
|
|
48
47
|
exports.useCandidAdapter = useCandidAdapter;
|
package/dist/hooks/types.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { IDL } from "@dfinity/candid";
|
|
3
|
-
import { AgentContext } from "../context/types";
|
|
4
2
|
import { ActorHooksReturnType, ActorManagerParameters, BaseActor } from "../types";
|
|
5
3
|
export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
6
4
|
canisterId: string;
|
|
7
5
|
idlFactory?: IDL.InterfaceFactory;
|
|
8
|
-
agentContext?: React.Context<AgentContext | null>;
|
|
9
6
|
didjsCanisterId?: string;
|
|
10
7
|
}
|
|
11
8
|
export interface UseActorReturn<A = BaseActor> {
|
package/dist/hooks/useActor.js
CHANGED
|
@@ -90,7 +90,7 @@ const useCandidAdapter_1 = require("./agent/useCandidAdapter");
|
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
92
|
const useActor = (config) => {
|
|
93
|
-
const { canisterId, idlFactory: maybeIdlFactory,
|
|
93
|
+
const { canisterId, idlFactory: maybeIdlFactory, didjsCanisterId } = config, actorConfig = __rest(config, ["canisterId", "idlFactory", "didjsCanisterId"]);
|
|
94
94
|
if (!canisterId) {
|
|
95
95
|
throw new Error("canisterId is required");
|
|
96
96
|
}
|
|
@@ -106,7 +106,6 @@ const useActor = (config) => {
|
|
|
106
106
|
fetchError: null,
|
|
107
107
|
});
|
|
108
108
|
const candidAdapter = (0, useCandidAdapter_1.useCandidAdapter)({
|
|
109
|
-
agentContext,
|
|
110
109
|
didjsCanisterId,
|
|
111
110
|
});
|
|
112
111
|
const authenticating = (0, agent_1.useAuthState)().authenticating;
|
|
@@ -134,7 +133,7 @@ const useActor = (config) => {
|
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
}), [canisterId, candidAdapter, authenticating, didjsCanisterId]);
|
|
137
|
-
const agentManager = (0, useAgentManager_1.useAgentManager)(
|
|
136
|
+
const agentManager = (0, useAgentManager_1.useAgentManager)();
|
|
138
137
|
const initialActorManager = (0, react_1.useCallback)((idlFactory) => {
|
|
139
138
|
if (authenticating)
|
|
140
139
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A React library for interacting with Internet Computer canisters",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/core": "^1.4.
|
|
38
|
+
"@ic-reactor/core": "^1.4.2",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"react": ">=16.8",
|
|
48
48
|
"zustand": "4.5"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "89bab92f75cbbe39c9bdd6a0ac60344c6844ce5d"
|
|
51
51
|
}
|