@ecency/wallets 1.5.2 → 1.5.4
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/browser/index.d.ts +68 -28
- package/dist/browser/index.js +324 -389
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +341 -387
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +324 -389
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -1263,7 +1263,7 @@ function getHivePowerDelegatingsQueryOptions(username) {
|
|
|
1263
1263
|
)
|
|
1264
1264
|
});
|
|
1265
1265
|
}
|
|
1266
|
-
async function transferHive(payload) {
|
|
1266
|
+
async function transferHive(payload, auth) {
|
|
1267
1267
|
const parsedAsset = parseAsset(payload.amount);
|
|
1268
1268
|
const token = parsedAsset.symbol;
|
|
1269
1269
|
const precision = token === "VESTS" /* VESTS */ ? 6 : 3;
|
|
@@ -1289,26 +1289,14 @@ async function transferHive(payload) {
|
|
|
1289
1289
|
},
|
|
1290
1290
|
key
|
|
1291
1291
|
);
|
|
1292
|
-
} else if (payload.type === "keychain") {
|
|
1293
|
-
|
|
1294
|
-
(
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
(resp) => {
|
|
1301
|
-
if (!resp.success) {
|
|
1302
|
-
reject({ message: "Operation cancelled" });
|
|
1303
|
-
}
|
|
1304
|
-
resolve(resp);
|
|
1305
|
-
},
|
|
1306
|
-
true,
|
|
1307
|
-
null
|
|
1308
|
-
)
|
|
1309
|
-
);
|
|
1310
|
-
} else if (payload.type === "hiveauth") {
|
|
1311
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1292
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1293
|
+
if (auth?.broadcast) {
|
|
1294
|
+
return auth.broadcast([operation], "active");
|
|
1295
|
+
}
|
|
1296
|
+
if (payload.type === "hiveauth") {
|
|
1297
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1298
|
+
}
|
|
1299
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1312
1300
|
} else {
|
|
1313
1301
|
return hs__default.default.sendOperation(
|
|
1314
1302
|
operation,
|
|
@@ -1318,7 +1306,7 @@ async function transferHive(payload) {
|
|
|
1318
1306
|
);
|
|
1319
1307
|
}
|
|
1320
1308
|
}
|
|
1321
|
-
async function transferToSavingsHive(payload) {
|
|
1309
|
+
async function transferToSavingsHive(payload, auth) {
|
|
1322
1310
|
const operationPayload = {
|
|
1323
1311
|
from: payload.from,
|
|
1324
1312
|
to: payload.to,
|
|
@@ -1332,16 +1320,20 @@ async function transferToSavingsHive(payload) {
|
|
|
1332
1320
|
[["transfer_to_savings", params]],
|
|
1333
1321
|
key
|
|
1334
1322
|
);
|
|
1335
|
-
} else if (payload.type === "keychain") {
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1323
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1324
|
+
if (auth?.broadcast) {
|
|
1325
|
+
return auth.broadcast([operation], "active");
|
|
1326
|
+
}
|
|
1327
|
+
if (payload.type === "hiveauth") {
|
|
1328
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1329
|
+
}
|
|
1330
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1339
1331
|
} else {
|
|
1340
1332
|
return hs__default.default.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1341
1333
|
});
|
|
1342
1334
|
}
|
|
1343
1335
|
}
|
|
1344
|
-
async function transferFromSavingsHive(payload) {
|
|
1336
|
+
async function transferFromSavingsHive(payload, auth) {
|
|
1345
1337
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1346
1338
|
const operationPayload = {
|
|
1347
1339
|
from: payload.from,
|
|
@@ -1358,16 +1350,19 @@ async function transferFromSavingsHive(payload) {
|
|
|
1358
1350
|
key
|
|
1359
1351
|
);
|
|
1360
1352
|
}
|
|
1361
|
-
if (payload.type === "keychain") {
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1353
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1354
|
+
if (auth?.broadcast) {
|
|
1355
|
+
return auth.broadcast([operation], "active");
|
|
1356
|
+
}
|
|
1357
|
+
if (payload.type === "hiveauth") {
|
|
1358
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1359
|
+
}
|
|
1360
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1366
1361
|
}
|
|
1367
1362
|
return hs__default.default.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1368
1363
|
});
|
|
1369
1364
|
}
|
|
1370
|
-
async function powerUpHive(payload) {
|
|
1365
|
+
async function powerUpHive(payload, auth) {
|
|
1371
1366
|
const operationPayload = {
|
|
1372
1367
|
from: payload.from,
|
|
1373
1368
|
to: payload.to,
|
|
@@ -1381,16 +1376,20 @@ async function powerUpHive(payload) {
|
|
|
1381
1376
|
[["transfer_to_vesting", params]],
|
|
1382
1377
|
key
|
|
1383
1378
|
);
|
|
1384
|
-
} else if (payload.type === "keychain") {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1379
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1380
|
+
if (auth?.broadcast) {
|
|
1381
|
+
return auth.broadcast([operation], "active");
|
|
1382
|
+
}
|
|
1383
|
+
if (payload.type === "hiveauth") {
|
|
1384
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1385
|
+
}
|
|
1386
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1388
1387
|
} else {
|
|
1389
1388
|
return hs__default.default.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1390
1389
|
});
|
|
1391
1390
|
}
|
|
1392
1391
|
}
|
|
1393
|
-
async function delegateHive(payload) {
|
|
1392
|
+
async function delegateHive(payload, auth) {
|
|
1394
1393
|
const operationPayload = {
|
|
1395
1394
|
delegator: payload.from,
|
|
1396
1395
|
delegatee: payload.to,
|
|
@@ -1403,16 +1402,20 @@ async function delegateHive(payload) {
|
|
|
1403
1402
|
[operation],
|
|
1404
1403
|
key
|
|
1405
1404
|
);
|
|
1406
|
-
} else if (payload.type === "keychain") {
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1405
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1406
|
+
if (auth?.broadcast) {
|
|
1407
|
+
return auth.broadcast([operation], "active");
|
|
1408
|
+
}
|
|
1409
|
+
if (payload.type === "hiveauth") {
|
|
1410
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1411
|
+
}
|
|
1412
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1410
1413
|
} else {
|
|
1411
1414
|
return hs__default.default.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1412
1415
|
});
|
|
1413
1416
|
}
|
|
1414
1417
|
}
|
|
1415
|
-
async function powerDownHive(payload) {
|
|
1418
|
+
async function powerDownHive(payload, auth) {
|
|
1416
1419
|
const operationPayload = {
|
|
1417
1420
|
account: payload.from,
|
|
1418
1421
|
vesting_shares: payload.amount
|
|
@@ -1424,16 +1427,20 @@ async function powerDownHive(payload) {
|
|
|
1424
1427
|
[operation],
|
|
1425
1428
|
key
|
|
1426
1429
|
);
|
|
1427
|
-
} else if (payload.type === "keychain") {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1430
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1431
|
+
if (auth?.broadcast) {
|
|
1432
|
+
return auth.broadcast([operation], "active");
|
|
1433
|
+
}
|
|
1434
|
+
if (payload.type === "hiveauth") {
|
|
1435
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1436
|
+
}
|
|
1437
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1431
1438
|
} else {
|
|
1432
1439
|
return hs__default.default.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1433
1440
|
});
|
|
1434
1441
|
}
|
|
1435
1442
|
}
|
|
1436
|
-
async function withdrawVestingRouteHive(payload) {
|
|
1443
|
+
async function withdrawVestingRouteHive(payload, auth) {
|
|
1437
1444
|
const baseParams = {
|
|
1438
1445
|
from_account: payload.from_account,
|
|
1439
1446
|
to_account: payload.to_account,
|
|
@@ -1448,24 +1455,25 @@ async function withdrawVestingRouteHive(payload) {
|
|
|
1448
1455
|
key
|
|
1449
1456
|
);
|
|
1450
1457
|
}
|
|
1451
|
-
if (payload.type === "keychain") {
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1458
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1459
|
+
if (auth?.broadcast) {
|
|
1460
|
+
return auth.broadcast([operation], "active");
|
|
1461
|
+
}
|
|
1462
|
+
if (payload.type === "hiveauth") {
|
|
1463
|
+
return broadcastWithWalletHiveAuth(payload.from_account, [operation], "active");
|
|
1464
|
+
}
|
|
1465
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1457
1466
|
}
|
|
1458
1467
|
const { type, ...params } = payload;
|
|
1459
1468
|
return hs__default.default.sendOperation(operation, { callback: `https://ecency.com/@${params.from_account}/wallet` }, () => {
|
|
1460
1469
|
});
|
|
1461
1470
|
}
|
|
1462
|
-
function useClaimRewards(username,
|
|
1471
|
+
function useClaimRewards(username, auth, onSuccess) {
|
|
1463
1472
|
const { data } = reactQuery.useQuery(sdk.getAccountFullQueryOptions(username));
|
|
1464
1473
|
const queryClient = reactQuery.useQueryClient();
|
|
1465
1474
|
return sdk.useBroadcastMutation(
|
|
1466
1475
|
["assets", "hive", "claim-rewards", data?.name],
|
|
1467
1476
|
username,
|
|
1468
|
-
accessToken,
|
|
1469
1477
|
() => {
|
|
1470
1478
|
if (!data) {
|
|
1471
1479
|
throw new Error("Failed to fetch account while claiming balance");
|
|
@@ -1493,13 +1501,25 @@ function useClaimRewards(username, accessToken, onSuccess) {
|
|
|
1493
1501
|
queryClient.invalidateQueries({
|
|
1494
1502
|
queryKey: sdk.getAccountFullQueryOptions(username).queryKey
|
|
1495
1503
|
});
|
|
1504
|
+
queryClient.invalidateQueries({
|
|
1505
|
+
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
1506
|
+
});
|
|
1507
|
+
queryClient.invalidateQueries({
|
|
1508
|
+
queryKey: getHbdAssetGeneralInfoQueryOptions(username).queryKey
|
|
1509
|
+
});
|
|
1496
1510
|
queryClient.invalidateQueries({
|
|
1497
1511
|
queryKey: getHivePowerAssetGeneralInfoQueryOptions(username).queryKey
|
|
1498
1512
|
});
|
|
1499
|
-
|
|
1513
|
+
["HIVE", "HBD", "HP"].forEach((asset) => {
|
|
1514
|
+
queryClient.invalidateQueries({
|
|
1515
|
+
queryKey: ["ecency-wallets", "asset-info", username, asset]
|
|
1516
|
+
});
|
|
1517
|
+
});
|
|
1518
|
+
},
|
|
1519
|
+
auth
|
|
1500
1520
|
);
|
|
1501
1521
|
}
|
|
1502
|
-
async function claimInterestHive(payload) {
|
|
1522
|
+
async function claimInterestHive(payload, auth) {
|
|
1503
1523
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1504
1524
|
const baseOperation = {
|
|
1505
1525
|
from: payload.from,
|
|
@@ -1520,11 +1540,14 @@ async function claimInterestHive(payload) {
|
|
|
1520
1540
|
const { key } = payload;
|
|
1521
1541
|
return sdk.CONFIG.hiveClient.broadcast.sendOperations(operations, key);
|
|
1522
1542
|
}
|
|
1523
|
-
if (payload.type === "keychain") {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1543
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1544
|
+
if (auth?.broadcast) {
|
|
1545
|
+
return auth.broadcast(operations, "active");
|
|
1546
|
+
}
|
|
1547
|
+
if (payload.type === "hiveauth") {
|
|
1548
|
+
return broadcastWithWalletHiveAuth(payload.from, operations, "active");
|
|
1549
|
+
}
|
|
1550
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1528
1551
|
}
|
|
1529
1552
|
return hs__default.default.sendOperations(operations, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1530
1553
|
});
|
|
@@ -1551,7 +1574,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1551
1574
|
AssetOperation2["Undelegate"] = "undelegate";
|
|
1552
1575
|
return AssetOperation2;
|
|
1553
1576
|
})(AssetOperation || {});
|
|
1554
|
-
async function transferSpk(payload) {
|
|
1577
|
+
async function transferSpk(payload, auth) {
|
|
1555
1578
|
const json = JSON.stringify({
|
|
1556
1579
|
to: payload.to,
|
|
1557
1580
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1575,16 +1598,14 @@ async function transferSpk(payload) {
|
|
|
1575
1598
|
if (payload.type === "key" && "key" in payload) {
|
|
1576
1599
|
const { key } = payload;
|
|
1577
1600
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1578
|
-
} else if (payload.type === "keychain") {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
);
|
|
1586
|
-
} else if (payload.type === "hiveauth") {
|
|
1587
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1601
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1602
|
+
if (auth?.broadcast) {
|
|
1603
|
+
return auth.broadcast([operation], "active");
|
|
1604
|
+
}
|
|
1605
|
+
if (payload.type === "hiveauth") {
|
|
1606
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1607
|
+
}
|
|
1608
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1588
1609
|
} else {
|
|
1589
1610
|
const { amount } = parseAsset(payload.amount);
|
|
1590
1611
|
return hs__default.default.sign(
|
|
@@ -1604,7 +1625,7 @@ async function transferSpk(payload) {
|
|
|
1604
1625
|
);
|
|
1605
1626
|
}
|
|
1606
1627
|
}
|
|
1607
|
-
var lockLarynx = async (payload) => {
|
|
1628
|
+
var lockLarynx = async (payload, auth) => {
|
|
1608
1629
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1609
1630
|
const op = {
|
|
1610
1631
|
id: payload.mode === "lock" ? "spkcc_gov_up" : "spkcc_gov_down",
|
|
@@ -1624,16 +1645,14 @@ var lockLarynx = async (payload) => {
|
|
|
1624
1645
|
if (payload.type === "key" && "key" in payload) {
|
|
1625
1646
|
const { key } = payload;
|
|
1626
1647
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1627
|
-
} else if (payload.type === "keychain") {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
);
|
|
1635
|
-
} else if (payload.type === "hiveauth") {
|
|
1636
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1648
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1649
|
+
if (auth?.broadcast) {
|
|
1650
|
+
return auth.broadcast([operation], "active");
|
|
1651
|
+
}
|
|
1652
|
+
if (payload.type === "hiveauth") {
|
|
1653
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1654
|
+
}
|
|
1655
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1637
1656
|
} else {
|
|
1638
1657
|
const { amount } = parseAsset(payload.amount);
|
|
1639
1658
|
return hs__default.default.sign(
|
|
@@ -1649,7 +1668,7 @@ var lockLarynx = async (payload) => {
|
|
|
1649
1668
|
);
|
|
1650
1669
|
}
|
|
1651
1670
|
};
|
|
1652
|
-
async function powerUpLarynx(payload) {
|
|
1671
|
+
async function powerUpLarynx(payload, auth) {
|
|
1653
1672
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1654
1673
|
const op = {
|
|
1655
1674
|
id: `spkcc_power_${payload.mode}`,
|
|
@@ -1669,16 +1688,14 @@ async function powerUpLarynx(payload) {
|
|
|
1669
1688
|
if (payload.type === "key" && "key" in payload) {
|
|
1670
1689
|
const { key } = payload;
|
|
1671
1690
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1672
|
-
} else if (payload.type === "keychain") {
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
);
|
|
1680
|
-
} else if (payload.type === "hiveauth") {
|
|
1681
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1691
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1692
|
+
if (auth?.broadcast) {
|
|
1693
|
+
return auth.broadcast([operation], "active");
|
|
1694
|
+
}
|
|
1695
|
+
if (payload.type === "hiveauth") {
|
|
1696
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1697
|
+
}
|
|
1698
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1682
1699
|
} else {
|
|
1683
1700
|
const { amount } = parseAsset(payload.amount);
|
|
1684
1701
|
return hs__default.default.sign(
|
|
@@ -1694,7 +1711,7 @@ async function powerUpLarynx(payload) {
|
|
|
1694
1711
|
);
|
|
1695
1712
|
}
|
|
1696
1713
|
}
|
|
1697
|
-
async function transferLarynx(payload) {
|
|
1714
|
+
async function transferLarynx(payload, auth) {
|
|
1698
1715
|
const json = JSON.stringify({
|
|
1699
1716
|
to: payload.to,
|
|
1700
1717
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1718,16 +1735,14 @@ async function transferLarynx(payload) {
|
|
|
1718
1735
|
if (payload.type === "key" && "key" in payload) {
|
|
1719
1736
|
const { key } = payload;
|
|
1720
1737
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1721
|
-
} else if (payload.type === "keychain") {
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
);
|
|
1729
|
-
} else if (payload.type === "hiveauth") {
|
|
1730
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1738
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1739
|
+
if (auth?.broadcast) {
|
|
1740
|
+
return auth.broadcast([operation], "active");
|
|
1741
|
+
}
|
|
1742
|
+
if (payload.type === "hiveauth") {
|
|
1743
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1744
|
+
}
|
|
1745
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1731
1746
|
} else {
|
|
1732
1747
|
const { amount } = parseAsset(payload.amount);
|
|
1733
1748
|
return hs__default.default.sign(
|
|
@@ -1753,8 +1768,7 @@ function getSpkMarketsQueryOptions() {
|
|
|
1753
1768
|
staleTime: 6e4,
|
|
1754
1769
|
refetchInterval: 9e4,
|
|
1755
1770
|
queryFn: async () => {
|
|
1756
|
-
const
|
|
1757
|
-
const data = await response.json();
|
|
1771
|
+
const data = await sdk.getSpkMarkets();
|
|
1758
1772
|
return {
|
|
1759
1773
|
list: Object.entries(data.markets.node).map(([name, node]) => ({
|
|
1760
1774
|
name,
|
|
@@ -1769,8 +1783,10 @@ function getSpkWalletQueryOptions(username) {
|
|
|
1769
1783
|
return reactQuery.queryOptions({
|
|
1770
1784
|
queryKey: ["assets", "spk", "wallet", username],
|
|
1771
1785
|
queryFn: async () => {
|
|
1772
|
-
|
|
1773
|
-
|
|
1786
|
+
if (!username) {
|
|
1787
|
+
throw new Error("[SDK][Wallets][SPK] \u2013 username wasn't provided");
|
|
1788
|
+
}
|
|
1789
|
+
return sdk.getSpkWallet(username);
|
|
1774
1790
|
},
|
|
1775
1791
|
enabled: !!username,
|
|
1776
1792
|
staleTime: 6e4,
|
|
@@ -1942,32 +1958,7 @@ function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
|
1942
1958
|
return reactQuery.queryOptions({
|
|
1943
1959
|
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1944
1960
|
queryFn: async () => {
|
|
1945
|
-
|
|
1946
|
-
const response = await fetch(
|
|
1947
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1948
|
-
{
|
|
1949
|
-
method: "POST",
|
|
1950
|
-
body: JSON.stringify({
|
|
1951
|
-
jsonrpc: "2.0",
|
|
1952
|
-
method: "find",
|
|
1953
|
-
params: {
|
|
1954
|
-
contract: "market",
|
|
1955
|
-
table: "metrics",
|
|
1956
|
-
query: {
|
|
1957
|
-
...symbol && { symbol },
|
|
1958
|
-
...account && { account }
|
|
1959
|
-
}
|
|
1960
|
-
},
|
|
1961
|
-
id: 1
|
|
1962
|
-
}),
|
|
1963
|
-
headers: { "Content-type": "application/json" }
|
|
1964
|
-
}
|
|
1965
|
-
);
|
|
1966
|
-
const data = await response.json();
|
|
1967
|
-
return data.result;
|
|
1968
|
-
} catch (e) {
|
|
1969
|
-
return [];
|
|
1970
|
-
}
|
|
1961
|
+
return sdk.getHiveEngineTokensMarket(account, symbol);
|
|
1971
1962
|
}
|
|
1972
1963
|
});
|
|
1973
1964
|
}
|
|
@@ -2073,48 +2064,10 @@ function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allToke
|
|
|
2073
2064
|
if (!account) {
|
|
2074
2065
|
throw new Error("[HiveEngine] No account in a balances query");
|
|
2075
2066
|
}
|
|
2076
|
-
const
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
method: "POST",
|
|
2080
|
-
body: JSON.stringify({
|
|
2081
|
-
jsonrpc: "2.0",
|
|
2082
|
-
method: "find",
|
|
2083
|
-
params: {
|
|
2084
|
-
contract: "tokens",
|
|
2085
|
-
table: "balances",
|
|
2086
|
-
query: {
|
|
2087
|
-
account
|
|
2088
|
-
}
|
|
2089
|
-
},
|
|
2090
|
-
id: 1
|
|
2091
|
-
}),
|
|
2092
|
-
headers: { "Content-type": "application/json" }
|
|
2093
|
-
}
|
|
2067
|
+
const balances = await sdk.getHiveEngineTokensBalances(account);
|
|
2068
|
+
const tokens = await sdk.getHiveEngineTokensMetadata(
|
|
2069
|
+
balances.map((t) => t.symbol)
|
|
2094
2070
|
);
|
|
2095
|
-
const balancesData = await balancesResponse.json();
|
|
2096
|
-
const balances = balancesData.result || [];
|
|
2097
|
-
const tokensResponse = await fetch(
|
|
2098
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2099
|
-
{
|
|
2100
|
-
method: "POST",
|
|
2101
|
-
body: JSON.stringify({
|
|
2102
|
-
jsonrpc: "2.0",
|
|
2103
|
-
method: "find",
|
|
2104
|
-
params: {
|
|
2105
|
-
contract: "tokens",
|
|
2106
|
-
table: "tokens",
|
|
2107
|
-
query: {
|
|
2108
|
-
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2109
|
-
}
|
|
2110
|
-
},
|
|
2111
|
-
id: 2
|
|
2112
|
-
}),
|
|
2113
|
-
headers: { "Content-type": "application/json" }
|
|
2114
|
-
}
|
|
2115
|
-
);
|
|
2116
|
-
const tokensData = await tokensResponse.json();
|
|
2117
|
-
const tokens = tokensData.result || [];
|
|
2118
2071
|
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2119
2072
|
const metrics = Array.isArray(
|
|
2120
2073
|
allTokens
|
|
@@ -2159,27 +2112,7 @@ function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
|
2159
2112
|
staleTime: 6e4,
|
|
2160
2113
|
refetchInterval: 9e4,
|
|
2161
2114
|
queryFn: async () => {
|
|
2162
|
-
|
|
2163
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2164
|
-
{
|
|
2165
|
-
method: "POST",
|
|
2166
|
-
body: JSON.stringify({
|
|
2167
|
-
jsonrpc: "2.0",
|
|
2168
|
-
method: "find",
|
|
2169
|
-
params: {
|
|
2170
|
-
contract: "tokens",
|
|
2171
|
-
table: "tokens",
|
|
2172
|
-
query: {
|
|
2173
|
-
symbol: { $in: tokens }
|
|
2174
|
-
}
|
|
2175
|
-
},
|
|
2176
|
-
id: 2
|
|
2177
|
-
}),
|
|
2178
|
-
headers: { "Content-type": "application/json" }
|
|
2179
|
-
}
|
|
2180
|
-
);
|
|
2181
|
-
const data = await response.json();
|
|
2182
|
-
return data.result;
|
|
2115
|
+
return sdk.getHiveEngineTokensMetadata(tokens);
|
|
2183
2116
|
}
|
|
2184
2117
|
});
|
|
2185
2118
|
}
|
|
@@ -2189,27 +2122,7 @@ function getHiveEngineTokensBalancesQueryOptions(username) {
|
|
|
2189
2122
|
staleTime: 6e4,
|
|
2190
2123
|
refetchInterval: 9e4,
|
|
2191
2124
|
queryFn: async () => {
|
|
2192
|
-
|
|
2193
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2194
|
-
{
|
|
2195
|
-
method: "POST",
|
|
2196
|
-
body: JSON.stringify({
|
|
2197
|
-
jsonrpc: "2.0",
|
|
2198
|
-
method: "find",
|
|
2199
|
-
params: {
|
|
2200
|
-
contract: "tokens",
|
|
2201
|
-
table: "balances",
|
|
2202
|
-
query: {
|
|
2203
|
-
account: username
|
|
2204
|
-
}
|
|
2205
|
-
},
|
|
2206
|
-
id: 1
|
|
2207
|
-
}),
|
|
2208
|
-
headers: { "Content-type": "application/json" }
|
|
2209
|
-
}
|
|
2210
|
-
);
|
|
2211
|
-
const data = await response.json();
|
|
2212
|
-
return data.result;
|
|
2125
|
+
return sdk.getHiveEngineTokensBalances(username);
|
|
2213
2126
|
}
|
|
2214
2127
|
});
|
|
2215
2128
|
}
|
|
@@ -2219,25 +2132,7 @@ function getHiveEngineTokensMarketQueryOptions() {
|
|
|
2219
2132
|
staleTime: 6e4,
|
|
2220
2133
|
refetchInterval: 9e4,
|
|
2221
2134
|
queryFn: async () => {
|
|
2222
|
-
|
|
2223
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2224
|
-
{
|
|
2225
|
-
method: "POST",
|
|
2226
|
-
body: JSON.stringify({
|
|
2227
|
-
jsonrpc: "2.0",
|
|
2228
|
-
method: "find",
|
|
2229
|
-
params: {
|
|
2230
|
-
contract: "market",
|
|
2231
|
-
table: "metrics",
|
|
2232
|
-
query: {}
|
|
2233
|
-
},
|
|
2234
|
-
id: 1
|
|
2235
|
-
}),
|
|
2236
|
-
headers: { "Content-type": "application/json" }
|
|
2237
|
-
}
|
|
2238
|
-
);
|
|
2239
|
-
const data = await response.json();
|
|
2240
|
-
return data.result;
|
|
2135
|
+
return sdk.getHiveEngineTokensMarket();
|
|
2241
2136
|
}
|
|
2242
2137
|
});
|
|
2243
2138
|
}
|
|
@@ -2307,18 +2202,12 @@ function getHiveEngineTokenTransactionsQueryOptions(username, symbol, limit = 20
|
|
|
2307
2202
|
"[SDK][Wallets] \u2013 hive engine token or username missed"
|
|
2308
2203
|
);
|
|
2309
2204
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2205
|
+
return sdk.getHiveEngineTokenTransactions(
|
|
2206
|
+
username,
|
|
2207
|
+
symbol,
|
|
2208
|
+
limit,
|
|
2209
|
+
pageParam
|
|
2312
2210
|
);
|
|
2313
|
-
url.searchParams.set("account", username);
|
|
2314
|
-
url.searchParams.set("symbol", symbol);
|
|
2315
|
-
url.searchParams.set("limit", limit.toString());
|
|
2316
|
-
url.searchParams.set("offset", pageParam.toString());
|
|
2317
|
-
const response = await fetch(url, {
|
|
2318
|
-
method: "GET",
|
|
2319
|
-
headers: { "Content-type": "application/json" }
|
|
2320
|
-
});
|
|
2321
|
-
return await response.json();
|
|
2322
2211
|
}
|
|
2323
2212
|
});
|
|
2324
2213
|
}
|
|
@@ -2328,15 +2217,7 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2328
2217
|
staleTime: 6e4,
|
|
2329
2218
|
refetchInterval: 9e4,
|
|
2330
2219
|
queryFn: async () => {
|
|
2331
|
-
|
|
2332
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-chart-api`
|
|
2333
|
-
);
|
|
2334
|
-
url.searchParams.set("symbol", symbol);
|
|
2335
|
-
url.searchParams.set("interval", interval);
|
|
2336
|
-
const response = await fetch(url, {
|
|
2337
|
-
headers: { "Content-type": "application/json" }
|
|
2338
|
-
});
|
|
2339
|
-
return await response.json();
|
|
2220
|
+
return sdk.getHiveEngineTokenMetrics(symbol, interval);
|
|
2340
2221
|
}
|
|
2341
2222
|
});
|
|
2342
2223
|
}
|
|
@@ -2348,13 +2229,9 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2348
2229
|
enabled: !!username,
|
|
2349
2230
|
queryFn: async () => {
|
|
2350
2231
|
try {
|
|
2351
|
-
const
|
|
2352
|
-
|
|
2232
|
+
const data = await sdk.getHiveEngineUnclaimedRewards(
|
|
2233
|
+
username
|
|
2353
2234
|
);
|
|
2354
|
-
if (!response.ok) {
|
|
2355
|
-
return [];
|
|
2356
|
-
}
|
|
2357
|
-
const data = await response.json();
|
|
2358
2235
|
return Object.values(data).filter(
|
|
2359
2236
|
({ pending_token }) => pending_token > 0
|
|
2360
2237
|
);
|
|
@@ -2364,7 +2241,25 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2364
2241
|
}
|
|
2365
2242
|
});
|
|
2366
2243
|
}
|
|
2367
|
-
|
|
2244
|
+
|
|
2245
|
+
// src/modules/assets/hive-engine/mutations/broadcast-hive-engine-operation.ts
|
|
2246
|
+
async function broadcastHiveEngineOperation(payload, operation, auth) {
|
|
2247
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2248
|
+
if (auth?.broadcast) {
|
|
2249
|
+
return auth.broadcast([operation], "active");
|
|
2250
|
+
}
|
|
2251
|
+
if (payload.type === "hiveauth") {
|
|
2252
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2253
|
+
}
|
|
2254
|
+
if (payload.type === "keychain") {
|
|
2255
|
+
throw new Error("[SDK][Wallets] \u2013 keychain requires auth.broadcast");
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
// src/modules/assets/hive-engine/mutations/delegate.ts
|
|
2262
|
+
async function delegateEngineToken(payload, auth) {
|
|
2368
2263
|
const parsedAsset = parseAsset(payload.amount);
|
|
2369
2264
|
const quantity = parsedAsset.amount.toString();
|
|
2370
2265
|
const operation = [
|
|
@@ -2401,24 +2296,8 @@ async function delegateEngineToken(payload) {
|
|
|
2401
2296
|
required_posting_auths: []
|
|
2402
2297
|
};
|
|
2403
2298
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2404
|
-
} else if (payload.type === "keychain") {
|
|
2405
|
-
return
|
|
2406
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2407
|
-
payload.from,
|
|
2408
|
-
"ssc-mainnet-hive",
|
|
2409
|
-
"Active",
|
|
2410
|
-
operation[1].json,
|
|
2411
|
-
"Token Delegation",
|
|
2412
|
-
(resp) => {
|
|
2413
|
-
if (!resp.success) {
|
|
2414
|
-
reject({ message: "Operation cancelled" });
|
|
2415
|
-
}
|
|
2416
|
-
resolve(resp);
|
|
2417
|
-
}
|
|
2418
|
-
)
|
|
2419
|
-
);
|
|
2420
|
-
} else if (payload.type === "hiveauth") {
|
|
2421
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2299
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2300
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2422
2301
|
} else {
|
|
2423
2302
|
return hs__default.default.sendOperation(
|
|
2424
2303
|
operation,
|
|
@@ -2428,7 +2307,7 @@ async function delegateEngineToken(payload) {
|
|
|
2428
2307
|
);
|
|
2429
2308
|
}
|
|
2430
2309
|
}
|
|
2431
|
-
async function undelegateEngineToken(payload) {
|
|
2310
|
+
async function undelegateEngineToken(payload, auth) {
|
|
2432
2311
|
const parsedAsset = parseAsset(payload.amount);
|
|
2433
2312
|
const quantity = parsedAsset.amount.toString();
|
|
2434
2313
|
const operation = [
|
|
@@ -2465,24 +2344,8 @@ async function undelegateEngineToken(payload) {
|
|
|
2465
2344
|
required_posting_auths: []
|
|
2466
2345
|
};
|
|
2467
2346
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2468
|
-
} else if (payload.type === "keychain") {
|
|
2469
|
-
return
|
|
2470
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2471
|
-
payload.from,
|
|
2472
|
-
"ssc-mainnet-hive",
|
|
2473
|
-
"Active",
|
|
2474
|
-
operation[1].json,
|
|
2475
|
-
"Token Undelegation",
|
|
2476
|
-
(resp) => {
|
|
2477
|
-
if (!resp.success) {
|
|
2478
|
-
reject({ message: "Operation cancelled" });
|
|
2479
|
-
}
|
|
2480
|
-
resolve(resp);
|
|
2481
|
-
}
|
|
2482
|
-
)
|
|
2483
|
-
);
|
|
2484
|
-
} else if (payload.type === "hiveauth") {
|
|
2485
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2347
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2348
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2486
2349
|
} else {
|
|
2487
2350
|
return hs__default.default.sendOperation(
|
|
2488
2351
|
operation,
|
|
@@ -2492,7 +2355,7 @@ async function undelegateEngineToken(payload) {
|
|
|
2492
2355
|
);
|
|
2493
2356
|
}
|
|
2494
2357
|
}
|
|
2495
|
-
async function stakeEngineToken(payload) {
|
|
2358
|
+
async function stakeEngineToken(payload, auth) {
|
|
2496
2359
|
const parsedAsset = parseAsset(payload.amount);
|
|
2497
2360
|
const quantity = parsedAsset.amount.toString();
|
|
2498
2361
|
const operation = [
|
|
@@ -2529,24 +2392,8 @@ async function stakeEngineToken(payload) {
|
|
|
2529
2392
|
required_posting_auths: []
|
|
2530
2393
|
};
|
|
2531
2394
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2532
|
-
} else if (payload.type === "keychain") {
|
|
2533
|
-
return
|
|
2534
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2535
|
-
payload.from,
|
|
2536
|
-
"ssc-mainnet-hive",
|
|
2537
|
-
"Active",
|
|
2538
|
-
operation[1].json,
|
|
2539
|
-
"Token Staking",
|
|
2540
|
-
(resp) => {
|
|
2541
|
-
if (!resp.success) {
|
|
2542
|
-
reject({ message: "Operation cancelled" });
|
|
2543
|
-
}
|
|
2544
|
-
resolve(resp);
|
|
2545
|
-
}
|
|
2546
|
-
)
|
|
2547
|
-
);
|
|
2548
|
-
} else if (payload.type === "hiveauth") {
|
|
2549
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2395
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2396
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2550
2397
|
} else {
|
|
2551
2398
|
return hs__default.default.sendOperation(
|
|
2552
2399
|
operation,
|
|
@@ -2556,7 +2403,7 @@ async function stakeEngineToken(payload) {
|
|
|
2556
2403
|
);
|
|
2557
2404
|
}
|
|
2558
2405
|
}
|
|
2559
|
-
async function unstakeEngineToken(payload) {
|
|
2406
|
+
async function unstakeEngineToken(payload, auth) {
|
|
2560
2407
|
const parsedAsset = parseAsset(payload.amount);
|
|
2561
2408
|
const quantity = parsedAsset.amount.toString();
|
|
2562
2409
|
const operation = [
|
|
@@ -2593,24 +2440,8 @@ async function unstakeEngineToken(payload) {
|
|
|
2593
2440
|
required_posting_auths: []
|
|
2594
2441
|
};
|
|
2595
2442
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2596
|
-
} else if (payload.type === "keychain") {
|
|
2597
|
-
return
|
|
2598
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2599
|
-
payload.from,
|
|
2600
|
-
"ssc-mainnet-hive",
|
|
2601
|
-
"Active",
|
|
2602
|
-
operation[1].json,
|
|
2603
|
-
"Token Unstaking",
|
|
2604
|
-
(resp) => {
|
|
2605
|
-
if (!resp.success) {
|
|
2606
|
-
reject({ message: "Operation cancelled" });
|
|
2607
|
-
}
|
|
2608
|
-
resolve(resp);
|
|
2609
|
-
}
|
|
2610
|
-
)
|
|
2611
|
-
);
|
|
2612
|
-
} else if (payload.type === "hiveauth") {
|
|
2613
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2443
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2444
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2614
2445
|
} else {
|
|
2615
2446
|
return hs__default.default.sendOperation(
|
|
2616
2447
|
operation,
|
|
@@ -2620,7 +2451,7 @@ async function unstakeEngineToken(payload) {
|
|
|
2620
2451
|
);
|
|
2621
2452
|
}
|
|
2622
2453
|
}
|
|
2623
|
-
async function transferEngineToken(payload) {
|
|
2454
|
+
async function transferEngineToken(payload, auth) {
|
|
2624
2455
|
const parsedAsset = parseAsset(payload.amount);
|
|
2625
2456
|
const quantity = parsedAsset.amount.toString();
|
|
2626
2457
|
const operation = [
|
|
@@ -2659,24 +2490,8 @@ async function transferEngineToken(payload) {
|
|
|
2659
2490
|
required_posting_auths: []
|
|
2660
2491
|
};
|
|
2661
2492
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2662
|
-
} else if (payload.type === "keychain") {
|
|
2663
|
-
return
|
|
2664
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2665
|
-
payload.from,
|
|
2666
|
-
"ssc-mainnet-hive",
|
|
2667
|
-
"Active",
|
|
2668
|
-
operation[1].json,
|
|
2669
|
-
"Token Transfer",
|
|
2670
|
-
(resp) => {
|
|
2671
|
-
if (!resp.success) {
|
|
2672
|
-
reject({ message: "Operation cancelled" });
|
|
2673
|
-
}
|
|
2674
|
-
resolve(resp);
|
|
2675
|
-
}
|
|
2676
|
-
)
|
|
2677
|
-
);
|
|
2678
|
-
} else if (payload.type === "hiveauth") {
|
|
2679
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2493
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2494
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2680
2495
|
} else {
|
|
2681
2496
|
return hs__default.default.sendOperation(
|
|
2682
2497
|
operation,
|
|
@@ -2686,6 +2501,105 @@ async function transferEngineToken(payload) {
|
|
|
2686
2501
|
);
|
|
2687
2502
|
}
|
|
2688
2503
|
}
|
|
2504
|
+
var ENGINE_CONTRACT_ID = "ssc-mainnet-hive";
|
|
2505
|
+
function buildEngineOrderPayload(action, symbol, quantity, price) {
|
|
2506
|
+
return {
|
|
2507
|
+
contractName: "market",
|
|
2508
|
+
contractAction: action,
|
|
2509
|
+
contractPayload: { symbol, quantity, price }
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
function buildEngineCancelPayload(type, orderId) {
|
|
2513
|
+
return {
|
|
2514
|
+
contractName: "market",
|
|
2515
|
+
contractAction: "cancel",
|
|
2516
|
+
contractPayload: { type, id: orderId }
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
function buildEngineOperation(account, payload) {
|
|
2520
|
+
return {
|
|
2521
|
+
id: ENGINE_CONTRACT_ID,
|
|
2522
|
+
required_auths: [account],
|
|
2523
|
+
required_posting_auths: [],
|
|
2524
|
+
json: JSON.stringify(payload)
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
async function broadcastEngineOperation(account, payload, options2) {
|
|
2528
|
+
const operation = buildEngineOperation(account, payload);
|
|
2529
|
+
const opTuple = ["custom_json", operation];
|
|
2530
|
+
switch (options2?.method) {
|
|
2531
|
+
case "key": {
|
|
2532
|
+
if (!options2.key) {
|
|
2533
|
+
throw new Error("[SDK][Wallets] \u2013 active key is required");
|
|
2534
|
+
}
|
|
2535
|
+
return sdk.CONFIG.hiveClient.broadcast.json(operation, options2.key);
|
|
2536
|
+
}
|
|
2537
|
+
case "keychain":
|
|
2538
|
+
case "hiveauth": {
|
|
2539
|
+
if (options2.auth?.broadcast) {
|
|
2540
|
+
return options2.auth.broadcast([opTuple], "active");
|
|
2541
|
+
}
|
|
2542
|
+
if (options2.method === "hiveauth") {
|
|
2543
|
+
return broadcastWithWalletHiveAuth(account, [opTuple], "active");
|
|
2544
|
+
}
|
|
2545
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2546
|
+
}
|
|
2547
|
+
case "hivesigner":
|
|
2548
|
+
return hs__default.default.sendOperation(
|
|
2549
|
+
opTuple,
|
|
2550
|
+
{ callback: `https://ecency.com/@${account}/wallet/engine` },
|
|
2551
|
+
() => {
|
|
2552
|
+
}
|
|
2553
|
+
);
|
|
2554
|
+
default:
|
|
2555
|
+
throw new Error("[SDK][Wallets] \u2013 broadcast method is required");
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
var placeHiveEngineBuyOrder = async (account, symbol, quantity, price, options2) => broadcastEngineOperation(
|
|
2559
|
+
account,
|
|
2560
|
+
buildEngineOrderPayload("buy", symbol, quantity, price),
|
|
2561
|
+
options2
|
|
2562
|
+
);
|
|
2563
|
+
var placeHiveEngineSellOrder = async (account, symbol, quantity, price, options2) => broadcastEngineOperation(
|
|
2564
|
+
account,
|
|
2565
|
+
buildEngineOrderPayload("sell", symbol, quantity, price),
|
|
2566
|
+
options2
|
|
2567
|
+
);
|
|
2568
|
+
var cancelHiveEngineOrder = async (account, type, orderId, options2) => broadcastEngineOperation(
|
|
2569
|
+
account,
|
|
2570
|
+
buildEngineCancelPayload(type, orderId),
|
|
2571
|
+
options2
|
|
2572
|
+
);
|
|
2573
|
+
async function claimHiveEngineRewards(payload, auth) {
|
|
2574
|
+
const json = JSON.stringify(payload.tokens.map((symbol) => ({ symbol })));
|
|
2575
|
+
const operation = [
|
|
2576
|
+
"custom_json",
|
|
2577
|
+
{
|
|
2578
|
+
id: "scot_claim_token",
|
|
2579
|
+
required_auths: [],
|
|
2580
|
+
required_posting_auths: [payload.account],
|
|
2581
|
+
json
|
|
2582
|
+
}
|
|
2583
|
+
];
|
|
2584
|
+
if (payload.type === "key" && "key" in payload) {
|
|
2585
|
+
return sdk.CONFIG.hiveClient.broadcast.sendOperations([operation], payload.key);
|
|
2586
|
+
}
|
|
2587
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2588
|
+
if (auth?.broadcast) {
|
|
2589
|
+
return auth.broadcast([operation], "posting");
|
|
2590
|
+
}
|
|
2591
|
+
if (payload.type === "hiveauth") {
|
|
2592
|
+
return broadcastWithWalletHiveAuth(payload.account, [operation], "posting");
|
|
2593
|
+
}
|
|
2594
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2595
|
+
}
|
|
2596
|
+
return hs__default.default.sendOperation(
|
|
2597
|
+
operation,
|
|
2598
|
+
{ callback: `https://ecency.com/@${payload.account}/wallet/engine` },
|
|
2599
|
+
() => {
|
|
2600
|
+
}
|
|
2601
|
+
);
|
|
2602
|
+
}
|
|
2689
2603
|
function getPointsQueryOptions(username) {
|
|
2690
2604
|
return reactQuery.queryOptions({
|
|
2691
2605
|
queryKey: ["assets", "points", username],
|
|
@@ -2773,7 +2687,7 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2773
2687
|
}
|
|
2774
2688
|
|
|
2775
2689
|
// src/modules/assets/points/mutations/claim-points.ts
|
|
2776
|
-
function useClaimPoints(username, onSuccess, onError) {
|
|
2690
|
+
function useClaimPoints(username, accessToken, onSuccess, onError) {
|
|
2777
2691
|
const { mutateAsync: recordActivity } = sdk.EcencyAnalytics.useRecordActivity(
|
|
2778
2692
|
username,
|
|
2779
2693
|
"points-claimed"
|
|
@@ -2783,16 +2697,31 @@ function useClaimPoints(username, onSuccess, onError) {
|
|
|
2783
2697
|
mutationFn: async () => {
|
|
2784
2698
|
if (!username) {
|
|
2785
2699
|
throw new Error(
|
|
2786
|
-
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn
|
|
2700
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn't provided"
|
|
2787
2701
|
);
|
|
2788
2702
|
}
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2703
|
+
if (!accessToken) {
|
|
2704
|
+
throw new Error(
|
|
2705
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 access token wasn't found"
|
|
2706
|
+
);
|
|
2707
|
+
}
|
|
2708
|
+
const response = await fetchApi(
|
|
2709
|
+
sdk.CONFIG.privateApiHost + "/private-api/points-claim",
|
|
2710
|
+
{
|
|
2711
|
+
method: "POST",
|
|
2712
|
+
headers: {
|
|
2713
|
+
"Content-Type": "application/json"
|
|
2714
|
+
},
|
|
2715
|
+
body: JSON.stringify({ code: accessToken })
|
|
2716
|
+
}
|
|
2717
|
+
);
|
|
2718
|
+
if (!response.ok) {
|
|
2719
|
+
const body = await response.text();
|
|
2720
|
+
throw new Error(
|
|
2721
|
+
`[SDK][Wallets][Assets][Points][Claim] \u2013 failed with status ${response.status}${body ? `: ${body}` : ""}`
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2724
|
+
return response.json();
|
|
2796
2725
|
},
|
|
2797
2726
|
onError,
|
|
2798
2727
|
onSuccess: () => {
|
|
@@ -2820,7 +2749,7 @@ async function transferPoint({
|
|
|
2820
2749
|
memo,
|
|
2821
2750
|
type,
|
|
2822
2751
|
...payload
|
|
2823
|
-
}) {
|
|
2752
|
+
}, auth) {
|
|
2824
2753
|
const op = [
|
|
2825
2754
|
"custom_json",
|
|
2826
2755
|
{
|
|
@@ -2839,11 +2768,14 @@ async function transferPoint({
|
|
|
2839
2768
|
const { key } = payload;
|
|
2840
2769
|
return sdk.CONFIG.hiveClient.broadcast.sendOperations([op], key);
|
|
2841
2770
|
}
|
|
2842
|
-
if (type === "keychain") {
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2771
|
+
if (type === "keychain" || type === "hiveauth") {
|
|
2772
|
+
if (auth?.broadcast) {
|
|
2773
|
+
return auth.broadcast([op], "active");
|
|
2774
|
+
}
|
|
2775
|
+
if (type === "hiveauth") {
|
|
2776
|
+
return broadcastWithWalletHiveAuth(from, [op], "active");
|
|
2777
|
+
}
|
|
2778
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2847
2779
|
}
|
|
2848
2780
|
return hs__default.default.sendOperation(op, { callback: `https://ecency.com/@${from}/wallet` }, () => {
|
|
2849
2781
|
});
|
|
@@ -4067,7 +3999,7 @@ function useCheckWalletExistence() {
|
|
|
4067
3999
|
}
|
|
4068
4000
|
});
|
|
4069
4001
|
}
|
|
4070
|
-
function useUpdateAccountWithWallets(username) {
|
|
4002
|
+
function useUpdateAccountWithWallets(username, accessToken) {
|
|
4071
4003
|
const fetchApi = getBoundFetch();
|
|
4072
4004
|
return reactQuery.useMutation({
|
|
4073
4005
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
|
|
@@ -4077,6 +4009,11 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4077
4009
|
return new Response(null, { status: 204 });
|
|
4078
4010
|
}
|
|
4079
4011
|
const [primaryToken, primaryAddress] = entries[0] ?? ["", ""];
|
|
4012
|
+
if (!accessToken) {
|
|
4013
|
+
throw new Error(
|
|
4014
|
+
"[SDK][Wallets][PrivateApi][WalletsAdd] \u2013 access token wasn`t found"
|
|
4015
|
+
);
|
|
4016
|
+
}
|
|
4080
4017
|
return fetchApi(sdk.CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
4081
4018
|
method: "POST",
|
|
4082
4019
|
headers: {
|
|
@@ -4084,7 +4021,7 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4084
4021
|
},
|
|
4085
4022
|
body: JSON.stringify({
|
|
4086
4023
|
username,
|
|
4087
|
-
code:
|
|
4024
|
+
code: accessToken,
|
|
4088
4025
|
token: primaryToken,
|
|
4089
4026
|
address: primaryAddress,
|
|
4090
4027
|
status: 3,
|
|
@@ -4218,14 +4155,10 @@ function getGroupedChainTokens(tokens, defaultShow) {
|
|
|
4218
4155
|
)
|
|
4219
4156
|
);
|
|
4220
4157
|
}
|
|
4221
|
-
function useSaveWalletInformationToMetadata(username,
|
|
4158
|
+
function useSaveWalletInformationToMetadata(username, auth, options2) {
|
|
4222
4159
|
const queryClient = reactQuery.useQueryClient();
|
|
4223
4160
|
const { data: accountData } = reactQuery.useQuery(sdk.getAccountFullQueryOptions(username));
|
|
4224
|
-
const { mutateAsync: updateProfile } = sdk.useAccountUpdate(
|
|
4225
|
-
username,
|
|
4226
|
-
accessToken,
|
|
4227
|
-
auth
|
|
4228
|
-
);
|
|
4161
|
+
const { mutateAsync: updateProfile } = sdk.useAccountUpdate(username, auth);
|
|
4229
4162
|
return reactQuery.useMutation({
|
|
4230
4163
|
mutationKey: [
|
|
4231
4164
|
"ecency-wallets",
|
|
@@ -4307,7 +4240,7 @@ var engineOperationToFunctionMap = {
|
|
|
4307
4240
|
["delegate" /* Delegate */]: delegateEngineToken,
|
|
4308
4241
|
["undelegate" /* Undelegate */]: undelegateEngineToken
|
|
4309
4242
|
};
|
|
4310
|
-
function useWalletOperation(username, asset, operation) {
|
|
4243
|
+
function useWalletOperation(username, asset, operation, auth) {
|
|
4311
4244
|
const { mutateAsync: recordActivity } = sdk.EcencyAnalytics.useRecordActivity(
|
|
4312
4245
|
username,
|
|
4313
4246
|
operation
|
|
@@ -4317,17 +4250,18 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4317
4250
|
mutationFn: async (payload) => {
|
|
4318
4251
|
const operationFn = operationToFunctionMap[asset]?.[operation];
|
|
4319
4252
|
if (operationFn) {
|
|
4320
|
-
return operationFn(payload);
|
|
4253
|
+
return operationFn(payload, auth);
|
|
4321
4254
|
}
|
|
4322
4255
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
4323
4256
|
await sdk.getQueryClient().prefetchQuery(balancesListQuery);
|
|
4324
4257
|
const balances = sdk.getQueryClient().getQueryData(
|
|
4325
4258
|
balancesListQuery.queryKey
|
|
4326
4259
|
);
|
|
4327
|
-
|
|
4260
|
+
const engineBalances = balances ?? [];
|
|
4261
|
+
if (engineBalances.some((balance) => balance.symbol === asset)) {
|
|
4328
4262
|
const operationFn2 = engineOperationToFunctionMap[operation];
|
|
4329
4263
|
if (operationFn2) {
|
|
4330
|
-
return operationFn2({ ...payload, asset });
|
|
4264
|
+
return operationFn2({ ...payload, asset }, auth);
|
|
4331
4265
|
}
|
|
4332
4266
|
}
|
|
4333
4267
|
throw new Error("[SDK][Wallets] \u2013 no operation for given asset");
|
|
@@ -4364,6 +4298,22 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4364
4298
|
// src/index.ts
|
|
4365
4299
|
rememberScryptBsvVersion();
|
|
4366
4300
|
|
|
4301
|
+
Object.defineProperty(exports, "getHiveEngineMetrics", {
|
|
4302
|
+
enumerable: true,
|
|
4303
|
+
get: function () { return sdk.getHiveEngineMetrics; }
|
|
4304
|
+
});
|
|
4305
|
+
Object.defineProperty(exports, "getHiveEngineOpenOrders", {
|
|
4306
|
+
enumerable: true,
|
|
4307
|
+
get: function () { return sdk.getHiveEngineOpenOrders; }
|
|
4308
|
+
});
|
|
4309
|
+
Object.defineProperty(exports, "getHiveEngineOrderBook", {
|
|
4310
|
+
enumerable: true,
|
|
4311
|
+
get: function () { return sdk.getHiveEngineOrderBook; }
|
|
4312
|
+
});
|
|
4313
|
+
Object.defineProperty(exports, "getHiveEngineTradeHistory", {
|
|
4314
|
+
enumerable: true,
|
|
4315
|
+
get: function () { return sdk.getHiveEngineTradeHistory; }
|
|
4316
|
+
});
|
|
4367
4317
|
exports.AssetOperation = AssetOperation;
|
|
4368
4318
|
exports.EcencyWalletBasicTokens = EcencyWalletBasicTokens;
|
|
4369
4319
|
exports.EcencyWalletCurrency = EcencyWalletCurrency;
|
|
@@ -4384,6 +4334,8 @@ exports.buildPsbt = buildPsbt;
|
|
|
4384
4334
|
exports.buildSolTx = buildSolTx;
|
|
4385
4335
|
exports.buildTonTx = buildTonTx;
|
|
4386
4336
|
exports.buildTronTx = buildTronTx;
|
|
4337
|
+
exports.cancelHiveEngineOrder = cancelHiveEngineOrder;
|
|
4338
|
+
exports.claimHiveEngineRewards = claimHiveEngineRewards;
|
|
4387
4339
|
exports.claimInterestHive = claimInterestHive;
|
|
4388
4340
|
exports.decryptMemoWithAccounts = decryptMemoWithAccounts;
|
|
4389
4341
|
exports.decryptMemoWithKeys = decryptMemoWithKeys;
|
|
@@ -4438,6 +4390,8 @@ exports.isEmptyDate = isEmptyDate;
|
|
|
4438
4390
|
exports.lockLarynx = lockLarynx;
|
|
4439
4391
|
exports.mnemonicToSeedBip39 = mnemonicToSeedBip39;
|
|
4440
4392
|
exports.parseAsset = parseAsset;
|
|
4393
|
+
exports.placeHiveEngineBuyOrder = placeHiveEngineBuyOrder;
|
|
4394
|
+
exports.placeHiveEngineSellOrder = placeHiveEngineSellOrder;
|
|
4441
4395
|
exports.powerDownHive = powerDownHive;
|
|
4442
4396
|
exports.powerUpHive = powerUpHive;
|
|
4443
4397
|
exports.powerUpLarynx = powerUpLarynx;
|