@ic-reactor/react 1.0.2 → 1.0.4
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/helpers/actor.d.ts +21 -3
- package/dist/helpers/actor.js +42 -45
- package/dist/helpers/agent.d.ts +2 -5
- package/dist/helpers/agent.js +4 -6
- package/dist/helpers/auth.d.ts +2 -20
- package/dist/helpers/auth.js +65 -87
- package/dist/helpers/types.d.ts +86 -4
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +1 -2
- package/dist/hooks/types.d.ts +19 -0
- package/dist/hooks/useReactor.d.ts +41 -0
- package/dist/hooks/useReactor.js +121 -0
- package/dist/index.d.ts +3 -29
- package/dist/index.js +4 -39
- package/dist/main.d.ts +2 -0
- package/dist/main.js +35 -0
- package/dist/provider/actor/context.d.ts +20 -0
- package/dist/provider/actor/context.js +184 -0
- package/dist/provider/actor/index.d.ts +3 -0
- package/dist/provider/actor/index.js +9 -0
- package/dist/{context → provider}/actor/types.d.ts +4 -11
- package/dist/{context → provider}/agent/hooks.d.ts +4 -16
- package/dist/{context → provider}/agent/hooks.js +9 -9
- package/dist/provider/agent/types.js +2 -0
- package/dist/types.d.ts +7 -72
- package/dist/types.js +3 -2
- package/package.json +3 -3
- package/dist/context/actor/index.d.ts +0 -16
- package/dist/context/actor/index.js +0 -88
- package/dist/hooks/useActor.d.ts +0 -21
- package/dist/hooks/useActor.js +0 -48
- package/dist/hooks/useCandid.d.ts +0 -18
- package/dist/hooks/useCandid.js +0 -54
- /package/dist/{context/actor → hooks}/types.js +0 -0
- /package/dist/{context/agent → provider/actor}/types.js +0 -0
- /package/dist/{context → provider}/agent/context.d.ts +0 -0
- /package/dist/{context → provider}/agent/context.js +0 -0
- /package/dist/{context → provider}/agent/index.d.ts +0 -0
- /package/dist/{context → provider}/agent/index.js +0 -0
- /package/dist/{context → provider}/agent/types.d.ts +0 -0
- /package/dist/{context → provider}/index.d.ts +0 -0
- /package/dist/{context → provider}/index.js +0 -0
package/dist/types.d.ts
CHANGED
|
@@ -1,76 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import type { AgentHooks, AuthHooks } from "./helpers/types";
|
|
1
|
+
import type { HttpAgent, VisitService } from "@ic-reactor/core/dist/types";
|
|
2
|
+
import type { ActorHooks, AgentHooks, AuthHooks } from "./helpers/types";
|
|
4
3
|
export * from "@ic-reactor/core/dist/types";
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
4
|
+
export * from "./provider/agent/types";
|
|
5
|
+
export * from "./provider/actor/types";
|
|
6
|
+
export * from "./hooks/types";
|
|
7
7
|
export * from "./helpers/types";
|
|
8
|
-
export
|
|
9
|
-
onAuthentication?: (promise: () => Promise<Identity>) => void;
|
|
10
|
-
onAuthenticationSuccess?: (identity: Identity) => void;
|
|
11
|
-
onAuthenticationFailure?: (error: Error) => void;
|
|
12
|
-
onLoginSuccess?: (principal: Principal) => void;
|
|
13
|
-
onLoginError?: (error: Error) => void;
|
|
14
|
-
onLogin?: (promise: () => Promise<Principal>) => void;
|
|
15
|
-
onLoggedOut?: () => void;
|
|
16
|
-
};
|
|
17
|
-
export type ActorCallArgs<A, M extends FunctionName<A>> = {
|
|
18
|
-
functionName: M;
|
|
19
|
-
args?: ActorMethodArgs<A[M]>;
|
|
20
|
-
onLoading?: (loading: boolean) => void;
|
|
21
|
-
onError?: (error: Error | undefined) => void;
|
|
22
|
-
onSuccess?: (data: ActorMethodReturnType<A[M]> | undefined) => void;
|
|
23
|
-
throwOnError?: boolean;
|
|
24
|
-
};
|
|
25
|
-
export type ActorHookState<A, M extends FunctionName<A>> = {
|
|
26
|
-
data: ActorMethodReturnType<A[M]> | undefined;
|
|
27
|
-
error: Error | undefined;
|
|
28
|
-
loading: boolean;
|
|
29
|
-
};
|
|
30
|
-
export interface ActorUseQueryArgs<A, M extends FunctionName<A>> extends ActorCallArgs<A, M> {
|
|
31
|
-
refetchOnMount?: boolean;
|
|
32
|
-
refetchInterval?: number | false;
|
|
33
|
-
}
|
|
34
|
-
export interface ActorUseUpdateArgs<A, M extends FunctionName<A>> extends ActorCallArgs<A, M> {
|
|
35
|
-
}
|
|
36
|
-
export type ActorCallReturn<A, M extends FunctionName<A>> = ActorHookState<A, M> & {
|
|
37
|
-
reset: () => void;
|
|
38
|
-
call: (eventOrReplaceArgs?: React.MouseEvent | ActorMethodArgs<A[M]>) => Promise<ActorMethodReturnType<A[M]> | undefined>;
|
|
39
|
-
};
|
|
40
|
-
export type ActorCall<A> = <M extends FunctionName<A>>(args: ActorCallArgs<A, M>) => ActorCallReturn<A, M>;
|
|
41
|
-
export type ActorQueryCall<A> = <M extends FunctionName<A>>(args: ActorUseQueryArgs<A, M>) => ActorCallReturn<A, M>;
|
|
42
|
-
export type ActorUpdateCall<A> = <M extends FunctionName<A>>(args: ActorUseUpdateArgs<A, M>) => ActorCallReturn<A, M>;
|
|
43
|
-
export type ActorMethodCall<A, M extends FunctionName<A>> = (args: ActorUseMethodCallArg<A, M>) => ActorUseMethodCallReturn<A, M>;
|
|
44
|
-
export interface ActorUseMethodCallReturn<A, M extends FunctionName<A>, F extends boolean = false> extends ActorCallReturn<A, M> {
|
|
45
|
-
visit: F extends true ? VisitService<A>[M] : undefined;
|
|
46
|
-
reset: () => void;
|
|
47
|
-
error: Error | undefined;
|
|
48
|
-
loading: boolean;
|
|
49
|
-
}
|
|
50
|
-
export type ActorUseMethodCallArg<A, M extends FunctionName<A>> = ActorCallArgs<A, M>;
|
|
51
|
-
export type ActorHooks<A, F extends boolean = false> = ActorDefaultHooks<A, F> & (F extends true ? ActorFieldHooks<A> : object);
|
|
52
|
-
export interface ActorFieldHooks<A> {
|
|
53
|
-
useVisitMethod: <M extends FunctionName<A>>(functionName: M) => VisitService<A>[M];
|
|
54
|
-
}
|
|
55
|
-
export type UseActorStoreReturn<A> = ActorState<A> & {
|
|
56
|
-
canisterId: CanisterId;
|
|
57
|
-
};
|
|
58
|
-
export interface ActorDefaultHooks<A, F extends boolean> {
|
|
59
|
-
initialize: () => Promise<void>;
|
|
60
|
-
useActorState: () => UseActorStoreReturn<A>;
|
|
61
|
-
useQueryCall: ActorQueryCall<A>;
|
|
62
|
-
useUpdateCall: ActorUpdateCall<A>;
|
|
63
|
-
useMethodCall: <M extends FunctionName<A>>(args: ActorUseMethodCallArg<A, M>) => ActorUseMethodCallReturn<A, M, F>;
|
|
64
|
-
}
|
|
65
|
-
export type GetFunctions<A> = {
|
|
8
|
+
export interface CreateReactorReturn<A> extends ActorHooks<A>, AuthHooks, AgentHooks {
|
|
66
9
|
getAgent: () => HttpAgent;
|
|
67
10
|
getVisitFunction: () => VisitService<A>;
|
|
68
|
-
}
|
|
69
|
-
export type CreateReactor = {
|
|
70
|
-
<A>(options: CreateReactorOptions & {
|
|
71
|
-
withVisitor: true;
|
|
72
|
-
}): GetFunctions<A> & ActorHooks<A, true> & AuthHooks & AgentHooks;
|
|
73
|
-
<A>(options: CreateReactorOptions & {
|
|
74
|
-
withVisitor?: false | undefined;
|
|
75
|
-
}): GetFunctions<A> & ActorHooks<A, false> & AuthHooks & AgentHooks;
|
|
76
|
-
};
|
|
11
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("@ic-reactor/core/dist/types"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./provider/agent/types"), exports);
|
|
19
|
+
__exportStar(require("./provider/actor/types"), exports);
|
|
20
|
+
__exportStar(require("./hooks/types"), exports);
|
|
20
21
|
__exportStar(require("./helpers/types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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.0.
|
|
38
|
+
"@ic-reactor/core": "^1.0.3",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": ">=16.8",
|
|
49
49
|
"zustand": "4.5"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "031413fceeddbdac2fa281e1e07940182ac1e1ef"
|
|
52
52
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ActorUseMethodCallArg, ActorUseQueryArgs, ActorUseUpdateArgs } from "../../types";
|
|
3
|
-
import { CreateActorOptions, ActorContextType, ActorProviderProps } from "./types";
|
|
4
|
-
import type { ActorSubclass } from "@dfinity/agent";
|
|
5
|
-
export declare const ActorContext: React.Context<ActorContextType | null>, ActorProvider: React.FC<ActorProviderProps>, useActorContext: <A extends unknown = unknown>() => ActorContextType<A>, useActorState: () => import("../../types").UseActorStoreReturn<unknown>, useQueryCall: <M extends never>(args: ActorUseQueryArgs<unknown, M>) => import("../../types").ActorCallReturn<unknown, M>, useUpdateCall: <M extends never>(args: ActorUseUpdateArgs<unknown, M>) => import("../../types").ActorCallReturn<unknown, M>, useMethodCall: <M extends never>(args: ActorUseMethodCallArg<unknown, M>) => import("../../types").ActorUseMethodCallReturn<unknown, M, true>, useVisitMethod: (functionName: never) => never;
|
|
6
|
-
export declare function createReactorContext<Actor extends ActorSubclass<any>>({ canisterId: defaultCanisterId, ...defaultConfig }?: Partial<CreateActorOptions>): {
|
|
7
|
-
ActorContext: React.Context<ActorContextType | null>;
|
|
8
|
-
ActorProvider: React.FC<ActorProviderProps>;
|
|
9
|
-
useActorContext: <A extends unknown = Actor>() => ActorContextType<A>;
|
|
10
|
-
useActorState: () => import("../../types").UseActorStoreReturn<Actor>;
|
|
11
|
-
useQueryCall: <M extends keyof Actor & string>(args: ActorUseQueryArgs<Actor, M>) => import("../../types").ActorCallReturn<Actor, M>;
|
|
12
|
-
useUpdateCall: <M_1 extends keyof Actor & string>(args: ActorUseUpdateArgs<Actor, M_1>) => import("../../types").ActorCallReturn<Actor, M_1>;
|
|
13
|
-
useMethodCall: <M_2 extends keyof Actor & string>(args: ActorUseMethodCallArg<Actor, M_2>) => import("../../types").ActorUseMethodCallReturn<Actor, M_2, true>;
|
|
14
|
-
useVisitMethod: (functionName: keyof Actor & string) => import("@ic-reactor/core/dist/actor/types").VisitService<Actor>[keyof Actor & string];
|
|
15
|
-
initialize: () => Promise<void>;
|
|
16
|
-
};
|
|
@@ -1,88 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
var _a;
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.createReactorContext = exports.useVisitMethod = exports.useMethodCall = exports.useUpdateCall = exports.useQueryCall = exports.useActorState = exports.useActorContext = exports.ActorProvider = exports.ActorContext = void 0;
|
|
39
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
40
|
-
const react_1 = __importStar(require("react"));
|
|
41
|
-
const actor_1 = require("../../helpers/actor");
|
|
42
|
-
const useActor_1 = require("../../hooks/useActor");
|
|
43
|
-
_a = createReactorContext(), exports.ActorContext = _a.ActorContext, exports.ActorProvider = _a.ActorProvider, exports.useActorContext = _a.useActorContext, exports.useActorState = _a.useActorState, exports.useQueryCall = _a.useQueryCall, exports.useUpdateCall = _a.useUpdateCall, exports.useMethodCall = _a.useMethodCall, exports.useVisitMethod = _a.useVisitMethod;
|
|
44
|
-
function createReactorContext(_a = {}) {
|
|
45
|
-
var { canisterId: defaultCanisterId } = _a, defaultConfig = __rest(_a, ["canisterId"]);
|
|
46
|
-
const ActorContext = (0, react_1.createContext)(null);
|
|
47
|
-
const ActorProvider = (_a) => {
|
|
48
|
-
var { children, canisterId = defaultCanisterId, loadingComponent = react_1.default.createElement("div", null, "Fetching canister...") } = _a, restConfig = __rest(_a, ["children", "canisterId", "loadingComponent"]);
|
|
49
|
-
if (!canisterId) {
|
|
50
|
-
throw new Error("canisterId is required");
|
|
51
|
-
}
|
|
52
|
-
const config = (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
|
|
53
|
-
const { actorManager, fetchError, fetching } = (0, useActor_1.useActor)(Object.assign({ canisterId }, config));
|
|
54
|
-
const hooks = (0, react_1.useMemo)(() => {
|
|
55
|
-
if (actorManager) {
|
|
56
|
-
return (0, actor_1.getActorHooks)(actorManager);
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}, [actorManager === null || actorManager === void 0 ? void 0 : actorManager.canisterId]);
|
|
60
|
-
return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, fetching || hooks === null ? fetchError !== null && fetchError !== void 0 ? fetchError : loadingComponent : children));
|
|
61
|
-
};
|
|
62
|
-
ActorProvider.displayName = "ActorProvider";
|
|
63
|
-
const useActorContext = () => {
|
|
64
|
-
const context = (0, react_1.useContext)(ActorContext);
|
|
65
|
-
if (!context) {
|
|
66
|
-
throw new Error("useActor must be used within a ActorProvider");
|
|
67
|
-
}
|
|
68
|
-
return context;
|
|
69
|
-
};
|
|
70
|
-
const initialize = () => useActorContext().initialize();
|
|
71
|
-
const useActorState = () => useActorContext().useActorState();
|
|
72
|
-
const useQueryCall = (args) => useActorContext().useQueryCall(args);
|
|
73
|
-
const useUpdateCall = (args) => useActorContext().useUpdateCall(args);
|
|
74
|
-
const useMethodCall = (args) => useActorContext().useMethodCall(args);
|
|
75
|
-
const useVisitMethod = (functionName) => useActorContext().useVisitMethod(functionName);
|
|
76
|
-
return {
|
|
77
|
-
ActorContext,
|
|
78
|
-
ActorProvider,
|
|
79
|
-
useActorContext,
|
|
80
|
-
useActorState,
|
|
81
|
-
useQueryCall,
|
|
82
|
-
useUpdateCall,
|
|
83
|
-
useMethodCall,
|
|
84
|
-
useVisitMethod,
|
|
85
|
-
initialize,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
exports.createReactorContext = createReactorContext;
|
package/dist/hooks/useActor.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { IDL } from "@dfinity/candid";
|
|
2
|
-
import { ActorManagerOptions, BaseActor } from "@ic-reactor/core/dist/types";
|
|
3
|
-
import { AgentContextType } from "../types";
|
|
4
|
-
interface DynamicActorArgs extends Omit<ActorManagerOptions, "idlFactory" | "agentManager" | "canisterId"> {
|
|
5
|
-
canisterId: string;
|
|
6
|
-
idlFactory?: IDL.InterfaceFactory;
|
|
7
|
-
agentContext?: AgentContextType;
|
|
8
|
-
didjsCanisterId?: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A hook to create an actor manager and fetch the actor's candid interface.
|
|
12
|
-
*
|
|
13
|
-
* @category Hooks
|
|
14
|
-
*/
|
|
15
|
-
export declare const useActor: <A = BaseActor>({ canisterId, agentContext, idlFactory: maybeIdlFactory, didjsCanisterId, ...config }: DynamicActorArgs) => {
|
|
16
|
-
fetchCandid: () => Promise<import("@ic-reactor/core/dist/types").CandidDefenition | undefined>;
|
|
17
|
-
fetching: boolean;
|
|
18
|
-
fetchError: string | null;
|
|
19
|
-
actorManager: import("@ic-reactor/core").ActorManager<A> | null;
|
|
20
|
-
};
|
|
21
|
-
export {};
|
package/dist/hooks/useActor.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.useActor = void 0;
|
|
15
|
-
const core_1 = require("@ic-reactor/core");
|
|
16
|
-
const react_1 = require("react");
|
|
17
|
-
const agent_1 = require("../context/agent");
|
|
18
|
-
const useCandid_1 = require("./useCandid");
|
|
19
|
-
/**
|
|
20
|
-
* A hook to create an actor manager and fetch the actor's candid interface.
|
|
21
|
-
*
|
|
22
|
-
* @category Hooks
|
|
23
|
-
*/
|
|
24
|
-
const useActor = (_a) => {
|
|
25
|
-
var { canisterId, agentContext, idlFactory: maybeIdlFactory, didjsCanisterId } = _a, config = __rest(_a, ["canisterId", "agentContext", "idlFactory", "didjsCanisterId"]);
|
|
26
|
-
const agentManager = (0, agent_1.useAgentManager)(agentContext);
|
|
27
|
-
const _b = (0, useCandid_1.useCandid)({
|
|
28
|
-
canisterId,
|
|
29
|
-
didjsCanisterId,
|
|
30
|
-
idlFactory: maybeIdlFactory,
|
|
31
|
-
}), { candid: { idlFactory } } = _b, rest = __rest(_b, ["candid"]);
|
|
32
|
-
const actorManager = (0, react_1.useMemo)(() => {
|
|
33
|
-
if (!idlFactory) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const manager = (0, core_1.createReactorStore)({
|
|
38
|
-
agentManager,
|
|
39
|
-
idlFactory,
|
|
40
|
-
canisterId,
|
|
41
|
-
withDevtools: config.withDevtools,
|
|
42
|
-
});
|
|
43
|
-
return manager;
|
|
44
|
-
}
|
|
45
|
-
}, [idlFactory]);
|
|
46
|
-
return Object.assign({ actorManager }, rest);
|
|
47
|
-
};
|
|
48
|
-
exports.useActor = useActor;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { IDL } from "@dfinity/candid";
|
|
2
|
-
interface UseIDLFactoryArgs {
|
|
3
|
-
canisterId: string;
|
|
4
|
-
didjsCanisterId?: string;
|
|
5
|
-
idlFactory?: IDL.InterfaceFactory;
|
|
6
|
-
}
|
|
7
|
-
export declare const useCandid: ({ canisterId, didjsCanisterId, idlFactory, }: UseIDLFactoryArgs) => {
|
|
8
|
-
fetchCandid: () => Promise<import("@ic-reactor/core/dist/types").CandidDefenition | undefined>;
|
|
9
|
-
candid: {
|
|
10
|
-
idlFactory?: IDL.InterfaceFactory | undefined;
|
|
11
|
-
init: ({ idl }: {
|
|
12
|
-
idl: typeof IDL;
|
|
13
|
-
}) => never[];
|
|
14
|
-
};
|
|
15
|
-
fetching: boolean;
|
|
16
|
-
fetchError: string | null;
|
|
17
|
-
};
|
|
18
|
-
export {};
|
package/dist/hooks/useCandid.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.useCandid = void 0;
|
|
13
|
-
const react_1 = require("react");
|
|
14
|
-
const core_1 = require("@ic-reactor/core");
|
|
15
|
-
const agent_1 = require("../context/agent");
|
|
16
|
-
const DEFAULT_STATE = {
|
|
17
|
-
candid: { idlFactory: undefined, init: () => [] },
|
|
18
|
-
fetching: false,
|
|
19
|
-
fetchError: null,
|
|
20
|
-
};
|
|
21
|
-
const useCandid = ({ canisterId, didjsCanisterId, idlFactory, }) => {
|
|
22
|
-
const [{ candid, fetchError, fetching }, setCandid] = (0, react_1.useState)(Object.assign(Object.assign({}, DEFAULT_STATE), { candid: {
|
|
23
|
-
idlFactory,
|
|
24
|
-
init: () => [],
|
|
25
|
-
} }));
|
|
26
|
-
const agent = (0, agent_1.useAgent)();
|
|
27
|
-
const fetchCandid = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
if (!canisterId || !agent)
|
|
29
|
-
return;
|
|
30
|
-
setCandid((prevState) => (Object.assign(Object.assign({}, prevState), { candid: DEFAULT_STATE.candid, fetching: true, fetchError: null })));
|
|
31
|
-
try {
|
|
32
|
-
const candidManager = (0, core_1.createCandidAdapter)({ agent, didjsCanisterId });
|
|
33
|
-
const fetchedCandid = yield candidManager.getCandidDefinition(canisterId);
|
|
34
|
-
setCandid({
|
|
35
|
-
candid: fetchedCandid,
|
|
36
|
-
fetching: false,
|
|
37
|
-
fetchError: null,
|
|
38
|
-
});
|
|
39
|
-
return fetchedCandid;
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.error(err);
|
|
44
|
-
setCandid((prevState) => (Object.assign(Object.assign({}, prevState), { fetchError: `Error fetching canister ${canisterId}`, fetching: false })));
|
|
45
|
-
}
|
|
46
|
-
}), [canisterId, didjsCanisterId, agent]);
|
|
47
|
-
(0, react_1.useEffect)(() => {
|
|
48
|
-
if (!fetching && !idlFactory) {
|
|
49
|
-
fetchCandid();
|
|
50
|
-
}
|
|
51
|
-
}, [fetchCandid]);
|
|
52
|
-
return { fetchCandid, candid, fetching, fetchError };
|
|
53
|
-
};
|
|
54
|
-
exports.useCandid = useCandid;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|