@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/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,24 +1430,25 @@ 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,
|
|
1446
|
+
function useClaimRewards(username, auth, onSuccess) {
|
|
1437
1447
|
const { data } = useQuery(getAccountFullQueryOptions(username));
|
|
1438
1448
|
const queryClient = useQueryClient();
|
|
1439
1449
|
return useBroadcastMutation(
|
|
1440
1450
|
["assets", "hive", "claim-rewards", data?.name],
|
|
1441
1451
|
username,
|
|
1442
|
-
accessToken,
|
|
1443
1452
|
() => {
|
|
1444
1453
|
if (!data) {
|
|
1445
1454
|
throw new Error("Failed to fetch account while claiming balance");
|
|
@@ -1470,10 +1479,11 @@ function useClaimRewards(username, accessToken, onSuccess) {
|
|
|
1470
1479
|
queryClient.invalidateQueries({
|
|
1471
1480
|
queryKey: getHivePowerAssetGeneralInfoQueryOptions(username).queryKey
|
|
1472
1481
|
});
|
|
1473
|
-
}
|
|
1482
|
+
},
|
|
1483
|
+
auth
|
|
1474
1484
|
);
|
|
1475
1485
|
}
|
|
1476
|
-
async function claimInterestHive(payload) {
|
|
1486
|
+
async function claimInterestHive(payload, auth) {
|
|
1477
1487
|
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1478
1488
|
const baseOperation = {
|
|
1479
1489
|
from: payload.from,
|
|
@@ -1494,11 +1504,14 @@ async function claimInterestHive(payload) {
|
|
|
1494
1504
|
const { key } = payload;
|
|
1495
1505
|
return CONFIG.hiveClient.broadcast.sendOperations(operations, key);
|
|
1496
1506
|
}
|
|
1497
|
-
if (payload.type === "keychain") {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
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");
|
|
1502
1515
|
}
|
|
1503
1516
|
return hs.sendOperations(operations, { callback: `https://ecency.com/@${payload.from}/wallet` }, () => {
|
|
1504
1517
|
});
|
|
@@ -1525,7 +1538,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1525
1538
|
AssetOperation2["Undelegate"] = "undelegate";
|
|
1526
1539
|
return AssetOperation2;
|
|
1527
1540
|
})(AssetOperation || {});
|
|
1528
|
-
async function transferSpk(payload) {
|
|
1541
|
+
async function transferSpk(payload, auth) {
|
|
1529
1542
|
const json = JSON.stringify({
|
|
1530
1543
|
to: payload.to,
|
|
1531
1544
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1549,16 +1562,14 @@ async function transferSpk(payload) {
|
|
|
1549
1562
|
if (payload.type === "key" && "key" in payload) {
|
|
1550
1563
|
const { key } = payload;
|
|
1551
1564
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1552
|
-
} else if (payload.type === "keychain") {
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
);
|
|
1560
|
-
} else if (payload.type === "hiveauth") {
|
|
1561
|
-
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");
|
|
1562
1573
|
} else {
|
|
1563
1574
|
const { amount } = parseAsset(payload.amount);
|
|
1564
1575
|
return hs.sign(
|
|
@@ -1578,7 +1589,7 @@ async function transferSpk(payload) {
|
|
|
1578
1589
|
);
|
|
1579
1590
|
}
|
|
1580
1591
|
}
|
|
1581
|
-
var lockLarynx = async (payload) => {
|
|
1592
|
+
var lockLarynx = async (payload, auth) => {
|
|
1582
1593
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1583
1594
|
const op = {
|
|
1584
1595
|
id: payload.mode === "lock" ? "spkcc_gov_up" : "spkcc_gov_down",
|
|
@@ -1598,16 +1609,14 @@ var lockLarynx = async (payload) => {
|
|
|
1598
1609
|
if (payload.type === "key" && "key" in payload) {
|
|
1599
1610
|
const { key } = payload;
|
|
1600
1611
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1601
|
-
} else if (payload.type === "keychain") {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
);
|
|
1609
|
-
} else if (payload.type === "hiveauth") {
|
|
1610
|
-
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");
|
|
1611
1620
|
} else {
|
|
1612
1621
|
const { amount } = parseAsset(payload.amount);
|
|
1613
1622
|
return hs.sign(
|
|
@@ -1623,7 +1632,7 @@ var lockLarynx = async (payload) => {
|
|
|
1623
1632
|
);
|
|
1624
1633
|
}
|
|
1625
1634
|
};
|
|
1626
|
-
async function powerUpLarynx(payload) {
|
|
1635
|
+
async function powerUpLarynx(payload, auth) {
|
|
1627
1636
|
const json = JSON.stringify({ amount: +payload.amount * 1e3 });
|
|
1628
1637
|
const op = {
|
|
1629
1638
|
id: `spkcc_power_${payload.mode}`,
|
|
@@ -1643,16 +1652,14 @@ async function powerUpLarynx(payload) {
|
|
|
1643
1652
|
if (payload.type === "key" && "key" in payload) {
|
|
1644
1653
|
const { key } = payload;
|
|
1645
1654
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1646
|
-
} else if (payload.type === "keychain") {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
);
|
|
1654
|
-
} else if (payload.type === "hiveauth") {
|
|
1655
|
-
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");
|
|
1656
1663
|
} else {
|
|
1657
1664
|
const { amount } = parseAsset(payload.amount);
|
|
1658
1665
|
return hs.sign(
|
|
@@ -1668,7 +1675,7 @@ async function powerUpLarynx(payload) {
|
|
|
1668
1675
|
);
|
|
1669
1676
|
}
|
|
1670
1677
|
}
|
|
1671
|
-
async function transferLarynx(payload) {
|
|
1678
|
+
async function transferLarynx(payload, auth) {
|
|
1672
1679
|
const json = JSON.stringify({
|
|
1673
1680
|
to: payload.to,
|
|
1674
1681
|
amount: parseAsset(payload.amount).amount * 1e3,
|
|
@@ -1692,16 +1699,14 @@ async function transferLarynx(payload) {
|
|
|
1692
1699
|
if (payload.type === "key" && "key" in payload) {
|
|
1693
1700
|
const { key } = payload;
|
|
1694
1701
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
1695
|
-
} else if (payload.type === "keychain") {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
);
|
|
1703
|
-
} else if (payload.type === "hiveauth") {
|
|
1704
|
-
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");
|
|
1705
1710
|
} else {
|
|
1706
1711
|
const { amount } = parseAsset(payload.amount);
|
|
1707
1712
|
return hs.sign(
|
|
@@ -1727,8 +1732,7 @@ function getSpkMarketsQueryOptions() {
|
|
|
1727
1732
|
staleTime: 6e4,
|
|
1728
1733
|
refetchInterval: 9e4,
|
|
1729
1734
|
queryFn: async () => {
|
|
1730
|
-
const
|
|
1731
|
-
const data = await response.json();
|
|
1735
|
+
const data = await getSpkMarkets();
|
|
1732
1736
|
return {
|
|
1733
1737
|
list: Object.entries(data.markets.node).map(([name, node]) => ({
|
|
1734
1738
|
name,
|
|
@@ -1743,8 +1747,10 @@ function getSpkWalletQueryOptions(username) {
|
|
|
1743
1747
|
return queryOptions({
|
|
1744
1748
|
queryKey: ["assets", "spk", "wallet", username],
|
|
1745
1749
|
queryFn: async () => {
|
|
1746
|
-
|
|
1747
|
-
|
|
1750
|
+
if (!username) {
|
|
1751
|
+
throw new Error("[SDK][Wallets][SPK] \u2013 username wasn't provided");
|
|
1752
|
+
}
|
|
1753
|
+
return getSpkWallet(username);
|
|
1748
1754
|
},
|
|
1749
1755
|
enabled: !!username,
|
|
1750
1756
|
staleTime: 6e4,
|
|
@@ -1916,32 +1922,7 @@ function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
|
1916
1922
|
return queryOptions({
|
|
1917
1923
|
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1918
1924
|
queryFn: async () => {
|
|
1919
|
-
|
|
1920
|
-
const response = await fetch(
|
|
1921
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1922
|
-
{
|
|
1923
|
-
method: "POST",
|
|
1924
|
-
body: JSON.stringify({
|
|
1925
|
-
jsonrpc: "2.0",
|
|
1926
|
-
method: "find",
|
|
1927
|
-
params: {
|
|
1928
|
-
contract: "market",
|
|
1929
|
-
table: "metrics",
|
|
1930
|
-
query: {
|
|
1931
|
-
...symbol && { symbol },
|
|
1932
|
-
...account && { account }
|
|
1933
|
-
}
|
|
1934
|
-
},
|
|
1935
|
-
id: 1
|
|
1936
|
-
}),
|
|
1937
|
-
headers: { "Content-type": "application/json" }
|
|
1938
|
-
}
|
|
1939
|
-
);
|
|
1940
|
-
const data = await response.json();
|
|
1941
|
-
return data.result;
|
|
1942
|
-
} catch (e) {
|
|
1943
|
-
return [];
|
|
1944
|
-
}
|
|
1925
|
+
return getHiveEngineTokensMarket(account, symbol);
|
|
1945
1926
|
}
|
|
1946
1927
|
});
|
|
1947
1928
|
}
|
|
@@ -2047,48 +2028,10 @@ function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allToke
|
|
|
2047
2028
|
if (!account) {
|
|
2048
2029
|
throw new Error("[HiveEngine] No account in a balances query");
|
|
2049
2030
|
}
|
|
2050
|
-
const
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
method: "POST",
|
|
2054
|
-
body: JSON.stringify({
|
|
2055
|
-
jsonrpc: "2.0",
|
|
2056
|
-
method: "find",
|
|
2057
|
-
params: {
|
|
2058
|
-
contract: "tokens",
|
|
2059
|
-
table: "balances",
|
|
2060
|
-
query: {
|
|
2061
|
-
account
|
|
2062
|
-
}
|
|
2063
|
-
},
|
|
2064
|
-
id: 1
|
|
2065
|
-
}),
|
|
2066
|
-
headers: { "Content-type": "application/json" }
|
|
2067
|
-
}
|
|
2068
|
-
);
|
|
2069
|
-
const balancesData = await balancesResponse.json();
|
|
2070
|
-
const balances = balancesData.result || [];
|
|
2071
|
-
const tokensResponse = await fetch(
|
|
2072
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2073
|
-
{
|
|
2074
|
-
method: "POST",
|
|
2075
|
-
body: JSON.stringify({
|
|
2076
|
-
jsonrpc: "2.0",
|
|
2077
|
-
method: "find",
|
|
2078
|
-
params: {
|
|
2079
|
-
contract: "tokens",
|
|
2080
|
-
table: "tokens",
|
|
2081
|
-
query: {
|
|
2082
|
-
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2083
|
-
}
|
|
2084
|
-
},
|
|
2085
|
-
id: 2
|
|
2086
|
-
}),
|
|
2087
|
-
headers: { "Content-type": "application/json" }
|
|
2088
|
-
}
|
|
2031
|
+
const balances = await getHiveEngineTokensBalances(account);
|
|
2032
|
+
const tokens = await getHiveEngineTokensMetadata(
|
|
2033
|
+
balances.map((t) => t.symbol)
|
|
2089
2034
|
);
|
|
2090
|
-
const tokensData = await tokensResponse.json();
|
|
2091
|
-
const tokens = tokensData.result || [];
|
|
2092
2035
|
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2093
2036
|
const metrics = Array.isArray(
|
|
2094
2037
|
allTokens
|
|
@@ -2133,27 +2076,7 @@ function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
|
2133
2076
|
staleTime: 6e4,
|
|
2134
2077
|
refetchInterval: 9e4,
|
|
2135
2078
|
queryFn: async () => {
|
|
2136
|
-
|
|
2137
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2138
|
-
{
|
|
2139
|
-
method: "POST",
|
|
2140
|
-
body: JSON.stringify({
|
|
2141
|
-
jsonrpc: "2.0",
|
|
2142
|
-
method: "find",
|
|
2143
|
-
params: {
|
|
2144
|
-
contract: "tokens",
|
|
2145
|
-
table: "tokens",
|
|
2146
|
-
query: {
|
|
2147
|
-
symbol: { $in: tokens }
|
|
2148
|
-
}
|
|
2149
|
-
},
|
|
2150
|
-
id: 2
|
|
2151
|
-
}),
|
|
2152
|
-
headers: { "Content-type": "application/json" }
|
|
2153
|
-
}
|
|
2154
|
-
);
|
|
2155
|
-
const data = await response.json();
|
|
2156
|
-
return data.result;
|
|
2079
|
+
return getHiveEngineTokensMetadata(tokens);
|
|
2157
2080
|
}
|
|
2158
2081
|
});
|
|
2159
2082
|
}
|
|
@@ -2163,27 +2086,7 @@ function getHiveEngineTokensBalancesQueryOptions(username) {
|
|
|
2163
2086
|
staleTime: 6e4,
|
|
2164
2087
|
refetchInterval: 9e4,
|
|
2165
2088
|
queryFn: async () => {
|
|
2166
|
-
|
|
2167
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2168
|
-
{
|
|
2169
|
-
method: "POST",
|
|
2170
|
-
body: JSON.stringify({
|
|
2171
|
-
jsonrpc: "2.0",
|
|
2172
|
-
method: "find",
|
|
2173
|
-
params: {
|
|
2174
|
-
contract: "tokens",
|
|
2175
|
-
table: "balances",
|
|
2176
|
-
query: {
|
|
2177
|
-
account: username
|
|
2178
|
-
}
|
|
2179
|
-
},
|
|
2180
|
-
id: 1
|
|
2181
|
-
}),
|
|
2182
|
-
headers: { "Content-type": "application/json" }
|
|
2183
|
-
}
|
|
2184
|
-
);
|
|
2185
|
-
const data = await response.json();
|
|
2186
|
-
return data.result;
|
|
2089
|
+
return getHiveEngineTokensBalances(username);
|
|
2187
2090
|
}
|
|
2188
2091
|
});
|
|
2189
2092
|
}
|
|
@@ -2193,25 +2096,7 @@ function getHiveEngineTokensMarketQueryOptions() {
|
|
|
2193
2096
|
staleTime: 6e4,
|
|
2194
2097
|
refetchInterval: 9e4,
|
|
2195
2098
|
queryFn: async () => {
|
|
2196
|
-
|
|
2197
|
-
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2198
|
-
{
|
|
2199
|
-
method: "POST",
|
|
2200
|
-
body: JSON.stringify({
|
|
2201
|
-
jsonrpc: "2.0",
|
|
2202
|
-
method: "find",
|
|
2203
|
-
params: {
|
|
2204
|
-
contract: "market",
|
|
2205
|
-
table: "metrics",
|
|
2206
|
-
query: {}
|
|
2207
|
-
},
|
|
2208
|
-
id: 1
|
|
2209
|
-
}),
|
|
2210
|
-
headers: { "Content-type": "application/json" }
|
|
2211
|
-
}
|
|
2212
|
-
);
|
|
2213
|
-
const data = await response.json();
|
|
2214
|
-
return data.result;
|
|
2099
|
+
return getHiveEngineTokensMarket();
|
|
2215
2100
|
}
|
|
2216
2101
|
});
|
|
2217
2102
|
}
|
|
@@ -2281,18 +2166,12 @@ function getHiveEngineTokenTransactionsQueryOptions(username, symbol, limit = 20
|
|
|
2281
2166
|
"[SDK][Wallets] \u2013 hive engine token or username missed"
|
|
2282
2167
|
);
|
|
2283
2168
|
}
|
|
2284
|
-
|
|
2285
|
-
|
|
2169
|
+
return getHiveEngineTokenTransactions(
|
|
2170
|
+
username,
|
|
2171
|
+
symbol,
|
|
2172
|
+
limit,
|
|
2173
|
+
pageParam
|
|
2286
2174
|
);
|
|
2287
|
-
url.searchParams.set("account", username);
|
|
2288
|
-
url.searchParams.set("symbol", symbol);
|
|
2289
|
-
url.searchParams.set("limit", limit.toString());
|
|
2290
|
-
url.searchParams.set("offset", pageParam.toString());
|
|
2291
|
-
const response = await fetch(url, {
|
|
2292
|
-
method: "GET",
|
|
2293
|
-
headers: { "Content-type": "application/json" }
|
|
2294
|
-
});
|
|
2295
|
-
return await response.json();
|
|
2296
2175
|
}
|
|
2297
2176
|
});
|
|
2298
2177
|
}
|
|
@@ -2302,15 +2181,7 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2302
2181
|
staleTime: 6e4,
|
|
2303
2182
|
refetchInterval: 9e4,
|
|
2304
2183
|
queryFn: async () => {
|
|
2305
|
-
|
|
2306
|
-
`${CONFIG.privateApiHost}/private-api/engine-chart-api`
|
|
2307
|
-
);
|
|
2308
|
-
url.searchParams.set("symbol", symbol);
|
|
2309
|
-
url.searchParams.set("interval", interval);
|
|
2310
|
-
const response = await fetch(url, {
|
|
2311
|
-
headers: { "Content-type": "application/json" }
|
|
2312
|
-
});
|
|
2313
|
-
return await response.json();
|
|
2184
|
+
return getHiveEngineTokenMetrics(symbol, interval);
|
|
2314
2185
|
}
|
|
2315
2186
|
});
|
|
2316
2187
|
}
|
|
@@ -2322,13 +2193,9 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2322
2193
|
enabled: !!username,
|
|
2323
2194
|
queryFn: async () => {
|
|
2324
2195
|
try {
|
|
2325
|
-
const
|
|
2326
|
-
|
|
2196
|
+
const data = await getHiveEngineUnclaimedRewards(
|
|
2197
|
+
username
|
|
2327
2198
|
);
|
|
2328
|
-
if (!response.ok) {
|
|
2329
|
-
return [];
|
|
2330
|
-
}
|
|
2331
|
-
const data = await response.json();
|
|
2332
2199
|
return Object.values(data).filter(
|
|
2333
2200
|
({ pending_token }) => pending_token > 0
|
|
2334
2201
|
);
|
|
@@ -2338,7 +2205,25 @@ function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
|
2338
2205
|
}
|
|
2339
2206
|
});
|
|
2340
2207
|
}
|
|
2341
|
-
|
|
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) {
|
|
2342
2227
|
const parsedAsset = parseAsset(payload.amount);
|
|
2343
2228
|
const quantity = parsedAsset.amount.toString();
|
|
2344
2229
|
const operation = [
|
|
@@ -2375,24 +2260,8 @@ async function delegateEngineToken(payload) {
|
|
|
2375
2260
|
required_posting_auths: []
|
|
2376
2261
|
};
|
|
2377
2262
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2378
|
-
} else if (payload.type === "keychain") {
|
|
2379
|
-
return
|
|
2380
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2381
|
-
payload.from,
|
|
2382
|
-
"ssc-mainnet-hive",
|
|
2383
|
-
"Active",
|
|
2384
|
-
operation[1].json,
|
|
2385
|
-
"Token Delegation",
|
|
2386
|
-
(resp) => {
|
|
2387
|
-
if (!resp.success) {
|
|
2388
|
-
reject({ message: "Operation cancelled" });
|
|
2389
|
-
}
|
|
2390
|
-
resolve(resp);
|
|
2391
|
-
}
|
|
2392
|
-
)
|
|
2393
|
-
);
|
|
2394
|
-
} else if (payload.type === "hiveauth") {
|
|
2395
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2263
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2264
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2396
2265
|
} else {
|
|
2397
2266
|
return hs.sendOperation(
|
|
2398
2267
|
operation,
|
|
@@ -2402,7 +2271,7 @@ async function delegateEngineToken(payload) {
|
|
|
2402
2271
|
);
|
|
2403
2272
|
}
|
|
2404
2273
|
}
|
|
2405
|
-
async function undelegateEngineToken(payload) {
|
|
2274
|
+
async function undelegateEngineToken(payload, auth) {
|
|
2406
2275
|
const parsedAsset = parseAsset(payload.amount);
|
|
2407
2276
|
const quantity = parsedAsset.amount.toString();
|
|
2408
2277
|
const operation = [
|
|
@@ -2439,24 +2308,8 @@ async function undelegateEngineToken(payload) {
|
|
|
2439
2308
|
required_posting_auths: []
|
|
2440
2309
|
};
|
|
2441
2310
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2442
|
-
} else if (payload.type === "keychain") {
|
|
2443
|
-
return
|
|
2444
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2445
|
-
payload.from,
|
|
2446
|
-
"ssc-mainnet-hive",
|
|
2447
|
-
"Active",
|
|
2448
|
-
operation[1].json,
|
|
2449
|
-
"Token Undelegation",
|
|
2450
|
-
(resp) => {
|
|
2451
|
-
if (!resp.success) {
|
|
2452
|
-
reject({ message: "Operation cancelled" });
|
|
2453
|
-
}
|
|
2454
|
-
resolve(resp);
|
|
2455
|
-
}
|
|
2456
|
-
)
|
|
2457
|
-
);
|
|
2458
|
-
} else if (payload.type === "hiveauth") {
|
|
2459
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2311
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2312
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2460
2313
|
} else {
|
|
2461
2314
|
return hs.sendOperation(
|
|
2462
2315
|
operation,
|
|
@@ -2466,7 +2319,7 @@ async function undelegateEngineToken(payload) {
|
|
|
2466
2319
|
);
|
|
2467
2320
|
}
|
|
2468
2321
|
}
|
|
2469
|
-
async function stakeEngineToken(payload) {
|
|
2322
|
+
async function stakeEngineToken(payload, auth) {
|
|
2470
2323
|
const parsedAsset = parseAsset(payload.amount);
|
|
2471
2324
|
const quantity = parsedAsset.amount.toString();
|
|
2472
2325
|
const operation = [
|
|
@@ -2503,24 +2356,8 @@ async function stakeEngineToken(payload) {
|
|
|
2503
2356
|
required_posting_auths: []
|
|
2504
2357
|
};
|
|
2505
2358
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2506
|
-
} else if (payload.type === "keychain") {
|
|
2507
|
-
return
|
|
2508
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2509
|
-
payload.from,
|
|
2510
|
-
"ssc-mainnet-hive",
|
|
2511
|
-
"Active",
|
|
2512
|
-
operation[1].json,
|
|
2513
|
-
"Token Staking",
|
|
2514
|
-
(resp) => {
|
|
2515
|
-
if (!resp.success) {
|
|
2516
|
-
reject({ message: "Operation cancelled" });
|
|
2517
|
-
}
|
|
2518
|
-
resolve(resp);
|
|
2519
|
-
}
|
|
2520
|
-
)
|
|
2521
|
-
);
|
|
2522
|
-
} else if (payload.type === "hiveauth") {
|
|
2523
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2359
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2360
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2524
2361
|
} else {
|
|
2525
2362
|
return hs.sendOperation(
|
|
2526
2363
|
operation,
|
|
@@ -2530,7 +2367,7 @@ async function stakeEngineToken(payload) {
|
|
|
2530
2367
|
);
|
|
2531
2368
|
}
|
|
2532
2369
|
}
|
|
2533
|
-
async function unstakeEngineToken(payload) {
|
|
2370
|
+
async function unstakeEngineToken(payload, auth) {
|
|
2534
2371
|
const parsedAsset = parseAsset(payload.amount);
|
|
2535
2372
|
const quantity = parsedAsset.amount.toString();
|
|
2536
2373
|
const operation = [
|
|
@@ -2567,24 +2404,8 @@ async function unstakeEngineToken(payload) {
|
|
|
2567
2404
|
required_posting_auths: []
|
|
2568
2405
|
};
|
|
2569
2406
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2570
|
-
} else if (payload.type === "keychain") {
|
|
2571
|
-
return
|
|
2572
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2573
|
-
payload.from,
|
|
2574
|
-
"ssc-mainnet-hive",
|
|
2575
|
-
"Active",
|
|
2576
|
-
operation[1].json,
|
|
2577
|
-
"Token Unstaking",
|
|
2578
|
-
(resp) => {
|
|
2579
|
-
if (!resp.success) {
|
|
2580
|
-
reject({ message: "Operation cancelled" });
|
|
2581
|
-
}
|
|
2582
|
-
resolve(resp);
|
|
2583
|
-
}
|
|
2584
|
-
)
|
|
2585
|
-
);
|
|
2586
|
-
} else if (payload.type === "hiveauth") {
|
|
2587
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2407
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2408
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2588
2409
|
} else {
|
|
2589
2410
|
return hs.sendOperation(
|
|
2590
2411
|
operation,
|
|
@@ -2594,7 +2415,7 @@ async function unstakeEngineToken(payload) {
|
|
|
2594
2415
|
);
|
|
2595
2416
|
}
|
|
2596
2417
|
}
|
|
2597
|
-
async function transferEngineToken(payload) {
|
|
2418
|
+
async function transferEngineToken(payload, auth) {
|
|
2598
2419
|
const parsedAsset = parseAsset(payload.amount);
|
|
2599
2420
|
const quantity = parsedAsset.amount.toString();
|
|
2600
2421
|
const operation = [
|
|
@@ -2633,24 +2454,8 @@ async function transferEngineToken(payload) {
|
|
|
2633
2454
|
required_posting_auths: []
|
|
2634
2455
|
};
|
|
2635
2456
|
return CONFIG.hiveClient.broadcast.json(op, key);
|
|
2636
|
-
} else if (payload.type === "keychain") {
|
|
2637
|
-
return
|
|
2638
|
-
(resolve, reject) => window.hive_keychain?.requestCustomJson(
|
|
2639
|
-
payload.from,
|
|
2640
|
-
"ssc-mainnet-hive",
|
|
2641
|
-
"Active",
|
|
2642
|
-
operation[1].json,
|
|
2643
|
-
"Token Transfer",
|
|
2644
|
-
(resp) => {
|
|
2645
|
-
if (!resp.success) {
|
|
2646
|
-
reject({ message: "Operation cancelled" });
|
|
2647
|
-
}
|
|
2648
|
-
resolve(resp);
|
|
2649
|
-
}
|
|
2650
|
-
)
|
|
2651
|
-
);
|
|
2652
|
-
} else if (payload.type === "hiveauth") {
|
|
2653
|
-
return broadcastWithWalletHiveAuth(payload.from, [operation], "active");
|
|
2457
|
+
} else if (payload.type === "keychain" || payload.type === "hiveauth") {
|
|
2458
|
+
return broadcastHiveEngineOperation(payload, operation, auth);
|
|
2654
2459
|
} else {
|
|
2655
2460
|
return hs.sendOperation(
|
|
2656
2461
|
operation,
|
|
@@ -2660,6 +2465,105 @@ async function transferEngineToken(payload) {
|
|
|
2660
2465
|
);
|
|
2661
2466
|
}
|
|
2662
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
|
+
}
|
|
2663
2567
|
function getPointsQueryOptions(username) {
|
|
2664
2568
|
return queryOptions({
|
|
2665
2569
|
queryKey: ["assets", "points", username],
|
|
@@ -2747,7 +2651,7 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2747
2651
|
}
|
|
2748
2652
|
|
|
2749
2653
|
// src/modules/assets/points/mutations/claim-points.ts
|
|
2750
|
-
function useClaimPoints(username, onSuccess, onError) {
|
|
2654
|
+
function useClaimPoints(username, accessToken, onSuccess, onError) {
|
|
2751
2655
|
const { mutateAsync: recordActivity } = EcencyAnalytics.useRecordActivity(
|
|
2752
2656
|
username,
|
|
2753
2657
|
"points-claimed"
|
|
@@ -2757,16 +2661,31 @@ function useClaimPoints(username, onSuccess, onError) {
|
|
|
2757
2661
|
mutationFn: async () => {
|
|
2758
2662
|
if (!username) {
|
|
2759
2663
|
throw new Error(
|
|
2760
|
-
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn
|
|
2664
|
+
"[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn't provided"
|
|
2761
2665
|
);
|
|
2762
2666
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
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();
|
|
2770
2689
|
},
|
|
2771
2690
|
onError,
|
|
2772
2691
|
onSuccess: () => {
|
|
@@ -2794,7 +2713,7 @@ async function transferPoint({
|
|
|
2794
2713
|
memo,
|
|
2795
2714
|
type,
|
|
2796
2715
|
...payload
|
|
2797
|
-
}) {
|
|
2716
|
+
}, auth) {
|
|
2798
2717
|
const op = [
|
|
2799
2718
|
"custom_json",
|
|
2800
2719
|
{
|
|
@@ -2813,11 +2732,14 @@ async function transferPoint({
|
|
|
2813
2732
|
const { key } = payload;
|
|
2814
2733
|
return CONFIG.hiveClient.broadcast.sendOperations([op], key);
|
|
2815
2734
|
}
|
|
2816
|
-
if (type === "keychain") {
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
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");
|
|
2821
2743
|
}
|
|
2822
2744
|
return hs.sendOperation(op, { callback: `https://ecency.com/@${from}/wallet` }, () => {
|
|
2823
2745
|
});
|
|
@@ -4041,7 +3963,7 @@ function useCheckWalletExistence() {
|
|
|
4041
3963
|
}
|
|
4042
3964
|
});
|
|
4043
3965
|
}
|
|
4044
|
-
function useUpdateAccountWithWallets(username) {
|
|
3966
|
+
function useUpdateAccountWithWallets(username, accessToken) {
|
|
4045
3967
|
const fetchApi = getBoundFetch();
|
|
4046
3968
|
return useMutation({
|
|
4047
3969
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
|
|
@@ -4051,6 +3973,11 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4051
3973
|
return new Response(null, { status: 204 });
|
|
4052
3974
|
}
|
|
4053
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
|
+
}
|
|
4054
3981
|
return fetchApi(CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
4055
3982
|
method: "POST",
|
|
4056
3983
|
headers: {
|
|
@@ -4058,7 +3985,7 @@ function useUpdateAccountWithWallets(username) {
|
|
|
4058
3985
|
},
|
|
4059
3986
|
body: JSON.stringify({
|
|
4060
3987
|
username,
|
|
4061
|
-
code:
|
|
3988
|
+
code: accessToken,
|
|
4062
3989
|
token: primaryToken,
|
|
4063
3990
|
address: primaryAddress,
|
|
4064
3991
|
status: 3,
|
|
@@ -4192,14 +4119,10 @@ function getGroupedChainTokens(tokens, defaultShow) {
|
|
|
4192
4119
|
)
|
|
4193
4120
|
);
|
|
4194
4121
|
}
|
|
4195
|
-
function useSaveWalletInformationToMetadata(username,
|
|
4122
|
+
function useSaveWalletInformationToMetadata(username, auth, options2) {
|
|
4196
4123
|
const queryClient = useQueryClient();
|
|
4197
4124
|
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
|
|
4198
|
-
const { mutateAsync: updateProfile } = useAccountUpdate(
|
|
4199
|
-
username,
|
|
4200
|
-
accessToken,
|
|
4201
|
-
auth
|
|
4202
|
-
);
|
|
4125
|
+
const { mutateAsync: updateProfile } = useAccountUpdate(username, auth);
|
|
4203
4126
|
return useMutation({
|
|
4204
4127
|
mutationKey: [
|
|
4205
4128
|
"ecency-wallets",
|
|
@@ -4281,7 +4204,7 @@ var engineOperationToFunctionMap = {
|
|
|
4281
4204
|
["delegate" /* Delegate */]: delegateEngineToken,
|
|
4282
4205
|
["undelegate" /* Undelegate */]: undelegateEngineToken
|
|
4283
4206
|
};
|
|
4284
|
-
function useWalletOperation(username, asset, operation) {
|
|
4207
|
+
function useWalletOperation(username, asset, operation, auth) {
|
|
4285
4208
|
const { mutateAsync: recordActivity } = EcencyAnalytics.useRecordActivity(
|
|
4286
4209
|
username,
|
|
4287
4210
|
operation
|
|
@@ -4291,17 +4214,18 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4291
4214
|
mutationFn: async (payload) => {
|
|
4292
4215
|
const operationFn = operationToFunctionMap[asset]?.[operation];
|
|
4293
4216
|
if (operationFn) {
|
|
4294
|
-
return operationFn(payload);
|
|
4217
|
+
return operationFn(payload, auth);
|
|
4295
4218
|
}
|
|
4296
4219
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
4297
4220
|
await getQueryClient().prefetchQuery(balancesListQuery);
|
|
4298
4221
|
const balances = getQueryClient().getQueryData(
|
|
4299
4222
|
balancesListQuery.queryKey
|
|
4300
4223
|
);
|
|
4301
|
-
|
|
4224
|
+
const engineBalances = balances ?? [];
|
|
4225
|
+
if (engineBalances.some((balance) => balance.symbol === asset)) {
|
|
4302
4226
|
const operationFn2 = engineOperationToFunctionMap[operation];
|
|
4303
4227
|
if (operationFn2) {
|
|
4304
|
-
return operationFn2({ ...payload, asset });
|
|
4228
|
+
return operationFn2({ ...payload, asset }, auth);
|
|
4305
4229
|
}
|
|
4306
4230
|
}
|
|
4307
4231
|
throw new Error("[SDK][Wallets] \u2013 no operation for given asset");
|
|
@@ -4338,6 +4262,6 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4338
4262
|
// src/index.ts
|
|
4339
4263
|
rememberScryptBsvVersion();
|
|
4340
4264
|
|
|
4341
|
-
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 };
|
|
4342
4266
|
//# sourceMappingURL=index.js.map
|
|
4343
4267
|
//# sourceMappingURL=index.js.map
|