@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.
@@ -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 } = config, actorConfig = __rest(config, ["canisterId", "candidString", "idlFactory", "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 ((actorManager === null || actorManager === void 0 ? void 0 : actorManager.canisterId) !== canisterId.toString()) {
80
+ if (actorManager?.canisterId !== canisterId.toString()) {
101
81
  setActorManager(null);
102
82
  }
103
- return actorManager === null || actorManager === void 0 ? void 0 : actorManager.cleanup();
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)().authenticating;
111
- const fetchCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
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
- const { idlFactory } = yield candidAdapter.getCandidDefinition(canisterId);
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
- }), [canisterId]);
135
- const evaluateCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
118
+ }, [canisterId]);
119
+ const evaluateCandid = (0, react_1.useCallback)(async () => {
136
120
  try {
137
- const definition = yield candidAdapter.dynamicEvalJs(candidString);
138
- if (typeof (definition === null || definition === void 0 ? void 0 : definition.idlFactory) !== "function") {
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
- }), [candidString]);
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)(Object.assign(Object.assign({ agentManager,
144
+ const newActorManager = (0, core_1.createActorManager)({
145
+ agentManager,
157
146
  idlFactory,
158
- canisterId }, actorConfig), actorReConfig));
147
+ canisterId,
148
+ ...actorConfig,
149
+ ...actorReConfig,
150
+ });
159
151
  setActorManager(newActorManager);
160
152
  }, [canisterId, agentManager, authenticating]);
161
- const handleActorInitialization = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
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 = yield evaluateCandid();
172
+ idlFactory = await evaluateCandid();
181
173
  }
182
174
  else {
183
- idlFactory = yield fetchCandid();
175
+ idlFactory = await fetchCandid();
184
176
  }
185
177
  if (!idlFactory)
186
178
  return;
187
179
  initializeActor(idlFactory);
188
- }), [fetchCandid, evaluateCandid, maybeIdlFactory, initializeActor]);
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 { hooks, authenticating, fetching, fetchError, initializeActor };
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 (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
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 interface CreateReactorParameters extends CreateReactorCoreParameters {
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": "1.16.0",
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": "NODE_OPTIONS=\"--experimental-vm-modules\" npx jest",
30
- "start": "tsc watch",
31
- "build": "tsc",
32
- "clean": "npx rimraf dist && npx rimraf umd"
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": ">=10"
35
+ "node": ">=22.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "@ic-reactor/core": "^1.16.0",
39
- "zustand": "5.0.2",
40
- "zustand-utils": "^1.3.2"
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": ">=2.1",
44
- "@dfinity/auth-client": ">=2.1",
45
- "@dfinity/candid": ">=2.1",
46
- "@dfinity/identity": ">=2.1",
47
- "@dfinity/principal": ">=2.1",
48
- "react": ">=16.8",
49
- "zustand": ">=5.0.0"
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": "6110fb3f75c7927086d828c912855589e2a33eb3",
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
  }