@ecency/wallets 1.5.2 → 1.5.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/dist/browser/index.d.ts +68 -28
- package/dist/browser/index.js +313 -389
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +330 -387
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +313 -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");
|
|
@@ -1496,10 +1504,11 @@ function useClaimRewards(username, accessToken, onSuccess) {
|
|
|
1496
1504
|
queryClient.invalidateQueries({
|
|
1497
1505
|
queryKey: getHivePowerAssetGeneralInfoQueryOptions(username).queryKey
|
|
1498
1506
|
});
|
|
1499
|
-
}
|
|
1507
|
+
},
|
|
1508
|
+
auth
|
|
1500
1509
|
);
|
|
1501
1510
|
}
|
|
1502
|
-
async function claimInterestHive(payload) {
|
|
1511
|
+
async function claimInterestHive(payload, auth) {
|
|
1503
1512
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1504
1513
|
const baseOperation = {
|
|
1505
1514
|
from: payload.from,
|
|
@@ -1520,11 +1529,14 @@ async function claimInterestHive(payload) {
|
|
|
1520
1529
|
const { key } = payload;
|
|
1521
1530
|
return sdk.CONFIG.hiveClient.broadcast.sendOperations(operations, key);
|
|
1522
1531
|
}
|
|
1523
|
-
if (payload.type === "keychain") {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1532
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1533
|
+
if (auth?.broadcast) {
|
|
1534
|
+
return auth.broadcast(operations, "active");
|
|
1535
|
+
}
|
|
1536
|
+
if (payload.type === "hiveauth") {
|
|
1537
|
+
return broadcastWithWalletHiveAuth(payload.from, operations, "active");
|
|
1538
|
+
}
|
|
1539
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1528
1540
|
}
|
|
1529
1541
|
return hs__default.default.sendOperations(operations, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1530
1542
|
});
|
|
@@ -1551,7 +1563,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1551
1563
|
AssetOperation2["Undelegate"] = "undelegate";
|
|
1552
1564
|
return AssetOperation2;
|
|
1553
1565
|
})(AssetOperation || {});
|
|
1554
|
-
async function transferSpk(payload) {
|
|
1566
|
+
async function transferSpk(payload, auth) {
|
|
1555
1567
|
const json = JSON.stringify({
|
|
1556
1568
|
to: payload.to,
|
|
1557
1569
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1575,16 +1587,14 @@ async function transferSpk(payload) {
|
|
|
1575
1587
|
if (payload.type === "key" && "key" in payload) {
|
|
1576
1588
|
const { key } = payload;
|
|
1577
1589
|
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");
|
|
1590
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1591
|
+
if (auth?.broadcast) {
|
|
1592
|
+
return auth.broadcast([operation], "active");
|
|
1593
|
+
}
|
|
1594
|
+
if (payload.type === "hiveauth") {
|
|
1595
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1596
|
+
}
|
|
1597
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1588
1598
|
} else {
|
|
1589
1599
|
const { amount } = parseAsset(payload.amount);
|
|
1590
1600
|
return hs__default.default.sign(
|
|
@@ -1604,7 +1614,7 @@ async function transferSpk(payload) {
|
|
|
1604
1614
|
);
|
|
1605
1615
|
}
|
|
1606
1616
|
}
|
|
1607
|
-
var lockLarynx = async (payload) => {
|
|
1617
|
+
var lockLarynx = async (payload, auth) => {
|
|
1608
1618
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1609
1619
|
const op = {
|
|
1610
1620
|
id: payload.mode === "lock" ? "spkcc_gov_up" : "spkcc_gov_down",
|
|
@@ -1624,16 +1634,14 @@ var lockLarynx = async (payload) => {
|
|
|
1624
1634
|
if (payload.type === "key" && "key" in payload) {
|
|
1625
1635
|
const { key } = payload;
|
|
1626
1636
|
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");
|
|
1637
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1638
|
+
if (auth?.broadcast) {
|
|
1639
|
+
return auth.broadcast([operation], "active");
|
|
1640
|
+
}
|
|
1641
|
+
if (payload.type === "hiveauth") {
|
|
1642
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1643
|
+
}
|
|
1644
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1637
1645
|
} else {
|
|
1638
1646
|
const { amount } = parseAsset(payload.amount);
|
|
1639
1647
|
return hs__default.default.sign(
|
|
@@ -1649,7 +1657,7 @@ var lockLarynx = async (payload) => {
|
|
|
1649
1657
|
);
|
|
1650
1658
|
}
|
|
1651
1659
|
};
|
|
1652
|
-
async function powerUpLarynx(payload) {
|
|
1660
|
+
async function powerUpLarynx(payload, auth) {
|
|
1653
1661
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1654
1662
|
const op = {
|
|
1655
1663
|
id: `spkcc_power_${payload.mode}`,
|
|
@@ -1669,16 +1677,14 @@ async function powerUpLarynx(payload) {
|
|
|
1669
1677
|
if (payload.type === "key" && "key" in payload) {
|
|
1670
1678
|
const { key } = payload;
|
|
1671
1679
|
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");
|
|
1680
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1681
|
+
if (auth?.broadcast) {
|
|
1682
|
+
return auth.broadcast([operation], "active");
|
|
1683
|
+
}
|
|
1684
|
+
if (payload.type === "hiveauth") {
|
|
1685
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1686
|
+
}
|
|
1687
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1682
1688
|
} else {
|
|
1683
1689
|
const { amount } = parseAsset(payload.amount);
|
|
1684
1690
|
return hs__default.default.sign(
|
|
@@ -1694,7 +1700,7 @@ async function powerUpLarynx(payload) {
|
|
|
1694
1700
|
);
|
|
1695
1701
|
}
|
|
1696
1702
|
}
|
|
1697
|
-
async function transferLarynx(payload) {
|
|
1703
|
+
async function transferLarynx(payload, auth) {
|
|
1698
1704
|
const json = JSON.stringify({
|
|
1699
1705
|
to: payload.to,
|
|
1700
1706
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1718,16 +1724,14 @@ async function transferLarynx(payload) {
|
|
|
1718
1724
|
if (payload.type === "key" && "key" in payload) {
|
|
1719
1725
|
const { key } = payload;
|
|
1720
1726
|
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");
|
|
1727
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1728
|
+
if (auth?.broadcast) {
|
|
1729
|
+
return auth.broadcast([operation], "active");
|
|
1730
|
+
}
|
|
1731
|
+
if (payload.type === "hiveauth") {
|
|
1732
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1733
|
+
}
|
|
1734
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1731
1735
|
} else {
|
|
1732
1736
|
const { amount } = parseAsset(payload.amount);
|
|
1733
1737
|
return hs__default.default.sign(
|
|
@@ -1753,8 +1757,7 @@ function getSpkMarketsQueryOptions() {
|
|
|
1753
1757
|
staleTime: 6e4,
|
|
1754
1758
|
refetchInterval: 9e4,
|
|
1755
1759
|
queryFn: async () => {
|
|
1756
|
-
const
|
|
1757
|
-
const data = await response.json();
|
|
1760
|
+
const data = await sdk.getSpkMarkets();
|
|
1758
1761
|
return {
|
|
1759
1762
|
list: Object.entries(data.markets.node).map(([name, node]) => ({
|
|
1760
1763
|
name,
|
|
@@ -1769,8 +1772,10 @@ function getSpkWalletQueryOptions(username) {
|
|
|
1769
1772
|
return reactQuery.queryOptions({
|
|
1770
1773
|
queryKey: ["assets", "spk", "wallet", username],
|
|
1771
1774
|
queryFn: async () => {
|
|
1772
|
-
|
|
1773
|
-
|
|
1775
|
+
if (!username) {
|
|
1776
|
+
throw new Error("[SDK][Wallets][SPK] \u2013 username wasn't provided");
|
|
1777
|
+
}
|
|
1778
|
+
return sdk.getSpkWallet(username);
|
|
1774
1779
|
},
|
|
1775
1780
|
enabled: !!username,
|
|
1776
1781
|
staleTime: 6e4,
|
|
@@ -1942,32 +1947,7 @@ function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
|
1942
1947
|
return reactQuery.queryOptions({
|
|
1943
1948
|
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1944
1949
|
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
|
-
}
|
|
1950
|
+
return sdk.getHiveEngineTokensMarket(account, symbol);
|
|
1971
1951
|
}
|
|
1972
1952
|
});
|
|
1973
1953
|
}
|
|
@@ -2073,48 +2053,10 @@ function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allToke
|
|
|
2073
2053
|
if (!account) {
|
|
2074
2054
|
throw new Error("[HiveEngine] No account in a balances query");
|
|
2075
2055
|
}
|
|
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
|
-
}
|
|
2094
|
-
);
|
|
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
|
-
}
|
|
2056
|
+
const balances = await sdk.getHiveEngineTokensBalances(account);
|
|
2057
|
+
const tokens = await sdk.getHiveEngineTokensMetadata(
|
|
2058
|
+
balances.map((t) => t.symbol)
|
|
2115
2059
|
);
|
|
2116
|
-
const tokensData = await tokensResponse.json();
|
|
2117
|
-
const tokens = tokensData.result || [];
|
|
2118
2060
|
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2119
2061
|
const metrics = Array.isArray(
|
|
2120
2062
|
allTokens
|
|
@@ -2159,27 +2101,7 @@ function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
|
2159
2101
|
staleTime: 6e4,
|
|
2160
2102
|
refetchInterval: 9e4,
|
|
2161
2103
|
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;
|
|
2104
|
+
return sdk.getHiveEngineTokensMetadata(tokens);
|
|
2183
2105
|
}
|
|
2184
2106
|
});
|
|
2185
2107
|
}
|
|
@@ -2189,27 +2111,7 @@ function getHiveEngineTokensBalancesQueryOptions(username) {
|
|
|
2189
2111
|
staleTime: 6e4,
|
|
2190
2112
|
refetchInterval: 9e4,
|
|
2191
2113
|
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;
|
|
2114
|
+
return sdk.getHiveEngineTokensBalances(username);
|
|
2213
2115
|
}
|
|
2214
2116
|
});
|
|
2215
2117
|
}
|
|
@@ -2219,25 +2121,7 @@ function getHiveEngineTokensMarketQueryOptions() {
|
|
|
2219
2121
|
staleTime: 6e4,
|
|
2220
2122
|
refetchInterval: 9e4,
|
|
2221
2123
|
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;
|
|
2124
|
+
return sdk.getHiveEngineTokensMarket();
|
|
2241
2125
|
}
|
|
2242
2126
|
});
|
|
2243
2127
|
}
|
|
@@ -2307,18 +2191,12 @@ function getHiveEngineTokenTransactionsQueryOptions(username, symbol, limit = 20
|
|
|
2307
2191
|
"[SDK][Wallets] \u2013 hive engine token or username missed"
|
|
2308
2192
|
);
|
|
2309
2193
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2194
|
+
return sdk.getHiveEngineTokenTransactions(
|
|
2195
|
+
username,
|
|
2196
|
+
symbol,
|
|
2197
|
+
limit,
|
|
2198
|
+
pageParam
|
|
2312
2199
|
);
|
|
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
2200
|
}
|
|
2323
2201
|
});
|
|
2324
2202
|
}
|
|
@@ -2328,15 +2206,7 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2328
2206
|
staleTime: 6e4,
|
|
2329
2207
|
refetchInterval: 9e4,
|
|
2330
2208
|
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();
|
|
2209
|
+
return sdk.getHiveEngineTokenMetrics(symbol, interval);
|
|
2340
2210
|
}
|
|
2341
2211
|
});
|
|
2342
2212
|
}
|
|
@@ -2348,13 +2218,9 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2348
2218
|
enabled: !!username,
|
|
2349
2219
|
queryFn: async () => {
|
|
2350
2220
|
try {
|
|
2351
|
-
const
|
|
2352
|
-
|
|
2221
|
+
const data = await sdk.getHiveEngineUnclaimedRewards(
|
|
2222
|
+
username
|
|
2353
2223
|
);
|
|
2354
|
-
if (!response.ok) {
|
|
2355
|
-
return [];
|
|
2356
|
-
}
|
|
2357
|
-
const data = await response.json();
|
|
2358
2224
|
return Object.values(data).filter(
|
|
2359
2225
|
({ pending_token }) => pending_token > 0
|
|
2360
2226
|
);
|
|
@@ -2364,7 +2230,25 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2364
2230
|
}
|
|
2365
2231
|
});
|
|
2366
2232
|
}
|
|
2367
|
-
|
|
2233
|
+
|
|
2234
|
+
// src/modules/assets/hive-engine/mutations/broadcast-hive-engine-operation.ts
|
|
2235
|
+
async function broadcastHiveEngineOperation(payload, operation, auth) {
|
|
2236
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2237
|
+
if (auth?.broadcast) {
|
|
2238
|
+
return auth.broadcast([operation], "active");
|
|
2239
|
+
}
|
|
2240
|
+
if (payload.type === "hiveauth") {
|
|
2241
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2242
|
+
}
|
|
2243
|
+
if (payload.type === "keychain") {
|
|
2244
|
+
throw new Error("[SDK][Wallets] \u2013 keychain requires auth.broadcast");
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
// src/modules/assets/hive-engine/mutations/delegate.ts
|
|
2251
|
+
async function delegateEngineToken(payload, auth) {
|
|
2368
2252
|
const parsedAsset = parseAsset(payload.amount);
|
|
2369
2253
|
const quantity = parsedAsset.amount.toString();
|
|
2370
2254
|
const operation = [
|
|
@@ -2401,24 +2285,8 @@ async function delegateEngineToken(payload) {
|
|
|
2401
2285
|
required_posting_auths: []
|
|
2402
2286
|
};
|
|
2403
2287
|
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");
|
|
2288
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2289
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2422
2290
|
} else {
|
|
2423
2291
|
return hs__default.default.sendOperation(
|
|
2424
2292
|
operation,
|
|
@@ -2428,7 +2296,7 @@ async function delegateEngineToken(payload) {
|
|
|
2428
2296
|
);
|
|
2429
2297
|
}
|
|
2430
2298
|
}
|
|
2431
|
-
async function undelegateEngineToken(payload) {
|
|
2299
|
+
async function undelegateEngineToken(payload, auth) {
|
|
2432
2300
|
const parsedAsset = parseAsset(payload.amount);
|
|
2433
2301
|
const quantity = parsedAsset.amount.toString();
|
|
2434
2302
|
const operation = [
|
|
@@ -2465,24 +2333,8 @@ async function undelegateEngineToken(payload) {
|
|
|
2465
2333
|
required_posting_auths: []
|
|
2466
2334
|
};
|
|
2467
2335
|
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");
|
|
2336
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2337
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2486
2338
|
} else {
|
|
2487
2339
|
return hs__default.default.sendOperation(
|
|
2488
2340
|
operation,
|
|
@@ -2492,7 +2344,7 @@ async function undelegateEngineToken(payload) {
|
|
|
2492
2344
|
);
|
|
2493
2345
|
}
|
|
2494
2346
|
}
|
|
2495
|
-
async function stakeEngineToken(payload) {
|
|
2347
|
+
async function stakeEngineToken(payload, auth) {
|
|
2496
2348
|
const parsedAsset = parseAsset(payload.amount);
|
|
2497
2349
|
const quantity = parsedAsset.amount.toString();
|
|
2498
2350
|
const operation = [
|
|
@@ -2529,24 +2381,8 @@ async function stakeEngineToken(payload) {
|
|
|
2529
2381
|
required_posting_auths: []
|
|
2530
2382
|
};
|
|
2531
2383
|
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");
|
|
2384
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2385
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2550
2386
|
} else {
|
|
2551
2387
|
return hs__default.default.sendOperation(
|
|
2552
2388
|
operation,
|
|
@@ -2556,7 +2392,7 @@ async function stakeEngineToken(payload) {
|
|
|
2556
2392
|
);
|
|
2557
2393
|
}
|
|
2558
2394
|
}
|
|
2559
|
-
async function unstakeEngineToken(payload) {
|
|
2395
|
+
async function unstakeEngineToken(payload, auth) {
|
|
2560
2396
|
const parsedAsset = parseAsset(payload.amount);
|
|
2561
2397
|
const quantity = parsedAsset.amount.toString();
|
|
2562
2398
|
const operation = [
|
|
@@ -2593,24 +2429,8 @@ async function unstakeEngineToken(payload) {
|
|
|
2593
2429
|
required_posting_auths: []
|
|
2594
2430
|
};
|
|
2595
2431
|
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");
|
|
2432
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2433
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2614
2434
|
} else {
|
|
2615
2435
|
return hs__default.default.sendOperation(
|
|
2616
2436
|
operation,
|
|
@@ -2620,7 +2440,7 @@ async function unstakeEngineToken(payload) {
|
|
|
2620
2440
|
);
|
|
2621
2441
|
}
|
|
2622
2442
|
}
|
|
2623
|
-
async function transferEngineToken(payload) {
|
|
2443
|
+
async function transferEngineToken(payload, auth) {
|
|
2624
2444
|
const parsedAsset = parseAsset(payload.amount);
|
|
2625
2445
|
const quantity = parsedAsset.amount.toString();
|
|
2626
2446
|
const operation = [
|
|
@@ -2659,24 +2479,8 @@ async function transferEngineToken(payload) {
|
|
|
2659
2479
|
required_posting_auths: []
|
|
2660
2480
|
};
|
|
2661
2481
|
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");
|
|
2482
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2483
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2680
2484
|
} else {
|
|
2681
2485
|
return hs__default.default.sendOperation(
|
|
2682
2486
|
operation,
|
|
@@ -2686,6 +2490,105 @@ async function transferEngineToken(payload) {
|
|
|
2686
2490
|
);
|
|
2687
2491
|
}
|
|
2688
2492
|
}
|
|
2493
|
+
var ENGINE_CONTRACT_ID = "ssc-mainnet-hive";
|
|
2494
|
+
function buildEngineOrderPayload(action, symbol, quantity, price) {
|
|
2495
|
+
return {
|
|
2496
|
+
contractName: "market",
|
|
2497
|
+
contractAction: action,
|
|
2498
|
+
contractPayload: { symbol, quantity, price }
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
function buildEngineCancelPayload(type, orderId) {
|
|
2502
|
+
return {
|
|
2503
|
+
contractName: "market",
|
|
2504
|
+
contractAction: "cancel",
|
|
2505
|
+
contractPayload: { type, id: orderId }
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2508
|
+
function buildEngineOperation(account, payload) {
|
|
2509
|
+
return {
|
|
2510
|
+
id: ENGINE_CONTRACT_ID,
|
|
2511
|
+
required_auths: [account],
|
|
2512
|
+
required_posting_auths: [],
|
|
2513
|
+
json: JSON.stringify(payload)
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2516
|
+
async function broadcastEngineOperation(account, payload, options2) {
|
|
2517
|
+
const operation = buildEngineOperation(account, payload);
|
|
2518
|
+
const opTuple = ["custom_json", operation];
|
|
2519
|
+
switch (options2?.method) {
|
|
2520
|
+
case "key": {
|
|
2521
|
+
if (!options2.key) {
|
|
2522
|
+
throw new Error("[SDK][Wallets] \u2013 active key is required");
|
|
2523
|
+
}
|
|
2524
|
+
return sdk.CONFIG.hiveClient.broadcast.json(operation, options2.key);
|
|
2525
|
+
}
|
|
2526
|
+
case "keychain":
|
|
2527
|
+
case "hiveauth": {
|
|
2528
|
+
if (options2.auth?.broadcast) {
|
|
2529
|
+
return options2.auth.broadcast([opTuple], "active");
|
|
2530
|
+
}
|
|
2531
|
+
if (options2.method === "hiveauth") {
|
|
2532
|
+
return broadcastWithWalletHiveAuth(account, [opTuple], "active");
|
|
2533
|
+
}
|
|
2534
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2535
|
+
}
|
|
2536
|
+
case "hivesigner":
|
|
2537
|
+
return hs__default.default.sendOperation(
|
|
2538
|
+
opTuple,
|
|
2539
|
+
{ callback: `https://ecency.com/@${account}/wallet/engine` },
|
|
2540
|
+
() => {
|
|
2541
|
+
}
|
|
2542
|
+
);
|
|
2543
|
+
default:
|
|
2544
|
+
throw new Error("[SDK][Wallets] \u2013 broadcast method is required");
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
var placeHiveEngineBuyOrder = async (account, symbol, quantity, price, options2) => broadcastEngineOperation(
|
|
2548
|
+
account,
|
|
2549
|
+
buildEngineOrderPayload("buy", symbol, quantity, price),
|
|
2550
|
+
options2
|
|
2551
|
+
);
|
|
2552
|
+
var placeHiveEngineSellOrder = async (account, symbol, quantity, price, options2) => broadcastEngineOperation(
|
|
2553
|
+
account,
|
|
2554
|
+
buildEngineOrderPayload("sell", symbol, quantity, price),
|
|
2555
|
+
options2
|
|
2556
|
+
);
|
|
2557
|
+
var cancelHiveEngineOrder = async (account, type, orderId, options2) => broadcastEngineOperation(
|
|
2558
|
+
account,
|
|
2559
|
+
buildEngineCancelPayload(type, orderId),
|
|
2560
|
+
options2
|
|
2561
|
+
);
|
|
2562
|
+
async function claimHiveEngineRewards(payload, auth) {
|
|
2563
|
+
const json = JSON.stringify(payload.tokens.map((symbol) => ({ symbol })));
|
|
2564
|
+
const operation = [
|
|
2565
|
+
"custom_json",
|
|
2566
|
+
{
|
|
2567
|
+
id: "scot_claim_token",
|
|
2568
|
+
required_auths: [],
|
|
2569
|
+
required_posting_auths: [payload.account],
|
|
2570
|
+
json
|
|
2571
|
+
}
|
|
2572
|
+
];
|
|
2573
|
+
if (payload.type === "key" && "key" in payload) {
|
|
2574
|
+
return sdk.CONFIG.hiveClient.broadcast.sendOperations([operation], payload.key);
|
|
2575
|
+
}
|
|
2576
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2577
|
+
if (auth?.broadcast) {
|
|
2578
|
+
return auth.broadcast([operation], "posting");
|
|
2579
|
+
}
|
|
2580
|
+
if (payload.type === "hiveauth") {
|
|
2581
|
+
return broadcastWithWalletHiveAuth(payload.account, [operation], "posting");
|
|
2582
|
+
}
|
|
2583
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2584
|
+
}
|
|
2585
|
+
return hs__default.default.sendOperation(
|
|
2586
|
+
operation,
|
|
2587
|
+
{ callback: `https://ecency.com/@${payload.account}/wallet/engine` },
|
|
2588
|
+
() => {
|
|
2589
|
+
}
|
|
2590
|
+
);
|
|
2591
|
+
}
|
|
2689
2592
|
function getPointsQueryOptions(username) {
|
|
2690
2593
|
return reactQuery.queryOptions({
|
|
2691
2594
|
queryKey: ["assets", "points", username],
|
|
@@ -2773,7 +2676,7 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2773
2676
|
}
|
|
2774
2677
|
|
|
2775
2678
|
// src/modules/assets/points/mutations/claim-points.ts
|
|
2776
|
-
function useClaimPoints(username, onSuccess, onError) {
|
|
2679
|
+
function useClaimPoints(username, accessToken, onSuccess, onError) {
|
|
2777
2680
|
const { mutateAsync: recordActivity } = sdk.EcencyAnalytics.useRecordActivity(
|
|
2778
2681
|
username,
|
|
2779
2682
|
"points-claimed"
|
|
@@ -2783,16 +2686,31 @@ function useClaimPoints(username, onSuccess, onError) {
|
|
|
2783
2686
|
mutationFn: async () => {
|
|
2784
2687
|
if (!username) {
|
|
2785
2688
|
throw new Error(
|
|
2786
|
-
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn
|
|
2689
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn't provided"
|
|
2787
2690
|
);
|
|
2788
2691
|
}
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2692
|
+
if (!accessToken) {
|
|
2693
|
+
throw new Error(
|
|
2694
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 access token wasn't found"
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
const response = await fetchApi(
|
|
2698
|
+
sdk.CONFIG.privateApiHost + "/private-api/points-claim",
|
|
2699
|
+
{
|
|
2700
|
+
method: "POST",
|
|
2701
|
+
headers: {
|
|
2702
|
+
"Content-Type": "application/json"
|
|
2703
|
+
},
|
|
2704
|
+
body: JSON.stringify({ code: accessToken })
|
|
2705
|
+
}
|
|
2706
|
+
);
|
|
2707
|
+
if (!response.ok) {
|
|
2708
|
+
const body = await response.text();
|
|
2709
|
+
throw new Error(
|
|
2710
|
+
`[SDK][Wallets][Assets][Points][Claim] \u2013 failed with status ${response.status}${body ? `: ${body}` : ""}`
|
|
2711
|
+
);
|
|
2712
|
+
}
|
|
2713
|
+
return response.json();
|
|
2796
2714
|
},
|
|
2797
2715
|
onError,
|
|
2798
2716
|
onSuccess: () => {
|
|
@@ -2820,7 +2738,7 @@ async function transferPoint({
|
|
|
2820
2738
|
memo,
|
|
2821
2739
|
type,
|
|
2822
2740
|
...payload
|
|
2823
|
-
}) {
|
|
2741
|
+
}, auth) {
|
|
2824
2742
|
const op = [
|
|
2825
2743
|
"custom_json",
|
|
2826
2744
|
{
|
|
@@ -2839,11 +2757,14 @@ async function transferPoint({
|
|
|
2839
2757
|
const { key } = payload;
|
|
2840
2758
|
return sdk.CONFIG.hiveClient.broadcast.sendOperations([op], key);
|
|
2841
2759
|
}
|
|
2842
|
-
if (type === "keychain") {
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2760
|
+
if (type === "keychain" || type === "hiveauth") {
|
|
2761
|
+
if (auth?.broadcast) {
|
|
2762
|
+
return auth.broadcast([op], "active");
|
|
2763
|
+
}
|
|
2764
|
+
if (type === "hiveauth") {
|
|
2765
|
+
return broadcastWithWalletHiveAuth(from, [op], "active");
|
|
2766
|
+
}
|
|
2767
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2847
2768
|
}
|
|
2848
2769
|
return hs__default.default.sendOperation(op, { callback: `https://ecency.com/@${from}/wallet` }, () => {
|
|
2849
2770
|
});
|
|
@@ -4067,7 +3988,7 @@ function useCheckWalletExistence() {
|
|
|
4067
3988
|
}
|
|
4068
3989
|
});
|
|
4069
3990
|
}
|
|
4070
|
-
function useUpdateAccountWithWallets(username) {
|
|
3991
|
+
function useUpdateAccountWithWallets(username, accessToken) {
|
|
4071
3992
|
const fetchApi = getBoundFetch();
|
|
4072
3993
|
return reactQuery.useMutation({
|
|
4073
3994
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
|
|
@@ -4077,6 +3998,11 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4077
3998
|
return new Response(null, { status: 204 });
|
|
4078
3999
|
}
|
|
4079
4000
|
const [primaryToken, primaryAddress] = entries[0] ?? ["", ""];
|
|
4001
|
+
if (!accessToken) {
|
|
4002
|
+
throw new Error(
|
|
4003
|
+
"[SDK][Wallets][PrivateApi][WalletsAdd] \u2013 access token wasn`t found"
|
|
4004
|
+
);
|
|
4005
|
+
}
|
|
4080
4006
|
return fetchApi(sdk.CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
4081
4007
|
method: "POST",
|
|
4082
4008
|
headers: {
|
|
@@ -4084,7 +4010,7 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4084
4010
|
},
|
|
4085
4011
|
body: JSON.stringify({
|
|
4086
4012
|
username,
|
|
4087
|
-
code:
|
|
4013
|
+
code: accessToken,
|
|
4088
4014
|
token: primaryToken,
|
|
4089
4015
|
address: primaryAddress,
|
|
4090
4016
|
status: 3,
|
|
@@ -4218,14 +4144,10 @@ function getGroupedChainTokens(tokens, defaultShow) {
|
|
|
4218
4144
|
)
|
|
4219
4145
|
);
|
|
4220
4146
|
}
|
|
4221
|
-
function useSaveWalletInformationToMetadata(username,
|
|
4147
|
+
function useSaveWalletInformationToMetadata(username, auth, options2) {
|
|
4222
4148
|
const queryClient = reactQuery.useQueryClient();
|
|
4223
4149
|
const { data: accountData } = reactQuery.useQuery(sdk.getAccountFullQueryOptions(username));
|
|
4224
|
-
const { mutateAsync: updateProfile } = sdk.useAccountUpdate(
|
|
4225
|
-
username,
|
|
4226
|
-
accessToken,
|
|
4227
|
-
auth
|
|
4228
|
-
);
|
|
4150
|
+
const { mutateAsync: updateProfile } = sdk.useAccountUpdate(username, auth);
|
|
4229
4151
|
return reactQuery.useMutation({
|
|
4230
4152
|
mutationKey: [
|
|
4231
4153
|
"ecency-wallets",
|
|
@@ -4307,7 +4229,7 @@ var engineOperationToFunctionMap = {
|
|
|
4307
4229
|
["delegate" /* Delegate */]: delegateEngineToken,
|
|
4308
4230
|
["undelegate" /* Undelegate */]: undelegateEngineToken
|
|
4309
4231
|
};
|
|
4310
|
-
function useWalletOperation(username, asset, operation) {
|
|
4232
|
+
function useWalletOperation(username, asset, operation, auth) {
|
|
4311
4233
|
const { mutateAsync: recordActivity } = sdk.EcencyAnalytics.useRecordActivity(
|
|
4312
4234
|
username,
|
|
4313
4235
|
operation
|
|
@@ -4317,17 +4239,18 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4317
4239
|
mutationFn: async (payload) => {
|
|
4318
4240
|
const operationFn = operationToFunctionMap[asset]?.[operation];
|
|
4319
4241
|
if (operationFn) {
|
|
4320
|
-
return operationFn(payload);
|
|
4242
|
+
return operationFn(payload, auth);
|
|
4321
4243
|
}
|
|
4322
4244
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
4323
4245
|
await sdk.getQueryClient().prefetchQuery(balancesListQuery);
|
|
4324
4246
|
const balances = sdk.getQueryClient().getQueryData(
|
|
4325
4247
|
balancesListQuery.queryKey
|
|
4326
4248
|
);
|
|
4327
|
-
|
|
4249
|
+
const engineBalances = balances ?? [];
|
|
4250
|
+
if (engineBalances.some((balance) => balance.symbol === asset)) {
|
|
4328
4251
|
const operationFn2 = engineOperationToFunctionMap[operation];
|
|
4329
4252
|
if (operationFn2) {
|
|
4330
|
-
return operationFn2({ ...payload, asset });
|
|
4253
|
+
return operationFn2({ ...payload, asset }, auth);
|
|
4331
4254
|
}
|
|
4332
4255
|
}
|
|
4333
4256
|
throw new Error("[SDK][Wallets] \u2013 no operation for given asset");
|
|
@@ -4364,6 +4287,22 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4364
4287
|
// src/index.ts
|
|
4365
4288
|
rememberScryptBsvVersion();
|
|
4366
4289
|
|
|
4290
|
+
Object.defineProperty(exports, "getHiveEngineMetrics", {
|
|
4291
|
+
enumerable: true,
|
|
4292
|
+
get: function () { return sdk.getHiveEngineMetrics; }
|
|
4293
|
+
});
|
|
4294
|
+
Object.defineProperty(exports, "getHiveEngineOpenOrders", {
|
|
4295
|
+
enumerable: true,
|
|
4296
|
+
get: function () { return sdk.getHiveEngineOpenOrders; }
|
|
4297
|
+
});
|
|
4298
|
+
Object.defineProperty(exports, "getHiveEngineOrderBook", {
|
|
4299
|
+
enumerable: true,
|
|
4300
|
+
get: function () { return sdk.getHiveEngineOrderBook; }
|
|
4301
|
+
});
|
|
4302
|
+
Object.defineProperty(exports, "getHiveEngineTradeHistory", {
|
|
4303
|
+
enumerable: true,
|
|
4304
|
+
get: function () { return sdk.getHiveEngineTradeHistory; }
|
|
4305
|
+
});
|
|
4367
4306
|
exports.AssetOperation = AssetOperation;
|
|
4368
4307
|
exports.EcencyWalletBasicTokens = EcencyWalletBasicTokens;
|
|
4369
4308
|
exports.EcencyWalletCurrency = EcencyWalletCurrency;
|
|
@@ -4384,6 +4323,8 @@ exports.buildPsbt = buildPsbt;
|
|
|
4384
4323
|
exports.buildSolTx = buildSolTx;
|
|
4385
4324
|
exports.buildTonTx = buildTonTx;
|
|
4386
4325
|
exports.buildTronTx = buildTronTx;
|
|
4326
|
+
exports.cancelHiveEngineOrder = cancelHiveEngineOrder;
|
|
4327
|
+
exports.claimHiveEngineRewards = claimHiveEngineRewards;
|
|
4387
4328
|
exports.claimInterestHive = claimInterestHive;
|
|
4388
4329
|
exports.decryptMemoWithAccounts = decryptMemoWithAccounts;
|
|
4389
4330
|
exports.decryptMemoWithKeys = decryptMemoWithKeys;
|
|
@@ -4438,6 +4379,8 @@ exports.isEmptyDate = isEmptyDate;
|
|
|
4438
4379
|
exports.lockLarynx = lockLarynx;
|
|
4439
4380
|
exports.mnemonicToSeedBip39 = mnemonicToSeedBip39;
|
|
4440
4381
|
exports.parseAsset = parseAsset;
|
|
4382
|
+
exports.placeHiveEngineBuyOrder = placeHiveEngineBuyOrder;
|
|
4383
|
+
exports.placeHiveEngineSellOrder = placeHiveEngineSellOrder;
|
|
4441
4384
|
exports.powerDownHive = powerDownHive;
|
|
4442
4385
|
exports.powerUpHive = powerUpHive;
|
|
4443
4386
|
exports.powerUpLarynx = powerUpLarynx;
|