@ic-reactor/react 1.3.2 → 1.4.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.
@@ -8,12 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.authHooks = void 0;
16
- const react_1 = __importDefault(require("react"));
13
+ const React = require("react");
17
14
  const zustand_1 = require("zustand");
18
15
  const utils_1 = require("@ic-reactor/core/dist/utils");
19
16
  const authHooks = (agentManager) => {
@@ -21,12 +18,12 @@ const authHooks = (agentManager) => {
21
18
  const useAuthState = () => (0, zustand_1.useStore)(authStore);
22
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(); };
23
20
  const useAuth = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
24
- const [loginState, setLoginState] = react_1.default.useState({
21
+ const [loginState, setLoginState] = React.useState({
25
22
  loading: false,
26
23
  error: undefined,
27
24
  });
28
25
  const { authenticated, authenticating, error, identity } = useAuthState();
29
- const authenticate = react_1.default.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
26
+ const authenticate = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
30
27
  const authenticatePromise = new Promise((resolve, reject) => {
31
28
  authenticator()
32
29
  .then((identity) => {
@@ -46,7 +43,7 @@ const authHooks = (agentManager) => {
46
43
  onAuthenticationSuccess,
47
44
  onAuthenticationFailure,
48
45
  ]);
49
- const login = react_1.default.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
46
+ const login = React.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
50
47
  setLoginState({ loading: true, error: undefined });
51
48
  const loginPromise = new Promise((resolve, reject) => {
52
49
  try {
@@ -56,12 +53,12 @@ const authHooks = (agentManager) => {
56
53
  }
57
54
  authClient.login(Object.assign(Object.assign({ identityProvider: getIsLocal()
58
55
  ? utils_1.LOCAL_INTERNET_IDENTITY_PROVIDER
59
- : utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: () => {
56
+ : utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: (msg) => {
60
57
  authenticate()
61
58
  .then((identity) => {
62
59
  var _a;
63
60
  const principal = identity.getPrincipal();
64
- (_a = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _a === void 0 ? void 0 : _a.call(options);
61
+ (_a = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _a === void 0 ? void 0 : _a.call(options, msg);
65
62
  onLoginSuccess === null || onLoginSuccess === void 0 ? void 0 : onLoginSuccess(principal);
66
63
  resolve(principal);
67
64
  setLoginState({ loading: false, error: undefined });
@@ -88,7 +85,7 @@ const authHooks = (agentManager) => {
88
85
  });
89
86
  onLogin === null || onLogin === void 0 ? void 0 : onLogin(() => loginPromise);
90
87
  }), [onLogin, onLoginSuccess, onLoginError, authenticate]);
91
- const logout = react_1.default.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
88
+ const logout = React.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
92
89
  const authClient = getAuth();
93
90
  if (!authClient) {
94
91
  throw new Error("Auth client not initialized");
@@ -97,7 +94,7 @@ const authHooks = (agentManager) => {
97
94
  yield authenticate();
98
95
  onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
99
96
  }), [onLoggedOut]);
100
- react_1.default.useEffect(() => {
97
+ React.useEffect(() => {
101
98
  const authClient = getAuth();
102
99
  if (!authClient && !authenticating) {
103
100
  authenticate();
@@ -4,3 +4,4 @@ export * from "./useAgentManager";
4
4
  export * from "./useAuth";
5
5
  export * from "./useAuthState";
6
6
  export * from "./useUserPrincipal";
7
+ export * from "./useCandidAdapter";
@@ -20,3 +20,4 @@ __exportStar(require("./useAgentManager"), exports);
20
20
  __exportStar(require("./useAuth"), exports);
21
21
  __exportStar(require("./useAuthState"), exports);
22
22
  __exportStar(require("./useUserPrincipal"), exports);
23
+ __exportStar(require("./useCandidAdapter"), exports);
@@ -6,16 +6,25 @@ export interface UseCandidAdapterParams {
6
6
  didjsCanisterId?: string;
7
7
  }
8
8
  /**
9
- * Accesses the `AgentManager` instance for managing agent configurations and state.
9
+ * Accesses the `CandidAdapter` to download the actor's Candid interface.
10
+ *
11
+ * @param config - `UseCandidAdapterParams` The configuration object.
12
+ * @returns The `CandidAdapter` instance.
10
13
  *
11
14
  * @example
12
- *```jsx
13
- * function AgentManagerComponent() {
14
- * const agentManager = useAgentManager();
15
+ * ```jsx
16
+ * function CandidAdapterComponent() {
17
+ * const candidAdapter = useCandidAdapter();
18
+ *
19
+ * const getActor = async () => {
20
+ * const { idlFactory } = await candidAdapter.getCandidDefinition(canisterId)
21
+ * console.log(idlFactory)
22
+ * }
15
23
  *
16
- * // Use agentManager for managing agent configurations, etc.
17
- * return <div>Agent Manager ready.</div>;
18
- * }
24
+ * return (
25
+ * <button onClick={getActor}>Get Actor</button>
26
+ * );
27
+ * }
19
28
  *```
20
29
  */
21
30
  export declare const useCandidAdapter: (config: UseCandidAdapterParams) => CandidAdapter | undefined;
@@ -5,16 +5,25 @@ const useAgentManager_1 = require("./useAgentManager");
5
5
  const react_1 = require("react");
6
6
  const core_1 = require("@ic-reactor/core");
7
7
  /**
8
- * Accesses the `AgentManager` instance for managing agent configurations and state.
8
+ * Accesses the `CandidAdapter` to download the actor's Candid interface.
9
+ *
10
+ * @param config - `UseCandidAdapterParams` The configuration object.
11
+ * @returns The `CandidAdapter` instance.
9
12
  *
10
13
  * @example
11
- *```jsx
12
- * function AgentManagerComponent() {
13
- * const agentManager = useAgentManager();
14
+ * ```jsx
15
+ * function CandidAdapterComponent() {
16
+ * const candidAdapter = useCandidAdapter();
17
+ *
18
+ * const getActor = async () => {
19
+ * const { idlFactory } = await candidAdapter.getCandidDefinition(canisterId)
20
+ * console.log(idlFactory)
21
+ * }
14
22
  *
15
- * // Use agentManager for managing agent configurations, etc.
16
- * return <div>Agent Manager ready.</div>;
17
- * }
23
+ * return (
24
+ * <button onClick={getActor}>Get Actor</button>
25
+ * );
26
+ * }
18
27
  *```
19
28
  */
20
29
  const useCandidAdapter = (config) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.3.2",
3
+ "version": "1.4.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",
@@ -35,17 +35,17 @@
35
35
  "node": ">=10"
36
36
  },
37
37
  "dependencies": {
38
- "@ic-reactor/core": "^1.3.1",
38
+ "@ic-reactor/core": "^1.4.0",
39
39
  "zustand-utils": "^1.3"
40
40
  },
41
41
  "peerDependencies": {
42
- "@dfinity/agent": ">=1.0",
43
- "@dfinity/auth-client": ">=1.0",
44
- "@dfinity/candid": ">=1.0",
45
- "@dfinity/identity": ">=1.0",
46
- "@dfinity/principal": ">=1.0",
42
+ "@dfinity/agent": "^1.2",
43
+ "@dfinity/auth-client": "^1.2",
44
+ "@dfinity/candid": "^1.2",
45
+ "@dfinity/identity": "^1.2",
46
+ "@dfinity/principal": "^1.2",
47
47
  "react": ">=16.8",
48
48
  "zustand": "4.5"
49
49
  },
50
- "gitHead": "02ebf0dfbd01792ded00b91a69b4196aab018285"
50
+ "gitHead": "a302e73db60f96faf9f0119ecdd02ee8dfcaa1df"
51
51
  }