@ic-reactor/core 1.1.1 → 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/README.md +1 -1
- package/dist/classes/actor/index.d.ts +2 -0
- package/dist/classes/actor/index.js +8 -4
- package/dist/classes/agent/index.js +6 -1
- package/dist/classes/agent/types.d.ts +1 -0
- package/dist/classes/candid/index.d.ts +1 -0
- package/dist/classes/candid/index.js +21 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ yarn add @ic-reactor/core
|
|
|
19
19
|
or you can use the UMD version:
|
|
20
20
|
|
|
21
21
|
```html
|
|
22
|
-
<script src="https://github.com/B3Pay/ic-reactor/releases/download/1.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.1.2/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CanisterId, ActorMethodParameters, ActorMethodReturnType, ActorStore, ActorManagerParameters, FunctionName, VisitService, BaseActor, ActorMethodState } from "./types";
|
|
2
|
+
import { IDL } from "@dfinity/candid";
|
|
2
3
|
import type { AgentManager } from "../agent";
|
|
3
4
|
import type { UpdateAgentParameters } from "../../types";
|
|
4
5
|
export declare class ActorManager<A = BaseActor> {
|
|
@@ -20,6 +21,7 @@ export declare class ActorManager<A = BaseActor> {
|
|
|
20
21
|
constructor(actorConfig: ActorManagerParameters);
|
|
21
22
|
initialize: (options?: UpdateAgentParameters) => Promise<void>;
|
|
22
23
|
extractService: () => VisitService<A>;
|
|
24
|
+
extractInterface: () => IDL.ServiceClass;
|
|
23
25
|
private initializeActor;
|
|
24
26
|
callMethod: <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
|
|
25
27
|
get agentManager(): AgentManager;
|
|
@@ -38,10 +38,8 @@ class ActorManager {
|
|
|
38
38
|
yield this._agentManager.updateAgent(options);
|
|
39
39
|
});
|
|
40
40
|
this.extractService = () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return agent_1.Actor.interfaceOf(this._actor)._fields.reduce((acc, service) => {
|
|
41
|
+
const iface = this.extractInterface();
|
|
42
|
+
return iface._fields.reduce((acc, service) => {
|
|
45
43
|
const functionName = service[0];
|
|
46
44
|
const type = service[1];
|
|
47
45
|
const visit = ((extractorClass, data) => {
|
|
@@ -51,6 +49,12 @@ class ActorManager {
|
|
|
51
49
|
return acc;
|
|
52
50
|
}, {});
|
|
53
51
|
};
|
|
52
|
+
this.extractInterface = () => {
|
|
53
|
+
if (this._actor === null) {
|
|
54
|
+
throw new Error("For extracting interface, actor must be initialized");
|
|
55
|
+
}
|
|
56
|
+
return agent_1.Actor.interfaceOf(this._actor);
|
|
57
|
+
};
|
|
54
58
|
this.initializeActor = (agent) => {
|
|
55
59
|
console.info(`Initializing actor ${this.canisterId} on ${agent.isLocal() ? "local" : "ic"} network`);
|
|
56
60
|
const { _idlFactory, canisterId } = this;
|
|
@@ -33,6 +33,7 @@ class AgentManager {
|
|
|
33
33
|
initialized: false,
|
|
34
34
|
initializing: false,
|
|
35
35
|
error: undefined,
|
|
36
|
+
network: "ic",
|
|
36
37
|
};
|
|
37
38
|
this.initialAuthState = {
|
|
38
39
|
identity: null,
|
|
@@ -47,7 +48,11 @@ class AgentManager {
|
|
|
47
48
|
this.authStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
|
|
48
49
|
};
|
|
49
50
|
this.initializeAgent = () => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
this.updateAgentState({
|
|
51
|
+
this.updateAgentState({
|
|
52
|
+
initializing: true,
|
|
53
|
+
error: undefined,
|
|
54
|
+
network: this.isLocalEnv ? "local" : "ic",
|
|
55
|
+
}, "initializing");
|
|
51
56
|
if (this.isLocalEnv) {
|
|
52
57
|
try {
|
|
53
58
|
yield this._agent.fetchRootKey();
|
|
@@ -3,6 +3,7 @@ import type { CanisterId, CandidAdapterParameters, CandidDefenition } from "../.
|
|
|
3
3
|
export declare class CandidAdapter {
|
|
4
4
|
agent: HttpAgent;
|
|
5
5
|
didjsCanisterId: string;
|
|
6
|
+
unsubscribeAgent: () => void;
|
|
6
7
|
constructor({ agentManager, agent, didjsCanisterId, }: CandidAdapterParameters);
|
|
7
8
|
private getDefaultDidJsId;
|
|
8
9
|
getCandidDefinition(canisterId: CanisterId): Promise<CandidDefenition>;
|
|
@@ -14,12 +14,13 @@ const agent_1 = require("@dfinity/agent");
|
|
|
14
14
|
const constants_1 = require("../../utils/constants");
|
|
15
15
|
class CandidAdapter {
|
|
16
16
|
constructor({ agentManager, agent, didjsCanisterId, }) {
|
|
17
|
+
this.unsubscribeAgent = () => { };
|
|
17
18
|
if (agent) {
|
|
18
19
|
this.agent = agent;
|
|
19
20
|
}
|
|
20
21
|
else if (agentManager) {
|
|
21
22
|
this.agent = agentManager.getAgent();
|
|
22
|
-
agentManager.subscribeAgent((agent) => {
|
|
23
|
+
this.unsubscribeAgent = agentManager.subscribeAgent((agent) => {
|
|
23
24
|
this.agent = agent;
|
|
24
25
|
this.didjsCanisterId = didjsCanisterId || this.getDefaultDidJsId();
|
|
25
26
|
});
|
|
@@ -34,16 +35,25 @@ class CandidAdapter {
|
|
|
34
35
|
}
|
|
35
36
|
getCandidDefinition(canisterId) {
|
|
36
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
try {
|
|
39
|
+
// First attempt: Try getting Candid definition from metadata
|
|
40
|
+
const fromMetadata = yield this.getFromMetadata(canisterId).catch(() => {
|
|
41
|
+
return undefined;
|
|
42
|
+
});
|
|
43
|
+
if (fromMetadata)
|
|
44
|
+
return fromMetadata;
|
|
45
|
+
// Second attempt: Try the temporary hack method
|
|
46
|
+
const fromTmpHack = yield this.getFromTmpHack(canisterId).catch(() => {
|
|
47
|
+
return undefined;
|
|
48
|
+
});
|
|
49
|
+
if (fromTmpHack)
|
|
50
|
+
return fromTmpHack;
|
|
51
|
+
// If both attempts fail, throw an error
|
|
52
|
+
throw "Failed to retrieve Candid definition by any method.";
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
throw new Error(`Error fetching canister ${canisterId}: ${err}`);
|
|
56
|
+
}
|
|
47
57
|
});
|
|
48
58
|
}
|
|
49
59
|
getFromMetadata(canisterId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "A library for intracting with the Internet Computer canisters",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=10"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "4181bc6228d5efb98f14c48b2855a37bcada97dd"
|
|
50
50
|
}
|