@ic-reactor/core 1.4.1 → 1.5.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 +14 -15
- package/dist/classes/agent/index.js +8 -3
- package/dist/createReactorStore.d.ts +1 -1
- package/dist/createReactorStore.js +1 -1
- 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/v1.4.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.4.2/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -101,27 +101,27 @@ import { createAgentManager } from "@ic-reactor/core"
|
|
|
101
101
|
export const agentManager = createAgentManager() // Connects to IC network by default
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Then you can create a
|
|
104
|
+
Then you can create a Actor for each canister:
|
|
105
105
|
|
|
106
106
|
```typescript
|
|
107
107
|
// Assuming you've already set up `candidA`, `candidB`, and `agentManager`
|
|
108
108
|
import { createActorManager } from "@ic-reactor/core"
|
|
109
|
-
import candidA from "./declarations/candidA"
|
|
110
|
-
import candidB from "./declarations/candidB"
|
|
109
|
+
import * as candidA from "./declarations/candidA"
|
|
110
|
+
import * as candidB from "./declarations/candidB"
|
|
111
111
|
import { agentManager } from "./agent"
|
|
112
112
|
|
|
113
|
-
type CandidA = typeof candidA
|
|
114
|
-
type CandidB = typeof candidB
|
|
113
|
+
type CandidA = typeof candidA.candidA
|
|
114
|
+
type CandidB = typeof candidB.candidB
|
|
115
115
|
|
|
116
116
|
const actorA = createActorManager<CandidA>({
|
|
117
117
|
agentManager,
|
|
118
|
-
canisterId:
|
|
118
|
+
canisterId: candidA.canisterId,
|
|
119
119
|
idlFactory: candidA.idlFactory,
|
|
120
120
|
})
|
|
121
121
|
|
|
122
122
|
const actorB = createActorManager<CandidB>({
|
|
123
123
|
agentManager,
|
|
124
|
-
canisterId:
|
|
124
|
+
canisterId: candidB.canisterId,
|
|
125
125
|
idlFactory: candidB.idlFactory,
|
|
126
126
|
})
|
|
127
127
|
```
|
|
@@ -129,17 +129,16 @@ const actorB = createActorManager<CandidB>({
|
|
|
129
129
|
You can now use the `actorA` and `actorB` instances to interact with their respective canisters:
|
|
130
130
|
|
|
131
131
|
```typescript
|
|
132
|
-
|
|
133
|
-
const { dataPromise: versionActorA } = actorA.queryCall({
|
|
132
|
+
const { dataPromise: version } = actorA.queryCall({
|
|
134
133
|
functionName: "version",
|
|
135
134
|
})
|
|
136
|
-
console.log("Response from CanisterA method:", await
|
|
135
|
+
console.log("Response from CanisterA method:", await version)
|
|
137
136
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
const { dataPromise: balance } = actorB.queryCall({
|
|
138
|
+
functionName: "balance",
|
|
139
|
+
args: [principal, []],
|
|
141
140
|
})
|
|
142
|
-
console.log("Response from CanisterB method:", await
|
|
141
|
+
console.log("Response from CanisterB method:", await balance)
|
|
143
142
|
```
|
|
144
143
|
|
|
145
144
|
### Using Candid Adapter
|
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.AgentManager = void 0;
|
|
24
|
+
/* eslint-disable no-console */
|
|
24
25
|
const agent_1 = require("@dfinity/agent");
|
|
25
26
|
const helper_1 = require("../../utils/helper");
|
|
26
27
|
const auth_client_1 = require("@dfinity/auth-client");
|
|
@@ -89,6 +90,7 @@ class AgentManager {
|
|
|
89
90
|
yield this.notifySubscribers();
|
|
90
91
|
});
|
|
91
92
|
this.authenticate = () => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
console.log(`Authenticating on ${this.getIsLocal() ? "local" : "ic"} network`);
|
|
92
94
|
this.updateAuthState({ authenticating: true }, "authenticating");
|
|
93
95
|
try {
|
|
94
96
|
this._auth = yield auth_client_1.AuthClient.create();
|
|
@@ -116,10 +118,13 @@ class AgentManager {
|
|
|
116
118
|
if (!this._auth) {
|
|
117
119
|
throw new Error("Auth client not initialized");
|
|
118
120
|
}
|
|
119
|
-
yield this._auth.login(Object.assign({ identityProvider: this.getIsLocal()
|
|
121
|
+
yield this._auth.login(Object.assign(Object.assign({ identityProvider: this.getIsLocal()
|
|
120
122
|
? constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER
|
|
121
|
-
: constants_1.IC_INTERNET_IDENTITY_PROVIDER }, options))
|
|
122
|
-
|
|
123
|
+
: constants_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
var _b;
|
|
125
|
+
yield this.authenticate();
|
|
126
|
+
(_b = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _b === void 0 ? void 0 : _b.call(options, msg);
|
|
127
|
+
}) }));
|
|
123
128
|
});
|
|
124
129
|
this.logout = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
125
130
|
if (!this._auth) {
|
|
@@ -6,6 +6,6 @@ import type { BaseActor, CreateReactorStoreParameters } from "./types";
|
|
|
6
6
|
* It also creates a new actor manager with the given options.
|
|
7
7
|
*
|
|
8
8
|
* @category Main
|
|
9
|
-
* @includeExample ./packages/core/README.md:200-
|
|
9
|
+
* @includeExample ./packages/core/README.md:200-225
|
|
10
10
|
*/
|
|
11
11
|
export declare const createReactorStore: <A = BaseActor>(config: CreateReactorStoreParameters) => ActorManager<A>;
|
|
@@ -21,7 +21,7 @@ const createAgentManager_1 = require("./createAgentManager");
|
|
|
21
21
|
* It also creates a new actor manager with the given options.
|
|
22
22
|
*
|
|
23
23
|
* @category Main
|
|
24
|
-
* @includeExample ./packages/core/README.md:200-
|
|
24
|
+
* @includeExample ./packages/core/README.md:200-225
|
|
25
25
|
*/
|
|
26
26
|
const createReactorStore = (config) => {
|
|
27
27
|
const withLocalEnv = config.withProcessEnv
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=10"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "02efba3e5948cb004777b8b54d623c4c537d3354"
|
|
56
56
|
}
|