@ecency/wallets 1.5.1 → 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 -25
- package/dist/browser/index.js +313 -384
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +330 -382
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +313 -384
- 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,18 +1455,20 @@ 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, onSuccess) {
|
|
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(
|
|
@@ -1495,10 +1504,11 @@ function useClaimRewards(username, onSuccess) {
|
|
|
1495
1504
|
queryClient.invalidateQueries({
|
|
1496
1505
|
queryKey: getHivePowerAssetGeneralInfoQueryOptions(username).queryKey
|
|
1497
1506
|
});
|
|
1498
|
-
}
|
|
1507
|
+
},
|
|
1508
|
+
auth
|
|
1499
1509
|
);
|
|
1500
1510
|
}
|
|
1501
|
-
async function claimInterestHive(payload) {
|
|
1511
|
+
async function claimInterestHive(payload, auth) {
|
|
1502
1512
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1503
1513
|
const baseOperation = {
|
|
1504
1514
|
from: payload.from,
|
|
@@ -1519,11 +1529,14 @@ async function claimInterestHive(payload) {
|
|
|
1519
1529
|
const { key } = payload;
|
|
1520
1530
|
return sdk.CONFIG.hiveClient.broadcast.sendOperations(operations, key);
|
|
1521
1531
|
}
|
|
1522
|
-
if (payload.type === "keychain") {
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
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");
|
|
1527
1540
|
}
|
|
1528
1541
|
return hs__default.default.sendOperations(operations, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1529
1542
|
});
|
|
@@ -1550,7 +1563,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1550
1563
|
AssetOperation2["Undelegate"] = "undelegate";
|
|
1551
1564
|
return AssetOperation2;
|
|
1552
1565
|
})(AssetOperation || {});
|
|
1553
|
-
async function transferSpk(payload) {
|
|
1566
|
+
async function transferSpk(payload, auth) {
|
|
1554
1567
|
const json = JSON.stringify({
|
|
1555
1568
|
to: payload.to,
|
|
1556
1569
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1574,16 +1587,14 @@ async function transferSpk(payload) {
|
|
|
1574
1587
|
if (payload.type === "key" && "key" in payload) {
|
|
1575
1588
|
const { key } = payload;
|
|
1576
1589
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1577
|
-
} else if (payload.type === "keychain") {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
);
|
|
1585
|
-
} else if (payload.type === "hiveauth") {
|
|
1586
|
-
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");
|
|
1587
1598
|
} else {
|
|
1588
1599
|
const { amount } = parseAsset(payload.amount);
|
|
1589
1600
|
return hs__default.default.sign(
|
|
@@ -1603,7 +1614,7 @@ async function transferSpk(payload) {
|
|
|
1603
1614
|
);
|
|
1604
1615
|
}
|
|
1605
1616
|
}
|
|
1606
|
-
var lockLarynx = async (payload) => {
|
|
1617
|
+
var lockLarynx = async (payload, auth) => {
|
|
1607
1618
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1608
1619
|
const op = {
|
|
1609
1620
|
id: payload.mode === "lock" ? "spkcc_gov_up" : "spkcc_gov_down",
|
|
@@ -1623,16 +1634,14 @@ var lockLarynx = async (payload) => {
|
|
|
1623
1634
|
if (payload.type === "key" && "key" in payload) {
|
|
1624
1635
|
const { key } = payload;
|
|
1625
1636
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1626
|
-
} else if (payload.type === "keychain") {
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
);
|
|
1634
|
-
} else if (payload.type === "hiveauth") {
|
|
1635
|
-
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");
|
|
1636
1645
|
} else {
|
|
1637
1646
|
const { amount } = parseAsset(payload.amount);
|
|
1638
1647
|
return hs__default.default.sign(
|
|
@@ -1648,7 +1657,7 @@ var lockLarynx = async (payload) => {
|
|
|
1648
1657
|
);
|
|
1649
1658
|
}
|
|
1650
1659
|
};
|
|
1651
|
-
async function powerUpLarynx(payload) {
|
|
1660
|
+
async function powerUpLarynx(payload, auth) {
|
|
1652
1661
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1653
1662
|
const op = {
|
|
1654
1663
|
id: `spkcc_power_${payload.mode}`,
|
|
@@ -1668,16 +1677,14 @@ async function powerUpLarynx(payload) {
|
|
|
1668
1677
|
if (payload.type === "key" && "key" in payload) {
|
|
1669
1678
|
const { key } = payload;
|
|
1670
1679
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1671
|
-
} else if (payload.type === "keychain") {
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
);
|
|
1679
|
-
} else if (payload.type === "hiveauth") {
|
|
1680
|
-
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");
|
|
1681
1688
|
} else {
|
|
1682
1689
|
const { amount } = parseAsset(payload.amount);
|
|
1683
1690
|
return hs__default.default.sign(
|
|
@@ -1693,7 +1700,7 @@ async function powerUpLarynx(payload) {
|
|
|
1693
1700
|
);
|
|
1694
1701
|
}
|
|
1695
1702
|
}
|
|
1696
|
-
async function transferLarynx(payload) {
|
|
1703
|
+
async function transferLarynx(payload, auth) {
|
|
1697
1704
|
const json = JSON.stringify({
|
|
1698
1705
|
to: payload.to,
|
|
1699
1706
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1717,16 +1724,14 @@ async function transferLarynx(payload) {
|
|
|
1717
1724
|
if (payload.type === "key" && "key" in payload) {
|
|
1718
1725
|
const { key } = payload;
|
|
1719
1726
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
1720
|
-
} else if (payload.type === "keychain") {
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
);
|
|
1728
|
-
} else if (payload.type === "hiveauth") {
|
|
1729
|
-
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");
|
|
1730
1735
|
} else {
|
|
1731
1736
|
const { amount } = parseAsset(payload.amount);
|
|
1732
1737
|
return hs__default.default.sign(
|
|
@@ -1752,8 +1757,7 @@ function getSpkMarketsQueryOptions() {
|
|
|
1752
1757
|
staleTime: 6e4,
|
|
1753
1758
|
refetchInterval: 9e4,
|
|
1754
1759
|
queryFn: async () => {
|
|
1755
|
-
const
|
|
1756
|
-
const data = await response.json();
|
|
1760
|
+
const data = await sdk.getSpkMarkets();
|
|
1757
1761
|
return {
|
|
1758
1762
|
list: Object.entries(data.markets.node).map(([name, node]) => ({
|
|
1759
1763
|
name,
|
|
@@ -1768,8 +1772,10 @@ function getSpkWalletQueryOptions(username) {
|
|
|
1768
1772
|
return reactQuery.queryOptions({
|
|
1769
1773
|
queryKey: ["assets", "spk", "wallet", username],
|
|
1770
1774
|
queryFn: async () => {
|
|
1771
|
-
|
|
1772
|
-
|
|
1775
|
+
if (!username) {
|
|
1776
|
+
throw new Error("[SDK][Wallets][SPK] \u2013 username wasn't provided");
|
|
1777
|
+
}
|
|
1778
|
+
return sdk.getSpkWallet(username);
|
|
1773
1779
|
},
|
|
1774
1780
|
enabled: !!username,
|
|
1775
1781
|
staleTime: 6e4,
|
|
@@ -1941,32 +1947,7 @@ function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
|
1941
1947
|
return reactQuery.queryOptions({
|
|
1942
1948
|
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1943
1949
|
queryFn: async () => {
|
|
1944
|
-
|
|
1945
|
-
const response = await fetch(
|
|
1946
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1947
|
-
{
|
|
1948
|
-
method: "POST",
|
|
1949
|
-
body: JSON.stringify({
|
|
1950
|
-
jsonrpc: "2.0",
|
|
1951
|
-
method: "find",
|
|
1952
|
-
params: {
|
|
1953
|
-
contract: "market",
|
|
1954
|
-
table: "metrics",
|
|
1955
|
-
query: {
|
|
1956
|
-
...symbol && { symbol },
|
|
1957
|
-
...account && { account }
|
|
1958
|
-
}
|
|
1959
|
-
},
|
|
1960
|
-
id: 1
|
|
1961
|
-
}),
|
|
1962
|
-
headers: { "Content-type": "application/json" }
|
|
1963
|
-
}
|
|
1964
|
-
);
|
|
1965
|
-
const data = await response.json();
|
|
1966
|
-
return data.result;
|
|
1967
|
-
} catch (e) {
|
|
1968
|
-
return [];
|
|
1969
|
-
}
|
|
1950
|
+
return sdk.getHiveEngineTokensMarket(account, symbol);
|
|
1970
1951
|
}
|
|
1971
1952
|
});
|
|
1972
1953
|
}
|
|
@@ -2072,48 +2053,10 @@ function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allToke
|
|
|
2072
2053
|
if (!account) {
|
|
2073
2054
|
throw new Error("[HiveEngine] No account in a balances query");
|
|
2074
2055
|
}
|
|
2075
|
-
const
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
method: "POST",
|
|
2079
|
-
body: JSON.stringify({
|
|
2080
|
-
jsonrpc: "2.0",
|
|
2081
|
-
method: "find",
|
|
2082
|
-
params: {
|
|
2083
|
-
contract: "tokens",
|
|
2084
|
-
table: "balances",
|
|
2085
|
-
query: {
|
|
2086
|
-
account
|
|
2087
|
-
}
|
|
2088
|
-
},
|
|
2089
|
-
id: 1
|
|
2090
|
-
}),
|
|
2091
|
-
headers: { "Content-type": "application/json" }
|
|
2092
|
-
}
|
|
2093
|
-
);
|
|
2094
|
-
const balancesData = await balancesResponse.json();
|
|
2095
|
-
const balances = balancesData.result || [];
|
|
2096
|
-
const tokensResponse = await fetch(
|
|
2097
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2098
|
-
{
|
|
2099
|
-
method: "POST",
|
|
2100
|
-
body: JSON.stringify({
|
|
2101
|
-
jsonrpc: "2.0",
|
|
2102
|
-
method: "find",
|
|
2103
|
-
params: {
|
|
2104
|
-
contract: "tokens",
|
|
2105
|
-
table: "tokens",
|
|
2106
|
-
query: {
|
|
2107
|
-
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2108
|
-
}
|
|
2109
|
-
},
|
|
2110
|
-
id: 2
|
|
2111
|
-
}),
|
|
2112
|
-
headers: { "Content-type": "application/json" }
|
|
2113
|
-
}
|
|
2056
|
+
const balances = await sdk.getHiveEngineTokensBalances(account);
|
|
2057
|
+
const tokens = await sdk.getHiveEngineTokensMetadata(
|
|
2058
|
+
balances.map((t) => t.symbol)
|
|
2114
2059
|
);
|
|
2115
|
-
const tokensData = await tokensResponse.json();
|
|
2116
|
-
const tokens = tokensData.result || [];
|
|
2117
2060
|
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2118
2061
|
const metrics = Array.isArray(
|
|
2119
2062
|
allTokens
|
|
@@ -2158,27 +2101,7 @@ function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
|
2158
2101
|
staleTime: 6e4,
|
|
2159
2102
|
refetchInterval: 9e4,
|
|
2160
2103
|
queryFn: async () => {
|
|
2161
|
-
|
|
2162
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2163
|
-
{
|
|
2164
|
-
method: "POST",
|
|
2165
|
-
body: JSON.stringify({
|
|
2166
|
-
jsonrpc: "2.0",
|
|
2167
|
-
method: "find",
|
|
2168
|
-
params: {
|
|
2169
|
-
contract: "tokens",
|
|
2170
|
-
table: "tokens",
|
|
2171
|
-
query: {
|
|
2172
|
-
symbol: { $in: tokens }
|
|
2173
|
-
}
|
|
2174
|
-
},
|
|
2175
|
-
id: 2
|
|
2176
|
-
}),
|
|
2177
|
-
headers: { "Content-type": "application/json" }
|
|
2178
|
-
}
|
|
2179
|
-
);
|
|
2180
|
-
const data = await response.json();
|
|
2181
|
-
return data.result;
|
|
2104
|
+
return sdk.getHiveEngineTokensMetadata(tokens);
|
|
2182
2105
|
}
|
|
2183
2106
|
});
|
|
2184
2107
|
}
|
|
@@ -2188,27 +2111,7 @@ function getHiveEngineTokensBalancesQueryOptions(username) {
|
|
|
2188
2111
|
staleTime: 6e4,
|
|
2189
2112
|
refetchInterval: 9e4,
|
|
2190
2113
|
queryFn: async () => {
|
|
2191
|
-
|
|
2192
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2193
|
-
{
|
|
2194
|
-
method: "POST",
|
|
2195
|
-
body: JSON.stringify({
|
|
2196
|
-
jsonrpc: "2.0",
|
|
2197
|
-
method: "find",
|
|
2198
|
-
params: {
|
|
2199
|
-
contract: "tokens",
|
|
2200
|
-
table: "balances",
|
|
2201
|
-
query: {
|
|
2202
|
-
account: username
|
|
2203
|
-
}
|
|
2204
|
-
},
|
|
2205
|
-
id: 1
|
|
2206
|
-
}),
|
|
2207
|
-
headers: { "Content-type": "application/json" }
|
|
2208
|
-
}
|
|
2209
|
-
);
|
|
2210
|
-
const data = await response.json();
|
|
2211
|
-
return data.result;
|
|
2114
|
+
return sdk.getHiveEngineTokensBalances(username);
|
|
2212
2115
|
}
|
|
2213
2116
|
});
|
|
2214
2117
|
}
|
|
@@ -2218,25 +2121,7 @@ function getHiveEngineTokensMarketQueryOptions() {
|
|
|
2218
2121
|
staleTime: 6e4,
|
|
2219
2122
|
refetchInterval: 9e4,
|
|
2220
2123
|
queryFn: async () => {
|
|
2221
|
-
|
|
2222
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2223
|
-
{
|
|
2224
|
-
method: "POST",
|
|
2225
|
-
body: JSON.stringify({
|
|
2226
|
-
jsonrpc: "2.0",
|
|
2227
|
-
method: "find",
|
|
2228
|
-
params: {
|
|
2229
|
-
contract: "market",
|
|
2230
|
-
table: "metrics",
|
|
2231
|
-
query: {}
|
|
2232
|
-
},
|
|
2233
|
-
id: 1
|
|
2234
|
-
}),
|
|
2235
|
-
headers: { "Content-type": "application/json" }
|
|
2236
|
-
}
|
|
2237
|
-
);
|
|
2238
|
-
const data = await response.json();
|
|
2239
|
-
return data.result;
|
|
2124
|
+
return sdk.getHiveEngineTokensMarket();
|
|
2240
2125
|
}
|
|
2241
2126
|
});
|
|
2242
2127
|
}
|
|
@@ -2306,18 +2191,12 @@ function getHiveEngineTokenTransactionsQueryOptions(username, symbol, limit = 20
|
|
|
2306
2191
|
"[SDK][Wallets] \u2013 hive engine token or username missed"
|
|
2307
2192
|
);
|
|
2308
2193
|
}
|
|
2309
|
-
|
|
2310
|
-
|
|
2194
|
+
return sdk.getHiveEngineTokenTransactions(
|
|
2195
|
+
username,
|
|
2196
|
+
symbol,
|
|
2197
|
+
limit,
|
|
2198
|
+
pageParam
|
|
2311
2199
|
);
|
|
2312
|
-
url.searchParams.set("account", username);
|
|
2313
|
-
url.searchParams.set("symbol", symbol);
|
|
2314
|
-
url.searchParams.set("limit", limit.toString());
|
|
2315
|
-
url.searchParams.set("offset", pageParam.toString());
|
|
2316
|
-
const response = await fetch(url, {
|
|
2317
|
-
method: "GET",
|
|
2318
|
-
headers: { "Content-type": "application/json" }
|
|
2319
|
-
});
|
|
2320
|
-
return await response.json();
|
|
2321
2200
|
}
|
|
2322
2201
|
});
|
|
2323
2202
|
}
|
|
@@ -2327,15 +2206,7 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2327
2206
|
staleTime: 6e4,
|
|
2328
2207
|
refetchInterval: 9e4,
|
|
2329
2208
|
queryFn: async () => {
|
|
2330
|
-
|
|
2331
|
-
`${sdk.CONFIG.privateApiHost}/private-api/engine-chart-api`
|
|
2332
|
-
);
|
|
2333
|
-
url.searchParams.set("symbol", symbol);
|
|
2334
|
-
url.searchParams.set("interval", interval);
|
|
2335
|
-
const response = await fetch(url, {
|
|
2336
|
-
headers: { "Content-type": "application/json" }
|
|
2337
|
-
});
|
|
2338
|
-
return await response.json();
|
|
2209
|
+
return sdk.getHiveEngineTokenMetrics(symbol, interval);
|
|
2339
2210
|
}
|
|
2340
2211
|
});
|
|
2341
2212
|
}
|
|
@@ -2347,13 +2218,9 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2347
2218
|
enabled: !!username,
|
|
2348
2219
|
queryFn: async () => {
|
|
2349
2220
|
try {
|
|
2350
|
-
const
|
|
2351
|
-
|
|
2221
|
+
const data = await sdk.getHiveEngineUnclaimedRewards(
|
|
2222
|
+
username
|
|
2352
2223
|
);
|
|
2353
|
-
if (!response.ok) {
|
|
2354
|
-
return [];
|
|
2355
|
-
}
|
|
2356
|
-
const data = await response.json();
|
|
2357
2224
|
return Object.values(data).filter(
|
|
2358
2225
|
({ pending_token }) => pending_token > 0
|
|
2359
2226
|
);
|
|
@@ -2363,7 +2230,25 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2363
2230
|
}
|
|
2364
2231
|
});
|
|
2365
2232
|
}
|
|
2366
|
-
|
|
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) {
|
|
2367
2252
|
const parsedAsset = parseAsset(payload.amount);
|
|
2368
2253
|
const quantity = parsedAsset.amount.toString();
|
|
2369
2254
|
const operation = [
|
|
@@ -2400,24 +2285,8 @@ async function delegateEngineToken(payload) {
|
|
|
2400
2285
|
required_posting_auths: []
|
|
2401
2286
|
};
|
|
2402
2287
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2403
|
-
} else if (payload.type === "keychain") {
|
|
2404
|
-
return
|
|
2405
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2406
|
-
payload.from,
|
|
2407
|
-
"ssc-mainnet-hive",
|
|
2408
|
-
"Active",
|
|
2409
|
-
operation[1].json,
|
|
2410
|
-
"Token Delegation",
|
|
2411
|
-
(resp) => {
|
|
2412
|
-
if (!resp.success) {
|
|
2413
|
-
reject({ message: "Operation cancelled" });
|
|
2414
|
-
}
|
|
2415
|
-
resolve(resp);
|
|
2416
|
-
}
|
|
2417
|
-
)
|
|
2418
|
-
);
|
|
2419
|
-
} else if (payload.type === "hiveauth") {
|
|
2420
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2288
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2289
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2421
2290
|
} else {
|
|
2422
2291
|
return hs__default.default.sendOperation(
|
|
2423
2292
|
operation,
|
|
@@ -2427,7 +2296,7 @@ async function delegateEngineToken(payload) {
|
|
|
2427
2296
|
);
|
|
2428
2297
|
}
|
|
2429
2298
|
}
|
|
2430
|
-
async function undelegateEngineToken(payload) {
|
|
2299
|
+
async function undelegateEngineToken(payload, auth) {
|
|
2431
2300
|
const parsedAsset = parseAsset(payload.amount);
|
|
2432
2301
|
const quantity = parsedAsset.amount.toString();
|
|
2433
2302
|
const operation = [
|
|
@@ -2464,24 +2333,8 @@ async function undelegateEngineToken(payload) {
|
|
|
2464
2333
|
required_posting_auths: []
|
|
2465
2334
|
};
|
|
2466
2335
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2467
|
-
} else if (payload.type === "keychain") {
|
|
2468
|
-
return
|
|
2469
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2470
|
-
payload.from,
|
|
2471
|
-
"ssc-mainnet-hive",
|
|
2472
|
-
"Active",
|
|
2473
|
-
operation[1].json,
|
|
2474
|
-
"Token Undelegation",
|
|
2475
|
-
(resp) => {
|
|
2476
|
-
if (!resp.success) {
|
|
2477
|
-
reject({ message: "Operation cancelled" });
|
|
2478
|
-
}
|
|
2479
|
-
resolve(resp);
|
|
2480
|
-
}
|
|
2481
|
-
)
|
|
2482
|
-
);
|
|
2483
|
-
} else if (payload.type === "hiveauth") {
|
|
2484
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2336
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2337
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2485
2338
|
} else {
|
|
2486
2339
|
return hs__default.default.sendOperation(
|
|
2487
2340
|
operation,
|
|
@@ -2491,7 +2344,7 @@ async function undelegateEngineToken(payload) {
|
|
|
2491
2344
|
);
|
|
2492
2345
|
}
|
|
2493
2346
|
}
|
|
2494
|
-
async function stakeEngineToken(payload) {
|
|
2347
|
+
async function stakeEngineToken(payload, auth) {
|
|
2495
2348
|
const parsedAsset = parseAsset(payload.amount);
|
|
2496
2349
|
const quantity = parsedAsset.amount.toString();
|
|
2497
2350
|
const operation = [
|
|
@@ -2528,24 +2381,8 @@ async function stakeEngineToken(payload) {
|
|
|
2528
2381
|
required_posting_auths: []
|
|
2529
2382
|
};
|
|
2530
2383
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2531
|
-
} else if (payload.type === "keychain") {
|
|
2532
|
-
return
|
|
2533
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2534
|
-
payload.from,
|
|
2535
|
-
"ssc-mainnet-hive",
|
|
2536
|
-
"Active",
|
|
2537
|
-
operation[1].json,
|
|
2538
|
-
"Token Staking",
|
|
2539
|
-
(resp) => {
|
|
2540
|
-
if (!resp.success) {
|
|
2541
|
-
reject({ message: "Operation cancelled" });
|
|
2542
|
-
}
|
|
2543
|
-
resolve(resp);
|
|
2544
|
-
}
|
|
2545
|
-
)
|
|
2546
|
-
);
|
|
2547
|
-
} else if (payload.type === "hiveauth") {
|
|
2548
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2384
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2385
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2549
2386
|
} else {
|
|
2550
2387
|
return hs__default.default.sendOperation(
|
|
2551
2388
|
operation,
|
|
@@ -2555,7 +2392,7 @@ async function stakeEngineToken(payload) {
|
|
|
2555
2392
|
);
|
|
2556
2393
|
}
|
|
2557
2394
|
}
|
|
2558
|
-
async function unstakeEngineToken(payload) {
|
|
2395
|
+
async function unstakeEngineToken(payload, auth) {
|
|
2559
2396
|
const parsedAsset = parseAsset(payload.amount);
|
|
2560
2397
|
const quantity = parsedAsset.amount.toString();
|
|
2561
2398
|
const operation = [
|
|
@@ -2592,24 +2429,8 @@ async function unstakeEngineToken(payload) {
|
|
|
2592
2429
|
required_posting_auths: []
|
|
2593
2430
|
};
|
|
2594
2431
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2595
|
-
} else if (payload.type === "keychain") {
|
|
2596
|
-
return
|
|
2597
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2598
|
-
payload.from,
|
|
2599
|
-
"ssc-mainnet-hive",
|
|
2600
|
-
"Active",
|
|
2601
|
-
operation[1].json,
|
|
2602
|
-
"Token Unstaking",
|
|
2603
|
-
(resp) => {
|
|
2604
|
-
if (!resp.success) {
|
|
2605
|
-
reject({ message: "Operation cancelled" });
|
|
2606
|
-
}
|
|
2607
|
-
resolve(resp);
|
|
2608
|
-
}
|
|
2609
|
-
)
|
|
2610
|
-
);
|
|
2611
|
-
} else if (payload.type === "hiveauth") {
|
|
2612
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2432
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2433
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2613
2434
|
} else {
|
|
2614
2435
|
return hs__default.default.sendOperation(
|
|
2615
2436
|
operation,
|
|
@@ -2619,7 +2440,7 @@ async function unstakeEngineToken(payload) {
|
|
|
2619
2440
|
);
|
|
2620
2441
|
}
|
|
2621
2442
|
}
|
|
2622
|
-
async function transferEngineToken(payload) {
|
|
2443
|
+
async function transferEngineToken(payload, auth) {
|
|
2623
2444
|
const parsedAsset = parseAsset(payload.amount);
|
|
2624
2445
|
const quantity = parsedAsset.amount.toString();
|
|
2625
2446
|
const operation = [
|
|
@@ -2658,24 +2479,8 @@ async function transferEngineToken(payload) {
|
|
|
2658
2479
|
required_posting_auths: []
|
|
2659
2480
|
};
|
|
2660
2481
|
return sdk.CONFIG.hiveClient.broadcast.json(op, key);
|
|
2661
|
-
} else if (payload.type === "keychain") {
|
|
2662
|
-
return
|
|
2663
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2664
|
-
payload.from,
|
|
2665
|
-
"ssc-mainnet-hive",
|
|
2666
|
-
"Active",
|
|
2667
|
-
operation[1].json,
|
|
2668
|
-
"Token Transfer",
|
|
2669
|
-
(resp) => {
|
|
2670
|
-
if (!resp.success) {
|
|
2671
|
-
reject({ message: "Operation cancelled" });
|
|
2672
|
-
}
|
|
2673
|
-
resolve(resp);
|
|
2674
|
-
}
|
|
2675
|
-
)
|
|
2676
|
-
);
|
|
2677
|
-
} else if (payload.type === "hiveauth") {
|
|
2678
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2482
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2483
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2679
2484
|
} else {
|
|
2680
2485
|
return hs__default.default.sendOperation(
|
|
2681
2486
|
operation,
|
|
@@ -2685,6 +2490,105 @@ async function transferEngineToken(payload) {
|
|
|
2685
2490
|
);
|
|
2686
2491
|
}
|
|
2687
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
|
+
}
|
|
2688
2592
|
function getPointsQueryOptions(username) {
|
|
2689
2593
|
return reactQuery.queryOptions({
|
|
2690
2594
|
queryKey: ["assets", "points", username],
|
|
@@ -2772,7 +2676,7 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2772
2676
|
}
|
|
2773
2677
|
|
|
2774
2678
|
// src/modules/assets/points/mutations/claim-points.ts
|
|
2775
|
-
function useClaimPoints(username, onSuccess, onError) {
|
|
2679
|
+
function useClaimPoints(username, accessToken, onSuccess, onError) {
|
|
2776
2680
|
const { mutateAsync: recordActivity } = sdk.EcencyAnalytics.useRecordActivity(
|
|
2777
2681
|
username,
|
|
2778
2682
|
"points-claimed"
|
|
@@ -2782,16 +2686,31 @@ function useClaimPoints(username, onSuccess, onError) {
|
|
|
2782
2686
|
mutationFn: async () => {
|
|
2783
2687
|
if (!username) {
|
|
2784
2688
|
throw new Error(
|
|
2785
|
-
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn
|
|
2689
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn't provided"
|
|
2786
2690
|
);
|
|
2787
2691
|
}
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
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();
|
|
2795
2714
|
},
|
|
2796
2715
|
onError,
|
|
2797
2716
|
onSuccess: () => {
|
|
@@ -2819,7 +2738,7 @@ async function transferPoint({
|
|
|
2819
2738
|
memo,
|
|
2820
2739
|
type,
|
|
2821
2740
|
...payload
|
|
2822
|
-
}) {
|
|
2741
|
+
}, auth) {
|
|
2823
2742
|
const op = [
|
|
2824
2743
|
"custom_json",
|
|
2825
2744
|
{
|
|
@@ -2838,11 +2757,14 @@ async function transferPoint({
|
|
|
2838
2757
|
const { key } = payload;
|
|
2839
2758
|
return sdk.CONFIG.hiveClient.broadcast.sendOperations([op], key);
|
|
2840
2759
|
}
|
|
2841
|
-
if (type === "keychain") {
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
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");
|
|
2846
2768
|
}
|
|
2847
2769
|
return hs__default.default.sendOperation(op, { callback: `https://ecency.com/@${from}/wallet` }, () => {
|
|
2848
2770
|
});
|
|
@@ -4066,7 +3988,7 @@ function useCheckWalletExistence() {
|
|
|
4066
3988
|
}
|
|
4067
3989
|
});
|
|
4068
3990
|
}
|
|
4069
|
-
function useUpdateAccountWithWallets(username) {
|
|
3991
|
+
function useUpdateAccountWithWallets(username, accessToken) {
|
|
4070
3992
|
const fetchApi = getBoundFetch();
|
|
4071
3993
|
return reactQuery.useMutation({
|
|
4072
3994
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
|
|
@@ -4076,6 +3998,11 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4076
3998
|
return new Response(null, { status: 204 });
|
|
4077
3999
|
}
|
|
4078
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
|
+
}
|
|
4079
4006
|
return fetchApi(sdk.CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
4080
4007
|
method: "POST",
|
|
4081
4008
|
headers: {
|
|
@@ -4083,7 +4010,7 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4083
4010
|
},
|
|
4084
4011
|
body: JSON.stringify({
|
|
4085
4012
|
username,
|
|
4086
|
-
code:
|
|
4013
|
+
code: accessToken,
|
|
4087
4014
|
token: primaryToken,
|
|
4088
4015
|
address: primaryAddress,
|
|
4089
4016
|
status: 3,
|
|
@@ -4217,10 +4144,10 @@ function getGroupedChainTokens(tokens, defaultShow) {
|
|
|
4217
4144
|
)
|
|
4218
4145
|
);
|
|
4219
4146
|
}
|
|
4220
|
-
function useSaveWalletInformationToMetadata(username, options2) {
|
|
4147
|
+
function useSaveWalletInformationToMetadata(username, auth, options2) {
|
|
4221
4148
|
const queryClient = reactQuery.useQueryClient();
|
|
4222
4149
|
const { data: accountData } = reactQuery.useQuery(sdk.getAccountFullQueryOptions(username));
|
|
4223
|
-
const { mutateAsync: updateProfile } = sdk.useAccountUpdate(username);
|
|
4150
|
+
const { mutateAsync: updateProfile } = sdk.useAccountUpdate(username, auth);
|
|
4224
4151
|
return reactQuery.useMutation({
|
|
4225
4152
|
mutationKey: [
|
|
4226
4153
|
"ecency-wallets",
|
|
@@ -4302,7 +4229,7 @@ var engineOperationToFunctionMap = {
|
|
|
4302
4229
|
["delegate" /* Delegate */]: delegateEngineToken,
|
|
4303
4230
|
["undelegate" /* Undelegate */]: undelegateEngineToken
|
|
4304
4231
|
};
|
|
4305
|
-
function useWalletOperation(username, asset, operation) {
|
|
4232
|
+
function useWalletOperation(username, asset, operation, auth) {
|
|
4306
4233
|
const { mutateAsync: recordActivity } = sdk.EcencyAnalytics.useRecordActivity(
|
|
4307
4234
|
username,
|
|
4308
4235
|
operation
|
|
@@ -4312,17 +4239,18 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4312
4239
|
mutationFn: async (payload) => {
|
|
4313
4240
|
const operationFn = operationToFunctionMap[asset]?.[operation];
|
|
4314
4241
|
if (operationFn) {
|
|
4315
|
-
return operationFn(payload);
|
|
4242
|
+
return operationFn(payload, auth);
|
|
4316
4243
|
}
|
|
4317
4244
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
4318
4245
|
await sdk.getQueryClient().prefetchQuery(balancesListQuery);
|
|
4319
4246
|
const balances = sdk.getQueryClient().getQueryData(
|
|
4320
4247
|
balancesListQuery.queryKey
|
|
4321
4248
|
);
|
|
4322
|
-
|
|
4249
|
+
const engineBalances = balances ?? [];
|
|
4250
|
+
if (engineBalances.some((balance) => balance.symbol === asset)) {
|
|
4323
4251
|
const operationFn2 = engineOperationToFunctionMap[operation];
|
|
4324
4252
|
if (operationFn2) {
|
|
4325
|
-
return operationFn2({ ...payload, asset });
|
|
4253
|
+
return operationFn2({ ...payload, asset }, auth);
|
|
4326
4254
|
}
|
|
4327
4255
|
}
|
|
4328
4256
|
throw new Error("[SDK][Wallets] \u2013 no operation for given asset");
|
|
@@ -4359,6 +4287,22 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4359
4287
|
// src/index.ts
|
|
4360
4288
|
rememberScryptBsvVersion();
|
|
4361
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
|
+
});
|
|
4362
4306
|
exports.AssetOperation = AssetOperation;
|
|
4363
4307
|
exports.EcencyWalletBasicTokens = EcencyWalletBasicTokens;
|
|
4364
4308
|
exports.EcencyWalletCurrency = EcencyWalletCurrency;
|
|
@@ -4379,6 +4323,8 @@ exports.buildPsbt = buildPsbt;
|
|
|
4379
4323
|
exports.buildSolTx = buildSolTx;
|
|
4380
4324
|
exports.buildTonTx = buildTonTx;
|
|
4381
4325
|
exports.buildTronTx = buildTronTx;
|
|
4326
|
+
exports.cancelHiveEngineOrder = cancelHiveEngineOrder;
|
|
4327
|
+
exports.claimHiveEngineRewards = claimHiveEngineRewards;
|
|
4382
4328
|
exports.claimInterestHive = claimInterestHive;
|
|
4383
4329
|
exports.decryptMemoWithAccounts = decryptMemoWithAccounts;
|
|
4384
4330
|
exports.decryptMemoWithKeys = decryptMemoWithKeys;
|
|
@@ -4433,6 +4379,8 @@ exports.isEmptyDate = isEmptyDate;
|
|
|
4433
4379
|
exports.lockLarynx = lockLarynx;
|
|
4434
4380
|
exports.mnemonicToSeedBip39 = mnemonicToSeedBip39;
|
|
4435
4381
|
exports.parseAsset = parseAsset;
|
|
4382
|
+
exports.placeHiveEngineBuyOrder = placeHiveEngineBuyOrder;
|
|
4383
|
+
exports.placeHiveEngineSellOrder = placeHiveEngineSellOrder;
|
|
4436
4384
|
exports.powerDownHive = powerDownHive;
|
|
4437
4385
|
exports.powerUpHive = powerUpHive;
|
|
4438
4386
|
exports.powerUpLarynx = powerUpLarynx;
|