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