@ic-reactor/react 2.0.0 → 3.0.0-beta.1
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/README.md +105 -79
- package/dist/createActorHooks.d.ts +39 -0
- package/dist/createActorHooks.d.ts.map +1 -0
- package/dist/createActorHooks.js +30 -0
- package/dist/createActorHooks.js.map +1 -0
- package/dist/createAuthHooks.d.ts +37 -0
- package/dist/createAuthHooks.d.ts.map +1 -0
- package/dist/createAuthHooks.js +94 -0
- package/dist/createAuthHooks.js.map +1 -0
- package/dist/createInfiniteQuery.d.ts +129 -0
- package/dist/createInfiniteQuery.d.ts.map +1 -0
- package/dist/createInfiniteQuery.js +160 -0
- package/dist/createInfiniteQuery.js.map +1 -0
- package/dist/createMutation.d.ts +19 -0
- package/dist/createMutation.d.ts.map +1 -0
- package/dist/createMutation.js +98 -0
- package/dist/createMutation.js.map +1 -0
- package/dist/createQuery.d.ts +20 -0
- package/dist/createQuery.d.ts.map +1 -0
- package/dist/createQuery.js +111 -0
- package/dist/createQuery.js.map +1 -0
- package/dist/createSuspenseInfiniteQuery.d.ts +122 -0
- package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -0
- package/dist/createSuspenseInfiniteQuery.js +160 -0
- package/dist/createSuspenseInfiniteQuery.js.map +1 -0
- package/dist/createSuspenseQuery.d.ts +25 -0
- package/dist/createSuspenseQuery.d.ts.map +1 -0
- package/dist/createSuspenseQuery.js +116 -0
- package/dist/createSuspenseQuery.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -2
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +6 -18
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useActorInfiniteQuery.d.ts +37 -0
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -0
- package/dist/hooks/useActorInfiniteQuery.js +33 -0
- package/dist/hooks/useActorInfiniteQuery.js.map +1 -0
- package/dist/hooks/useActorMutation.d.ts +23 -0
- package/dist/hooks/useActorMutation.d.ts.map +1 -0
- package/dist/hooks/useActorMutation.js +39 -0
- package/dist/hooks/useActorMutation.js.map +1 -0
- package/dist/hooks/useActorQuery.d.ts +32 -0
- package/dist/hooks/useActorQuery.d.ts.map +1 -0
- package/dist/hooks/useActorQuery.js +35 -0
- package/dist/hooks/useActorQuery.js.map +1 -0
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +36 -0
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -0
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +33 -0
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -0
- package/dist/hooks/useActorSuspenseQuery.d.ts +32 -0
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -0
- package/dist/hooks/useActorSuspenseQuery.js +36 -0
- package/dist/hooks/useActorSuspenseQuery.js.map +1 -0
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -49
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +232 -13
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -22
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +131 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +125 -0
- package/dist/validation.js.map +1 -0
- package/package.json +70 -35
- package/LICENSE.md +0 -8
- package/dist/context/actor/create.d.ts +0 -63
- package/dist/context/actor/create.js +0 -119
- package/dist/context/actor/hooks/useActorInterface.d.ts +0 -4
- package/dist/context/actor/hooks/useActorInterface.js +0 -10
- package/dist/context/actor/hooks/useActorState.d.ts +0 -21
- package/dist/context/actor/hooks/useActorState.js +0 -25
- package/dist/context/actor/hooks/useActorStore.d.ts +0 -32
- package/dist/context/actor/hooks/useActorStore.js +0 -36
- package/dist/context/actor/hooks/useInitializeActor.d.ts +0 -6
- package/dist/context/actor/hooks/useInitializeActor.js +0 -10
- package/dist/context/actor/hooks/useMethod.d.ts +0 -29
- package/dist/context/actor/hooks/useMethod.js +0 -34
- package/dist/context/actor/hooks/useMethodAttributes.d.ts +0 -7
- package/dist/context/actor/hooks/useMethodAttributes.js +0 -11
- package/dist/context/actor/hooks/useMethodNames.d.ts +0 -7
- package/dist/context/actor/hooks/useMethodNames.js +0 -11
- package/dist/context/actor/hooks/useQueryCall.d.ts +0 -28
- package/dist/context/actor/hooks/useQueryCall.js +0 -33
- package/dist/context/actor/hooks/useUpdateCall.d.ts +0 -29
- package/dist/context/actor/hooks/useUpdateCall.js +0 -34
- package/dist/context/actor/hooks/useVisitMethod.d.ts +0 -8
- package/dist/context/actor/hooks/useVisitMethod.js +0 -13
- package/dist/context/actor/hooks/useVisitService.d.ts +0 -8
- package/dist/context/actor/hooks/useVisitService.js +0 -13
- package/dist/context/actor/index.d.ts +0 -16
- package/dist/context/actor/index.js +0 -33
- package/dist/context/actor/provider.d.ts +0 -71
- package/dist/context/actor/provider.js +0 -75
- package/dist/context/actor/types.d.ts +0 -35
- package/dist/context/actor/types.js +0 -2
- package/dist/context/adapter/create.d.ts +0 -2
- package/dist/context/adapter/create.js +0 -102
- package/dist/context/adapter/hooks/useCandidAdapter.d.ts +0 -23
- package/dist/context/adapter/hooks/useCandidAdapter.js +0 -27
- package/dist/context/adapter/hooks/useCandidEvaluation.d.ts +0 -5
- package/dist/context/adapter/hooks/useCandidEvaluation.js +0 -9
- package/dist/context/adapter/index.d.ts +0 -6
- package/dist/context/adapter/index.js +0 -24
- package/dist/context/adapter/provider.d.ts +0 -23
- package/dist/context/adapter/provider.js +0 -27
- package/dist/context/adapter/types.d.ts +0 -52
- package/dist/context/adapter/types.js +0 -2
- package/dist/context/agent/create.d.ts +0 -74
- package/dist/context/agent/create.js +0 -104
- package/dist/context/agent/hooks/useAgent.d.ts +0 -14
- package/dist/context/agent/hooks/useAgent.js +0 -18
- package/dist/context/agent/hooks/useAgentManager.d.ts +0 -14
- package/dist/context/agent/hooks/useAgentManager.js +0 -18
- package/dist/context/agent/hooks/useAgentState.d.ts +0 -21
- package/dist/context/agent/hooks/useAgentState.js +0 -25
- package/dist/context/agent/hooks/useAuth.d.ts +0 -57
- package/dist/context/agent/hooks/useAuth.js +0 -61
- package/dist/context/agent/hooks/useAuthState.d.ts +0 -19
- package/dist/context/agent/hooks/useAuthState.js +0 -23
- package/dist/context/agent/hooks/useUserPrincipal.d.ts +0 -17
- package/dist/context/agent/hooks/useUserPrincipal.js +0 -21
- package/dist/context/agent/index.d.ts +0 -12
- package/dist/context/agent/index.js +0 -29
- package/dist/context/agent/provider.d.ts +0 -28
- package/dist/context/agent/provider.js +0 -32
- package/dist/context/agent/types.d.ts +0 -17
- package/dist/context/agent/types.js +0 -2
- package/dist/core.d.ts +0 -1
- package/dist/core.js +0 -9
- package/dist/createReactor.d.ts +0 -49
- package/dist/createReactor.js +0 -69
- package/dist/helpers/actorHooks.d.ts +0 -18
- package/dist/helpers/actorHooks.js +0 -283
- package/dist/helpers/agentHooks.d.ts +0 -3
- package/dist/helpers/agentHooks.js +0 -22
- package/dist/helpers/authHooks.d.ts +0 -2
- package/dist/helpers/authHooks.js +0 -120
- package/dist/helpers/extractActorContext.d.ts +0 -4
- package/dist/helpers/extractActorContext.js +0 -44
- package/dist/helpers/extractAgentContext.d.ts +0 -28
- package/dist/helpers/extractAgentContext.js +0 -59
- package/dist/helpers/index.d.ts +0 -5
- package/dist/helpers/index.js +0 -21
- package/dist/helpers/types.d.ts +0 -222
- package/dist/helpers/types.js +0 -2
- package/dist/hooks/types.d.ts +0 -22
- package/dist/hooks/types.js +0 -2
- package/dist/hooks/useActor.d.ts +0 -67
- package/dist/hooks/useActor.js +0 -197
- package/dist/hooks/useActorManager.d.ts +0 -68
- package/dist/hooks/useActorManager.js +0 -75
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -17
|
@@ -1,102 +0,0 @@
|
|
|
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.createAdapterContext = createAdapterContext;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const agent_1 = require("../agent");
|
|
9
|
-
const core_1 = require("@ic-reactor/core");
|
|
10
|
-
function createAdapterContext(config = {}) {
|
|
11
|
-
const { withParser: _withParser, didjsCanisterId: _didjsCanisterId, ...defaultConfig } = config;
|
|
12
|
-
const CandidAdapterContext = react_1.default.createContext(null);
|
|
13
|
-
const useCandidAdapter = () => {
|
|
14
|
-
const context = react_1.default.useContext(CandidAdapterContext);
|
|
15
|
-
if (!context) {
|
|
16
|
-
throw new Error("Actor hooks must be used within a ActorProvider");
|
|
17
|
-
}
|
|
18
|
-
return context;
|
|
19
|
-
};
|
|
20
|
-
const useCandidEvaluation = () => {
|
|
21
|
-
const [state, setState] = react_1.default.useState({
|
|
22
|
-
fetching: true,
|
|
23
|
-
isFetching: true,
|
|
24
|
-
fetchError: null,
|
|
25
|
-
});
|
|
26
|
-
const candidAdapter = useCandidAdapter();
|
|
27
|
-
const validateCandid = react_1.default.useCallback((candidString) => {
|
|
28
|
-
setState({
|
|
29
|
-
fetchError: null,
|
|
30
|
-
fetching: false,
|
|
31
|
-
isFetching: false,
|
|
32
|
-
});
|
|
33
|
-
try {
|
|
34
|
-
return candidAdapter.validateIDL(candidString);
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
setState({
|
|
38
|
-
fetchError: `Error validating Candid definition, ${err}`,
|
|
39
|
-
fetching: false,
|
|
40
|
-
isFetching: false,
|
|
41
|
-
});
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}, []);
|
|
45
|
-
const isCandidValid = react_1.default.useCallback((candidString) => {
|
|
46
|
-
return validateCandid(candidString) !== false;
|
|
47
|
-
}, [validateCandid]);
|
|
48
|
-
const evaluateCandid = react_1.default.useCallback(async (candidString) => {
|
|
49
|
-
setState({
|
|
50
|
-
fetchError: null,
|
|
51
|
-
fetching: true,
|
|
52
|
-
isFetching: true,
|
|
53
|
-
});
|
|
54
|
-
try {
|
|
55
|
-
const definition = await candidAdapter.evaluateCandidDefinition(candidString);
|
|
56
|
-
if (typeof definition?.idlFactory !== "function") {
|
|
57
|
-
throw new Error("No Function found in Candid definition!");
|
|
58
|
-
}
|
|
59
|
-
setState({
|
|
60
|
-
fetchError: null,
|
|
61
|
-
fetching: false,
|
|
62
|
-
isFetching: false,
|
|
63
|
-
});
|
|
64
|
-
return definition.idlFactory;
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
setState({
|
|
68
|
-
fetchError: `Error evaluating Candid definition, ${err}`,
|
|
69
|
-
fetching: false,
|
|
70
|
-
isFetching: false,
|
|
71
|
-
});
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
}, []);
|
|
75
|
-
return { evaluateCandid, isCandidValid, validateCandid, ...state };
|
|
76
|
-
};
|
|
77
|
-
const CandidAdapterProvider = ({ children, withParser = _withParser, loadingComponent = react_1.default.createElement("div", null, "Loading Parser..."), didjsCanisterId = _didjsCanisterId, ...restConfig }) => {
|
|
78
|
-
const config = react_1.default.useMemo(() => ({
|
|
79
|
-
...defaultConfig,
|
|
80
|
-
...restConfig,
|
|
81
|
-
}), [defaultConfig, restConfig]);
|
|
82
|
-
const [initalized, setInitialized] = react_1.default.useState(false);
|
|
83
|
-
const agentManager = (0, agent_1.useAgentManager)();
|
|
84
|
-
const candidAdapter = react_1.default.useMemo(() => (0, core_1.createCandidAdapter)({ agentManager, didjsCanisterId, ...config }), [didjsCanisterId, agentManager]);
|
|
85
|
-
react_1.default.useEffect(() => {
|
|
86
|
-
if (withParser) {
|
|
87
|
-
candidAdapter.initializeParser().then(() => setInitialized(true));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
setInitialized(true);
|
|
91
|
-
}
|
|
92
|
-
}, []);
|
|
93
|
-
return (react_1.default.createElement(CandidAdapterContext.Provider, { value: candidAdapter }, initalized ? children : loadingComponent));
|
|
94
|
-
};
|
|
95
|
-
CandidAdapterProvider.displayName = "CandidAdapterProvider";
|
|
96
|
-
return {
|
|
97
|
-
CandidAdapterContext,
|
|
98
|
-
CandidAdapterProvider,
|
|
99
|
-
useCandidEvaluation,
|
|
100
|
-
useCandidAdapter,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accesses the `CandidAdapter` to download the actor's Candid interface.
|
|
3
|
-
*
|
|
4
|
-
* @param config - `UseCandidAdapterParams` The configuration object.
|
|
5
|
-
* @returns The `CandidAdapter` instance.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```jsx
|
|
9
|
-
* function CandidAdapterComponent() {
|
|
10
|
-
* const candidAdapter = useCandidAdapter();
|
|
11
|
-
*
|
|
12
|
-
* const getActor = async () => {
|
|
13
|
-
* const { idlFactory } = await candidAdapter.getCandidDefinition(canisterId)
|
|
14
|
-
* console.log(idlFactory)
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* return (
|
|
18
|
-
* <button onClick={getActor}>Get Actor</button>
|
|
19
|
-
* );
|
|
20
|
-
* }
|
|
21
|
-
*```
|
|
22
|
-
*/
|
|
23
|
-
export declare const useCandidAdapter: () => import("@ic-reactor/core/dist/classes").CandidAdapter;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCandidAdapter = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
/**
|
|
6
|
-
* Accesses the `CandidAdapter` to download the actor's Candid interface.
|
|
7
|
-
*
|
|
8
|
-
* @param config - `UseCandidAdapterParams` The configuration object.
|
|
9
|
-
* @returns The `CandidAdapter` instance.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```jsx
|
|
13
|
-
* function CandidAdapterComponent() {
|
|
14
|
-
* const candidAdapter = useCandidAdapter();
|
|
15
|
-
*
|
|
16
|
-
* const getActor = async () => {
|
|
17
|
-
* const { idlFactory } = await candidAdapter.getCandidDefinition(canisterId)
|
|
18
|
-
* console.log(idlFactory)
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* return (
|
|
22
|
-
* <button onClick={getActor}>Get Actor</button>
|
|
23
|
-
* );
|
|
24
|
-
* }
|
|
25
|
-
*```
|
|
26
|
-
*/
|
|
27
|
-
exports.useCandidAdapter = __1.AdapterHooks.useCandidAdapter;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCandidEvaluation = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
/**
|
|
6
|
-
* Accesses the `CandidEvaluation` function to evaluate the actor's Candid interface from a string
|
|
7
|
-
* into an `idlFactory`.
|
|
8
|
-
*/
|
|
9
|
-
exports.useCandidEvaluation = __1.AdapterHooks.useCandidEvaluation;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** @ignore */
|
|
2
|
-
export declare const AdapterHooks: import("./types").CreateCandidAdapterContextReturnType;
|
|
3
|
-
export declare const CandidAdapterContext: import("react").Context<import("@ic-reactor/core/dist/classes").CandidAdapter | null>;
|
|
4
|
-
export * from "./provider";
|
|
5
|
-
export * from "./hooks/useCandidAdapter";
|
|
6
|
-
export * from "./hooks/useCandidEvaluation";
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
exports.CandidAdapterContext = exports.AdapterHooks = void 0;
|
|
18
|
-
const create_1 = require("./create");
|
|
19
|
-
/** @ignore */
|
|
20
|
-
exports.AdapterHooks = (0, create_1.createAdapterContext)();
|
|
21
|
-
exports.CandidAdapterContext = exports.AdapterHooks.CandidAdapterContext;
|
|
22
|
-
__exportStar(require("./provider"), exports);
|
|
23
|
-
__exportStar(require("./hooks/useCandidAdapter"), exports);
|
|
24
|
-
__exportStar(require("./hooks/useCandidEvaluation"), exports);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `CandidAdapterProvider` is a React component that provides the CandidAdapter to its children.
|
|
3
|
-
* It initializes the CandidAdapter with the provided options and makes it available to all children.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```tsx
|
|
7
|
-
* import { AgentProvider, CandidAdapterProvider, ActorProvider } from "@ic-reactor/react"
|
|
8
|
-
*
|
|
9
|
-
* const App = () => (
|
|
10
|
-
* <AgentProvider>
|
|
11
|
-
* <CandidAdapterProvider>
|
|
12
|
-
* Your Actors here, it will able to fetch the Candid interface
|
|
13
|
-
* you dont need to pass the idlFactory to the Actor component
|
|
14
|
-
* e.g.
|
|
15
|
-
* <ActorProvider canisterId="ryjl3-tyaaa-aaaaa-aaaba-cai" />
|
|
16
|
-
* </CandidAdapterProvider>
|
|
17
|
-
* </AgentProvider>
|
|
18
|
-
* )
|
|
19
|
-
*
|
|
20
|
-
* export default App
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare const CandidAdapterProvider: import("react").FC<import("./types").CandidAdapterProviderProps>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CandidAdapterProvider = void 0;
|
|
4
|
-
const _1 = require(".");
|
|
5
|
-
/**
|
|
6
|
-
* `CandidAdapterProvider` is a React component that provides the CandidAdapter to its children.
|
|
7
|
-
* It initializes the CandidAdapter with the provided options and makes it available to all children.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* import { AgentProvider, CandidAdapterProvider, ActorProvider } from "@ic-reactor/react"
|
|
12
|
-
*
|
|
13
|
-
* const App = () => (
|
|
14
|
-
* <AgentProvider>
|
|
15
|
-
* <CandidAdapterProvider>
|
|
16
|
-
* Your Actors here, it will able to fetch the Candid interface
|
|
17
|
-
* you dont need to pass the idlFactory to the Actor component
|
|
18
|
-
* e.g.
|
|
19
|
-
* <ActorProvider canisterId="ryjl3-tyaaa-aaaaa-aaaba-cai" />
|
|
20
|
-
* </CandidAdapterProvider>
|
|
21
|
-
* </AgentProvider>
|
|
22
|
-
* )
|
|
23
|
-
*
|
|
24
|
-
* export default App
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
exports.CandidAdapterProvider = _1.AdapterHooks.CandidAdapterProvider;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { PropsWithChildren } from "react";
|
|
2
|
-
import type { IDL } from "@dfinity/candid";
|
|
3
|
-
import { CandidAdapter } from "@ic-reactor/core/dist/classes";
|
|
4
|
-
import { CandidAdapterParameters } from "../../types";
|
|
5
|
-
export type CandidAdapterContextType = CandidAdapter;
|
|
6
|
-
export interface CandidAdapterProviderProps extends PropsWithChildren, CandidAdapterParameters {
|
|
7
|
-
withParser?: boolean;
|
|
8
|
-
loadingComponent?: React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
export interface CreateCandidAdapterContextParameters extends CandidAdapterParameters {
|
|
11
|
-
withParser?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface UseCandidEvaluationReturnType {
|
|
14
|
-
/**
|
|
15
|
-
* The error message encountered during the fetch operation, or `null` if no error occurred.
|
|
16
|
-
*/
|
|
17
|
-
fetchError: string | null;
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Use `isFetching` instead.
|
|
20
|
-
* Indicates whether a fetch operation is currently in progress.
|
|
21
|
-
*/
|
|
22
|
-
fetching: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Indicates whether a fetch operation is currently in progress.
|
|
25
|
-
*/
|
|
26
|
-
isFetching: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use `isCandidValid` instead.
|
|
29
|
-
* Validates the provided Candid interface definition string.
|
|
30
|
-
* @param candidString - The Candid definition to validate.
|
|
31
|
-
* @returns `true` if the string is valid, `false` otherwise.
|
|
32
|
-
*/
|
|
33
|
-
validateCandid: (candidString: string) => boolean | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Validates the provided Candid interface definition string.
|
|
36
|
-
* @param candidString - The Candid definition to validate.
|
|
37
|
-
* @returns `true` if valid, `false` otherwise.
|
|
38
|
-
*/
|
|
39
|
-
isCandidValid: (candidString: string) => boolean | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Evaluates the provided Candid interface definition string.
|
|
42
|
-
* @param candidString - The Candid definition to evaluate.
|
|
43
|
-
* @returns A promise resolving to the corresponding InterfaceFactory if the evaluation succeeds, otherwise `undefined`.
|
|
44
|
-
*/
|
|
45
|
-
evaluateCandid: (candidString: string) => Promise<IDL.InterfaceFactory | undefined>;
|
|
46
|
-
}
|
|
47
|
-
export interface CreateCandidAdapterContextReturnType {
|
|
48
|
-
CandidAdapterContext: React.Context<CandidAdapterContextType | null>;
|
|
49
|
-
CandidAdapterProvider: React.FC<CandidAdapterProviderProps>;
|
|
50
|
-
useCandidEvaluation: () => UseCandidEvaluationReturnType;
|
|
51
|
-
useCandidAdapter: () => CandidAdapter;
|
|
52
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { CreateAgentContextReturnType, CreateAgentCotextParameters } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
4
|
-
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
5
|
-
*
|
|
6
|
-
* @param config A partial configuration object {@link CreateAgentCotextParameters}, allowing customization of the agent's behavior.
|
|
7
|
-
*
|
|
8
|
-
* @returns
|
|
9
|
-
* An object containing the {@link AgentProvider} component and various hooks for interacting with the agent and authentication state.
|
|
10
|
-
* The {@link AgentProvider} component is a React context provider that should wrap your app or components needing access to agent functionalities.
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
14
|
-
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
15
|
-
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
16
|
-
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* // agent.ts
|
|
21
|
-
* import { createAgentContext } from "@ic-reactor/react";
|
|
22
|
-
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
23
|
-
*
|
|
24
|
-
* // Optional: Define custom agent configuration
|
|
25
|
-
* const agentConfig: CreateAgentCotextParameters = {
|
|
26
|
-
* host: "https://localhost:8000",
|
|
27
|
-
* // or
|
|
28
|
-
* // withLocalEnv: true,
|
|
29
|
-
* // port: 8000,
|
|
30
|
-
* };
|
|
31
|
-
*
|
|
32
|
-
* export const {
|
|
33
|
-
* AgentProvider,
|
|
34
|
-
* useAgent,
|
|
35
|
-
* useAuth,
|
|
36
|
-
* useAuthState,
|
|
37
|
-
* useAgentState,
|
|
38
|
-
* useAgentManager,
|
|
39
|
-
* useUserPrincipal,
|
|
40
|
-
* } = createAgentContext(agentConfig);
|
|
41
|
-
*```
|
|
42
|
-
* Now you can use the returned hooks in your React components
|
|
43
|
-
*
|
|
44
|
-
* ```tsx
|
|
45
|
-
* // App.tsx
|
|
46
|
-
* import React from 'react';
|
|
47
|
-
* import { AgentProvider } from './agent';
|
|
48
|
-
*
|
|
49
|
-
* const App = () => (
|
|
50
|
-
* <AgentProvider>
|
|
51
|
-
* <Login />
|
|
52
|
-
* <YourActor />
|
|
53
|
-
* </AgentProvider>
|
|
54
|
-
* );
|
|
55
|
-
*
|
|
56
|
-
* const Login = () => {
|
|
57
|
-
* const { login } = useAuth()
|
|
58
|
-
* const principal = useUserPrincipal()
|
|
59
|
-
*
|
|
60
|
-
* return (
|
|
61
|
-
* <div>
|
|
62
|
-
* <button onClick={() => login()}>Login</button>
|
|
63
|
-
* <p>User: {principal?.toText()}</p>
|
|
64
|
-
* </div>
|
|
65
|
-
* )
|
|
66
|
-
* };
|
|
67
|
-
*
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* This setup allows you to use the agent and authentication hooks within
|
|
71
|
-
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
72
|
-
* with the Internet Computer blockchain.
|
|
73
|
-
*/
|
|
74
|
-
export declare function createAgentContext(config?: CreateAgentCotextParameters): CreateAgentContextReturnType;
|
|
@@ -1,104 +0,0 @@
|
|
|
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.createAgentContext = createAgentContext;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const core_1 = require("@ic-reactor/core");
|
|
9
|
-
const agentHooks_1 = require("../../helpers/agentHooks");
|
|
10
|
-
const authHooks_1 = require("../../helpers/authHooks");
|
|
11
|
-
const extractAgentContext_1 = require("../../helpers/extractAgentContext");
|
|
12
|
-
/**
|
|
13
|
-
* Creates a React context for managing IC agent and authentication states, providing hooks for interacting with the IC blockchain.
|
|
14
|
-
* This function initializes an `AgentContext` with a set of utilities and hooks based on the provided agent configuration.
|
|
15
|
-
*
|
|
16
|
-
* @param config A partial configuration object {@link CreateAgentCotextParameters}, allowing customization of the agent's behavior.
|
|
17
|
-
*
|
|
18
|
-
* @returns
|
|
19
|
-
* An object containing the {@link AgentProvider} component and various hooks for interacting with the agent and authentication state.
|
|
20
|
-
* The {@link AgentProvider} component is a React context provider that should wrap your app or components needing access to agent functionalities.
|
|
21
|
-
*
|
|
22
|
-
* Usage:
|
|
23
|
-
* - {@link AgentProvider}: React component to provide agent context to your application.
|
|
24
|
-
* - {@link useAgent}, {@link useAuth}, {@link useAuthState},
|
|
25
|
-
* {@link useAgentState}, {@link useAgentManager}, {@link useUserPrincipal}:
|
|
26
|
-
* Hooks extracted from the created context for managing agent and authentication state within components.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* // agent.ts
|
|
31
|
-
* import { createAgentContext } from "@ic-reactor/react";
|
|
32
|
-
* import { CreateAgentCotextParameters } from "@ic-reactor/react/dist/types";
|
|
33
|
-
*
|
|
34
|
-
* // Optional: Define custom agent configuration
|
|
35
|
-
* const agentConfig: CreateAgentCotextParameters = {
|
|
36
|
-
* host: "https://localhost:8000",
|
|
37
|
-
* // or
|
|
38
|
-
* // withLocalEnv: true,
|
|
39
|
-
* // port: 8000,
|
|
40
|
-
* };
|
|
41
|
-
*
|
|
42
|
-
* export const {
|
|
43
|
-
* AgentProvider,
|
|
44
|
-
* useAgent,
|
|
45
|
-
* useAuth,
|
|
46
|
-
* useAuthState,
|
|
47
|
-
* useAgentState,
|
|
48
|
-
* useAgentManager,
|
|
49
|
-
* useUserPrincipal,
|
|
50
|
-
* } = createAgentContext(agentConfig);
|
|
51
|
-
*```
|
|
52
|
-
* Now you can use the returned hooks in your React components
|
|
53
|
-
*
|
|
54
|
-
* ```tsx
|
|
55
|
-
* // App.tsx
|
|
56
|
-
* import React from 'react';
|
|
57
|
-
* import { AgentProvider } from './agent';
|
|
58
|
-
*
|
|
59
|
-
* const App = () => (
|
|
60
|
-
* <AgentProvider>
|
|
61
|
-
* <Login />
|
|
62
|
-
* <YourActor />
|
|
63
|
-
* </AgentProvider>
|
|
64
|
-
* );
|
|
65
|
-
*
|
|
66
|
-
* const Login = () => {
|
|
67
|
-
* const { login } = useAuth()
|
|
68
|
-
* const principal = useUserPrincipal()
|
|
69
|
-
*
|
|
70
|
-
* return (
|
|
71
|
-
* <div>
|
|
72
|
-
* <button onClick={() => login()}>Login</button>
|
|
73
|
-
* <p>User: {principal?.toText()}</p>
|
|
74
|
-
* </div>
|
|
75
|
-
* )
|
|
76
|
-
* };
|
|
77
|
-
*
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* This setup allows you to use the agent and authentication hooks within
|
|
81
|
-
* the components wrapped by {@link AgentProvider}, facilitating interaction
|
|
82
|
-
* with the Internet Computer blockchain.
|
|
83
|
-
*/
|
|
84
|
-
function createAgentContext(config = {}) {
|
|
85
|
-
const { disableAuthenticateOnMount: defaultDisable, ...contextOptions } = config;
|
|
86
|
-
const AgentContext = react_1.default.createContext(null);
|
|
87
|
-
const AgentProvider = ({ children, agentManager: mybeAgentManager, disableAuthenticateOnMount = defaultDisable ?? false, ...options }) => {
|
|
88
|
-
const hooks = react_1.default.useMemo(() => {
|
|
89
|
-
const agentManager = mybeAgentManager ??
|
|
90
|
-
(0, core_1.createAgentManager)({ ...options, ...contextOptions });
|
|
91
|
-
if (!disableAuthenticateOnMount) {
|
|
92
|
-
agentManager.authenticate();
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
...(0, agentHooks_1.agentHooks)(agentManager),
|
|
96
|
-
...(0, authHooks_1.authHooks)(agentManager),
|
|
97
|
-
agentManager,
|
|
98
|
-
};
|
|
99
|
-
}, []);
|
|
100
|
-
return (react_1.default.createElement(AgentContext.Provider, { value: hooks }, children));
|
|
101
|
-
};
|
|
102
|
-
AgentProvider.displayName = "AgentProvider";
|
|
103
|
-
return { AgentContext, AgentProvider, ...(0, extractAgentContext_1.extractAgentContext)(AgentContext) };
|
|
104
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accesses the current agent instance.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
*```jsx
|
|
6
|
-
* function AgentComponent() {
|
|
7
|
-
* const agent = useAgent();
|
|
8
|
-
*
|
|
9
|
-
* // Use agent for interacting with the Internet Computer.
|
|
10
|
-
* return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
|
|
11
|
-
* }
|
|
12
|
-
*```
|
|
13
|
-
*/
|
|
14
|
-
export declare const useAgent: () => import("@dfinity/agent").HttpAgent | undefined;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAgent = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
/**
|
|
6
|
-
* Accesses the current agent instance.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*```jsx
|
|
10
|
-
* function AgentComponent() {
|
|
11
|
-
* const agent = useAgent();
|
|
12
|
-
*
|
|
13
|
-
* // Use agent for interacting with the Internet Computer.
|
|
14
|
-
* return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
|
|
15
|
-
* }
|
|
16
|
-
*```
|
|
17
|
-
*/
|
|
18
|
-
exports.useAgent = __1.AgentHooks.useAgent;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
*```jsx
|
|
6
|
-
* function AgentManagerComponent() {
|
|
7
|
-
* const agentManager = useAgentManager();
|
|
8
|
-
*
|
|
9
|
-
* // Use agentManager for managing agent configurations, etc.
|
|
10
|
-
* return <div>Agent Manager ready.</div>;
|
|
11
|
-
* }
|
|
12
|
-
*```
|
|
13
|
-
*/
|
|
14
|
-
export declare const useAgentManager: () => import("@ic-reactor/core/dist/types").AgentManager;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAgentManager = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
/**
|
|
6
|
-
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*```jsx
|
|
10
|
-
* function AgentManagerComponent() {
|
|
11
|
-
* const agentManager = useAgentManager();
|
|
12
|
-
*
|
|
13
|
-
* // Use agentManager for managing agent configurations, etc.
|
|
14
|
-
* return <div>Agent Manager ready.</div>;
|
|
15
|
-
* }
|
|
16
|
-
*```
|
|
17
|
-
*/
|
|
18
|
-
exports.useAgentManager = __1.AgentHooks.useAgentManager;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accesses the current state of the agent.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```jsx
|
|
6
|
-
* function AgentStateComponent() {
|
|
7
|
-
* const { initialized, initializing } = useAgentState();
|
|
8
|
-
*
|
|
9
|
-
* return (
|
|
10
|
-
* <div>
|
|
11
|
-
* {initialized
|
|
12
|
-
* ? 'Agent is initialized.'
|
|
13
|
-
* : initializing
|
|
14
|
-
* ? 'Agent is initializing...'
|
|
15
|
-
* : 'Agent is not initialized.'}
|
|
16
|
-
* </div>
|
|
17
|
-
* );
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare const useAgentState: () => import("@ic-reactor/core/dist/types").AgentState;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAgentState = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
/**
|
|
6
|
-
* Accesses the current state of the agent.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```jsx
|
|
10
|
-
* function AgentStateComponent() {
|
|
11
|
-
* const { initialized, initializing } = useAgentState();
|
|
12
|
-
*
|
|
13
|
-
* return (
|
|
14
|
-
* <div>
|
|
15
|
-
* {initialized
|
|
16
|
-
* ? 'Agent is initialized.'
|
|
17
|
-
* : initializing
|
|
18
|
-
* ? 'Agent is initializing...'
|
|
19
|
-
* : 'Agent is not initialized.'}
|
|
20
|
-
* </div>
|
|
21
|
-
* );
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
exports.useAgentState = __1.AgentHooks.useAgentState;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `useAuth` is a custom React hook designed to manage authentication processes in applications interacting with the Internet Computer (IC).
|
|
3
|
-
* It encapsulates the logic for logging in, logging out, and maintaining the authentication state, leveraging an authentication client.
|
|
4
|
-
*
|
|
5
|
-
* @param options - An optional object containing the following properties:
|
|
6
|
-
* - `onAuthentication`: Callback function triggered before authentication starts.
|
|
7
|
-
* - `onAuthenticationSuccess`: Callback function triggered on successful authentication, receives the authenticated `Identity`.
|
|
8
|
-
* - `onAuthenticationFailure`: Callback function triggered on authentication failure, receives the error.
|
|
9
|
-
* - `onLogin`: Callback function triggered before the login process starts.
|
|
10
|
-
* - `onLoginSuccess`: Callback function triggered on successful login, receives the user's `Principal`.
|
|
11
|
-
* - `onLoginError`: Callback function triggered on login error, receives the error.
|
|
12
|
-
* - `onLoggedOut`: Callback function triggered after logging out.
|
|
13
|
-
*
|
|
14
|
-
* @returns An object containing the following properties:
|
|
15
|
-
* - `authenticated`: Boolean indicating if the user is currently authenticated.
|
|
16
|
-
* - `authenticating`: Boolean indicating if an authentication process is currently underway.
|
|
17
|
-
* - `identity`: The authenticated user's `Identity`, if available.
|
|
18
|
-
* - `error`: Any error that occurred during the authentication process.
|
|
19
|
-
* - `login`: Function to initiate the login process, optionally accepting `LoginParameters`.
|
|
20
|
-
* - `logout`: Function to log the user out, optionally accepting `LogoutParameters`.
|
|
21
|
-
* - `authenticate`: Function to authenticate the user, internally used by `login` and `logout`.
|
|
22
|
-
* - `loginLoading`: Boolean indicating if a login operation is in progress.
|
|
23
|
-
* - `loginError`: Error object if an error occurred during the login process.
|
|
24
|
-
*
|
|
25
|
-
* Usage:
|
|
26
|
-
* This hook can be used to add authentication functionality to your IC application components, handling user login, logout, and authentication state management seamlessly.
|
|
27
|
-
*
|
|
28
|
-
* Example:
|
|
29
|
-
* ```jsx
|
|
30
|
-
* const YourComponent = () => {
|
|
31
|
-
* const { login, logout, authenticated, identity, loginError } = useAuth({
|
|
32
|
-
* onLoginSuccess: (principal) => console.log(`Logged in as ${principal}`),
|
|
33
|
-
* onLoginError: (error) => console.error(`Login failed: ${error.message}`),
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* if (loginError) {
|
|
37
|
-
* return <div>Error logging in: {loginError.message}</div>;
|
|
38
|
-
* }
|
|
39
|
-
*
|
|
40
|
-
* return (
|
|
41
|
-
* <div>
|
|
42
|
-
* {authenticated ? (
|
|
43
|
-
* <>
|
|
44
|
-
* <div>Authenticated as {identity.getPrincipal().toText()}</div>
|
|
45
|
-
* <button onClick={() => logout()}>Logout</button>
|
|
46
|
-
* </>
|
|
47
|
-
* ) : (
|
|
48
|
-
* <button onClick={() => login()}>Login</button>
|
|
49
|
-
* )}
|
|
50
|
-
* </div>
|
|
51
|
-
* );
|
|
52
|
-
* };
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* This hook simplifies integrating authentication flows into your IC application, providing hooks for various stages of the authentication process.
|
|
56
|
-
*/
|
|
57
|
-
export declare const useAuth: (options?: import("../../../types").UseAuthParameters) => import("../../../types").UseAuthReturnType;
|