@ic-reactor/core 1.1.2 → 1.2.0
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/1.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.1.3/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -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.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"@dfinity/principal": ">=1.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@dfinity/agent": ">=1.0",
|
|
36
|
+
"@dfinity/auth-client": ">=1.0",
|
|
37
|
+
"@dfinity/candid": ">=1.0",
|
|
38
|
+
"@dfinity/principal": ">=1.0",
|
|
35
39
|
"zustand": "^4.5"
|
|
36
40
|
},
|
|
37
41
|
"scripts": {
|
|
@@ -46,5 +50,5 @@
|
|
|
46
50
|
"engines": {
|
|
47
51
|
"node": ">=10"
|
|
48
52
|
},
|
|
49
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "892d630dd751b60655e16eff5415b4e77d44c5cf"
|
|
50
54
|
}
|