@pollar/core 0.4.0 → 0.4.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 +205 -0
- package/dist/index.d.mts +34 -29
- package/dist/index.d.ts +34 -29
- package/dist/index.js +39 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -658,6 +658,7 @@ var StateStatus = {
|
|
|
658
658
|
ERROR: "ERROR"
|
|
659
659
|
};
|
|
660
660
|
var PollarStateVar = {
|
|
661
|
+
NETWORK: "network",
|
|
661
662
|
AUTHENTICATION: "authentication",
|
|
662
663
|
TRANSACTION: "transaction"
|
|
663
664
|
};
|
|
@@ -687,6 +688,7 @@ var STATE_VAR_CODES = {
|
|
|
687
688
|
FETCH_SESSION_START: "FETCH_SESSION_START",
|
|
688
689
|
FETCH_SESSION_SUCCESS: "FETCH_SESSION_SUCCESS",
|
|
689
690
|
FETCH_SESSION_ERROR: "FETCH_SESSION_ERROR",
|
|
691
|
+
NO_RESTORED_SESSION: "NO_RESTORED_SESSION",
|
|
690
692
|
RESTORED_SESSION_SUCCESS: "RESTORED_SESSION_SUCCESS",
|
|
691
693
|
RESTORED_SESSION_ERROR: "RESTORED_SESSION_ERROR",
|
|
692
694
|
SESSION_STORED: "SESSION_STORED",
|
|
@@ -704,12 +706,13 @@ var STATE_VAR_CODES = {
|
|
|
704
706
|
BUILD_TRANSACTION_START: "BUILD_TRANSACTION_START",
|
|
705
707
|
BUILD_TRANSACTION_SUCCESS: "BUILD_TRANSACTION_SUCCESS",
|
|
706
708
|
BUILD_TRANSACTION_ERROR: "BUILD_TRANSACTION_ERROR",
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
709
|
+
SIGN_SEND_TRANSACTION_START: "SIGN_SEND_TRANSACTION_START",
|
|
710
|
+
SIGN_SEND_TRANSACTION_SUCCESS: "SIGN_SEND_TRANSACTION_SUCCESS",
|
|
711
|
+
SIGN_SEND_TRANSACTION_ERROR: "SIGN_SEND_TRANSACTION_ERROR"
|
|
712
|
+
},
|
|
713
|
+
network: {
|
|
714
|
+
NONE: "NONE",
|
|
715
|
+
NETWORK_UPDATED: "NETWORK_UPDATED"
|
|
713
716
|
}
|
|
714
717
|
};
|
|
715
718
|
|
|
@@ -1261,6 +1264,7 @@ var PollarClient = class {
|
|
|
1261
1264
|
this._session = null;
|
|
1262
1265
|
this._stateListeners = /* @__PURE__ */ new Set();
|
|
1263
1266
|
this._state = {
|
|
1267
|
+
network: [],
|
|
1264
1268
|
authentication: [],
|
|
1265
1269
|
transaction: []
|
|
1266
1270
|
};
|
|
@@ -1288,6 +1292,9 @@ var PollarClient = class {
|
|
|
1288
1292
|
this._readStore();
|
|
1289
1293
|
}
|
|
1290
1294
|
});
|
|
1295
|
+
this._emitState("network", STATE_VAR_CODES.network.NETWORK_UPDATED, "info", StateStatus.SUCCESS, {
|
|
1296
|
+
network: "testnet"
|
|
1297
|
+
});
|
|
1291
1298
|
}
|
|
1292
1299
|
isAuthenticated() {
|
|
1293
1300
|
return !!this._session?.wallet?.publicKey;
|
|
@@ -1367,13 +1374,16 @@ var PollarClient = class {
|
|
|
1367
1374
|
);
|
|
1368
1375
|
}
|
|
1369
1376
|
}
|
|
1377
|
+
getNetwork() {
|
|
1378
|
+
return this._state.network.at(-1)?.data?.network === "public" ? "public" : "testnet";
|
|
1379
|
+
}
|
|
1370
1380
|
async buildTx(operation, params, options) {
|
|
1371
1381
|
if (!this._session?.wallet?.publicKey) {
|
|
1372
1382
|
this._emitState("transaction", STATE_VAR_CODES.transaction.BUILD_TRANSACTION_ERROR_NO_WALLET, "error", StateStatus.ERROR);
|
|
1373
1383
|
return;
|
|
1374
1384
|
}
|
|
1375
1385
|
const body = {
|
|
1376
|
-
network:
|
|
1386
|
+
network: this.getNetwork(),
|
|
1377
1387
|
publicKey: this._session?.wallet?.publicKey,
|
|
1378
1388
|
operation,
|
|
1379
1389
|
params,
|
|
@@ -1382,7 +1392,6 @@ var PollarClient = class {
|
|
|
1382
1392
|
try {
|
|
1383
1393
|
this._emitState("transaction", STATE_VAR_CODES.transaction.BUILD_TRANSACTION_START, "info", StateStatus.LOADING);
|
|
1384
1394
|
const response = await this._api.POST("/tx/build", { body });
|
|
1385
|
-
console.log({ response });
|
|
1386
1395
|
if (!emitResponse(
|
|
1387
1396
|
PollarStateVar.TRANSACTION,
|
|
1388
1397
|
response,
|
|
@@ -1401,19 +1410,28 @@ var PollarClient = class {
|
|
|
1401
1410
|
}
|
|
1402
1411
|
}
|
|
1403
1412
|
async submitTx(signedXdr) {
|
|
1413
|
+
const body = {
|
|
1414
|
+
network: this.getNetwork(),
|
|
1415
|
+
signedXdr
|
|
1416
|
+
};
|
|
1404
1417
|
try {
|
|
1405
|
-
|
|
1406
|
-
const
|
|
1407
|
-
if (
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1418
|
+
this._emitState("transaction", STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_START, "info", StateStatus.LOADING);
|
|
1419
|
+
const response = await this._api.POST("/tx/sign-and-send", { body });
|
|
1420
|
+
if (!emitResponse(
|
|
1421
|
+
PollarStateVar.TRANSACTION,
|
|
1422
|
+
response,
|
|
1423
|
+
{ code: STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_SUCCESS, status: StateStatus.SUCCESS },
|
|
1424
|
+
STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_ERROR,
|
|
1425
|
+
this._emitState.bind(this)
|
|
1426
|
+
)) {
|
|
1427
|
+
return;
|
|
1411
1428
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1429
|
+
} catch (error) {
|
|
1430
|
+
this._emitState("transaction", STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_ERROR, "error", StateStatus.ERROR, {
|
|
1431
|
+
body,
|
|
1432
|
+
error
|
|
1433
|
+
});
|
|
1434
|
+
return;
|
|
1417
1435
|
}
|
|
1418
1436
|
}
|
|
1419
1437
|
logout() {
|
|
@@ -1436,7 +1454,7 @@ var PollarClient = class {
|
|
|
1436
1454
|
);
|
|
1437
1455
|
console.info("[PollarClient] Session restored from storage");
|
|
1438
1456
|
} else {
|
|
1439
|
-
this._emitState("authentication", STATE_VAR_CODES.authentication.
|
|
1457
|
+
this._emitState("authentication", STATE_VAR_CODES.authentication.NO_RESTORED_SESSION, "info", StateStatus.NONE);
|
|
1440
1458
|
console.info("[PollarClient] Session NO restored from storage");
|
|
1441
1459
|
}
|
|
1442
1460
|
}
|
|
@@ -1457,6 +1475,7 @@ var PollarClient = class {
|
|
|
1457
1475
|
this._session = null;
|
|
1458
1476
|
removeStorage();
|
|
1459
1477
|
this._state = {
|
|
1478
|
+
network: [],
|
|
1460
1479
|
authentication: [],
|
|
1461
1480
|
transaction: []
|
|
1462
1481
|
};
|