@ic-reactor/core 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/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.0.8/ic-reactor-core.min.js"></script>
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`
@@ -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({ initializing: true }, "initializing");
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();
@@ -11,6 +11,7 @@ export interface AgentState {
11
11
  initialized: boolean;
12
12
  initializing: boolean;
13
13
  error: Error | undefined;
14
+ network: string;
14
15
  }
15
16
  export interface AuthState {
16
17
  identity: Identity | null;
@@ -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
- // First attempt: Try getting Candid definition from metadata
38
- const fromMetadata = yield this.getFromMetadata(canisterId);
39
- if (fromMetadata)
40
- return fromMetadata;
41
- // Second attempt: Try the temporary hack method
42
- const fromTmpHack = yield this.getFromTmpHack(canisterId);
43
- if (fromTmpHack)
44
- return fromTmpHack;
45
- // If both attempts fail, throw an error
46
- throw new Error("Failed to retrieve Candid definition by any method.");
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.2",
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": "5203d7142eda0153581cb3b6de00e12fc128eb33"
49
+ "gitHead": "4181bc6228d5efb98f14c48b2855a37bcada97dd"
50
50
  }