@ecency/wallets 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.ts +68 -28
- package/dist/browser/index.js +313 -389
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +330 -387
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +313 -389
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.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,24 +1428,25 @@ 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,
|
|
1444
|
+
function useClaimRewards(username, auth, onSuccess) {
|
|
1435
1445
|
const { data } = useQuery(getAccountFullQueryOptions(username));
|
|
1436
1446
|
const queryClient = useQueryClient();
|
|
1437
1447
|
return useBroadcastMutation(
|
|
1438
1448
|
["assets", "hive", "claim-rewards", data?.name],
|
|
1439
1449
|
username,
|
|
1440
|
-
accessToken,
|
|
1441
1450
|
() => {
|
|
1442
1451
|
if (!data) {
|
|
1443
1452
|
throw new Error("Failed to fetch account while claiming balance");
|
|
@@ -1468,10 +1477,11 @@ function useClaimRewards(username, accessToken, onSuccess) {
|
|
|
1468
1477
|
queryClient.invalidateQueries({
|
|
1469
1478
|
queryKey: getHivePowerAssetGeneralInfoQueryOptions(username).queryKey
|
|
1470
1479
|
});
|
|
1471
|
-
}
|
|
1480
|
+
},
|
|
1481
|
+
auth
|
|
1472
1482
|
);
|
|
1473
1483
|
}
|
|
1474
|
-
async function claimInterestHive(payload) {
|
|
1484
|
+
async function claimInterestHive(payload, auth) {
|
|
1475
1485
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1476
1486
|
const baseOperation = {
|
|
1477
1487
|
from: payload.from,
|
|
@@ -1492,11 +1502,14 @@ async function claimInterestHive(payload) {
|
|
|
1492
1502
|
const { key } = payload;
|
|
1493
1503
|
return CONFIG.hiveClient.broadcast.sendOperations(operations, key);
|
|
1494
1504
|
}
|
|
1495
|
-
if (payload.type === "keychain") {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
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");
|
|
1500
1513
|
}
|
|
1501
1514
|
return hs.sendOperations(operations, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1502
1515
|
});
|
|
@@ -1523,7 +1536,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1523
1536
|
AssetOperation2["Undelegate"] = "undelegate";
|
|
1524
1537
|
return AssetOperation2;
|
|
1525
1538
|
})(AssetOperation || {});
|
|
1526
|
-
async function transferSpk(payload) {
|
|
1539
|
+
async function transferSpk(payload, auth) {
|
|
1527
1540
|
const json = JSON.stringify({
|
|
1528
1541
|
to: payload.to,
|
|
1529
1542
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1547,16 +1560,14 @@ async function transferSpk(payload) {
|
|
|
1547
1560
|
if (payload.type === "key" && "key" in payload) {
|
|
1548
1561
|
const { key } = payload;
|
|
1549
1562
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1550
|
-
} else if (payload.type === "keychain") {
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
);
|
|
1558
|
-
} else if (payload.type === "hiveauth") {
|
|
1559
|
-
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");
|
|
1560
1571
|
} else {
|
|
1561
1572
|
const { amount } = parseAsset(payload.amount);
|
|
1562
1573
|
return hs.sign(
|
|
@@ -1576,7 +1587,7 @@ async function transferSpk(payload) {
|
|
|
1576
1587
|
);
|
|
1577
1588
|
}
|
|
1578
1589
|
}
|
|
1579
|
-
var lockLarynx = async (payload) => {
|
|
1590
|
+
var lockLarynx = async (payload, auth) => {
|
|
1580
1591
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1581
1592
|
const op = {
|
|
1582
1593
|
id: payload.mode === "lock" ? "spkcc_gov_up" : "spkcc_gov_down",
|
|
@@ -1596,16 +1607,14 @@ var lockLarynx = async (payload) => {
|
|
|
1596
1607
|
if (payload.type === "key" && "key" in payload) {
|
|
1597
1608
|
const { key } = payload;
|
|
1598
1609
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1599
|
-
} else if (payload.type === "keychain") {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
);
|
|
1607
|
-
} else if (payload.type === "hiveauth") {
|
|
1608
|
-
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");
|
|
1609
1618
|
} else {
|
|
1610
1619
|
const { amount } = parseAsset(payload.amount);
|
|
1611
1620
|
return hs.sign(
|
|
@@ -1621,7 +1630,7 @@ var lockLarynx = async (payload) => {
|
|
|
1621
1630
|
);
|
|
1622
1631
|
}
|
|
1623
1632
|
};
|
|
1624
|
-
async function powerUpLarynx(payload) {
|
|
1633
|
+
async function powerUpLarynx(payload, auth) {
|
|
1625
1634
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1626
1635
|
const op = {
|
|
1627
1636
|
id: `spkcc_power_${payload.mode}`,
|
|
@@ -1641,16 +1650,14 @@ async function powerUpLarynx(payload) {
|
|
|
1641
1650
|
if (payload.type === "key" && "key" in payload) {
|
|
1642
1651
|
const { key } = payload;
|
|
1643
1652
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1644
|
-
} else if (payload.type === "keychain") {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
);
|
|
1652
|
-
} else if (payload.type === "hiveauth") {
|
|
1653
|
-
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");
|
|
1654
1661
|
} else {
|
|
1655
1662
|
const { amount } = parseAsset(payload.amount);
|
|
1656
1663
|
return hs.sign(
|
|
@@ -1666,7 +1673,7 @@ async function powerUpLarynx(payload) {
|
|
|
1666
1673
|
);
|
|
1667
1674
|
}
|
|
1668
1675
|
}
|
|
1669
|
-
async function transferLarynx(payload) {
|
|
1676
|
+
async function transferLarynx(payload, auth) {
|
|
1670
1677
|
const json = JSON.stringify({
|
|
1671
1678
|
to: payload.to,
|
|
1672
1679
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1690,16 +1697,14 @@ async function transferLarynx(payload) {
|
|
|
1690
1697
|
if (payload.type === "key" && "key" in payload) {
|
|
1691
1698
|
const { key } = payload;
|
|
1692
1699
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1693
|
-
} else if (payload.type === "keychain") {
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
);
|
|
1701
|
-
} else if (payload.type === "hiveauth") {
|
|
1702
|
-
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");
|
|
1703
1708
|
} else {
|
|
1704
1709
|
const { amount } = parseAsset(payload.amount);
|
|
1705
1710
|
return hs.sign(
|
|
@@ -1725,8 +1730,7 @@ function getSpkMarketsQueryOptions() {
|
|
|
1725
1730
|
staleTime: 6e4,
|
|
1726
1731
|
refetchInterval: 9e4,
|
|
1727
1732
|
queryFn: async () => {
|
|
1728
|
-
const
|
|
1729
|
-
const data = await response.json();
|
|
1733
|
+
const data = await getSpkMarkets();
|
|
1730
1734
|
return {
|
|
1731
1735
|
list: Object.entries(data.markets.node).map(([name, node]) => ({
|
|
1732
1736
|
name,
|
|
@@ -1741,8 +1745,10 @@ function getSpkWalletQueryOptions(username) {
|
|
|
1741
1745
|
return queryOptions({
|
|
1742
1746
|
queryKey: ["assets", "spk", "wallet", username],
|
|
1743
1747
|
queryFn: async () => {
|
|
1744
|
-
|
|
1745
|
-
|
|
1748
|
+
if (!username) {
|
|
1749
|
+
throw new Error("[SDK][Wallets][SPK] \u2013 username wasn't provided");
|
|
1750
|
+
}
|
|
1751
|
+
return getSpkWallet(username);
|
|
1746
1752
|
},
|
|
1747
1753
|
enabled: !!username,
|
|
1748
1754
|
staleTime: 6e4,
|
|
@@ -1914,32 +1920,7 @@ function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
|
1914
1920
|
return queryOptions({
|
|
1915
1921
|
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1916
1922
|
queryFn: async () => {
|
|
1917
|
-
|
|
1918
|
-
const response = await fetch(
|
|
1919
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1920
|
-
{
|
|
1921
|
-
method: "POST",
|
|
1922
|
-
body: JSON.stringify({
|
|
1923
|
-
jsonrpc: "2.0",
|
|
1924
|
-
method: "find",
|
|
1925
|
-
params: {
|
|
1926
|
-
contract: "market",
|
|
1927
|
-
table: "metrics",
|
|
1928
|
-
query: {
|
|
1929
|
-
...symbol && { symbol },
|
|
1930
|
-
...account && { account }
|
|
1931
|
-
}
|
|
1932
|
-
},
|
|
1933
|
-
id: 1
|
|
1934
|
-
}),
|
|
1935
|
-
headers: { "Content-type": "application/json" }
|
|
1936
|
-
}
|
|
1937
|
-
);
|
|
1938
|
-
const data = await response.json();
|
|
1939
|
-
return data.result;
|
|
1940
|
-
} catch (e) {
|
|
1941
|
-
return [];
|
|
1942
|
-
}
|
|
1923
|
+
return getHiveEngineTokensMarket(account, symbol);
|
|
1943
1924
|
}
|
|
1944
1925
|
});
|
|
1945
1926
|
}
|
|
@@ -2045,48 +2026,10 @@ function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allToke
|
|
|
2045
2026
|
if (!account) {
|
|
2046
2027
|
throw new Error("[HiveEngine] No account in a balances query");
|
|
2047
2028
|
}
|
|
2048
|
-
const
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
method: "POST",
|
|
2052
|
-
body: JSON.stringify({
|
|
2053
|
-
jsonrpc: "2.0",
|
|
2054
|
-
method: "find",
|
|
2055
|
-
params: {
|
|
2056
|
-
contract: "tokens",
|
|
2057
|
-
table: "balances",
|
|
2058
|
-
query: {
|
|
2059
|
-
account
|
|
2060
|
-
}
|
|
2061
|
-
},
|
|
2062
|
-
id: 1
|
|
2063
|
-
}),
|
|
2064
|
-
headers: { "Content-type": "application/json" }
|
|
2065
|
-
}
|
|
2066
|
-
);
|
|
2067
|
-
const balancesData = await balancesResponse.json();
|
|
2068
|
-
const balances = balancesData.result || [];
|
|
2069
|
-
const tokensResponse = await fetch(
|
|
2070
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2071
|
-
{
|
|
2072
|
-
method: "POST",
|
|
2073
|
-
body: JSON.stringify({
|
|
2074
|
-
jsonrpc: "2.0",
|
|
2075
|
-
method: "find",
|
|
2076
|
-
params: {
|
|
2077
|
-
contract: "tokens",
|
|
2078
|
-
table: "tokens",
|
|
2079
|
-
query: {
|
|
2080
|
-
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2081
|
-
}
|
|
2082
|
-
},
|
|
2083
|
-
id: 2
|
|
2084
|
-
}),
|
|
2085
|
-
headers: { "Content-type": "application/json" }
|
|
2086
|
-
}
|
|
2029
|
+
const balances = await getHiveEngineTokensBalances(account);
|
|
2030
|
+
const tokens = await getHiveEngineTokensMetadata(
|
|
2031
|
+
balances.map((t) => t.symbol)
|
|
2087
2032
|
);
|
|
2088
|
-
const tokensData = await tokensResponse.json();
|
|
2089
|
-
const tokens = tokensData.result || [];
|
|
2090
2033
|
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2091
2034
|
const metrics = Array.isArray(
|
|
2092
2035
|
allTokens
|
|
@@ -2131,27 +2074,7 @@ function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
|
2131
2074
|
staleTime: 6e4,
|
|
2132
2075
|
refetchInterval: 9e4,
|
|
2133
2076
|
queryFn: async () => {
|
|
2134
|
-
|
|
2135
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2136
|
-
{
|
|
2137
|
-
method: "POST",
|
|
2138
|
-
body: JSON.stringify({
|
|
2139
|
-
jsonrpc: "2.0",
|
|
2140
|
-
method: "find",
|
|
2141
|
-
params: {
|
|
2142
|
-
contract: "tokens",
|
|
2143
|
-
table: "tokens",
|
|
2144
|
-
query: {
|
|
2145
|
-
symbol: { $in: tokens }
|
|
2146
|
-
}
|
|
2147
|
-
},
|
|
2148
|
-
id: 2
|
|
2149
|
-
}),
|
|
2150
|
-
headers: { "Content-type": "application/json" }
|
|
2151
|
-
}
|
|
2152
|
-
);
|
|
2153
|
-
const data = await response.json();
|
|
2154
|
-
return data.result;
|
|
2077
|
+
return getHiveEngineTokensMetadata(tokens);
|
|
2155
2078
|
}
|
|
2156
2079
|
});
|
|
2157
2080
|
}
|
|
@@ -2161,27 +2084,7 @@ function getHiveEngineTokensBalancesQueryOptions(username) {
|
|
|
2161
2084
|
staleTime: 6e4,
|
|
2162
2085
|
refetchInterval: 9e4,
|
|
2163
2086
|
queryFn: async () => {
|
|
2164
|
-
|
|
2165
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2166
|
-
{
|
|
2167
|
-
method: "POST",
|
|
2168
|
-
body: JSON.stringify({
|
|
2169
|
-
jsonrpc: "2.0",
|
|
2170
|
-
method: "find",
|
|
2171
|
-
params: {
|
|
2172
|
-
contract: "tokens",
|
|
2173
|
-
table: "balances",
|
|
2174
|
-
query: {
|
|
2175
|
-
account: username
|
|
2176
|
-
}
|
|
2177
|
-
},
|
|
2178
|
-
id: 1
|
|
2179
|
-
}),
|
|
2180
|
-
headers: { "Content-type": "application/json" }
|
|
2181
|
-
}
|
|
2182
|
-
);
|
|
2183
|
-
const data = await response.json();
|
|
2184
|
-
return data.result;
|
|
2087
|
+
return getHiveEngineTokensBalances(username);
|
|
2185
2088
|
}
|
|
2186
2089
|
});
|
|
2187
2090
|
}
|
|
@@ -2191,25 +2094,7 @@ function getHiveEngineTokensMarketQueryOptions() {
|
|
|
2191
2094
|
staleTime: 6e4,
|
|
2192
2095
|
refetchInterval: 9e4,
|
|
2193
2096
|
queryFn: async () => {
|
|
2194
|
-
|
|
2195
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2196
|
-
{
|
|
2197
|
-
method: "POST",
|
|
2198
|
-
body: JSON.stringify({
|
|
2199
|
-
jsonrpc: "2.0",
|
|
2200
|
-
method: "find",
|
|
2201
|
-
params: {
|
|
2202
|
-
contract: "market",
|
|
2203
|
-
table: "metrics",
|
|
2204
|
-
query: {}
|
|
2205
|
-
},
|
|
2206
|
-
id: 1
|
|
2207
|
-
}),
|
|
2208
|
-
headers: { "Content-type": "application/json" }
|
|
2209
|
-
}
|
|
2210
|
-
);
|
|
2211
|
-
const data = await response.json();
|
|
2212
|
-
return data.result;
|
|
2097
|
+
return getHiveEngineTokensMarket();
|
|
2213
2098
|
}
|
|
2214
2099
|
});
|
|
2215
2100
|
}
|
|
@@ -2279,18 +2164,12 @@ function getHiveEngineTokenTransactionsQueryOptions(username, symbol, limit = 20
|
|
|
2279
2164
|
"[SDK][Wallets] \u2013 hive engine token or username missed"
|
|
2280
2165
|
);
|
|
2281
2166
|
}
|
|
2282
|
-
|
|
2283
|
-
|
|
2167
|
+
return getHiveEngineTokenTransactions(
|
|
2168
|
+
username,
|
|
2169
|
+
symbol,
|
|
2170
|
+
limit,
|
|
2171
|
+
pageParam
|
|
2284
2172
|
);
|
|
2285
|
-
url.searchParams.set("account", username);
|
|
2286
|
-
url.searchParams.set("symbol", symbol);
|
|
2287
|
-
url.searchParams.set("limit", limit.toString());
|
|
2288
|
-
url.searchParams.set("offset", pageParam.toString());
|
|
2289
|
-
const response = await fetch(url, {
|
|
2290
|
-
method: "GET",
|
|
2291
|
-
headers: { "Content-type": "application/json" }
|
|
2292
|
-
});
|
|
2293
|
-
return await response.json();
|
|
2294
2173
|
}
|
|
2295
2174
|
});
|
|
2296
2175
|
}
|
|
@@ -2300,15 +2179,7 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2300
2179
|
staleTime: 6e4,
|
|
2301
2180
|
refetchInterval: 9e4,
|
|
2302
2181
|
queryFn: async () => {
|
|
2303
|
-
|
|
2304
|
-
`${CONFIG.privateApiHost}/private-api/engine-chart-api`
|
|
2305
|
-
);
|
|
2306
|
-
url.searchParams.set("symbol", symbol);
|
|
2307
|
-
url.searchParams.set("interval", interval);
|
|
2308
|
-
const response = await fetch(url, {
|
|
2309
|
-
headers: { "Content-type": "application/json" }
|
|
2310
|
-
});
|
|
2311
|
-
return await response.json();
|
|
2182
|
+
return getHiveEngineTokenMetrics(symbol, interval);
|
|
2312
2183
|
}
|
|
2313
2184
|
});
|
|
2314
2185
|
}
|
|
@@ -2320,13 +2191,9 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2320
2191
|
enabled: !!username,
|
|
2321
2192
|
queryFn: async () => {
|
|
2322
2193
|
try {
|
|
2323
|
-
const
|
|
2324
|
-
|
|
2194
|
+
const data = await getHiveEngineUnclaimedRewards(
|
|
2195
|
+
username
|
|
2325
2196
|
);
|
|
2326
|
-
if (!response.ok) {
|
|
2327
|
-
return [];
|
|
2328
|
-
}
|
|
2329
|
-
const data = await response.json();
|
|
2330
2197
|
return Object.values(data).filter(
|
|
2331
2198
|
({ pending_token }) => pending_token > 0
|
|
2332
2199
|
);
|
|
@@ -2336,7 +2203,25 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2336
2203
|
}
|
|
2337
2204
|
});
|
|
2338
2205
|
}
|
|
2339
|
-
|
|
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) {
|
|
2340
2225
|
const parsedAsset = parseAsset(payload.amount);
|
|
2341
2226
|
const quantity = parsedAsset.amount.toString();
|
|
2342
2227
|
const operation = [
|
|
@@ -2373,24 +2258,8 @@ async function delegateEngineToken(payload) {
|
|
|
2373
2258
|
required_posting_auths: []
|
|
2374
2259
|
};
|
|
2375
2260
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2376
|
-
} else if (payload.type === "keychain") {
|
|
2377
|
-
return
|
|
2378
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2379
|
-
payload.from,
|
|
2380
|
-
"ssc-mainnet-hive",
|
|
2381
|
-
"Active",
|
|
2382
|
-
operation[1].json,
|
|
2383
|
-
"Token Delegation",
|
|
2384
|
-
(resp) => {
|
|
2385
|
-
if (!resp.success) {
|
|
2386
|
-
reject({ message: "Operation cancelled" });
|
|
2387
|
-
}
|
|
2388
|
-
resolve(resp);
|
|
2389
|
-
}
|
|
2390
|
-
)
|
|
2391
|
-
);
|
|
2392
|
-
} else if (payload.type === "hiveauth") {
|
|
2393
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2261
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2262
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2394
2263
|
} else {
|
|
2395
2264
|
return hs.sendOperation(
|
|
2396
2265
|
operation,
|
|
@@ -2400,7 +2269,7 @@ async function delegateEngineToken(payload) {
|
|
|
2400
2269
|
);
|
|
2401
2270
|
}
|
|
2402
2271
|
}
|
|
2403
|
-
async function undelegateEngineToken(payload) {
|
|
2272
|
+
async function undelegateEngineToken(payload, auth) {
|
|
2404
2273
|
const parsedAsset = parseAsset(payload.amount);
|
|
2405
2274
|
const quantity = parsedAsset.amount.toString();
|
|
2406
2275
|
const operation = [
|
|
@@ -2437,24 +2306,8 @@ async function undelegateEngineToken(payload) {
|
|
|
2437
2306
|
required_posting_auths: []
|
|
2438
2307
|
};
|
|
2439
2308
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2440
|
-
} else if (payload.type === "keychain") {
|
|
2441
|
-
return
|
|
2442
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2443
|
-
payload.from,
|
|
2444
|
-
"ssc-mainnet-hive",
|
|
2445
|
-
"Active",
|
|
2446
|
-
operation[1].json,
|
|
2447
|
-
"Token Undelegation",
|
|
2448
|
-
(resp) => {
|
|
2449
|
-
if (!resp.success) {
|
|
2450
|
-
reject({ message: "Operation cancelled" });
|
|
2451
|
-
}
|
|
2452
|
-
resolve(resp);
|
|
2453
|
-
}
|
|
2454
|
-
)
|
|
2455
|
-
);
|
|
2456
|
-
} else if (payload.type === "hiveauth") {
|
|
2457
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2309
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2310
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2458
2311
|
} else {
|
|
2459
2312
|
return hs.sendOperation(
|
|
2460
2313
|
operation,
|
|
@@ -2464,7 +2317,7 @@ async function undelegateEngineToken(payload) {
|
|
|
2464
2317
|
);
|
|
2465
2318
|
}
|
|
2466
2319
|
}
|
|
2467
|
-
async function stakeEngineToken(payload) {
|
|
2320
|
+
async function stakeEngineToken(payload, auth) {
|
|
2468
2321
|
const parsedAsset = parseAsset(payload.amount);
|
|
2469
2322
|
const quantity = parsedAsset.amount.toString();
|
|
2470
2323
|
const operation = [
|
|
@@ -2501,24 +2354,8 @@ async function stakeEngineToken(payload) {
|
|
|
2501
2354
|
required_posting_auths: []
|
|
2502
2355
|
};
|
|
2503
2356
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2504
|
-
} else if (payload.type === "keychain") {
|
|
2505
|
-
return
|
|
2506
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2507
|
-
payload.from,
|
|
2508
|
-
"ssc-mainnet-hive",
|
|
2509
|
-
"Active",
|
|
2510
|
-
operation[1].json,
|
|
2511
|
-
"Token Staking",
|
|
2512
|
-
(resp) => {
|
|
2513
|
-
if (!resp.success) {
|
|
2514
|
-
reject({ message: "Operation cancelled" });
|
|
2515
|
-
}
|
|
2516
|
-
resolve(resp);
|
|
2517
|
-
}
|
|
2518
|
-
)
|
|
2519
|
-
);
|
|
2520
|
-
} else if (payload.type === "hiveauth") {
|
|
2521
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2357
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2358
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2522
2359
|
} else {
|
|
2523
2360
|
return hs.sendOperation(
|
|
2524
2361
|
operation,
|
|
@@ -2528,7 +2365,7 @@ async function stakeEngineToken(payload) {
|
|
|
2528
2365
|
);
|
|
2529
2366
|
}
|
|
2530
2367
|
}
|
|
2531
|
-
async function unstakeEngineToken(payload) {
|
|
2368
|
+
async function unstakeEngineToken(payload, auth) {
|
|
2532
2369
|
const parsedAsset = parseAsset(payload.amount);
|
|
2533
2370
|
const quantity = parsedAsset.amount.toString();
|
|
2534
2371
|
const operation = [
|
|
@@ -2565,24 +2402,8 @@ async function unstakeEngineToken(payload) {
|
|
|
2565
2402
|
required_posting_auths: []
|
|
2566
2403
|
};
|
|
2567
2404
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2568
|
-
} else if (payload.type === "keychain") {
|
|
2569
|
-
return
|
|
2570
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2571
|
-
payload.from,
|
|
2572
|
-
"ssc-mainnet-hive",
|
|
2573
|
-
"Active",
|
|
2574
|
-
operation[1].json,
|
|
2575
|
-
"Token Unstaking",
|
|
2576
|
-
(resp) => {
|
|
2577
|
-
if (!resp.success) {
|
|
2578
|
-
reject({ message: "Operation cancelled" });
|
|
2579
|
-
}
|
|
2580
|
-
resolve(resp);
|
|
2581
|
-
}
|
|
2582
|
-
)
|
|
2583
|
-
);
|
|
2584
|
-
} else if (payload.type === "hiveauth") {
|
|
2585
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2405
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2406
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2586
2407
|
} else {
|
|
2587
2408
|
return hs.sendOperation(
|
|
2588
2409
|
operation,
|
|
@@ -2592,7 +2413,7 @@ async function unstakeEngineToken(payload) {
|
|
|
2592
2413
|
);
|
|
2593
2414
|
}
|
|
2594
2415
|
}
|
|
2595
|
-
async function transferEngineToken(payload) {
|
|
2416
|
+
async function transferEngineToken(payload, auth) {
|
|
2596
2417
|
const parsedAsset = parseAsset(payload.amount);
|
|
2597
2418
|
const quantity = parsedAsset.amount.toString();
|
|
2598
2419
|
const operation = [
|
|
@@ -2631,24 +2452,8 @@ async function transferEngineToken(payload) {
|
|
|
2631
2452
|
required_posting_auths: []
|
|
2632
2453
|
};
|
|
2633
2454
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2634
|
-
} else if (payload.type === "keychain") {
|
|
2635
|
-
return
|
|
2636
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2637
|
-
payload.from,
|
|
2638
|
-
"ssc-mainnet-hive",
|
|
2639
|
-
"Active",
|
|
2640
|
-
operation[1].json,
|
|
2641
|
-
"Token Transfer",
|
|
2642
|
-
(resp) => {
|
|
2643
|
-
if (!resp.success) {
|
|
2644
|
-
reject({ message: "Operation cancelled" });
|
|
2645
|
-
}
|
|
2646
|
-
resolve(resp);
|
|
2647
|
-
}
|
|
2648
|
-
)
|
|
2649
|
-
);
|
|
2650
|
-
} else if (payload.type === "hiveauth") {
|
|
2651
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2455
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2456
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2652
2457
|
} else {
|
|
2653
2458
|
return hs.sendOperation(
|
|
2654
2459
|
operation,
|
|
@@ -2658,6 +2463,105 @@ async function transferEngineToken(payload) {
|
|
|
2658
2463
|
);
|
|
2659
2464
|
}
|
|
2660
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
|
+
}
|
|
2661
2565
|
function getPointsQueryOptions(username) {
|
|
2662
2566
|
return queryOptions({
|
|
2663
2567
|
queryKey: ["assets", "points", username],
|
|
@@ -2745,7 +2649,7 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2745
2649
|
}
|
|
2746
2650
|
|
|
2747
2651
|
// src/modules/assets/points/mutations/claim-points.ts
|
|
2748
|
-
function useClaimPoints(username, onSuccess, onError) {
|
|
2652
|
+
function useClaimPoints(username, accessToken, onSuccess, onError) {
|
|
2749
2653
|
const { mutateAsync: recordActivity } = EcencyAnalytics.useRecordActivity(
|
|
2750
2654
|
username,
|
|
2751
2655
|
"points-claimed"
|
|
@@ -2755,16 +2659,31 @@ function useClaimPoints(username, onSuccess, onError) {
|
|
|
2755
2659
|
mutationFn: async () => {
|
|
2756
2660
|
if (!username) {
|
|
2757
2661
|
throw new Error(
|
|
2758
|
-
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn
|
|
2662
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn't provided"
|
|
2759
2663
|
);
|
|
2760
2664
|
}
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
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();
|
|
2768
2687
|
},
|
|
2769
2688
|
onError,
|
|
2770
2689
|
onSuccess: () => {
|
|
@@ -2792,7 +2711,7 @@ async function transferPoint({
|
|
|
2792
2711
|
memo,
|
|
2793
2712
|
type,
|
|
2794
2713
|
...payload
|
|
2795
|
-
}) {
|
|
2714
|
+
}, auth) {
|
|
2796
2715
|
const op = [
|
|
2797
2716
|
"custom_json",
|
|
2798
2717
|
{
|
|
@@ -2811,11 +2730,14 @@ async function transferPoint({
|
|
|
2811
2730
|
const { key } = payload;
|
|
2812
2731
|
return CONFIG.hiveClient.broadcast.sendOperations([op], key);
|
|
2813
2732
|
}
|
|
2814
|
-
if (type === "keychain") {
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
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");
|
|
2819
2741
|
}
|
|
2820
2742
|
return hs.sendOperation(op, { callback: `https://ecency.com/@${from}/wallet` }, () => {
|
|
2821
2743
|
});
|
|
@@ -4039,7 +3961,7 @@ function useCheckWalletExistence() {
|
|
|
4039
3961
|
}
|
|
4040
3962
|
});
|
|
4041
3963
|
}
|
|
4042
|
-
function useUpdateAccountWithWallets(username) {
|
|
3964
|
+
function useUpdateAccountWithWallets(username, accessToken) {
|
|
4043
3965
|
const fetchApi = getBoundFetch();
|
|
4044
3966
|
return useMutation({
|
|
4045
3967
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
|
|
@@ -4049,6 +3971,11 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4049
3971
|
return new Response(null, { status: 204 });
|
|
4050
3972
|
}
|
|
4051
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
|
+
}
|
|
4052
3979
|
return fetchApi(CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
4053
3980
|
method: "POST",
|
|
4054
3981
|
headers: {
|
|
@@ -4056,7 +3983,7 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4056
3983
|
},
|
|
4057
3984
|
body: JSON.stringify({
|
|
4058
3985
|
username,
|
|
4059
|
-
code:
|
|
3986
|
+
code: accessToken,
|
|
4060
3987
|
token: primaryToken,
|
|
4061
3988
|
address: primaryAddress,
|
|
4062
3989
|
status: 3,
|
|
@@ -4190,14 +4117,10 @@ function getGroupedChainTokens(tokens, defaultShow) {
|
|
|
4190
4117
|
)
|
|
4191
4118
|
);
|
|
4192
4119
|
}
|
|
4193
|
-
function useSaveWalletInformationToMetadata(username,
|
|
4120
|
+
function useSaveWalletInformationToMetadata(username, auth, options2) {
|
|
4194
4121
|
const queryClient = useQueryClient();
|
|
4195
4122
|
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
|
|
4196
|
-
const { mutateAsync: updateProfile } = useAccountUpdate(
|
|
4197
|
-
username,
|
|
4198
|
-
accessToken,
|
|
4199
|
-
auth
|
|
4200
|
-
);
|
|
4123
|
+
const { mutateAsync: updateProfile } = useAccountUpdate(username, auth);
|
|
4201
4124
|
return useMutation({
|
|
4202
4125
|
mutationKey: [
|
|
4203
4126
|
"ecency-wallets",
|
|
@@ -4279,7 +4202,7 @@ var engineOperationToFunctionMap = {
|
|
|
4279
4202
|
["delegate" /* Delegate */]: delegateEngineToken,
|
|
4280
4203
|
["undelegate" /* Undelegate */]: undelegateEngineToken
|
|
4281
4204
|
};
|
|
4282
|
-
function useWalletOperation(username, asset, operation) {
|
|
4205
|
+
function useWalletOperation(username, asset, operation, auth) {
|
|
4283
4206
|
const { mutateAsync: recordActivity } = EcencyAnalytics.useRecordActivity(
|
|
4284
4207
|
username,
|
|
4285
4208
|
operation
|
|
@@ -4289,17 +4212,18 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4289
4212
|
mutationFn: async (payload) => {
|
|
4290
4213
|
const operationFn = operationToFunctionMap[asset]?.[operation];
|
|
4291
4214
|
if (operationFn) {
|
|
4292
|
-
return operationFn(payload);
|
|
4215
|
+
return operationFn(payload, auth);
|
|
4293
4216
|
}
|
|
4294
4217
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
4295
4218
|
await getQueryClient().prefetchQuery(balancesListQuery);
|
|
4296
4219
|
const balances = getQueryClient().getQueryData(
|
|
4297
4220
|
balancesListQuery.queryKey
|
|
4298
4221
|
);
|
|
4299
|
-
|
|
4222
|
+
const engineBalances = balances ?? [];
|
|
4223
|
+
if (engineBalances.some((balance) => balance.symbol === asset)) {
|
|
4300
4224
|
const operationFn2 = engineOperationToFunctionMap[operation];
|
|
4301
4225
|
if (operationFn2) {
|
|
4302
|
-
return operationFn2({ ...payload, asset });
|
|
4226
|
+
return operationFn2({ ...payload, asset }, auth);
|
|
4303
4227
|
}
|
|
4304
4228
|
}
|
|
4305
4229
|
throw new Error("[SDK][Wallets] \u2013 no operation for given asset");
|
|
@@ -4336,6 +4260,6 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4336
4260
|
// src/index.ts
|
|
4337
4261
|
rememberScryptBsvVersion();
|
|
4338
4262
|
|
|
4339
|
-
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 };
|
|
4340
4264
|
//# sourceMappingURL=index.mjs.map
|
|
4341
4265
|
//# sourceMappingURL=index.mjs.map
|