@ic-reactor/react 1.2.1 → 1.2.3

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.
@@ -47,10 +47,13 @@ const DEFAULT_STATE = {
47
47
  * Each hook is designed to simplify the process of interacting with actors in IC projects by abstracting away the complexity of state management, error handling, and method invocation.
48
48
  */
49
49
  const actorHooks = (actorManager) => {
50
- const { actorStore, canisterId, visitFunction, extractInterface, callMethod, initialize, } = actorManager;
50
+ const { actorStore, canisterId, visitFunction, extractInterface, extractMethodNames, callMethod, initialize, } = actorManager;
51
51
  const useActorState = () => (Object.assign(Object.assign({}, (0, zustand_1.useStore)(actorStore)), { canisterId }));
52
+ const useMethodNames = () => {
53
+ return react_1.default.useMemo(() => extractMethodNames(), []);
54
+ };
52
55
  const useActorInterface = () => {
53
- return extractInterface();
56
+ return react_1.default.useMemo(() => extractInterface(), []);
54
57
  };
55
58
  const useVisitService = () => {
56
59
  return visitFunction;
@@ -116,6 +119,7 @@ const actorHooks = (actorManager) => {
116
119
  return {
117
120
  initialize,
118
121
  useMethod,
122
+ useMethodNames,
119
123
  useQueryCall,
120
124
  useUpdateCall,
121
125
  useActorState,
@@ -17,7 +17,7 @@ const react_1 = __importDefault(require("react"));
17
17
  const zustand_1 = require("zustand");
18
18
  const utils_1 = require("@ic-reactor/core/dist/utils");
19
19
  const authHooks = (agentManager) => {
20
- const { authenticate: authenticator, getAuth, authStore, isLocalEnv, } = agentManager;
20
+ const { authenticate: authenticator, getIsLocal, getAuth, authStore, } = agentManager;
21
21
  const useAuthState = () => (0, zustand_1.useStore)(authStore);
22
22
  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(); };
23
23
  const useAuth = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
@@ -54,7 +54,7 @@ const authHooks = (agentManager) => {
54
54
  if (!authClient) {
55
55
  throw new Error("Auth client not initialized");
56
56
  }
57
- authClient.login(Object.assign(Object.assign({ identityProvider: isLocalEnv
57
+ authClient.login(Object.assign(Object.assign({ identityProvider: getIsLocal()
58
58
  ? utils_1.LOCAL_INTERNET_IDENTITY_PROVIDER
59
59
  : utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: () => {
60
60
  authenticate()
@@ -87,7 +87,7 @@ const authHooks = (agentManager) => {
87
87
  }
88
88
  });
89
89
  onLogin === null || onLogin === void 0 ? void 0 : onLogin(() => loginPromise);
90
- }), [onLogin, onLoginSuccess, onLoginError, isLocalEnv, authenticate]);
90
+ }), [onLogin, onLoginSuccess, onLoginError, authenticate]);
91
91
  const logout = react_1.default.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
92
92
  const authClient = getAuth();
93
93
  if (!authClient) {
@@ -39,6 +39,7 @@ function extractActorContext(actorContext) {
39
39
  return context;
40
40
  };
41
41
  const initialize = () => useActorContext().initialize();
42
+ const useMethodNames = () => useActorContext().useMethodNames();
42
43
  const useActorState = () => useActorContext().useActorState();
43
44
  const useMethod = (args) => useActorContext().useMethod(args);
44
45
  const useQueryCall = (args) => useActorContext().useQueryCall(args);
@@ -49,6 +50,7 @@ function extractActorContext(actorContext) {
49
50
  return {
50
51
  useActorState,
51
52
  useMethod,
53
+ useMethodNames,
52
54
  useQueryCall,
53
55
  useUpdateCall,
54
56
  useVisitMethod,
@@ -88,6 +88,7 @@ export interface ActorHooksReturnType<A = BaseActor> {
88
88
  initialize: () => Promise<void>;
89
89
  useActorState: () => UseActorState;
90
90
  useActorInterface: () => ServiceClass;
91
+ useMethodNames: () => FunctionName<A>[];
91
92
  useMethod: UseMethod<A>;
92
93
  useQueryCall: UseQueryCall<A>;
93
94
  useUpdateCall: UseUpdateCall<A>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Hook for accessing the method names of an actor.
3
+ *
4
+ * @returns An array of method names for the actor.
5
+ */
6
+ export declare const useMethodNames: () => string[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMethodNames = void 0;
4
+ const hooks_1 = require("./hooks");
5
+ /**
6
+ * Hook for accessing the method names of an actor.
7
+ *
8
+ * @returns An array of method names for the actor.
9
+ */
10
+ exports.useMethodNames = hooks_1.ActorHooks.useMethodNames;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
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.2.1",
38
+ "@ic-reactor/core": "^1.2.3",
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": "c45e2ae6da1eee146b9e5f3178318de4d66419de"
50
+ "gitHead": "ae71ae0c7eee0ebe8a97751d4222054668a6b994"
51
51
  }