@ic-reactor/react 1.5.5-beta.2 → 1.6.0-beta.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.d.ts → actor/index.d.ts} +1 -1
- package/dist/context/{actor.js → actor/index.js} +5 -4
- package/dist/context/actor/types.d.ts +17 -0
- package/dist/context/actor/types.js +2 -0
- package/dist/context/adapter/index.d.ts +7 -0
- package/dist/context/adapter/index.js +13 -0
- package/dist/context/adapter/types.d.ts +10 -0
- package/dist/context/adapter/types.js +2 -0
- package/dist/context/{agent.js → agent/index.js} +3 -3
- package/dist/context/agent/types.d.ts +16 -0
- package/dist/context/agent/types.js +2 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.js +19 -0
- package/dist/context/types.d.ts +3 -29
- package/dist/context/types.js +17 -0
- package/dist/helpers/extractActorContext.d.ts +2 -1
- package/dist/hooks/actor/hooks.d.ts +1 -1
- package/dist/hooks/adapter/index.d.ts +1 -0
- package/dist/hooks/adapter/index.js +5 -0
- package/dist/hooks/{agent → adapter}/useCandidAdapter.d.ts +1 -5
- package/dist/hooks/{agent → adapter}/useCandidAdapter.js +7 -19
- package/dist/hooks/agent/index.d.ts +1 -1
- package/dist/hooks/agent/index.js +1 -1
- package/dist/hooks/types.d.ts +2 -1
- package/dist/hooks/types.js +15 -0
- package/dist/hooks/useActor.js +48 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/provider/actor.d.ts +1 -1
- package/dist/provider/adapter.d.ts +31 -0
- package/dist/provider/adapter.js +62 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/package.json +3 -3
- /package/dist/context/{agent.d.ts → agent/index.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseActor } from "
|
|
1
|
+
import { BaseActor } from "../../types";
|
|
2
2
|
import { CreateActorContextParameters, CreateActorContextReturnType } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
|
|
@@ -16,8 +16,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createActorContext = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
|
-
const useActor_1 = require("
|
|
20
|
-
const extractActorContext_1 = require("
|
|
19
|
+
const useActor_1 = require("../../hooks/useActor");
|
|
20
|
+
const extractActorContext_1 = require("../../helpers/extractActorContext");
|
|
21
21
|
/**
|
|
22
22
|
* Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
|
|
23
23
|
* This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
|
|
@@ -82,12 +82,13 @@ function createActorContext(contextConfig = {}) {
|
|
|
82
82
|
const { canisterId: defaultCanisterId } = contextConfig, defaultConfig = __rest(contextConfig, ["canisterId"]);
|
|
83
83
|
const ActorContext = react_1.default.createContext(null);
|
|
84
84
|
const ActorProvider = (_a) => {
|
|
85
|
-
var { children, canisterId = defaultCanisterId, loadingComponent = react_1.default.createElement("div", null, "Fetching canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "canisterId", "loadingComponent", "authenticatingComponent"]);
|
|
85
|
+
var { children, canisterId = defaultCanisterId, loadingComponent = react_1.default.createElement("div", null, "Fetching canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating..."), candidString } = _a, restConfig = __rest(_a, ["children", "canisterId", "loadingComponent", "authenticatingComponent", "candidString"]);
|
|
86
86
|
if (!canisterId) {
|
|
87
87
|
throw new Error("canisterId is required");
|
|
88
88
|
}
|
|
89
89
|
const config = react_1.default.useMemo(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
|
|
90
|
-
const { fetchError, authenticating, hooks } = (0, useActor_1.useActor)(Object.assign({ canisterId
|
|
90
|
+
const { fetchError, authenticating, hooks } = (0, useActor_1.useActor)(Object.assign({ canisterId,
|
|
91
|
+
candidString }, config));
|
|
91
92
|
return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, hooks === null
|
|
92
93
|
? fetchError
|
|
93
94
|
? fetchError
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { IDL, ActorHooksReturnType, BaseActor, ActorManagerParameters, CanisterId } from "../../types";
|
|
3
|
+
export interface CreateActorContextReturnType<A = BaseActor> extends ActorHooksReturnType<A> {
|
|
4
|
+
ActorProvider: React.FC<ActorProviderProps>;
|
|
5
|
+
}
|
|
6
|
+
export interface ActorProviderProps extends CreateActorContextParameters {
|
|
7
|
+
children?: React.ReactNode | undefined;
|
|
8
|
+
candidString?: string;
|
|
9
|
+
loadingComponent?: React.ReactNode;
|
|
10
|
+
authenticatingComponent?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateActorContextParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
13
|
+
didjsId?: string;
|
|
14
|
+
canisterId?: CanisterId;
|
|
15
|
+
idlFactory?: IDL.InterfaceFactory;
|
|
16
|
+
initializeParser?: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CandidAdapterContext = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
/**
|
|
9
|
+
* Adapter context for the Candid adapter.
|
|
10
|
+
*/
|
|
11
|
+
const CandidAdapterContext = react_1.default.createContext(null);
|
|
12
|
+
exports.CandidAdapterContext = CandidAdapterContext;
|
|
13
|
+
CandidAdapterContext.displayName = "CandidAdapterContext";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import type { CandidAdapterParameters } from "../../types";
|
|
3
|
+
import type { CandidAdapter } from "@ic-reactor/core/dist/classes";
|
|
4
|
+
export type { CandidAdapter };
|
|
5
|
+
export interface CandidAdapterContextType extends CandidAdapter {
|
|
6
|
+
}
|
|
7
|
+
export interface CandidAdapterProviderProps extends PropsWithChildren, CandidAdapterParameters {
|
|
8
|
+
initialParser?: boolean;
|
|
9
|
+
loadingComponent?: React.ReactNode;
|
|
10
|
+
}
|
|
@@ -17,9 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.createAgentContext = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const core_1 = require("@ic-reactor/core");
|
|
20
|
-
const agentHooks_1 = require("
|
|
21
|
-
const authHooks_1 = require("
|
|
22
|
-
const extractAgentContext_1 = require("
|
|
20
|
+
const agentHooks_1 = require("../../helpers/agentHooks");
|
|
21
|
+
const authHooks_1 = require("../../helpers/authHooks");
|
|
22
|
+
const extractAgentContext_1 = require("../../helpers/extractAgentContext");
|
|
23
23
|
/**
|
|
24
24
|
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
25
25
|
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentHooksReturnType, AuthHooksReturnType, AgentManager, AgentManagerParameters } from "../../types";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
3
|
+
export interface AgentContext extends AgentHooksReturnType, AuthHooksReturnType {
|
|
4
|
+
agentManager: AgentManager;
|
|
5
|
+
}
|
|
6
|
+
export interface CreateAgentCotextParameters extends AgentManagerParameters {
|
|
7
|
+
withProcessEnv?: boolean;
|
|
8
|
+
disableAuthenticateOnMount?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
|
|
11
|
+
useAgentManager: () => AgentManager;
|
|
12
|
+
AgentProvider: React.FC<AgentProviderProps>;
|
|
13
|
+
}
|
|
14
|
+
export interface AgentProviderProps extends PropsWithChildren, CreateAgentCotextParameters {
|
|
15
|
+
agentManager?: AgentManager;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./agent"), exports);
|
|
18
|
+
__exportStar(require("./actor"), exports);
|
|
19
|
+
__exportStar(require("./adapter"), exports);
|
package/dist/context/types.d.ts
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
agentManager: AgentManager;
|
|
5
|
-
}
|
|
6
|
-
export interface CreateAgentCotextParameters extends AgentManagerParameters {
|
|
7
|
-
withProcessEnv?: boolean;
|
|
8
|
-
disableAuthenticateOnMount?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
|
|
11
|
-
useAgentManager: () => AgentManager;
|
|
12
|
-
AgentProvider: React.FC<AgentProviderProps>;
|
|
13
|
-
}
|
|
14
|
-
export interface AgentProviderProps extends PropsWithChildren, CreateAgentCotextParameters {
|
|
15
|
-
agentManager?: AgentManager;
|
|
16
|
-
}
|
|
17
|
-
export interface CreateActorContextReturnType<A = BaseActor> extends ActorHooksReturnType<A> {
|
|
18
|
-
ActorProvider: React.FC<ActorProviderProps>;
|
|
19
|
-
}
|
|
20
|
-
export interface ActorProviderProps extends CreateActorContextParameters {
|
|
21
|
-
children?: React.ReactNode | undefined;
|
|
22
|
-
loadingComponent?: React.ReactNode;
|
|
23
|
-
authenticatingComponent?: React.ReactNode;
|
|
24
|
-
}
|
|
25
|
-
export interface CreateActorContextParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
26
|
-
didjsId?: string;
|
|
27
|
-
canisterId?: CanisterId;
|
|
28
|
-
idlFactory?: IDL.InterfaceFactory;
|
|
29
|
-
}
|
|
1
|
+
export * from "./actor/types";
|
|
2
|
+
export * from "./agent/types";
|
|
3
|
+
export * from "./adapter/types";
|
package/dist/context/types.js
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./actor/types"), exports);
|
|
18
|
+
__exportStar(require("./agent/types"), exports);
|
|
19
|
+
__exportStar(require("./adapter/types"), exports);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { ActorHooksReturnType, BaseActor
|
|
2
|
+
import type { ActorHooksReturnType, BaseActor } from "../types";
|
|
3
|
+
import { CreateActorContextReturnType } from "../context/actor/types";
|
|
3
4
|
export declare function extractActorContext<A = BaseActor>(actorContext: React.Context<ActorHooksReturnType<A> | null>): Omit<CreateActorContextReturnType<A>, "ActorProvider">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ActorHooks: import("../../types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
|
|
1
|
+
export declare const ActorHooks: import("../../context/types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCandidAdapter } from "./useCandidAdapter";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCandidAdapter = void 0;
|
|
4
|
+
var useCandidAdapter_1 = require("./useCandidAdapter");
|
|
5
|
+
Object.defineProperty(exports, "useCandidAdapter", { enumerable: true, get: function () { return useCandidAdapter_1.useCandidAdapter; } });
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { CandidAdapter } from "@ic-reactor/core/dist/classes";
|
|
2
|
-
export interface UseCandidAdapterParams {
|
|
3
|
-
didjsCanisterId?: string;
|
|
4
|
-
}
|
|
5
1
|
/**
|
|
6
2
|
* Accesses the `CandidAdapter` to download the actor's Candid interface.
|
|
7
3
|
*
|
|
@@ -24,4 +20,4 @@ export interface UseCandidAdapterParams {
|
|
|
24
20
|
* }
|
|
25
21
|
*```
|
|
26
22
|
*/
|
|
27
|
-
export declare const useCandidAdapter: (
|
|
23
|
+
export declare const useCandidAdapter: () => import("../../context/types").CandidAdapterContextType | null;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useCandidAdapter = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const
|
|
6
|
-
const useAgent_1 = require("./useAgent");
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const adapter_1 = require("../../context/adapter");
|
|
7
9
|
/**
|
|
8
10
|
* Accesses the `CandidAdapter` to download the actor's Candid interface.
|
|
9
11
|
*
|
|
@@ -26,22 +28,8 @@ const useAgent_1 = require("./useAgent");
|
|
|
26
28
|
* }
|
|
27
29
|
*```
|
|
28
30
|
*/
|
|
29
|
-
const useCandidAdapter = (
|
|
30
|
-
const
|
|
31
|
-
const agent = (0, useAgent_1.useAgent)();
|
|
32
|
-
(0, react_1.useEffect)(() => {
|
|
33
|
-
try {
|
|
34
|
-
const candidManager = (0, core_1.createCandidAdapter)({
|
|
35
|
-
agent,
|
|
36
|
-
didjsCanisterId: config.didjsCanisterId,
|
|
37
|
-
});
|
|
38
|
-
setCandidAdapter(candidManager);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
// eslint-disable-next-line no-console
|
|
42
|
-
console.error("Error creating CandidAdapter", error);
|
|
43
|
-
}
|
|
44
|
-
}, [agent, config.didjsCanisterId]);
|
|
31
|
+
const useCandidAdapter = () => {
|
|
32
|
+
const candidAdapter = react_1.default.useContext(adapter_1.CandidAdapterContext);
|
|
45
33
|
return candidAdapter;
|
|
46
34
|
};
|
|
47
35
|
exports.useCandidAdapter = useCandidAdapter;
|
|
@@ -20,4 +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("
|
|
23
|
+
__exportStar(require("../adapter/useCandidAdapter"), exports);
|
package/dist/hooks/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { IDL } from "@dfinity/candid";
|
|
2
2
|
import { ActorHooksReturnType, ActorManagerParameters, BaseActor, CanisterId } from "../types";
|
|
3
|
+
export * from "./adapter/useCandidAdapter";
|
|
3
4
|
export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
5
|
+
candidString?: string;
|
|
4
6
|
canisterId: CanisterId;
|
|
5
7
|
idlFactory?: IDL.InterfaceFactory;
|
|
6
|
-
didjsCanisterId?: string;
|
|
7
8
|
}
|
|
8
9
|
export interface UseActorReturn<A = BaseActor> {
|
|
9
10
|
hooks: ActorHooksReturnType<A> | null;
|
package/dist/hooks/types.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./adapter/useCandidAdapter"), exports);
|
package/dist/hooks/useActor.js
CHANGED
|
@@ -26,7 +26,7 @@ const react_1 = require("react");
|
|
|
26
26
|
const useAgentManager_1 = require("./agent/useAgentManager");
|
|
27
27
|
const helpers_1 = require("../helpers");
|
|
28
28
|
const agent_1 = require("./agent");
|
|
29
|
-
const useCandidAdapter_1 = require("./
|
|
29
|
+
const useCandidAdapter_1 = require("./adapter/useCandidAdapter");
|
|
30
30
|
/**
|
|
31
31
|
* A comprehensive hook that manages both the fetching of Candid interfaces
|
|
32
32
|
* and the initialization of actor stores for Internet Computer (IC) canisters.
|
|
@@ -90,7 +90,7 @@ const useCandidAdapter_1 = require("./agent/useCandidAdapter");
|
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
92
|
const useActor = (config) => {
|
|
93
|
-
const { canisterId, idlFactory: maybeIdlFactory
|
|
93
|
+
const { canisterId, candidString, idlFactory: maybeIdlFactory } = config, actorConfig = __rest(config, ["canisterId", "candidString", "idlFactory"]);
|
|
94
94
|
if (!canisterId) {
|
|
95
95
|
throw new Error("canisterId is required");
|
|
96
96
|
}
|
|
@@ -105,9 +105,7 @@ const useActor = (config) => {
|
|
|
105
105
|
fetching: false,
|
|
106
106
|
fetchError: null,
|
|
107
107
|
});
|
|
108
|
-
const candidAdapter = (0, useCandidAdapter_1.useCandidAdapter)(
|
|
109
|
-
didjsCanisterId,
|
|
110
|
-
});
|
|
108
|
+
const candidAdapter = (0, useCandidAdapter_1.useCandidAdapter)();
|
|
111
109
|
const authenticating = (0, agent_1.useAuthState)().authenticating;
|
|
112
110
|
const fetchCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
111
|
if (fetching || authenticating || !candidAdapter)
|
|
@@ -132,28 +130,63 @@ const useActor = (config) => {
|
|
|
132
130
|
fetching: false,
|
|
133
131
|
});
|
|
134
132
|
}
|
|
135
|
-
}), [canisterId, candidAdapter, authenticating
|
|
133
|
+
}), [canisterId, candidAdapter, authenticating]);
|
|
136
134
|
const agentManager = (0, useAgentManager_1.useAgentManager)();
|
|
137
135
|
const initialActorManager = (0, react_1.useCallback)((idlFactory) => {
|
|
138
|
-
if (authenticating)
|
|
136
|
+
if (authenticating || !idlFactory)
|
|
139
137
|
return;
|
|
140
138
|
const actorManager = (0, core_1.createActorManager)(Object.assign({ agentManager,
|
|
141
139
|
idlFactory,
|
|
142
140
|
canisterId }, actorConfig));
|
|
143
141
|
setActorManager(actorManager);
|
|
144
142
|
}, [canisterId, agentManager, authenticating]);
|
|
145
|
-
(0, react_1.
|
|
143
|
+
const evaluateCandid = (0, react_1.useCallback)((candidString) => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
if (!candidAdapter) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const definition = yield candidAdapter.dynamicEvalJs(candidString);
|
|
149
|
+
if (typeof (definition === null || definition === void 0 ? void 0 : definition.idlFactory) !== "function") {
|
|
150
|
+
throw new Error("Error evaluating Candid definition");
|
|
151
|
+
}
|
|
152
|
+
return definition.idlFactory;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.error(err);
|
|
157
|
+
setState({
|
|
158
|
+
fetchError: `Error evaluating Candid definition, ${err}`,
|
|
159
|
+
fetching: false,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}), [candidAdapter]);
|
|
163
|
+
const handleActorInitialization = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
164
|
if (maybeIdlFactory) {
|
|
147
|
-
initialActorManager(maybeIdlFactory);
|
|
165
|
+
return initialActorManager(maybeIdlFactory);
|
|
166
|
+
}
|
|
167
|
+
if (!candidAdapter) {
|
|
168
|
+
throw new Error("CandidAdapter is not available, make sure you have wrapped your component with CandidAdapterProvider");
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
if (candidString) {
|
|
172
|
+
const idlFactory = yield evaluateCandid(candidString);
|
|
173
|
+
return initialActorManager(idlFactory);
|
|
174
|
+
}
|
|
175
|
+
const idlFactory = yield fetchCandid();
|
|
176
|
+
return initialActorManager(idlFactory);
|
|
148
177
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
178
|
+
catch (error) {
|
|
179
|
+
// eslint-disable-next-line no-console
|
|
180
|
+
console.error(error);
|
|
181
|
+
setState({
|
|
182
|
+
fetchError: "Error occurred during actor initialization",
|
|
183
|
+
fetching: false,
|
|
154
184
|
});
|
|
155
185
|
}
|
|
156
|
-
}, [fetchCandid, maybeIdlFactory, initialActorManager]);
|
|
186
|
+
}), [fetchCandid, evaluateCandid, maybeIdlFactory, initialActorManager]);
|
|
187
|
+
(0, react_1.useEffect)(() => {
|
|
188
|
+
handleActorInitialization();
|
|
189
|
+
}, [handleActorInitialization]);
|
|
157
190
|
const hooks = (0, react_1.useMemo)(() => {
|
|
158
191
|
if (!actorManager)
|
|
159
192
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from "./createReactor";
|
|
2
|
-
export * from "./context
|
|
3
|
-
export * from "./context/agent";
|
|
2
|
+
export * from "./context";
|
|
4
3
|
export * from "./provider/actor";
|
|
5
4
|
export * from "./provider/agent";
|
|
5
|
+
export * from "./provider/adapter";
|
|
6
6
|
export * from "./hooks";
|
|
7
7
|
export * as helpers from "./helpers";
|
|
8
8
|
export * as types from "./types";
|
package/dist/index.js
CHANGED
|
@@ -28,10 +28,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.utils = exports.core = exports.types = exports.helpers = void 0;
|
|
30
30
|
__exportStar(require("./createReactor"), exports);
|
|
31
|
-
__exportStar(require("./context
|
|
32
|
-
__exportStar(require("./context/agent"), exports);
|
|
31
|
+
__exportStar(require("./context"), exports);
|
|
33
32
|
__exportStar(require("./provider/actor"), exports);
|
|
34
33
|
__exportStar(require("./provider/agent"), exports);
|
|
34
|
+
__exportStar(require("./provider/adapter"), exports);
|
|
35
35
|
__exportStar(require("./hooks"), exports);
|
|
36
36
|
exports.helpers = __importStar(require("./helpers"));
|
|
37
37
|
exports.types = __importStar(require("./types"));
|
package/dist/provider/actor.d.ts
CHANGED
|
@@ -25,4 +25,4 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
* This setup ensures that `YourComponent` and any of its children can interact with the specified IC actor through the context provided by `ActorProvider`.
|
|
27
27
|
*/
|
|
28
|
-
export declare const ActorProvider: import("react").FC<import("../types").ActorProviderProps>;
|
|
28
|
+
export declare const ActorProvider: import("react").FC<import("../context/types").ActorProviderProps>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CandidAdapterProviderProps } from "../context/types";
|
|
3
|
+
/**
|
|
4
|
+
* `CandidAdapterProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
5
|
+
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
6
|
+
*
|
|
7
|
+
* The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
|
|
8
|
+
* create various hooks related to agent operations and authentication processes. These hooks are made available to all
|
|
9
|
+
* child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
|
|
10
|
+
*
|
|
11
|
+
* @param children - Child components that can consume the context.
|
|
12
|
+
* @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
|
|
13
|
+
* will be created based on the provided options combined with default configuration.
|
|
14
|
+
* @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
|
|
15
|
+
* specified during the context creation and can include custom settings for the agent, such as identity,
|
|
16
|
+
* host URL, etc.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Wrap your component tree with `CandidAdapterProvider` to provide all child components access to IC agent and authentication hooks.
|
|
20
|
+
*
|
|
21
|
+
* ```jsx
|
|
22
|
+
* <CandidAdapterProvider>
|
|
23
|
+
* <YourComponent />
|
|
24
|
+
* </CandidAdapterProvider>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
28
|
+
* manage authentication, and perform other agent-related tasks.
|
|
29
|
+
*/
|
|
30
|
+
declare const CandidAdapterProvider: React.FC<CandidAdapterProviderProps>;
|
|
31
|
+
export { CandidAdapterProvider };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.CandidAdapterProvider = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const core_1 = require("@ic-reactor/core");
|
|
20
|
+
const adapter_1 = require("../context/adapter");
|
|
21
|
+
const hooks_1 = require("../hooks");
|
|
22
|
+
/**
|
|
23
|
+
* `CandidAdapterProvider` is a React functional component that serves as a context provider for IC agent and authentication hooks.
|
|
24
|
+
* It enables any child components to access and use the agent and authentication functionalities seamlessly.
|
|
25
|
+
*
|
|
26
|
+
* The provider encapsulates the logic for initializing and managing an agent manager instance, which is then used to
|
|
27
|
+
* create various hooks related to agent operations and authentication processes. These hooks are made available to all
|
|
28
|
+
* child components through the context, facilitating a centralized and efficient way to interact with the Internet Computer (IC) blockchain.
|
|
29
|
+
*
|
|
30
|
+
* @param children - Child components that can consume the context.
|
|
31
|
+
* @param agentManager - An optional `AgentManager` instance to be used by the provider. If not provided, a new instance
|
|
32
|
+
* will be created based on the provided options combined with default configuration.
|
|
33
|
+
* @param options - Configuration options for the `AgentManager`. These options are merged with any default configurations
|
|
34
|
+
* specified during the context creation and can include custom settings for the agent, such as identity,
|
|
35
|
+
* host URL, etc.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* Wrap your component tree with `CandidAdapterProvider` to provide all child components access to IC agent and authentication hooks.
|
|
39
|
+
*
|
|
40
|
+
* ```jsx
|
|
41
|
+
* <CandidAdapterProvider>
|
|
42
|
+
* <YourComponent />
|
|
43
|
+
* </CandidAdapterProvider>
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Inside `YourComponent` or any of its children, you can use the hooks provided through the context to interact with the IC,
|
|
47
|
+
* manage authentication, and perform other agent-related tasks.
|
|
48
|
+
*/
|
|
49
|
+
const CandidAdapterProvider = (_a) => {
|
|
50
|
+
var { children, initialParser, loadingComponent = react_1.default.createElement("div", null, "Loading...") } = _a, options = __rest(_a, ["children", "initialParser", "loadingComponent"]);
|
|
51
|
+
const [initalized, setInitialized] = react_1.default.useState(false);
|
|
52
|
+
const agentManager = (0, hooks_1.useAgentManager)();
|
|
53
|
+
const candidAdapter = react_1.default.useMemo(() => (0, core_1.createCandidAdapter)(Object.assign({ agentManager }, options)), [options, agentManager]);
|
|
54
|
+
react_1.default.useEffect(() => {
|
|
55
|
+
if (initialParser) {
|
|
56
|
+
candidAdapter.initializeParser().then(() => setInitialized(true));
|
|
57
|
+
}
|
|
58
|
+
}, []);
|
|
59
|
+
return (react_1.default.createElement(adapter_1.CandidAdapterContext.Provider, { value: candidAdapter }, initalized ? children : loadingComponent));
|
|
60
|
+
};
|
|
61
|
+
exports.CandidAdapterProvider = CandidAdapterProvider;
|
|
62
|
+
CandidAdapterProvider.displayName = "CandidAdapterContext";
|
package/dist/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface CreateReactorReturnType<A> extends ActorHooksReturnType<A>, Aut
|
|
|
6
6
|
getAgent: () => HttpAgent;
|
|
7
7
|
getVisitFunction: () => VisitService<A>;
|
|
8
8
|
}
|
|
9
|
-
export * from "./context/types";
|
|
9
|
+
export * from "./context/agent/types";
|
|
10
10
|
export * from "./helpers/types";
|
|
11
11
|
export * from "./hooks/types";
|
|
12
12
|
export * from "@ic-reactor/core/dist/types";
|
package/dist/types.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./context/types"), exports);
|
|
17
|
+
__exportStar(require("./context/agent/types"), exports);
|
|
18
18
|
__exportStar(require("./helpers/types"), exports);
|
|
19
19
|
__exportStar(require("./hooks/types"), exports);
|
|
20
20
|
__exportStar(require("@ic-reactor/core/dist/types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-beta.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,7 +35,7 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/core": "^1.
|
|
38
|
+
"@ic-reactor/core": "^1.6.0-beta.0",
|
|
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": "
|
|
50
|
+
"gitHead": "4911f0639b420406550150f789f34ecf3e6167c1"
|
|
51
51
|
}
|
|
File without changes
|