@pollar/core 0.4.0 → 0.4.1
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/dist/index.d.mts +33 -29
- package/dist/index.d.ts +33 -29
- package/dist/index.js +37 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -19
- 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
|
};
|
|
@@ -704,12 +705,13 @@ var STATE_VAR_CODES = {
|
|
|
704
705
|
BUILD_TRANSACTION_START: "BUILD_TRANSACTION_START",
|
|
705
706
|
BUILD_TRANSACTION_SUCCESS: "BUILD_TRANSACTION_SUCCESS",
|
|
706
707
|
BUILD_TRANSACTION_ERROR: "BUILD_TRANSACTION_ERROR",
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
708
|
+
SIGN_SEND_TRANSACTION_START: "SIGN_SEND_TRANSACTION_START",
|
|
709
|
+
SIGN_SEND_TRANSACTION_SUCCESS: "SIGN_SEND_TRANSACTION_SUCCESS",
|
|
710
|
+
SIGN_SEND_TRANSACTION_ERROR: "SIGN_SEND_TRANSACTION_ERROR"
|
|
711
|
+
},
|
|
712
|
+
network: {
|
|
713
|
+
NONE: "NONE",
|
|
714
|
+
NETWORK_UPDATED: "NETWORK_UPDATED"
|
|
713
715
|
}
|
|
714
716
|
};
|
|
715
717
|
|
|
@@ -1261,6 +1263,7 @@ var PollarClient = class {
|
|
|
1261
1263
|
this._session = null;
|
|
1262
1264
|
this._stateListeners = /* @__PURE__ */ new Set();
|
|
1263
1265
|
this._state = {
|
|
1266
|
+
network: [],
|
|
1264
1267
|
authentication: [],
|
|
1265
1268
|
transaction: []
|
|
1266
1269
|
};
|
|
@@ -1288,6 +1291,9 @@ var PollarClient = class {
|
|
|
1288
1291
|
this._readStore();
|
|
1289
1292
|
}
|
|
1290
1293
|
});
|
|
1294
|
+
this._emitState("network", STATE_VAR_CODES.network.NETWORK_UPDATED, "info", StateStatus.SUCCESS, {
|
|
1295
|
+
network: "testnet"
|
|
1296
|
+
});
|
|
1291
1297
|
}
|
|
1292
1298
|
isAuthenticated() {
|
|
1293
1299
|
return !!this._session?.wallet?.publicKey;
|
|
@@ -1367,13 +1373,16 @@ var PollarClient = class {
|
|
|
1367
1373
|
);
|
|
1368
1374
|
}
|
|
1369
1375
|
}
|
|
1376
|
+
getNetwork() {
|
|
1377
|
+
return this._state.network.at(-1)?.data?.network === "public" ? "public" : "testnet";
|
|
1378
|
+
}
|
|
1370
1379
|
async buildTx(operation, params, options) {
|
|
1371
1380
|
if (!this._session?.wallet?.publicKey) {
|
|
1372
1381
|
this._emitState("transaction", STATE_VAR_CODES.transaction.BUILD_TRANSACTION_ERROR_NO_WALLET, "error", StateStatus.ERROR);
|
|
1373
1382
|
return;
|
|
1374
1383
|
}
|
|
1375
1384
|
const body = {
|
|
1376
|
-
network:
|
|
1385
|
+
network: this.getNetwork(),
|
|
1377
1386
|
publicKey: this._session?.wallet?.publicKey,
|
|
1378
1387
|
operation,
|
|
1379
1388
|
params,
|
|
@@ -1382,7 +1391,6 @@ var PollarClient = class {
|
|
|
1382
1391
|
try {
|
|
1383
1392
|
this._emitState("transaction", STATE_VAR_CODES.transaction.BUILD_TRANSACTION_START, "info", StateStatus.LOADING);
|
|
1384
1393
|
const response = await this._api.POST("/tx/build", { body });
|
|
1385
|
-
console.log({ response });
|
|
1386
1394
|
if (!emitResponse(
|
|
1387
1395
|
PollarStateVar.TRANSACTION,
|
|
1388
1396
|
response,
|
|
@@ -1401,19 +1409,28 @@ var PollarClient = class {
|
|
|
1401
1409
|
}
|
|
1402
1410
|
}
|
|
1403
1411
|
async submitTx(signedXdr) {
|
|
1412
|
+
const body = {
|
|
1413
|
+
network: this.getNetwork(),
|
|
1414
|
+
signedXdr
|
|
1415
|
+
};
|
|
1404
1416
|
try {
|
|
1405
|
-
|
|
1406
|
-
const
|
|
1407
|
-
if (
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1417
|
+
this._emitState("transaction", STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_START, "info", StateStatus.LOADING);
|
|
1418
|
+
const response = await this._api.POST("/tx/sign-and-send", { body });
|
|
1419
|
+
if (!emitResponse(
|
|
1420
|
+
PollarStateVar.TRANSACTION,
|
|
1421
|
+
response,
|
|
1422
|
+
{ code: STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_SUCCESS, status: StateStatus.SUCCESS },
|
|
1423
|
+
STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_ERROR,
|
|
1424
|
+
this._emitState.bind(this)
|
|
1425
|
+
)) {
|
|
1426
|
+
return;
|
|
1411
1427
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1428
|
+
} catch (error) {
|
|
1429
|
+
this._emitState("transaction", STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_ERROR, "error", StateStatus.ERROR, {
|
|
1430
|
+
body,
|
|
1431
|
+
error
|
|
1432
|
+
});
|
|
1433
|
+
return;
|
|
1417
1434
|
}
|
|
1418
1435
|
}
|
|
1419
1436
|
logout() {
|
|
@@ -1457,6 +1474,7 @@ var PollarClient = class {
|
|
|
1457
1474
|
this._session = null;
|
|
1458
1475
|
removeStorage();
|
|
1459
1476
|
this._state = {
|
|
1477
|
+
network: [],
|
|
1460
1478
|
authentication: [],
|
|
1461
1479
|
transaction: []
|
|
1462
1480
|
};
|