@ic-reactor/react 1.16.0 → 2.0.0
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 +19 -22
- package/dist/context/actor/hooks/useActorInterface.d.ts +1 -1
- package/dist/context/actor/hooks/useMethod.d.ts +3 -3
- package/dist/context/actor/hooks/useMethod.js +3 -3
- package/dist/context/actor/hooks/useQueryCall.d.ts +2 -2
- package/dist/context/actor/hooks/useQueryCall.js +2 -2
- package/dist/context/actor/hooks/useUpdateCall.d.ts +3 -3
- package/dist/context/actor/hooks/useUpdateCall.js +3 -3
- package/dist/context/actor/hooks/useVisitMethod.d.ts +1 -1
- package/dist/context/adapter/create.d.ts +2 -2
- package/dist/context/adapter/create.js +23 -30
- package/dist/context/adapter/index.d.ts +1 -1
- package/dist/context/adapter/types.d.ts +33 -6
- package/dist/context/agent/create.js +10 -17
- package/dist/createReactor.js +7 -2
- package/dist/helpers/actorHooks.js +77 -66
- package/dist/helpers/authHooks.js +46 -44
- package/dist/helpers/extractActorContext.js +1 -1
- package/dist/helpers/types.d.ts +123 -13
- package/dist/hooks/types.d.ts +2 -2
- package/dist/hooks/useActor.js +36 -38
- package/dist/index.js +17 -7
- package/dist/types.d.ts +1 -2
- package/package.json +17 -24
package/dist/hooks/useActor.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.useActor = void 0;
|
|
24
4
|
const core_1 = require("@ic-reactor/core");
|
|
@@ -91,24 +71,24 @@ const agent_1 = require("../context/agent");
|
|
|
91
71
|
* ```
|
|
92
72
|
*/
|
|
93
73
|
const useActor = (config) => {
|
|
94
|
-
const { canisterId, candidString, idlFactory: maybeIdlFactory, disableAutoFetch
|
|
74
|
+
const { canisterId, candidString, idlFactory: maybeIdlFactory, disableAutoFetch, ...actorConfig } = config;
|
|
95
75
|
if (!canisterId) {
|
|
96
76
|
throw new Error("canisterId is required");
|
|
97
77
|
}
|
|
98
78
|
const [actorManager, setActorManager] = (0, react_1.useState)(null);
|
|
99
79
|
(0, react_1.useEffect)(() => {
|
|
100
|
-
if (
|
|
80
|
+
if (actorManager?.canisterId !== canisterId.toString()) {
|
|
101
81
|
setActorManager(null);
|
|
102
82
|
}
|
|
103
|
-
return actorManager
|
|
83
|
+
return actorManager?.cleanup();
|
|
104
84
|
}, [canisterId, actorManager]);
|
|
105
85
|
const [{ fetching, fetchError }, setState] = (0, react_1.useState)({
|
|
106
86
|
fetching: false,
|
|
107
87
|
fetchError: null,
|
|
108
88
|
});
|
|
109
89
|
const candidAdapter = (0, react_1.useContext)(adapter_1.CandidAdapterContext);
|
|
110
|
-
const authenticating = (0, agent_1.useAuthState)().
|
|
111
|
-
const fetchCandid = (0, react_1.useCallback)(() =>
|
|
90
|
+
const authenticating = (0, agent_1.useAuthState)().isAuthenticating;
|
|
91
|
+
const fetchCandid = (0, react_1.useCallback)(async () => {
|
|
112
92
|
if (fetching)
|
|
113
93
|
return;
|
|
114
94
|
setState({
|
|
@@ -116,7 +96,10 @@ const useActor = (config) => {
|
|
|
116
96
|
fetchError: null,
|
|
117
97
|
});
|
|
118
98
|
try {
|
|
119
|
-
|
|
99
|
+
if (!candidAdapter) {
|
|
100
|
+
throw new Error("CandidAdapter is necessary to fetch the Candid interface. Please ensure your application is wrapped with the CandidAdapterProvider, or provide the idlFactory directly.");
|
|
101
|
+
}
|
|
102
|
+
const { idlFactory } = await candidAdapter.getCandidDefinition(canisterId);
|
|
120
103
|
setState({
|
|
121
104
|
fetching: false,
|
|
122
105
|
fetchError: null,
|
|
@@ -130,12 +113,16 @@ const useActor = (config) => {
|
|
|
130
113
|
fetchError: `Error fetching canister ${canisterId}`,
|
|
131
114
|
fetching: false,
|
|
132
115
|
});
|
|
116
|
+
return undefined;
|
|
133
117
|
}
|
|
134
|
-
}
|
|
135
|
-
const evaluateCandid = (0, react_1.useCallback)(() =>
|
|
118
|
+
}, [canisterId]);
|
|
119
|
+
const evaluateCandid = (0, react_1.useCallback)(async () => {
|
|
136
120
|
try {
|
|
137
|
-
|
|
138
|
-
|
|
121
|
+
if (!candidString) {
|
|
122
|
+
throw new Error("Candid string is required to evaluate the Candid definition");
|
|
123
|
+
}
|
|
124
|
+
const definition = await candidAdapter?.evaluateCandidDefinition(candidString);
|
|
125
|
+
if (typeof definition?.idlFactory !== "function") {
|
|
139
126
|
throw new Error("Error evaluating Candid definition");
|
|
140
127
|
}
|
|
141
128
|
return definition.idlFactory;
|
|
@@ -147,18 +134,23 @@ const useActor = (config) => {
|
|
|
147
134
|
fetchError: `Error evaluating Candid definition, ${err}`,
|
|
148
135
|
fetching: false,
|
|
149
136
|
});
|
|
137
|
+
return undefined;
|
|
150
138
|
}
|
|
151
|
-
}
|
|
139
|
+
}, [candidString]);
|
|
152
140
|
const agentManager = (0, agent_1.useAgentManager)();
|
|
153
141
|
const initializeActor = (0, react_1.useCallback)((idlFactory, actorReConfig) => {
|
|
154
142
|
if (authenticating || !idlFactory)
|
|
155
143
|
return;
|
|
156
|
-
const newActorManager = (0, core_1.createActorManager)(
|
|
144
|
+
const newActorManager = (0, core_1.createActorManager)({
|
|
145
|
+
agentManager,
|
|
157
146
|
idlFactory,
|
|
158
|
-
canisterId
|
|
147
|
+
canisterId,
|
|
148
|
+
...actorConfig,
|
|
149
|
+
...actorReConfig,
|
|
150
|
+
});
|
|
159
151
|
setActorManager(newActorManager);
|
|
160
152
|
}, [canisterId, agentManager, authenticating]);
|
|
161
|
-
const handleActorInitialization = (0, react_1.useCallback)(() =>
|
|
153
|
+
const handleActorInitialization = (0, react_1.useCallback)(async () => {
|
|
162
154
|
if (authenticating)
|
|
163
155
|
return;
|
|
164
156
|
if (maybeIdlFactory) {
|
|
@@ -177,15 +169,15 @@ const useActor = (config) => {
|
|
|
177
169
|
}
|
|
178
170
|
let idlFactory;
|
|
179
171
|
if (candidString) {
|
|
180
|
-
idlFactory =
|
|
172
|
+
idlFactory = await evaluateCandid();
|
|
181
173
|
}
|
|
182
174
|
else {
|
|
183
|
-
idlFactory =
|
|
175
|
+
idlFactory = await fetchCandid();
|
|
184
176
|
}
|
|
185
177
|
if (!idlFactory)
|
|
186
178
|
return;
|
|
187
179
|
initializeActor(idlFactory);
|
|
188
|
-
}
|
|
180
|
+
}, [fetchCandid, evaluateCandid, maybeIdlFactory, initializeActor]);
|
|
189
181
|
(0, react_1.useEffect)(() => {
|
|
190
182
|
handleActorInitialization();
|
|
191
183
|
}, [handleActorInitialization]);
|
|
@@ -194,6 +186,12 @@ const useActor = (config) => {
|
|
|
194
186
|
return null;
|
|
195
187
|
return (0, helpers_1.actorHooks)(actorManager);
|
|
196
188
|
}, [actorManager]);
|
|
197
|
-
return {
|
|
189
|
+
return {
|
|
190
|
+
hooks,
|
|
191
|
+
isAuthenticating: authenticating,
|
|
192
|
+
isFetching: fetching,
|
|
193
|
+
fetchError,
|
|
194
|
+
initializeActor,
|
|
195
|
+
};
|
|
198
196
|
};
|
|
199
197
|
exports.useActor = useActor;
|
package/dist/index.js
CHANGED
|
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.utils = exports.core = exports.types = exports.helpers = void 0;
|
|
30
40
|
// Note: Order of exports is important
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { HttpAgent, CreateReactorCoreParameters, VisitService } from "@ic-reactor/core/dist/types";
|
|
2
2
|
import type { ActorHooksReturnType, AgentHooksReturnType, AuthHooksReturnType } from "./helpers/types";
|
|
3
|
-
export
|
|
4
|
-
}
|
|
3
|
+
export type CreateReactorParameters = CreateReactorCoreParameters;
|
|
5
4
|
export interface CreateReactorReturnType<A> extends ActorHooksReturnType<A>, AuthHooksReturnType, AgentHooksReturnType {
|
|
6
5
|
getAgent: () => HttpAgent;
|
|
7
6
|
getVisitFunction: () => VisitService<A>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -26,34 +26,27 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://b3pay.github.io/ic-reactor/modules/react.html",
|
|
28
28
|
"scripts": {
|
|
29
|
-
"test": "
|
|
30
|
-
"start": "tsc watch",
|
|
31
|
-
"build": "tsc",
|
|
32
|
-
"clean": "
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"start": "bun run tsc watch",
|
|
31
|
+
"build": "bun run tsc",
|
|
32
|
+
"clean": "bun run rimraf dist && bun run rimraf umd"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">=22.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/core": "
|
|
39
|
-
"zustand": "5.0.
|
|
40
|
-
"zustand-utils": "^1.
|
|
38
|
+
"@ic-reactor/core": "2.0.0",
|
|
39
|
+
"zustand": "^5.0.6",
|
|
40
|
+
"zustand-utils": "^2.1.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@dfinity/agent": "
|
|
44
|
-
"@dfinity/auth-client": "
|
|
45
|
-
"@dfinity/candid": "
|
|
46
|
-
"@dfinity/identity": "
|
|
47
|
-
"@dfinity/principal": "
|
|
48
|
-
"react": ">=
|
|
49
|
-
"zustand": "
|
|
43
|
+
"@dfinity/agent": "^3.1.0",
|
|
44
|
+
"@dfinity/auth-client": "^3.1.0",
|
|
45
|
+
"@dfinity/candid": "^3.1.0",
|
|
46
|
+
"@dfinity/identity": "^3.1.0",
|
|
47
|
+
"@dfinity/principal": "^3.1.0",
|
|
48
|
+
"react": ">=19.0.0",
|
|
49
|
+
"zustand": "^5.0.6"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@dfinity/agent": ">=2.1",
|
|
54
|
-
"@dfinity/auth-client": ">=2.1",
|
|
55
|
-
"@types/node": "^22.9.0",
|
|
56
|
-
"@types/react": "^18",
|
|
57
|
-
"react": "^18"
|
|
58
|
-
}
|
|
51
|
+
"gitHead": "2677a090df726dc4f4216eb406b135a32334507b"
|
|
59
52
|
}
|