@ic-reactor/react 1.12.2 → 1.14.1
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/actor/create.js +1 -2
- package/dist/context/actor/hooks/useActorInterface.js +1 -2
- package/dist/context/actor/hooks/useMethod.js +1 -2
- package/dist/context/actor/hooks/useQueryCall.js +1 -2
- package/dist/context/actor/hooks/useUpdateCall.js +1 -2
- package/dist/context/actor/hooks/useVisitMethod.js +1 -2
- package/dist/context/actor/hooks/useVisitService.js +1 -2
- package/dist/context/actor/provider.d.ts +0 -1
- package/dist/context/actor/types.d.ts +0 -1
- package/dist/context/adapter/create.js +1 -2
- package/dist/context/adapter/index.d.ts +0 -1
- package/dist/context/adapter/provider.d.ts +0 -1
- package/dist/context/agent/create.js +1 -2
- package/dist/context/agent/hooks/useAuth.d.ts +1 -1
- package/dist/context/agent/index.d.ts +0 -1
- package/dist/context/agent/provider.d.ts +0 -1
- package/dist/helpers/actorHooks.js +16 -5
- package/dist/helpers/authHooks.js +11 -6
- package/dist/helpers/extractActorContext.js +1 -2
- package/dist/helpers/types.d.ts +2 -2
- package/package.json +9 -8
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createActorContext =
|
|
17
|
+
exports.createActorContext = createActorContext;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const useActor_1 = require("../../hooks/useActor");
|
|
20
20
|
const extractActorContext_1 = require("../../helpers/extractActorContext");
|
|
@@ -112,4 +112,3 @@ function createActorContext(contextConfig = {}) {
|
|
|
112
112
|
return Object.assign({ ActorProvider,
|
|
113
113
|
ActorHookProvider }, (0, extractActorContext_1.extractActorContext)(ActorContext));
|
|
114
114
|
}
|
|
115
|
-
exports.createActorContext = createActorContext;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useActorInterface =
|
|
3
|
+
exports.useActorInterface = useActorInterface;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -8,4 +8,3 @@ const __1 = require("..");
|
|
|
8
8
|
function useActorInterface() {
|
|
9
9
|
return __1.ActorHooks.useActorInterface();
|
|
10
10
|
}
|
|
11
|
-
exports.useActorInterface = useActorInterface;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useMethod =
|
|
3
|
+
exports.useMethod = useMethod;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
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.
|
|
@@ -32,4 +32,3 @@ const __1 = require("..");
|
|
|
32
32
|
function useMethod(args) {
|
|
33
33
|
return __1.ActorHooks.useMethod(args);
|
|
34
34
|
}
|
|
35
|
-
exports.useMethod = useMethod;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useQueryCall =
|
|
3
|
+
exports.useQueryCall = useQueryCall;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
6
|
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
@@ -31,4 +31,3 @@ const __1 = require("..");
|
|
|
31
31
|
function useQueryCall(args) {
|
|
32
32
|
return __1.ActorHooks.useQueryCall(args);
|
|
33
33
|
}
|
|
34
|
-
exports.useQueryCall = useQueryCall;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useUpdateCall =
|
|
3
|
+
exports.useUpdateCall = useUpdateCall;
|
|
4
4
|
const __1 = require("..");
|
|
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.
|
|
@@ -32,4 +32,3 @@ const __1 = require("..");
|
|
|
32
32
|
function useUpdateCall(args) {
|
|
33
33
|
return __1.ActorHooks.useUpdateCall(args);
|
|
34
34
|
}
|
|
35
|
-
exports.useUpdateCall = useUpdateCall;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useVisitMethod =
|
|
3
|
+
exports.useVisitMethod = useVisitMethod;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
6
|
* Memoizes and returns a visit service function for a specific actor method.
|
|
@@ -11,4 +11,3 @@ const __1 = require("..");
|
|
|
11
11
|
function useVisitMethod(functionName) {
|
|
12
12
|
return __1.ActorHooks.useVisitMethod(functionName);
|
|
13
13
|
}
|
|
14
|
-
exports.useVisitMethod = useVisitMethod;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useVisitService =
|
|
3
|
+
exports.useVisitService = useVisitService;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
6
|
* Memoizes and returns a visit service function for a specific actor method.
|
|
@@ -11,4 +11,3 @@ const __1 = require("..");
|
|
|
11
11
|
function useVisitService() {
|
|
12
12
|
return __1.ActorHooks.useVisitService();
|
|
13
13
|
}
|
|
14
|
-
exports.useVisitService = useVisitService;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/**
|
|
3
2
|
* `ActorProvider` is a React functional component that serves as a context provider for IC actor interactions within a React application.
|
|
4
3
|
* It wraps child components, providing them access to actor-specific hooks and functionalities based on the provided canister ID and configuration.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { IDL, ActorHooksReturnType, BaseActor, ActorManagerParameters, CanisterId, InitializeActor } from "../../types";
|
|
3
2
|
export interface CreateActorContextType<A = BaseActor> extends ActorHooksReturnType<A> {
|
|
4
3
|
useInitializeActor?: () => InitializeActor;
|
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createAdapterContext =
|
|
26
|
+
exports.createAdapterContext = createAdapterContext;
|
|
27
27
|
const react_1 = __importDefault(require("react"));
|
|
28
28
|
const agent_1 = require("../agent");
|
|
29
29
|
const core_1 = require("@ic-reactor/core");
|
|
@@ -107,4 +107,3 @@ function createAdapterContext(config = {}) {
|
|
|
107
107
|
useCandidAdapter,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
exports.createAdapterContext = createAdapterContext;
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createAgentContext =
|
|
17
|
+
exports.createAgentContext = createAgentContext;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const core_1 = require("@ic-reactor/core");
|
|
20
20
|
const agentHooks_1 = require("../../helpers/agentHooks");
|
|
@@ -109,4 +109,3 @@ function createAgentContext(config = {}) {
|
|
|
109
109
|
AgentProvider.displayName = "AgentProvider";
|
|
110
110
|
return Object.assign({ AgentContext, AgentProvider }, (0, extractAgentContext_1.extractAgentContext)(AgentContext));
|
|
111
111
|
}
|
|
112
|
-
exports.createAgentContext = createAgentContext;
|
|
@@ -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("../../../types").UseAuthParameters
|
|
57
|
+
export declare const useAuth: (options?: import("../../../types").UseAuthParameters) => import("../../../types").UseAuthReturnType;
|
|
@@ -114,7 +114,7 @@ const actorHooks = (actorManager) => {
|
|
|
114
114
|
}, [functionName]);
|
|
115
115
|
};
|
|
116
116
|
const useSharedCall = (_a) => {
|
|
117
|
-
var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess"]);
|
|
117
|
+
var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess, onSuccessResult } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess", "onSuccessResult"]);
|
|
118
118
|
const requestKey = React.useMemo(() => (0, utils_1.generateRequestHash)(args), [args]);
|
|
119
119
|
const [sharedState, setSharedState] = useMethodState(functionName, requestKey);
|
|
120
120
|
const latestDataRef = React.useRef();
|
|
@@ -130,7 +130,8 @@ const actorHooks = (actorManager) => {
|
|
|
130
130
|
const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
|
|
131
131
|
latestDataRef.current = data;
|
|
132
132
|
setSharedState({ data, error: undefined, loading: false });
|
|
133
|
-
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(
|
|
133
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
134
|
+
onSuccessResult === null || onSuccessResult === void 0 ? void 0 : onSuccessResult((0, utils_1.createCompiledResult)(data));
|
|
134
135
|
onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
|
|
135
136
|
return data;
|
|
136
137
|
}
|
|
@@ -147,7 +148,16 @@ const actorHooks = (actorManager) => {
|
|
|
147
148
|
if (throwOnError)
|
|
148
149
|
throw error;
|
|
149
150
|
}
|
|
150
|
-
}), [
|
|
151
|
+
}), [
|
|
152
|
+
args,
|
|
153
|
+
functionName,
|
|
154
|
+
options,
|
|
155
|
+
onError,
|
|
156
|
+
onLoading,
|
|
157
|
+
onSuccess,
|
|
158
|
+
onSuccessResult,
|
|
159
|
+
throwOnError,
|
|
160
|
+
]);
|
|
151
161
|
const compileResult = () => {
|
|
152
162
|
return (0, utils_1.createCompiledResult)(latestDataRef.current || (sharedState === null || sharedState === void 0 ? void 0 : sharedState.data));
|
|
153
163
|
};
|
|
@@ -161,7 +171,7 @@ const actorHooks = (actorManager) => {
|
|
|
161
171
|
const _b = useSharedCall(rest), { call, requestKey } = _b, state = __rest(_b, ["call", "requestKey"]);
|
|
162
172
|
const intervalId = React.useRef();
|
|
163
173
|
React.useEffect(() => {
|
|
164
|
-
var _a;
|
|
174
|
+
var _a, _b;
|
|
165
175
|
if (refetchInterval) {
|
|
166
176
|
intervalId.current = setInterval(call, refetchInterval);
|
|
167
177
|
}
|
|
@@ -169,7 +179,8 @@ const actorHooks = (actorManager) => {
|
|
|
169
179
|
call();
|
|
170
180
|
}
|
|
171
181
|
else if (refetchOnMount && state.data !== undefined) {
|
|
172
|
-
(_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest,
|
|
182
|
+
(_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, state.data);
|
|
183
|
+
(_b = rest.onSuccessResult) === null || _b === void 0 ? void 0 : _b.call(rest, (0, utils_1.createCompiledResult)(state.data));
|
|
173
184
|
}
|
|
174
185
|
return () => clearInterval(intervalId.current);
|
|
175
186
|
}, [refetchInterval, refetchOnMount, requestKey]);
|
|
@@ -98,12 +98,17 @@ const authHooks = (agentManager) => {
|
|
|
98
98
|
yield authenticate();
|
|
99
99
|
onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
|
|
100
100
|
}), [onLoggedOut]);
|
|
101
|
-
react_1.default.useEffect(() =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
react_1.default.useEffect(() => {
|
|
102
|
+
const unsubscribe = agentManager.subscribeAgent((agent) => {
|
|
103
|
+
const agentNetwork = (0, utils_1.getNetworkByHostname)(agent.host.hostname);
|
|
104
|
+
if (network.current !== agentNetwork) {
|
|
105
|
+
network.current = agentNetwork;
|
|
106
|
+
authenticate();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
authenticate();
|
|
110
|
+
return unsubscribe;
|
|
111
|
+
}, []);
|
|
107
112
|
return {
|
|
108
113
|
authenticated,
|
|
109
114
|
authenticating,
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractActorContext =
|
|
6
|
+
exports.extractActorContext = extractActorContext;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
function extractActorContext(actorContext) {
|
|
9
9
|
const useActorContext = () => {
|
|
@@ -42,4 +42,3 @@ function extractActorContext(actorContext) {
|
|
|
42
42
|
initialize,
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
exports.extractActorContext = extractActorContext;
|
package/dist/helpers/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { CallConfig } from "@dfinity/agent";
|
|
3
2
|
import type { IDL, ActorState, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService, AuthState, HttpAgent, AgentState, BaseActor, MethodAttributes, CompiledResult } from "../types";
|
|
4
3
|
export interface AgentHooksReturnType {
|
|
@@ -52,7 +51,8 @@ export interface UseSharedCallParameters<A, M extends FunctionName<A>> extends C
|
|
|
52
51
|
args?: ActorMethodParameters<A[M]>;
|
|
53
52
|
onLoading?: (loading: boolean) => void;
|
|
54
53
|
onError?: (error: Error | undefined) => void;
|
|
55
|
-
onSuccess?: (data:
|
|
54
|
+
onSuccess?: (data: ActorMethodReturnType<A[M]>) => void;
|
|
55
|
+
onSuccessResult?: (result: CompiledResult<ActorMethodReturnType<A[M]>>) => void;
|
|
56
56
|
throwOnError?: boolean;
|
|
57
57
|
compileResult?: boolean;
|
|
58
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
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,17 +35,18 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/core": "^1.
|
|
38
|
+
"@ic-reactor/core": "^1.14.0",
|
|
39
|
+
"zustand": "4.5",
|
|
39
40
|
"zustand-utils": "^1.3"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"@dfinity/agent": ">=2.
|
|
43
|
-
"@dfinity/auth-client": ">=2.
|
|
44
|
-
"@dfinity/candid": ">=2.
|
|
45
|
-
"@dfinity/identity": ">=2.
|
|
46
|
-
"@dfinity/principal": ">=2.
|
|
43
|
+
"@dfinity/agent": ">=2.1",
|
|
44
|
+
"@dfinity/auth-client": ">=2.1",
|
|
45
|
+
"@dfinity/candid": ">=2.1",
|
|
46
|
+
"@dfinity/identity": ">=2.1",
|
|
47
|
+
"@dfinity/principal": ">=2.1",
|
|
47
48
|
"react": ">=16.8",
|
|
48
49
|
"zustand": "4.5"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "fee4b92574ba3fd295e28fb49105f0a07c6fdb61"
|
|
51
52
|
}
|