@ic-reactor/react 0.3.3 → 0.3.5
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 +2 -0
- package/dist/context/actor.js +2 -2
- package/dist/context/agent.d.ts +8 -6
- package/dist/context/agent.js +17 -11
- package/package.json +2 -2
package/dist/context/actor.d.ts
CHANGED
|
@@ -2,11 +2,13 @@ import React, { PropsWithChildren } from "react";
|
|
|
2
2
|
import { type ActorHooks } from "../index";
|
|
3
3
|
import { IDL } from "@dfinity/candid";
|
|
4
4
|
import { ActorSubclass, ActorManagerOptions } from "@ic-reactor/store";
|
|
5
|
+
import { AgentContextType } from "./agent";
|
|
5
6
|
export type ActorContextType<A = ActorSubclass<any>> = ActorHooks<A>;
|
|
6
7
|
export declare const ActorContext: React.Context<ActorContextType<any> | null>;
|
|
7
8
|
type UseActorType = <A = ActorSubclass<any>>() => ActorContextType<A>;
|
|
8
9
|
export declare const useActor: UseActorType;
|
|
9
10
|
interface ActorProviderProps extends PropsWithChildren, Omit<ActorManagerOptions, "idlFactory" | "agentManager"> {
|
|
11
|
+
agentContext?: AgentContextType;
|
|
10
12
|
idlFactory?: IDL.InterfaceFactory;
|
|
11
13
|
loadingComponent?: React.ReactNode;
|
|
12
14
|
}
|
package/dist/context/actor.js
CHANGED
|
@@ -58,8 +58,8 @@ const useActor = () => {
|
|
|
58
58
|
};
|
|
59
59
|
exports.useActor = useActor;
|
|
60
60
|
const ActorProvider = (_a) => {
|
|
61
|
-
var { children, canisterId, loadingComponent = react_1.default.createElement("div", null, "Loading...") } = _a, config = __rest(_a, ["children", "canisterId", "loadingComponent"]);
|
|
62
|
-
const agentManager = (0, agent_1.useAgentManager)();
|
|
61
|
+
var { children, canisterId, agentContext, loadingComponent = react_1.default.createElement("div", null, "Loading...") } = _a, config = __rest(_a, ["children", "canisterId", "agentContext", "loadingComponent"]);
|
|
62
|
+
const agentManager = (0, agent_1.useAgentManager)(agentContext);
|
|
63
63
|
const [didJs, setDidJS] = (0, react_1.useState)();
|
|
64
64
|
const [fetching, setFetching] = (0, react_1.useState)(false);
|
|
65
65
|
const fetchDidJs = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
package/dist/context/agent.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
2
|
import { AgentManager, AgentManagerOptions } from "@ic-reactor/store";
|
|
3
3
|
import { getAuthHooks } from "../hooks/auth";
|
|
4
|
-
export type
|
|
4
|
+
export type AgentContextValue = ReturnType<typeof getAuthHooks> & {
|
|
5
5
|
agentManager: AgentManager;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
|
|
7
|
+
export type AgentContextType = React.Context<AgentContextValue | null>;
|
|
8
|
+
export declare const AgentContext: React.Context<AgentContextValue | null>;
|
|
9
|
+
export declare const useAgent: (agentContext?: AgentContextType) => AgentContextValue;
|
|
10
|
+
export declare const useAgentManager: (agentContext?: AgentContextType) => AgentManager;
|
|
11
|
+
export declare const createAgentContext: (config: AgentManagerOptions) => AgentContextValue;
|
|
12
|
+
interface AgentProviderProps extends PropsWithChildren, AgentManagerOptions {
|
|
11
13
|
agentManager?: AgentManager;
|
|
12
14
|
}
|
|
13
|
-
export declare const AgentProvider: React.FC<
|
|
15
|
+
export declare const AgentProvider: React.FC<AgentProviderProps>;
|
|
14
16
|
export {};
|
package/dist/context/agent.js
CHANGED
|
@@ -34,34 +34,40 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
34
34
|
return t;
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.AgentProvider = exports.useAgentManager = exports.useAgent = exports.AgentContext = void 0;
|
|
37
|
+
exports.AgentProvider = exports.createAgentContext = exports.useAgentManager = exports.useAgent = exports.AgentContext = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const store_1 = require("@ic-reactor/store");
|
|
40
40
|
const auth_1 = require("../hooks/auth");
|
|
41
41
|
exports.AgentContext = (0, react_1.createContext)(null);
|
|
42
|
-
const useAgent = () => {
|
|
43
|
-
const context = (0, react_1.useContext)(exports.AgentContext);
|
|
42
|
+
const useAgent = (agentContext) => {
|
|
43
|
+
const context = (0, react_1.useContext)(agentContext || exports.AgentContext);
|
|
44
44
|
if (!context) {
|
|
45
45
|
throw new Error("useAgent must be used within a AgentProvider");
|
|
46
46
|
}
|
|
47
47
|
return context;
|
|
48
48
|
};
|
|
49
49
|
exports.useAgent = useAgent;
|
|
50
|
-
const useAgentManager = () => {
|
|
51
|
-
const context = (0, react_1.useContext)(exports.AgentContext);
|
|
50
|
+
const useAgentManager = (agentContext) => {
|
|
51
|
+
const context = (0, react_1.useContext)(agentContext || exports.AgentContext);
|
|
52
52
|
if (!context) {
|
|
53
53
|
throw new Error("useAgentManager must be used within a AgentProvider");
|
|
54
54
|
}
|
|
55
55
|
return context.agentManager;
|
|
56
56
|
};
|
|
57
57
|
exports.useAgentManager = useAgentManager;
|
|
58
|
+
const createAgentContext = (config) => {
|
|
59
|
+
const agentManager = (0, store_1.createAgentManager)(config);
|
|
60
|
+
const hooks = (0, auth_1.getAuthHooks)(agentManager);
|
|
61
|
+
return Object.assign(Object.assign({}, hooks), { agentManager });
|
|
62
|
+
};
|
|
63
|
+
exports.createAgentContext = createAgentContext;
|
|
58
64
|
const AgentProvider = (_a) => {
|
|
59
65
|
var { children } = _a, config = __rest(_a, ["children"]);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const hooks = (0, auth_1.getAuthHooks)(agentManager
|
|
63
|
-
return Object.assign(Object.assign({}, hooks), { agentManager
|
|
64
|
-
}, []);
|
|
65
|
-
return react_1.default.createElement(exports.AgentContext.Provider, { value:
|
|
66
|
+
const value = (0, react_1.useMemo)(() => {
|
|
67
|
+
const agentManager = config.agentManager || (0, store_1.createAgentManager)(config);
|
|
68
|
+
const hooks = (0, auth_1.getAuthHooks)(agentManager);
|
|
69
|
+
return Object.assign(Object.assign({}, hooks), { agentManager });
|
|
70
|
+
}, [config]);
|
|
71
|
+
return react_1.default.createElement(exports.AgentContext.Provider, { value: value }, children);
|
|
66
72
|
};
|
|
67
73
|
exports.AgentProvider = AgentProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A React library for interacting with Dfinity actors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": ">=16.8",
|
|
49
49
|
"zustand": "4.4"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1d79f404bba4f4f8b04fe31dddeacbe18a738036"
|
|
52
52
|
}
|