@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.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions,
|
|
1
|
+
import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions, useBroadcastMutation, getSpkMarkets, getSpkWallet, getHiveEngineTokensMarket, getHiveEngineTokensBalances, getHiveEngineTokensMetadata, getHiveEngineTokenTransactions, getHiveEngineTokenMetrics, getHiveEngineUnclaimedRewards, EcencyAnalytics, useAccountUpdate } from '@ecency/sdk';
|
|
2
|
+
export { getHiveEngineMetrics, getHiveEngineOpenOrders, getHiveEngineOrderBook, getHiveEngineTradeHistory } from '@ecency/sdk';
|
|
2
3
|
import { useQuery, queryOptions, infiniteQueryOptions, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
3
4
|
import bip39, { mnemonicToSeedSync } from 'bip39';
|
|
4
5
|
import { LRUCache } from 'lru-cache';
|
|
@@ -1235,7 +1236,7 @@ function getHivePowerDelegatingsQueryOptions(username) {
|
|
|
1235
1236
|
)
|
|
1236
1237
|
});
|
|
1237
1238
|
}
|
|
1238
|
-
async function transferHive(payload) {
|
|
1239
|
+
async function transferHive(payload, auth) {
|
|
1239
1240
|
const parsedAsset = parseAsset(payload.amount);
|
|
1240
1241
|
const token = parsedAsset.symbol;
|
|
1241
1242
|
const precision = token === "VESTS" /* VESTS */ ? 6 : 3;
|
|
@@ -1261,26 +1262,14 @@ async function transferHive(payload) {
|
|
|
1261
1262
|
},
|
|
1262
1263
|
key
|
|
1263
1264
|
);
|
|
1264
|
-
} else if (payload.type === "keychain") {
|
|
1265
|
-
|
|
1266
|
-
(
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
(resp) => {
|
|
1273
|
-
if (!resp.success) {
|
|
1274
|
-
reject({ message: "Operation cancelled" });
|
|
1275
|
-
}
|
|
1276
|
-
resolve(resp);
|
|
1277
|
-
},
|
|
1278
|
-
true,
|
|
1279
|
-
null
|
|
1280
|
-
)
|
|
1281
|
-
);
|
|
1282
|
-
} else if (payload.type === "hiveauth") {
|
|
1283
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1265
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1266
|
+
if (auth?.broadcast) {
|
|
1267
|
+
return auth.broadcast([operation], "active");
|
|
1268
|
+
}
|
|
1269
|
+
if (payload.type === "hiveauth") {
|
|
1270
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1271
|
+
}
|
|
1272
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1284
1273
|
} else {
|
|
1285
1274
|
return hs.sendOperation(
|
|
1286
1275
|
operation,
|
|
@@ -1290,7 +1279,7 @@ async function transferHive(payload) {
|
|
|
1290
1279
|
);
|
|
1291
1280
|
}
|
|
1292
1281
|
}
|
|
1293
|
-
async function transferToSavingsHive(payload) {
|
|
1282
|
+
async function transferToSavingsHive(payload, auth) {
|
|
1294
1283
|
const operationPayload = {
|
|
1295
1284
|
from: payload.from,
|
|
1296
1285
|
to: payload.to,
|
|
@@ -1304,16 +1293,20 @@ async function transferToSavingsHive(payload) {
|
|
|
1304
1293
|
[["transfer_to_savings", params]],
|
|
1305
1294
|
key
|
|
1306
1295
|
);
|
|
1307
|
-
} else if (payload.type === "keychain") {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1296
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1297
|
+
if (auth?.broadcast) {
|
|
1298
|
+
return auth.broadcast([operation], "active");
|
|
1299
|
+
}
|
|
1300
|
+
if (payload.type === "hiveauth") {
|
|
1301
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1302
|
+
}
|
|
1303
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1311
1304
|
} else {
|
|
1312
1305
|
return hs.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1313
1306
|
});
|
|
1314
1307
|
}
|
|
1315
1308
|
}
|
|
1316
|
-
async function transferFromSavingsHive(payload) {
|
|
1309
|
+
async function transferFromSavingsHive(payload, auth) {
|
|
1317
1310
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1318
1311
|
const operationPayload = {
|
|
1319
1312
|
from: payload.from,
|
|
@@ -1330,16 +1323,19 @@ async function transferFromSavingsHive(payload) {
|
|
|
1330
1323
|
key
|
|
1331
1324
|
);
|
|
1332
1325
|
}
|
|
1333
|
-
if (payload.type === "keychain") {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1326
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1327
|
+
if (auth?.broadcast) {
|
|
1328
|
+
return auth.broadcast([operation], "active");
|
|
1329
|
+
}
|
|
1330
|
+
if (payload.type === "hiveauth") {
|
|
1331
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1332
|
+
}
|
|
1333
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1338
1334
|
}
|
|
1339
1335
|
return hs.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1340
1336
|
});
|
|
1341
1337
|
}
|
|
1342
|
-
async function powerUpHive(payload) {
|
|
1338
|
+
async function powerUpHive(payload, auth) {
|
|
1343
1339
|
const operationPayload = {
|
|
1344
1340
|
from: payload.from,
|
|
1345
1341
|
to: payload.to,
|
|
@@ -1353,16 +1349,20 @@ async function powerUpHive(payload) {
|
|
|
1353
1349
|
[["transfer_to_vesting", params]],
|
|
1354
1350
|
key
|
|
1355
1351
|
);
|
|
1356
|
-
} else if (payload.type === "keychain") {
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1352
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1353
|
+
if (auth?.broadcast) {
|
|
1354
|
+
return auth.broadcast([operation], "active");
|
|
1355
|
+
}
|
|
1356
|
+
if (payload.type === "hiveauth") {
|
|
1357
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1358
|
+
}
|
|
1359
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1360
1360
|
} else {
|
|
1361
1361
|
return hs.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1362
1362
|
});
|
|
1363
1363
|
}
|
|
1364
1364
|
}
|
|
1365
|
-
async function delegateHive(payload) {
|
|
1365
|
+
async function delegateHive(payload, auth) {
|
|
1366
1366
|
const operationPayload = {
|
|
1367
1367
|
delegator: payload.from,
|
|
1368
1368
|
delegatee: payload.to,
|
|
@@ -1375,16 +1375,20 @@ async function delegateHive(payload) {
|
|
|
1375
1375
|
[operation],
|
|
1376
1376
|
key
|
|
1377
1377
|
);
|
|
1378
|
-
} else if (payload.type === "keychain") {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1378
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1379
|
+
if (auth?.broadcast) {
|
|
1380
|
+
return auth.broadcast([operation], "active");
|
|
1381
|
+
}
|
|
1382
|
+
if (payload.type === "hiveauth") {
|
|
1383
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1384
|
+
}
|
|
1385
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1382
1386
|
} else {
|
|
1383
1387
|
return hs.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1384
1388
|
});
|
|
1385
1389
|
}
|
|
1386
1390
|
}
|
|
1387
|
-
async function powerDownHive(payload) {
|
|
1391
|
+
async function powerDownHive(payload, auth) {
|
|
1388
1392
|
const operationPayload = {
|
|
1389
1393
|
account: payload.from,
|
|
1390
1394
|
vesting_shares: payload.amount
|
|
@@ -1396,16 +1400,20 @@ async function powerDownHive(payload) {
|
|
|
1396
1400
|
[operation],
|
|
1397
1401
|
key
|
|
1398
1402
|
);
|
|
1399
|
-
} else if (payload.type === "keychain") {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1404
|
+
if (auth?.broadcast) {
|
|
1405
|
+
return auth.broadcast([operation], "active");
|
|
1406
|
+
}
|
|
1407
|
+
if (payload.type === "hiveauth") {
|
|
1408
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1409
|
+
}
|
|
1410
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1403
1411
|
} else {
|
|
1404
1412
|
return hs.sendOperation(operation, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1405
1413
|
});
|
|
1406
1414
|
}
|
|
1407
1415
|
}
|
|
1408
|
-
async function withdrawVestingRouteHive(payload) {
|
|
1416
|
+
async function withdrawVestingRouteHive(payload, auth) {
|
|
1409
1417
|
const baseParams = {
|
|
1410
1418
|
from_account: payload.from_account,
|
|
1411
1419
|
to_account: payload.to_account,
|
|
@@ -1420,18 +1428,20 @@ async function withdrawVestingRouteHive(payload) {
|
|
|
1420
1428
|
key
|
|
1421
1429
|
);
|
|
1422
1430
|
}
|
|
1423
|
-
if (payload.type === "keychain") {
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1431
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1432
|
+
if (auth?.broadcast) {
|
|
1433
|
+
return auth.broadcast([operation], "active");
|
|
1434
|
+
}
|
|
1435
|
+
if (payload.type === "hiveauth") {
|
|
1436
|
+
return broadcastWithWalletHiveAuth(payload.from_account, [operation], "active");
|
|
1437
|
+
}
|
|
1438
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1429
1439
|
}
|
|
1430
1440
|
const { type, ...params } = payload;
|
|
1431
1441
|
return hs.sendOperation(operation, { callback: `https://ecency.com/@${params.from_account}/wallet` }, () => {
|
|
1432
1442
|
});
|
|
1433
1443
|
}
|
|
1434
|
-
function useClaimRewards(username, onSuccess) {
|
|
1444
|
+
function useClaimRewards(username, auth, onSuccess) {
|
|
1435
1445
|
const { data } = useQuery(getAccountFullQueryOptions(username));
|
|
1436
1446
|
const queryClient = useQueryClient();
|
|
1437
1447
|
return useBroadcastMutation(
|
|
@@ -1467,10 +1477,11 @@ function useClaimRewards(username, onSuccess) {
|
|
|
1467
1477
|
queryClient.invalidateQueries({
|
|
1468
1478
|
queryKey: getHivePowerAssetGeneralInfoQueryOptions(username).queryKey
|
|
1469
1479
|
});
|
|
1470
|
-
}
|
|
1480
|
+
},
|
|
1481
|
+
auth
|
|
1471
1482
|
);
|
|
1472
1483
|
}
|
|
1473
|
-
async function claimInterestHive(payload) {
|
|
1484
|
+
async function claimInterestHive(payload, auth) {
|
|
1474
1485
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1475
1486
|
const baseOperation = {
|
|
1476
1487
|
from: payload.from,
|
|
@@ -1491,11 +1502,14 @@ async function claimInterestHive(payload) {
|
|
|
1491
1502
|
const { key } = payload;
|
|
1492
1503
|
return CONFIG.hiveClient.broadcast.sendOperations(operations, key);
|
|
1493
1504
|
}
|
|
1494
|
-
if (payload.type === "keychain") {
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1505
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1506
|
+
if (auth?.broadcast) {
|
|
1507
|
+
return auth.broadcast(operations, "active");
|
|
1508
|
+
}
|
|
1509
|
+
if (payload.type === "hiveauth") {
|
|
1510
|
+
return broadcastWithWalletHiveAuth(payload.from, operations, "active");
|
|
1511
|
+
}
|
|
1512
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1499
1513
|
}
|
|
1500
1514
|
return hs.sendOperations(operations, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1501
1515
|
});
|
|
@@ -1522,7 +1536,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1522
1536
|
AssetOperation2["Undelegate"] = "undelegate";
|
|
1523
1537
|
return AssetOperation2;
|
|
1524
1538
|
})(AssetOperation || {});
|
|
1525
|
-
async function transferSpk(payload) {
|
|
1539
|
+
async function transferSpk(payload, auth) {
|
|
1526
1540
|
const json = JSON.stringify({
|
|
1527
1541
|
to: payload.to,
|
|
1528
1542
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1546,16 +1560,14 @@ async function transferSpk(payload) {
|
|
|
1546
1560
|
if (payload.type === "key" && "key" in payload) {
|
|
1547
1561
|
const { key } = payload;
|
|
1548
1562
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1549
|
-
} else if (payload.type === "keychain") {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
);
|
|
1557
|
-
} else if (payload.type === "hiveauth") {
|
|
1558
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1563
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1564
|
+
if (auth?.broadcast) {
|
|
1565
|
+
return auth.broadcast([operation], "active");
|
|
1566
|
+
}
|
|
1567
|
+
if (payload.type === "hiveauth") {
|
|
1568
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1569
|
+
}
|
|
1570
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1559
1571
|
} else {
|
|
1560
1572
|
const { amount } = parseAsset(payload.amount);
|
|
1561
1573
|
return hs.sign(
|
|
@@ -1575,7 +1587,7 @@ async function transferSpk(payload) {
|
|
|
1575
1587
|
);
|
|
1576
1588
|
}
|
|
1577
1589
|
}
|
|
1578
|
-
var lockLarynx = async (payload) => {
|
|
1590
|
+
var lockLarynx = async (payload, auth) => {
|
|
1579
1591
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1580
1592
|
const op = {
|
|
1581
1593
|
id: payload.mode === "lock" ? "spkcc_gov_up" : "spkcc_gov_down",
|
|
@@ -1595,16 +1607,14 @@ var lockLarynx = async (payload) => {
|
|
|
1595
1607
|
if (payload.type === "key" && "key" in payload) {
|
|
1596
1608
|
const { key } = payload;
|
|
1597
1609
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1598
|
-
} else if (payload.type === "keychain") {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
);
|
|
1606
|
-
} else if (payload.type === "hiveauth") {
|
|
1607
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1610
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1611
|
+
if (auth?.broadcast) {
|
|
1612
|
+
return auth.broadcast([operation], "active");
|
|
1613
|
+
}
|
|
1614
|
+
if (payload.type === "hiveauth") {
|
|
1615
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1616
|
+
}
|
|
1617
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1608
1618
|
} else {
|
|
1609
1619
|
const { amount } = parseAsset(payload.amount);
|
|
1610
1620
|
return hs.sign(
|
|
@@ -1620,7 +1630,7 @@ var lockLarynx = async (payload) => {
|
|
|
1620
1630
|
);
|
|
1621
1631
|
}
|
|
1622
1632
|
};
|
|
1623
|
-
async function powerUpLarynx(payload) {
|
|
1633
|
+
async function powerUpLarynx(payload, auth) {
|
|
1624
1634
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1625
1635
|
const op = {
|
|
1626
1636
|
id: `spkcc_power_${payload.mode}`,
|
|
@@ -1640,16 +1650,14 @@ async function powerUpLarynx(payload) {
|
|
|
1640
1650
|
if (payload.type === "key" && "key" in payload) {
|
|
1641
1651
|
const { key } = payload;
|
|
1642
1652
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1643
|
-
} else if (payload.type === "keychain") {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
);
|
|
1651
|
-
} else if (payload.type === "hiveauth") {
|
|
1652
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1653
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1654
|
+
if (auth?.broadcast) {
|
|
1655
|
+
return auth.broadcast([operation], "active");
|
|
1656
|
+
}
|
|
1657
|
+
if (payload.type === "hiveauth") {
|
|
1658
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1659
|
+
}
|
|
1660
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1653
1661
|
} else {
|
|
1654
1662
|
const { amount } = parseAsset(payload.amount);
|
|
1655
1663
|
return hs.sign(
|
|
@@ -1665,7 +1673,7 @@ async function powerUpLarynx(payload) {
|
|
|
1665
1673
|
);
|
|
1666
1674
|
}
|
|
1667
1675
|
}
|
|
1668
|
-
async function transferLarynx(payload) {
|
|
1676
|
+
async function transferLarynx(payload, auth) {
|
|
1669
1677
|
const json = JSON.stringify({
|
|
1670
1678
|
to: payload.to,
|
|
1671
1679
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1689,16 +1697,14 @@ async function transferLarynx(payload) {
|
|
|
1689
1697
|
if (payload.type === "key" && "key" in payload) {
|
|
1690
1698
|
const { key } = payload;
|
|
1691
1699
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1692
|
-
} else if (payload.type === "keychain") {
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
);
|
|
1700
|
-
} else if (payload.type === "hiveauth") {
|
|
1701
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1700
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
1701
|
+
if (auth?.broadcast) {
|
|
1702
|
+
return auth.broadcast([operation], "active");
|
|
1703
|
+
}
|
|
1704
|
+
if (payload.type === "hiveauth") {
|
|
1705
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
1706
|
+
}
|
|
1707
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
1702
1708
|
} else {
|
|
1703
1709
|
const { amount } = parseAsset(payload.amount);
|
|
1704
1710
|
return hs.sign(
|
|
@@ -1724,8 +1730,7 @@ function getSpkMarketsQueryOptions() {
|
|
|
1724
1730
|
staleTime: 6e4,
|
|
1725
1731
|
refetchInterval: 9e4,
|
|
1726
1732
|
queryFn: async () => {
|
|
1727
|
-
const
|
|
1728
|
-
const data = await response.json();
|
|
1733
|
+
const data = await getSpkMarkets();
|
|
1729
1734
|
return {
|
|
1730
1735
|
list: Object.entries(data.markets.node).map(([name, node]) => ({
|
|
1731
1736
|
name,
|
|
@@ -1740,8 +1745,10 @@ function getSpkWalletQueryOptions(username) {
|
|
|
1740
1745
|
return queryOptions({
|
|
1741
1746
|
queryKey: ["assets", "spk", "wallet", username],
|
|
1742
1747
|
queryFn: async () => {
|
|
1743
|
-
|
|
1744
|
-
|
|
1748
|
+
if (!username) {
|
|
1749
|
+
throw new Error("[SDK][Wallets][SPK] \u2013 username wasn't provided");
|
|
1750
|
+
}
|
|
1751
|
+
return getSpkWallet(username);
|
|
1745
1752
|
},
|
|
1746
1753
|
enabled: !!username,
|
|
1747
1754
|
staleTime: 6e4,
|
|
@@ -1913,32 +1920,7 @@ function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
|
1913
1920
|
return queryOptions({
|
|
1914
1921
|
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1915
1922
|
queryFn: async () => {
|
|
1916
|
-
|
|
1917
|
-
const response = await fetch(
|
|
1918
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1919
|
-
{
|
|
1920
|
-
method: "POST",
|
|
1921
|
-
body: JSON.stringify({
|
|
1922
|
-
jsonrpc: "2.0",
|
|
1923
|
-
method: "find",
|
|
1924
|
-
params: {
|
|
1925
|
-
contract: "market",
|
|
1926
|
-
table: "metrics",
|
|
1927
|
-
query: {
|
|
1928
|
-
...symbol && { symbol },
|
|
1929
|
-
...account && { account }
|
|
1930
|
-
}
|
|
1931
|
-
},
|
|
1932
|
-
id: 1
|
|
1933
|
-
}),
|
|
1934
|
-
headers: { "Content-type": "application/json" }
|
|
1935
|
-
}
|
|
1936
|
-
);
|
|
1937
|
-
const data = await response.json();
|
|
1938
|
-
return data.result;
|
|
1939
|
-
} catch (e) {
|
|
1940
|
-
return [];
|
|
1941
|
-
}
|
|
1923
|
+
return getHiveEngineTokensMarket(account, symbol);
|
|
1942
1924
|
}
|
|
1943
1925
|
});
|
|
1944
1926
|
}
|
|
@@ -2044,48 +2026,10 @@ function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allToke
|
|
|
2044
2026
|
if (!account) {
|
|
2045
2027
|
throw new Error("[HiveEngine] No account in a balances query");
|
|
2046
2028
|
}
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
method: "POST",
|
|
2051
|
-
body: JSON.stringify({
|
|
2052
|
-
jsonrpc: "2.0",
|
|
2053
|
-
method: "find",
|
|
2054
|
-
params: {
|
|
2055
|
-
contract: "tokens",
|
|
2056
|
-
table: "balances",
|
|
2057
|
-
query: {
|
|
2058
|
-
account
|
|
2059
|
-
}
|
|
2060
|
-
},
|
|
2061
|
-
id: 1
|
|
2062
|
-
}),
|
|
2063
|
-
headers: { "Content-type": "application/json" }
|
|
2064
|
-
}
|
|
2029
|
+
const balances = await getHiveEngineTokensBalances(account);
|
|
2030
|
+
const tokens = await getHiveEngineTokensMetadata(
|
|
2031
|
+
balances.map((t) => t.symbol)
|
|
2065
2032
|
);
|
|
2066
|
-
const balancesData = await balancesResponse.json();
|
|
2067
|
-
const balances = balancesData.result || [];
|
|
2068
|
-
const tokensResponse = await fetch(
|
|
2069
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2070
|
-
{
|
|
2071
|
-
method: "POST",
|
|
2072
|
-
body: JSON.stringify({
|
|
2073
|
-
jsonrpc: "2.0",
|
|
2074
|
-
method: "find",
|
|
2075
|
-
params: {
|
|
2076
|
-
contract: "tokens",
|
|
2077
|
-
table: "tokens",
|
|
2078
|
-
query: {
|
|
2079
|
-
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2080
|
-
}
|
|
2081
|
-
},
|
|
2082
|
-
id: 2
|
|
2083
|
-
}),
|
|
2084
|
-
headers: { "Content-type": "application/json" }
|
|
2085
|
-
}
|
|
2086
|
-
);
|
|
2087
|
-
const tokensData = await tokensResponse.json();
|
|
2088
|
-
const tokens = tokensData.result || [];
|
|
2089
2033
|
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2090
2034
|
const metrics = Array.isArray(
|
|
2091
2035
|
allTokens
|
|
@@ -2130,27 +2074,7 @@ function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
|
2130
2074
|
staleTime: 6e4,
|
|
2131
2075
|
refetchInterval: 9e4,
|
|
2132
2076
|
queryFn: async () => {
|
|
2133
|
-
|
|
2134
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2135
|
-
{
|
|
2136
|
-
method: "POST",
|
|
2137
|
-
body: JSON.stringify({
|
|
2138
|
-
jsonrpc: "2.0",
|
|
2139
|
-
method: "find",
|
|
2140
|
-
params: {
|
|
2141
|
-
contract: "tokens",
|
|
2142
|
-
table: "tokens",
|
|
2143
|
-
query: {
|
|
2144
|
-
symbol: { $in: tokens }
|
|
2145
|
-
}
|
|
2146
|
-
},
|
|
2147
|
-
id: 2
|
|
2148
|
-
}),
|
|
2149
|
-
headers: { "Content-type": "application/json" }
|
|
2150
|
-
}
|
|
2151
|
-
);
|
|
2152
|
-
const data = await response.json();
|
|
2153
|
-
return data.result;
|
|
2077
|
+
return getHiveEngineTokensMetadata(tokens);
|
|
2154
2078
|
}
|
|
2155
2079
|
});
|
|
2156
2080
|
}
|
|
@@ -2160,27 +2084,7 @@ function getHiveEngineTokensBalancesQueryOptions(username) {
|
|
|
2160
2084
|
staleTime: 6e4,
|
|
2161
2085
|
refetchInterval: 9e4,
|
|
2162
2086
|
queryFn: async () => {
|
|
2163
|
-
|
|
2164
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2165
|
-
{
|
|
2166
|
-
method: "POST",
|
|
2167
|
-
body: JSON.stringify({
|
|
2168
|
-
jsonrpc: "2.0",
|
|
2169
|
-
method: "find",
|
|
2170
|
-
params: {
|
|
2171
|
-
contract: "tokens",
|
|
2172
|
-
table: "balances",
|
|
2173
|
-
query: {
|
|
2174
|
-
account: username
|
|
2175
|
-
}
|
|
2176
|
-
},
|
|
2177
|
-
id: 1
|
|
2178
|
-
}),
|
|
2179
|
-
headers: { "Content-type": "application/json" }
|
|
2180
|
-
}
|
|
2181
|
-
);
|
|
2182
|
-
const data = await response.json();
|
|
2183
|
-
return data.result;
|
|
2087
|
+
return getHiveEngineTokensBalances(username);
|
|
2184
2088
|
}
|
|
2185
2089
|
});
|
|
2186
2090
|
}
|
|
@@ -2190,25 +2094,7 @@ function getHiveEngineTokensMarketQueryOptions() {
|
|
|
2190
2094
|
staleTime: 6e4,
|
|
2191
2095
|
refetchInterval: 9e4,
|
|
2192
2096
|
queryFn: async () => {
|
|
2193
|
-
|
|
2194
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2195
|
-
{
|
|
2196
|
-
method: "POST",
|
|
2197
|
-
body: JSON.stringify({
|
|
2198
|
-
jsonrpc: "2.0",
|
|
2199
|
-
method: "find",
|
|
2200
|
-
params: {
|
|
2201
|
-
contract: "market",
|
|
2202
|
-
table: "metrics",
|
|
2203
|
-
query: {}
|
|
2204
|
-
},
|
|
2205
|
-
id: 1
|
|
2206
|
-
}),
|
|
2207
|
-
headers: { "Content-type": "application/json" }
|
|
2208
|
-
}
|
|
2209
|
-
);
|
|
2210
|
-
const data = await response.json();
|
|
2211
|
-
return data.result;
|
|
2097
|
+
return getHiveEngineTokensMarket();
|
|
2212
2098
|
}
|
|
2213
2099
|
});
|
|
2214
2100
|
}
|
|
@@ -2278,18 +2164,12 @@ function getHiveEngineTokenTransactionsQueryOptions(username, symbol, limit = 20
|
|
|
2278
2164
|
"[SDK][Wallets] \u2013 hive engine token or username missed"
|
|
2279
2165
|
);
|
|
2280
2166
|
}
|
|
2281
|
-
|
|
2282
|
-
|
|
2167
|
+
return getHiveEngineTokenTransactions(
|
|
2168
|
+
username,
|
|
2169
|
+
symbol,
|
|
2170
|
+
limit,
|
|
2171
|
+
pageParam
|
|
2283
2172
|
);
|
|
2284
|
-
url.searchParams.set("account", username);
|
|
2285
|
-
url.searchParams.set("symbol", symbol);
|
|
2286
|
-
url.searchParams.set("limit", limit.toString());
|
|
2287
|
-
url.searchParams.set("offset", pageParam.toString());
|
|
2288
|
-
const response = await fetch(url, {
|
|
2289
|
-
method: "GET",
|
|
2290
|
-
headers: { "Content-type": "application/json" }
|
|
2291
|
-
});
|
|
2292
|
-
return await response.json();
|
|
2293
2173
|
}
|
|
2294
2174
|
});
|
|
2295
2175
|
}
|
|
@@ -2299,15 +2179,7 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2299
2179
|
staleTime: 6e4,
|
|
2300
2180
|
refetchInterval: 9e4,
|
|
2301
2181
|
queryFn: async () => {
|
|
2302
|
-
|
|
2303
|
-
`${CONFIG.privateApiHost}/private-api/engine-chart-api`
|
|
2304
|
-
);
|
|
2305
|
-
url.searchParams.set("symbol", symbol);
|
|
2306
|
-
url.searchParams.set("interval", interval);
|
|
2307
|
-
const response = await fetch(url, {
|
|
2308
|
-
headers: { "Content-type": "application/json" }
|
|
2309
|
-
});
|
|
2310
|
-
return await response.json();
|
|
2182
|
+
return getHiveEngineTokenMetrics(symbol, interval);
|
|
2311
2183
|
}
|
|
2312
2184
|
});
|
|
2313
2185
|
}
|
|
@@ -2319,13 +2191,9 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2319
2191
|
enabled: !!username,
|
|
2320
2192
|
queryFn: async () => {
|
|
2321
2193
|
try {
|
|
2322
|
-
const
|
|
2323
|
-
|
|
2194
|
+
const data = await getHiveEngineUnclaimedRewards(
|
|
2195
|
+
username
|
|
2324
2196
|
);
|
|
2325
|
-
if (!response.ok) {
|
|
2326
|
-
return [];
|
|
2327
|
-
}
|
|
2328
|
-
const data = await response.json();
|
|
2329
2197
|
return Object.values(data).filter(
|
|
2330
2198
|
({ pending_token }) => pending_token > 0
|
|
2331
2199
|
);
|
|
@@ -2335,7 +2203,25 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2335
2203
|
}
|
|
2336
2204
|
});
|
|
2337
2205
|
}
|
|
2338
|
-
|
|
2206
|
+
|
|
2207
|
+
// src/modules/assets/hive-engine/mutations/broadcast-hive-engine-operation.ts
|
|
2208
|
+
async function broadcastHiveEngineOperation(payload, operation, auth) {
|
|
2209
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2210
|
+
if (auth?.broadcast) {
|
|
2211
|
+
return auth.broadcast([operation], "active");
|
|
2212
|
+
}
|
|
2213
|
+
if (payload.type === "hiveauth") {
|
|
2214
|
+
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2215
|
+
}
|
|
2216
|
+
if (payload.type === "keychain") {
|
|
2217
|
+
throw new Error("[SDK][Wallets] \u2013 keychain requires auth.broadcast");
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
// src/modules/assets/hive-engine/mutations/delegate.ts
|
|
2224
|
+
async function delegateEngineToken(payload, auth) {
|
|
2339
2225
|
const parsedAsset = parseAsset(payload.amount);
|
|
2340
2226
|
const quantity = parsedAsset.amount.toString();
|
|
2341
2227
|
const operation = [
|
|
@@ -2372,24 +2258,8 @@ async function delegateEngineToken(payload) {
|
|
|
2372
2258
|
required_posting_auths: []
|
|
2373
2259
|
};
|
|
2374
2260
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2375
|
-
} else if (payload.type === "keychain") {
|
|
2376
|
-
return
|
|
2377
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2378
|
-
payload.from,
|
|
2379
|
-
"ssc-mainnet-hive",
|
|
2380
|
-
"Active",
|
|
2381
|
-
operation[1].json,
|
|
2382
|
-
"Token Delegation",
|
|
2383
|
-
(resp) => {
|
|
2384
|
-
if (!resp.success) {
|
|
2385
|
-
reject({ message: "Operation cancelled" });
|
|
2386
|
-
}
|
|
2387
|
-
resolve(resp);
|
|
2388
|
-
}
|
|
2389
|
-
)
|
|
2390
|
-
);
|
|
2391
|
-
} else if (payload.type === "hiveauth") {
|
|
2392
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2261
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2262
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2393
2263
|
} else {
|
|
2394
2264
|
return hs.sendOperation(
|
|
2395
2265
|
operation,
|
|
@@ -2399,7 +2269,7 @@ async function delegateEngineToken(payload) {
|
|
|
2399
2269
|
);
|
|
2400
2270
|
}
|
|
2401
2271
|
}
|
|
2402
|
-
async function undelegateEngineToken(payload) {
|
|
2272
|
+
async function undelegateEngineToken(payload, auth) {
|
|
2403
2273
|
const parsedAsset = parseAsset(payload.amount);
|
|
2404
2274
|
const quantity = parsedAsset.amount.toString();
|
|
2405
2275
|
const operation = [
|
|
@@ -2436,24 +2306,8 @@ async function undelegateEngineToken(payload) {
|
|
|
2436
2306
|
required_posting_auths: []
|
|
2437
2307
|
};
|
|
2438
2308
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2439
|
-
} else if (payload.type === "keychain") {
|
|
2440
|
-
return
|
|
2441
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2442
|
-
payload.from,
|
|
2443
|
-
"ssc-mainnet-hive",
|
|
2444
|
-
"Active",
|
|
2445
|
-
operation[1].json,
|
|
2446
|
-
"Token Undelegation",
|
|
2447
|
-
(resp) => {
|
|
2448
|
-
if (!resp.success) {
|
|
2449
|
-
reject({ message: "Operation cancelled" });
|
|
2450
|
-
}
|
|
2451
|
-
resolve(resp);
|
|
2452
|
-
}
|
|
2453
|
-
)
|
|
2454
|
-
);
|
|
2455
|
-
} else if (payload.type === "hiveauth") {
|
|
2456
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2309
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2310
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2457
2311
|
} else {
|
|
2458
2312
|
return hs.sendOperation(
|
|
2459
2313
|
operation,
|
|
@@ -2463,7 +2317,7 @@ async function undelegateEngineToken(payload) {
|
|
|
2463
2317
|
);
|
|
2464
2318
|
}
|
|
2465
2319
|
}
|
|
2466
|
-
async function stakeEngineToken(payload) {
|
|
2320
|
+
async function stakeEngineToken(payload, auth) {
|
|
2467
2321
|
const parsedAsset = parseAsset(payload.amount);
|
|
2468
2322
|
const quantity = parsedAsset.amount.toString();
|
|
2469
2323
|
const operation = [
|
|
@@ -2500,24 +2354,8 @@ async function stakeEngineToken(payload) {
|
|
|
2500
2354
|
required_posting_auths: []
|
|
2501
2355
|
};
|
|
2502
2356
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2503
|
-
} else if (payload.type === "keychain") {
|
|
2504
|
-
return
|
|
2505
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2506
|
-
payload.from,
|
|
2507
|
-
"ssc-mainnet-hive",
|
|
2508
|
-
"Active",
|
|
2509
|
-
operation[1].json,
|
|
2510
|
-
"Token Staking",
|
|
2511
|
-
(resp) => {
|
|
2512
|
-
if (!resp.success) {
|
|
2513
|
-
reject({ message: "Operation cancelled" });
|
|
2514
|
-
}
|
|
2515
|
-
resolve(resp);
|
|
2516
|
-
}
|
|
2517
|
-
)
|
|
2518
|
-
);
|
|
2519
|
-
} else if (payload.type === "hiveauth") {
|
|
2520
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2357
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2358
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2521
2359
|
} else {
|
|
2522
2360
|
return hs.sendOperation(
|
|
2523
2361
|
operation,
|
|
@@ -2527,7 +2365,7 @@ async function stakeEngineToken(payload) {
|
|
|
2527
2365
|
);
|
|
2528
2366
|
}
|
|
2529
2367
|
}
|
|
2530
|
-
async function unstakeEngineToken(payload) {
|
|
2368
|
+
async function unstakeEngineToken(payload, auth) {
|
|
2531
2369
|
const parsedAsset = parseAsset(payload.amount);
|
|
2532
2370
|
const quantity = parsedAsset.amount.toString();
|
|
2533
2371
|
const operation = [
|
|
@@ -2564,24 +2402,8 @@ async function unstakeEngineToken(payload) {
|
|
|
2564
2402
|
required_posting_auths: []
|
|
2565
2403
|
};
|
|
2566
2404
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2567
|
-
} else if (payload.type === "keychain") {
|
|
2568
|
-
return
|
|
2569
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2570
|
-
payload.from,
|
|
2571
|
-
"ssc-mainnet-hive",
|
|
2572
|
-
"Active",
|
|
2573
|
-
operation[1].json,
|
|
2574
|
-
"Token Unstaking",
|
|
2575
|
-
(resp) => {
|
|
2576
|
-
if (!resp.success) {
|
|
2577
|
-
reject({ message: "Operation cancelled" });
|
|
2578
|
-
}
|
|
2579
|
-
resolve(resp);
|
|
2580
|
-
}
|
|
2581
|
-
)
|
|
2582
|
-
);
|
|
2583
|
-
} else if (payload.type === "hiveauth") {
|
|
2584
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2405
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2406
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2585
2407
|
} else {
|
|
2586
2408
|
return hs.sendOperation(
|
|
2587
2409
|
operation,
|
|
@@ -2591,7 +2413,7 @@ async function unstakeEngineToken(payload) {
|
|
|
2591
2413
|
);
|
|
2592
2414
|
}
|
|
2593
2415
|
}
|
|
2594
|
-
async function transferEngineToken(payload) {
|
|
2416
|
+
async function transferEngineToken(payload, auth) {
|
|
2595
2417
|
const parsedAsset = parseAsset(payload.amount);
|
|
2596
2418
|
const quantity = parsedAsset.amount.toString();
|
|
2597
2419
|
const operation = [
|
|
@@ -2630,24 +2452,8 @@ async function transferEngineToken(payload) {
|
|
|
2630
2452
|
required_posting_auths: []
|
|
2631
2453
|
};
|
|
2632
2454
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2633
|
-
} else if (payload.type === "keychain") {
|
|
2634
|
-
return
|
|
2635
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2636
|
-
payload.from,
|
|
2637
|
-
"ssc-mainnet-hive",
|
|
2638
|
-
"Active",
|
|
2639
|
-
operation[1].json,
|
|
2640
|
-
"Token Transfer",
|
|
2641
|
-
(resp) => {
|
|
2642
|
-
if (!resp.success) {
|
|
2643
|
-
reject({ message: "Operation cancelled" });
|
|
2644
|
-
}
|
|
2645
|
-
resolve(resp);
|
|
2646
|
-
}
|
|
2647
|
-
)
|
|
2648
|
-
);
|
|
2649
|
-
} else if (payload.type === "hiveauth") {
|
|
2650
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2455
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2456
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2651
2457
|
} else {
|
|
2652
2458
|
return hs.sendOperation(
|
|
2653
2459
|
operation,
|
|
@@ -2657,6 +2463,105 @@ async function transferEngineToken(payload) {
|
|
|
2657
2463
|
);
|
|
2658
2464
|
}
|
|
2659
2465
|
}
|
|
2466
|
+
var ENGINE_CONTRACT_ID = "ssc-mainnet-hive";
|
|
2467
|
+
function buildEngineOrderPayload(action, symbol, quantity, price) {
|
|
2468
|
+
return {
|
|
2469
|
+
contractName: "market",
|
|
2470
|
+
contractAction: action,
|
|
2471
|
+
contractPayload: { symbol, quantity, price }
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
function buildEngineCancelPayload(type, orderId) {
|
|
2475
|
+
return {
|
|
2476
|
+
contractName: "market",
|
|
2477
|
+
contractAction: "cancel",
|
|
2478
|
+
contractPayload: { type, id: orderId }
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
function buildEngineOperation(account, payload) {
|
|
2482
|
+
return {
|
|
2483
|
+
id: ENGINE_CONTRACT_ID,
|
|
2484
|
+
required_auths: [account],
|
|
2485
|
+
required_posting_auths: [],
|
|
2486
|
+
json: JSON.stringify(payload)
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
async function broadcastEngineOperation(account, payload, options2) {
|
|
2490
|
+
const operation = buildEngineOperation(account, payload);
|
|
2491
|
+
const opTuple = ["custom_json", operation];
|
|
2492
|
+
switch (options2?.method) {
|
|
2493
|
+
case "key": {
|
|
2494
|
+
if (!options2.key) {
|
|
2495
|
+
throw new Error("[SDK][Wallets] \u2013 active key is required");
|
|
2496
|
+
}
|
|
2497
|
+
return CONFIG.hiveClient.broadcast.json(operation, options2.key);
|
|
2498
|
+
}
|
|
2499
|
+
case "keychain":
|
|
2500
|
+
case "hiveauth": {
|
|
2501
|
+
if (options2.auth?.broadcast) {
|
|
2502
|
+
return options2.auth.broadcast([opTuple], "active");
|
|
2503
|
+
}
|
|
2504
|
+
if (options2.method === "hiveauth") {
|
|
2505
|
+
return broadcastWithWalletHiveAuth(account, [opTuple], "active");
|
|
2506
|
+
}
|
|
2507
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2508
|
+
}
|
|
2509
|
+
case "hivesigner":
|
|
2510
|
+
return hs.sendOperation(
|
|
2511
|
+
opTuple,
|
|
2512
|
+
{ callback: `https://ecency.com/@${account}/wallet/engine` },
|
|
2513
|
+
() => {
|
|
2514
|
+
}
|
|
2515
|
+
);
|
|
2516
|
+
default:
|
|
2517
|
+
throw new Error("[SDK][Wallets] \u2013 broadcast method is required");
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
var placeHiveEngineBuyOrder = async (account, symbol, quantity, price, options2) => broadcastEngineOperation(
|
|
2521
|
+
account,
|
|
2522
|
+
buildEngineOrderPayload("buy", symbol, quantity, price),
|
|
2523
|
+
options2
|
|
2524
|
+
);
|
|
2525
|
+
var placeHiveEngineSellOrder = async (account, symbol, quantity, price, options2) => broadcastEngineOperation(
|
|
2526
|
+
account,
|
|
2527
|
+
buildEngineOrderPayload("sell", symbol, quantity, price),
|
|
2528
|
+
options2
|
|
2529
|
+
);
|
|
2530
|
+
var cancelHiveEngineOrder = async (account, type, orderId, options2) => broadcastEngineOperation(
|
|
2531
|
+
account,
|
|
2532
|
+
buildEngineCancelPayload(type, orderId),
|
|
2533
|
+
options2
|
|
2534
|
+
);
|
|
2535
|
+
async function claimHiveEngineRewards(payload, auth) {
|
|
2536
|
+
const json = JSON.stringify(payload.tokens.map((symbol) => ({ symbol })));
|
|
2537
|
+
const operation = [
|
|
2538
|
+
"custom_json",
|
|
2539
|
+
{
|
|
2540
|
+
id: "scot_claim_token",
|
|
2541
|
+
required_auths: [],
|
|
2542
|
+
required_posting_auths: [payload.account],
|
|
2543
|
+
json
|
|
2544
|
+
}
|
|
2545
|
+
];
|
|
2546
|
+
if (payload.type === "key" && "key" in payload) {
|
|
2547
|
+
return CONFIG.hiveClient.broadcast.sendOperations([operation], payload.key);
|
|
2548
|
+
}
|
|
2549
|
+
if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2550
|
+
if (auth?.broadcast) {
|
|
2551
|
+
return auth.broadcast([operation], "posting");
|
|
2552
|
+
}
|
|
2553
|
+
if (payload.type === "hiveauth") {
|
|
2554
|
+
return broadcastWithWalletHiveAuth(payload.account, [operation], "posting");
|
|
2555
|
+
}
|
|
2556
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2557
|
+
}
|
|
2558
|
+
return hs.sendOperation(
|
|
2559
|
+
operation,
|
|
2560
|
+
{ callback: `https://ecency.com/@${payload.account}/wallet/engine` },
|
|
2561
|
+
() => {
|
|
2562
|
+
}
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2660
2565
|
function getPointsQueryOptions(username) {
|
|
2661
2566
|
return queryOptions({
|
|
2662
2567
|
queryKey: ["assets", "points", username],
|
|
@@ -2744,7 +2649,7 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2744
2649
|
}
|
|
2745
2650
|
|
|
2746
2651
|
// src/modules/assets/points/mutations/claim-points.ts
|
|
2747
|
-
function useClaimPoints(username, onSuccess, onError) {
|
|
2652
|
+
function useClaimPoints(username, accessToken, onSuccess, onError) {
|
|
2748
2653
|
const { mutateAsync: recordActivity } = EcencyAnalytics.useRecordActivity(
|
|
2749
2654
|
username,
|
|
2750
2655
|
"points-claimed"
|
|
@@ -2754,16 +2659,31 @@ function useClaimPoints(username, onSuccess, onError) {
|
|
|
2754
2659
|
mutationFn: async () => {
|
|
2755
2660
|
if (!username) {
|
|
2756
2661
|
throw new Error(
|
|
2757
|
-
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn
|
|
2662
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn't provided"
|
|
2758
2663
|
);
|
|
2759
2664
|
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2665
|
+
if (!accessToken) {
|
|
2666
|
+
throw new Error(
|
|
2667
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 access token wasn't found"
|
|
2668
|
+
);
|
|
2669
|
+
}
|
|
2670
|
+
const response = await fetchApi(
|
|
2671
|
+
CONFIG.privateApiHost + "/private-api/points-claim",
|
|
2672
|
+
{
|
|
2673
|
+
method: "POST",
|
|
2674
|
+
headers: {
|
|
2675
|
+
"Content-Type": "application/json"
|
|
2676
|
+
},
|
|
2677
|
+
body: JSON.stringify({ code: accessToken })
|
|
2678
|
+
}
|
|
2679
|
+
);
|
|
2680
|
+
if (!response.ok) {
|
|
2681
|
+
const body = await response.text();
|
|
2682
|
+
throw new Error(
|
|
2683
|
+
`[SDK][Wallets][Assets][Points][Claim] \u2013 failed with status ${response.status}${body ? `: ${body}` : ""}`
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2686
|
+
return response.json();
|
|
2767
2687
|
},
|
|
2768
2688
|
onError,
|
|
2769
2689
|
onSuccess: () => {
|
|
@@ -2791,7 +2711,7 @@ async function transferPoint({
|
|
|
2791
2711
|
memo,
|
|
2792
2712
|
type,
|
|
2793
2713
|
...payload
|
|
2794
|
-
}) {
|
|
2714
|
+
}, auth) {
|
|
2795
2715
|
const op = [
|
|
2796
2716
|
"custom_json",
|
|
2797
2717
|
{
|
|
@@ -2810,11 +2730,14 @@ async function transferPoint({
|
|
|
2810
2730
|
const { key } = payload;
|
|
2811
2731
|
return CONFIG.hiveClient.broadcast.sendOperations([op], key);
|
|
2812
2732
|
}
|
|
2813
|
-
if (type === "keychain") {
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2733
|
+
if (type === "keychain" || type === "hiveauth") {
|
|
2734
|
+
if (auth?.broadcast) {
|
|
2735
|
+
return auth.broadcast([op], "active");
|
|
2736
|
+
}
|
|
2737
|
+
if (type === "hiveauth") {
|
|
2738
|
+
return broadcastWithWalletHiveAuth(from, [op], "active");
|
|
2739
|
+
}
|
|
2740
|
+
throw new Error("[SDK][Wallets] \u2013 missing broadcaster");
|
|
2818
2741
|
}
|
|
2819
2742
|
return hs.sendOperation(op, { callback: `https://ecency.com/@${from}/wallet` }, () => {
|
|
2820
2743
|
});
|
|
@@ -4038,7 +3961,7 @@ function useCheckWalletExistence() {
|
|
|
4038
3961
|
}
|
|
4039
3962
|
});
|
|
4040
3963
|
}
|
|
4041
|
-
function useUpdateAccountWithWallets(username) {
|
|
3964
|
+
function useUpdateAccountWithWallets(username, accessToken) {
|
|
4042
3965
|
const fetchApi = getBoundFetch();
|
|
4043
3966
|
return useMutation({
|
|
4044
3967
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
|
|
@@ -4048,6 +3971,11 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4048
3971
|
return new Response(null, { status: 204 });
|
|
4049
3972
|
}
|
|
4050
3973
|
const [primaryToken, primaryAddress] = entries[0] ?? ["", ""];
|
|
3974
|
+
if (!accessToken) {
|
|
3975
|
+
throw new Error(
|
|
3976
|
+
"[SDK][Wallets][PrivateApi][WalletsAdd] \u2013 access token wasn`t found"
|
|
3977
|
+
);
|
|
3978
|
+
}
|
|
4051
3979
|
return fetchApi(CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
4052
3980
|
method: "POST",
|
|
4053
3981
|
headers: {
|
|
@@ -4055,7 +3983,7 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4055
3983
|
},
|
|
4056
3984
|
body: JSON.stringify({
|
|
4057
3985
|
username,
|
|
4058
|
-
code:
|
|
3986
|
+
code: accessToken,
|
|
4059
3987
|
token: primaryToken,
|
|
4060
3988
|
address: primaryAddress,
|
|
4061
3989
|
status: 3,
|
|
@@ -4189,10 +4117,10 @@ function getGroupedChainTokens(tokens, defaultShow) {
|
|
|
4189
4117
|
)
|
|
4190
4118
|
);
|
|
4191
4119
|
}
|
|
4192
|
-
function useSaveWalletInformationToMetadata(username, options2) {
|
|
4120
|
+
function useSaveWalletInformationToMetadata(username, auth, options2) {
|
|
4193
4121
|
const queryClient = useQueryClient();
|
|
4194
4122
|
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
|
|
4195
|
-
const { mutateAsync: updateProfile } = useAccountUpdate(username);
|
|
4123
|
+
const { mutateAsync: updateProfile } = useAccountUpdate(username, auth);
|
|
4196
4124
|
return useMutation({
|
|
4197
4125
|
mutationKey: [
|
|
4198
4126
|
"ecency-wallets",
|
|
@@ -4274,7 +4202,7 @@ var engineOperationToFunctionMap = {
|
|
|
4274
4202
|
["delegate" /* Delegate */]: delegateEngineToken,
|
|
4275
4203
|
["undelegate" /* Undelegate */]: undelegateEngineToken
|
|
4276
4204
|
};
|
|
4277
|
-
function useWalletOperation(username, asset, operation) {
|
|
4205
|
+
function useWalletOperation(username, asset, operation, auth) {
|
|
4278
4206
|
const { mutateAsync: recordActivity } = EcencyAnalytics.useRecordActivity(
|
|
4279
4207
|
username,
|
|
4280
4208
|
operation
|
|
@@ -4284,17 +4212,18 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4284
4212
|
mutationFn: async (payload) => {
|
|
4285
4213
|
const operationFn = operationToFunctionMap[asset]?.[operation];
|
|
4286
4214
|
if (operationFn) {
|
|
4287
|
-
return operationFn(payload);
|
|
4215
|
+
return operationFn(payload, auth);
|
|
4288
4216
|
}
|
|
4289
4217
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
4290
4218
|
await getQueryClient().prefetchQuery(balancesListQuery);
|
|
4291
4219
|
const balances = getQueryClient().getQueryData(
|
|
4292
4220
|
balancesListQuery.queryKey
|
|
4293
4221
|
);
|
|
4294
|
-
|
|
4222
|
+
const engineBalances = balances ?? [];
|
|
4223
|
+
if (engineBalances.some((balance) => balance.symbol === asset)) {
|
|
4295
4224
|
const operationFn2 = engineOperationToFunctionMap[operation];
|
|
4296
4225
|
if (operationFn2) {
|
|
4297
|
-
return operationFn2({ ...payload, asset });
|
|
4226
|
+
return operationFn2({ ...payload, asset }, auth);
|
|
4298
4227
|
}
|
|
4299
4228
|
}
|
|
4300
4229
|
throw new Error("[SDK][Wallets] \u2013 no operation for given asset");
|
|
@@ -4331,6 +4260,6 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4331
4260
|
// src/index.ts
|
|
4332
4261
|
rememberScryptBsvVersion();
|
|
4333
4262
|
|
|
4334
|
-
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, HiveEngineToken, NaiMap, PointTransactionType, Symbol2 as Symbol, broadcastWithWalletHiveAuth, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, claimInterestHive, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, formattedNumber, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllHiveEngineTokensQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineBalancesWithUsdQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHiveEngineUnclaimedRewardsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getSpkWalletQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getVisionPortfolioQueryOptions, getWallet, hasWalletHiveAuthBroadcast, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, registerWalletHiveAuthBroadcast, resolveHiveOperationFilters, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferFromSavingsHive, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
4263
|
+
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, HiveEngineToken, NaiMap, PointTransactionType, Symbol2 as Symbol, broadcastWithWalletHiveAuth, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, cancelHiveEngineOrder, claimHiveEngineRewards, claimInterestHive, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, formattedNumber, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllHiveEngineTokensQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineBalancesWithUsdQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHiveEngineUnclaimedRewardsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getSpkWalletQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getVisionPortfolioQueryOptions, getWallet, hasWalletHiveAuthBroadcast, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, placeHiveEngineBuyOrder, placeHiveEngineSellOrder, powerDownHive, powerUpHive, powerUpLarynx, registerWalletHiveAuthBroadcast, resolveHiveOperationFilters, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferFromSavingsHive, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
4335
4264
|
//# sourceMappingURL=index.mjs.map
|
|
4336
4265
|
//# sourceMappingURL=index.mjs.map
|