@ic-reactor/react 1.1.2 → 1.1.3
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.js
CHANGED
|
@@ -83,13 +83,17 @@ function createActorContext(config = {}) {
|
|
|
83
83
|
const { canisterId: defaultCanisterId } = config, defaultConfig = __rest(config, ["canisterId"]);
|
|
84
84
|
const ActorContext = react_1.default.createContext(null);
|
|
85
85
|
const ActorProvider = (_a) => {
|
|
86
|
-
var { children, canisterId = defaultCanisterId, loadingComponent = react_1.default.createElement("div", null, "Fetching canister...") } = _a, restConfig = __rest(_a, ["children", "canisterId", "loadingComponent"]);
|
|
86
|
+
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"]);
|
|
87
87
|
if (!canisterId) {
|
|
88
88
|
throw new Error("canisterId is required");
|
|
89
89
|
}
|
|
90
90
|
const config = react_1.default.useMemo(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
|
|
91
|
-
const { fetchError,
|
|
92
|
-
return (react_1.default.createElement(ActorContext.Provider, { value: hooks },
|
|
91
|
+
const { fetchError, authenticating, hooks } = (0, useActor_1.useActor)(Object.assign({ canisterId, fetchOnMount: false }, config));
|
|
92
|
+
return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, hooks === null
|
|
93
|
+
? (fetchError !== null && fetchError !== void 0 ? fetchError : authenticating)
|
|
94
|
+
? authenticatingComponent
|
|
95
|
+
: loadingComponent
|
|
96
|
+
: children));
|
|
93
97
|
};
|
|
94
98
|
ActorProvider.displayName = "ActorProvider";
|
|
95
99
|
return Object.assign({ ActorProvider }, (0, extractActorContext_1.extractActorContext)(ActorContext));
|
package/dist/context/agent.js
CHANGED
|
@@ -93,11 +93,15 @@ const extractAgentContext_1 = require("../helpers/extractAgentContext");
|
|
|
93
93
|
* with the Internet Computer blockchain.
|
|
94
94
|
*/
|
|
95
95
|
const createAgentContext = (config = {}) => {
|
|
96
|
+
const { disableAuthenticateOnMount: defaultDisable } = config, contextOptions = __rest(config, ["disableAuthenticateOnMount"]);
|
|
96
97
|
const AgentContext = react_1.default.createContext(null);
|
|
97
98
|
const AgentProvider = (_a) => {
|
|
98
|
-
var { children, agentManager: mybeAgentManager } = _a, options = __rest(_a, ["children", "agentManager"]);
|
|
99
|
+
var { children, agentManager: mybeAgentManager, disableAuthenticateOnMount = defaultDisable !== null && defaultDisable !== void 0 ? defaultDisable : false } = _a, options = __rest(_a, ["children", "agentManager", "disableAuthenticateOnMount"]);
|
|
99
100
|
const hooks = react_1.default.useMemo(() => {
|
|
100
|
-
const agentManager = mybeAgentManager !== null && mybeAgentManager !== void 0 ? mybeAgentManager : (0, core_1.createAgentManager)(Object.assign(Object.assign({}, options),
|
|
101
|
+
const agentManager = mybeAgentManager !== null && mybeAgentManager !== void 0 ? mybeAgentManager : (0, core_1.createAgentManager)(Object.assign(Object.assign({}, options), contextOptions));
|
|
102
|
+
if (!disableAuthenticateOnMount) {
|
|
103
|
+
agentManager.authenticate();
|
|
104
|
+
}
|
|
101
105
|
return Object.assign(Object.assign(Object.assign({}, (0, agentHooks_1.agentHooks)(agentManager)), (0, authHooks_1.authHooks)(agentManager)), { agentManager });
|
|
102
106
|
}, [options]);
|
|
103
107
|
return (react_1.default.createElement(AgentContext.Provider, { value: hooks }, children));
|
package/dist/context/types.d.ts
CHANGED
|
@@ -4,12 +4,13 @@ export interface AgentContext extends AgentHooksReturnType, AuthHooksReturnType
|
|
|
4
4
|
agentManager: AgentManager;
|
|
5
5
|
}
|
|
6
6
|
export interface CreateAgentCotextParameters extends AgentManagerParameters {
|
|
7
|
+
disableAuthenticateOnMount?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export interface CreateAgentContextReturnType extends AgentHooksReturnType, AuthHooksReturnType {
|
|
9
10
|
useAgentManager: (agentContext?: React.Context<AgentContext | null>) => AgentManager;
|
|
10
11
|
AgentProvider: React.FC<AgentProviderProps>;
|
|
11
12
|
}
|
|
12
|
-
export interface AgentProviderProps extends PropsWithChildren,
|
|
13
|
+
export interface AgentProviderProps extends PropsWithChildren, CreateAgentCotextParameters {
|
|
13
14
|
agentManager?: AgentManager;
|
|
14
15
|
}
|
|
15
16
|
export interface CreateActorContextReturnType<A = BaseActor> extends ActorHooksReturnType<A> {
|
|
@@ -18,6 +19,7 @@ export interface CreateActorContextReturnType<A = BaseActor> extends ActorHooksR
|
|
|
18
19
|
export interface ActorProviderProps extends CreateActorContextParameters {
|
|
19
20
|
children?: React.ReactNode | undefined;
|
|
20
21
|
loadingComponent?: React.ReactNode;
|
|
22
|
+
authenticatingComponent?: React.ReactNode;
|
|
21
23
|
}
|
|
22
24
|
export interface CreateActorContextParameters extends Omit<ActorManagerParameters, "idlFactory" | "agentManager" | "canisterId"> {
|
|
23
25
|
didjsId?: string;
|
package/dist/hooks/types.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export interface UseActorParameters extends Omit<ActorManagerParameters, "idlFac
|
|
|
6
6
|
canisterId: string;
|
|
7
7
|
idlFactory?: IDL.InterfaceFactory;
|
|
8
8
|
agentContext?: React.Context<AgentContext | null>;
|
|
9
|
+
fetchOnMount?: boolean;
|
|
9
10
|
didjsCanisterId?: string;
|
|
10
11
|
}
|
|
11
12
|
export interface UseActorReturn<A = BaseActor> {
|
|
12
13
|
hooks: ActorHooksReturnType<A> | null;
|
|
13
14
|
fetching: boolean;
|
|
14
15
|
fetchError: string | null;
|
|
16
|
+
authenticating: boolean;
|
|
15
17
|
}
|
package/dist/hooks/useActor.js
CHANGED
|
@@ -25,6 +25,7 @@ const core_1 = require("@ic-reactor/core");
|
|
|
25
25
|
const react_1 = require("react");
|
|
26
26
|
const useAgentManager_1 = require("./agent/useAgentManager");
|
|
27
27
|
const helpers_1 = require("../helpers");
|
|
28
|
+
const agent_1 = require("./agent");
|
|
28
29
|
/**
|
|
29
30
|
* A comprehensive hook that manages both the fetching of Candid interfaces
|
|
30
31
|
* and the initialization of actor stores for Internet Computer (IC) canisters.
|
|
@@ -88,7 +89,7 @@ const helpers_1 = require("../helpers");
|
|
|
88
89
|
* ```
|
|
89
90
|
*/
|
|
90
91
|
const useActor = (config) => {
|
|
91
|
-
const { canisterId, idlFactory: maybeIdlFactory, agentContext, didjsCanisterId } = config, actorConfig = __rest(config, ["canisterId", "idlFactory", "agentContext", "didjsCanisterId"]);
|
|
92
|
+
const { canisterId, idlFactory: maybeIdlFactory, agentContext, fetchOnMount = true, didjsCanisterId } = config, actorConfig = __rest(config, ["canisterId", "idlFactory", "agentContext", "fetchOnMount", "didjsCanisterId"]);
|
|
92
93
|
const [{ idlFactory, fetching, fetchError }, setState] = (0, react_1.useState)({
|
|
93
94
|
idlFactory: maybeIdlFactory,
|
|
94
95
|
fetching: false,
|
|
@@ -126,16 +127,29 @@ const useActor = (config) => {
|
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
129
|
}), [canisterId, didjsCanisterId]);
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
(0, react_1.useEffect)(() => {
|
|
131
|
+
if (maybeIdlFactory) {
|
|
132
|
+
setState(() => ({
|
|
133
|
+
idlFactory: maybeIdlFactory,
|
|
134
|
+
fetching: false,
|
|
135
|
+
fetchError: null,
|
|
136
|
+
}));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const unsubscribe = agentManager.subscribeAgent(fetchCandid, fetchOnMount);
|
|
140
|
+
return unsubscribe;
|
|
141
|
+
}, [agentManager, fetchOnMount]);
|
|
142
|
+
const authenticating = (0, agent_1.useAuthState)().authenticating;
|
|
131
143
|
const hooks = (0, react_1.useMemo)(() => {
|
|
132
144
|
if (!idlFactory)
|
|
133
145
|
return null;
|
|
146
|
+
if (authenticating)
|
|
147
|
+
return null;
|
|
134
148
|
const actorManager = (0, core_1.createActorManager)(Object.assign({ agentManager,
|
|
135
149
|
idlFactory,
|
|
136
150
|
canisterId }, actorConfig));
|
|
137
151
|
return (0, helpers_1.actorHooks)(actorManager);
|
|
138
|
-
}, [canisterId, idlFactory]);
|
|
139
|
-
return { hooks, fetching, fetchError };
|
|
152
|
+
}, [canisterId, authenticating, idlFactory]);
|
|
153
|
+
return { hooks, authenticating, fetching, fetchError };
|
|
140
154
|
};
|
|
141
155
|
exports.useActor = useActor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://b3pay.github.io/ic-reactor/modules/react.html",
|
|
28
28
|
"scripts": {
|
|
29
|
-
"test": "npx jest",
|
|
29
|
+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
|
|
30
30
|
"start": "tsc watch",
|
|
31
31
|
"build": "npx tsc",
|
|
32
32
|
"clean": "npx rimraf dist && npx rimraf umd"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"react": ">=16.8",
|
|
48
48
|
"zustand": "4.5"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5420fba37e2721dd9c4a41ba885151eb420c5332"
|
|
51
51
|
}
|