@ic-reactor/core 1.10.0 → 1.10.2
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
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/v1.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.10.1/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -70,7 +70,8 @@ class ActorManager {
|
|
|
70
70
|
}, {});
|
|
71
71
|
};
|
|
72
72
|
this.initializeActor = (agent) => {
|
|
73
|
-
|
|
73
|
+
const network = this._agentManager.getNetwork();
|
|
74
|
+
console.info(`Initializing actor ${this.canisterId} on ${network} network`);
|
|
74
75
|
const { _idlFactory, canisterId } = this;
|
|
75
76
|
this.updateState({
|
|
76
77
|
initializing: true,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { HttpAgent } from "@dfinity/agent";
|
|
2
2
|
import { AuthClient } from "@dfinity/auth-client";
|
|
3
3
|
import type { AuthClientLoginOptions } from "../../types";
|
|
4
|
-
import type { AgentStore, AgentManagerParameters, UpdateAgentParameters, AuthStore } from "./types";
|
|
4
|
+
import type { AgentStore, AgentManagerParameters, UpdateAgentParameters, AuthState, AuthStore } from "./types";
|
|
5
5
|
export declare class AgentManager {
|
|
6
|
+
private _anonymousAgent;
|
|
6
7
|
private _agent;
|
|
7
8
|
private _auth;
|
|
8
9
|
private _subscribers;
|
|
@@ -11,7 +12,7 @@ export declare class AgentManager {
|
|
|
11
12
|
private initialAgentState;
|
|
12
13
|
private initialAuthState;
|
|
13
14
|
private updateAgentState;
|
|
14
|
-
|
|
15
|
+
updateAuthState: (newState: Partial<AuthState>, action?: string) => void;
|
|
15
16
|
constructor(options?: AgentManagerParameters);
|
|
16
17
|
private initializeAgent;
|
|
17
18
|
subscribeAgent: (callback: (agent: HttpAgent) => void, initialize?: boolean) => () => void;
|
|
@@ -24,7 +25,8 @@ export declare class AgentManager {
|
|
|
24
25
|
returnTo?: string;
|
|
25
26
|
}) => Promise<void>;
|
|
26
27
|
getAgent: () => HttpAgent;
|
|
27
|
-
getAgentHost: () => URL;
|
|
28
|
+
getAgentHost: () => URL | undefined;
|
|
29
|
+
getAgentHostName: () => string;
|
|
28
30
|
getIsLocal: () => boolean;
|
|
29
31
|
getNetwork: () => "local" | "remote" | "ic";
|
|
30
32
|
getAgentState: AgentStore["getState"];
|
|
@@ -46,6 +46,7 @@ class AgentManager {
|
|
|
46
46
|
this.updateAgentState = (newState, action) => {
|
|
47
47
|
this.agentStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
|
|
48
48
|
};
|
|
49
|
+
//TODO: make it private
|
|
49
50
|
this.updateAuthState = (newState, action) => {
|
|
50
51
|
this.authStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
|
|
51
52
|
};
|
|
@@ -59,6 +60,7 @@ class AgentManager {
|
|
|
59
60
|
if (network !== "ic") {
|
|
60
61
|
try {
|
|
61
62
|
yield this._agent.fetchRootKey();
|
|
63
|
+
yield this._anonymousAgent.fetchRootKey();
|
|
62
64
|
}
|
|
63
65
|
catch (error) {
|
|
64
66
|
this.updateAgentState({ error: error, initializing: false }, "error");
|
|
@@ -141,11 +143,15 @@ class AgentManager {
|
|
|
141
143
|
this.getAgentHost = () => {
|
|
142
144
|
return this._agent.host;
|
|
143
145
|
};
|
|
146
|
+
this.getAgentHostName = () => {
|
|
147
|
+
var _a;
|
|
148
|
+
return ((_a = this.getAgentHost()) === null || _a === void 0 ? void 0 : _a.hostname) || "";
|
|
149
|
+
};
|
|
144
150
|
this.getIsLocal = () => {
|
|
145
151
|
return this.getNetwork() !== "ic";
|
|
146
152
|
};
|
|
147
153
|
this.getNetwork = () => {
|
|
148
|
-
const hostname = this.
|
|
154
|
+
const hostname = this.getAgentHostName();
|
|
149
155
|
if (constants_1.LOCAL_HOSTS.some((host) => hostname.endsWith(host))) {
|
|
150
156
|
return "local";
|
|
151
157
|
}
|
|
@@ -201,6 +207,7 @@ class AgentManager {
|
|
|
201
207
|
name: "reactor-agent",
|
|
202
208
|
store: "auth",
|
|
203
209
|
});
|
|
210
|
+
this._anonymousAgent = agent_1.HttpAgent.createSync(agentOptions);
|
|
204
211
|
this._agent = agent_1.HttpAgent.createSync(agentOptions);
|
|
205
212
|
this.initializeAgent();
|
|
206
213
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
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",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"@dfinity/principal": ">=2.1.2"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@dfinity/agent": ">=2.
|
|
37
|
-
"@dfinity/auth-client": ">=2.
|
|
38
|
-
"@dfinity/candid": ">=2.
|
|
39
|
-
"@dfinity/identity": ">=2.
|
|
40
|
-
"@dfinity/principal": ">=2.
|
|
36
|
+
"@dfinity/agent": ">=2.0.0",
|
|
37
|
+
"@dfinity/auth-client": ">=2.0.0",
|
|
38
|
+
"@dfinity/candid": ">=2.0.0",
|
|
39
|
+
"@dfinity/identity": ">=2.0.0",
|
|
40
|
+
"@dfinity/principal": ">=2.0.0",
|
|
41
41
|
"zustand": "4.5.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=10"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "3c9a15a85b8fcef02c5a3aaaeffecb91ad647ed2"
|
|
60
60
|
}
|