@ecency/wallets 1.4.18 → 1.4.20
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 +72 -2
- package/dist/browser/index.js +229 -29
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +230 -28
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +229 -29
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -681,11 +681,31 @@ function getHiveAssetGeneralInfoQueryOptions(username) {
|
|
|
681
681
|
);
|
|
682
682
|
const marketTicker = await sdk.CONFIG.hiveClient.call("condenser_api", "get_ticker", []).catch(() => void 0);
|
|
683
683
|
const marketPrice = Number.parseFloat(marketTicker?.latest ?? "");
|
|
684
|
+
if (!accountData) {
|
|
685
|
+
return {
|
|
686
|
+
name: "HIVE",
|
|
687
|
+
title: "Hive",
|
|
688
|
+
price: Number.isFinite(marketPrice) ? marketPrice : dynamicProps ? dynamicProps.base / dynamicProps.quote : 0,
|
|
689
|
+
accountBalance: 0
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
const liquidBalance = parseAsset(accountData.balance).amount;
|
|
693
|
+
const savingsBalance = parseAsset(accountData.savings_balance).amount;
|
|
684
694
|
return {
|
|
685
695
|
name: "HIVE",
|
|
686
696
|
title: "Hive",
|
|
687
697
|
price: Number.isFinite(marketPrice) ? marketPrice : dynamicProps ? dynamicProps.base / dynamicProps.quote : 0,
|
|
688
|
-
accountBalance:
|
|
698
|
+
accountBalance: liquidBalance + savingsBalance,
|
|
699
|
+
parts: [
|
|
700
|
+
{
|
|
701
|
+
name: "current",
|
|
702
|
+
balance: liquidBalance
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
name: "savings",
|
|
706
|
+
balance: savingsBalance
|
|
707
|
+
}
|
|
708
|
+
]
|
|
689
709
|
};
|
|
690
710
|
}
|
|
691
711
|
});
|
|
@@ -734,33 +754,76 @@ function getHivePowerAssetGeneralInfoQueryOptions(username) {
|
|
|
734
754
|
const marketTicker = await sdk.CONFIG.hiveClient.call("condenser_api", "get_ticker", []).catch(() => void 0);
|
|
735
755
|
const marketPrice = Number.parseFloat(marketTicker?.latest ?? "");
|
|
736
756
|
const price = Number.isFinite(marketPrice) ? marketPrice : dynamicProps.base / dynamicProps.quote;
|
|
757
|
+
const vestingShares = parseAsset(accountData.vesting_shares).amount;
|
|
758
|
+
const delegatedVests = parseAsset(accountData.delegated_vesting_shares).amount;
|
|
759
|
+
const receivedVests = parseAsset(accountData.received_vesting_shares).amount;
|
|
760
|
+
const withdrawRateVests = parseAsset(accountData.vesting_withdraw_rate).amount;
|
|
761
|
+
const remainingToWithdrawVests = Math.max(
|
|
762
|
+
(Number(accountData.to_withdraw) - Number(accountData.withdrawn)) / 1e6,
|
|
763
|
+
0
|
|
764
|
+
);
|
|
765
|
+
const nextWithdrawalVests = !isEmptyDate(accountData.next_vesting_withdrawal) ? Math.min(withdrawRateVests, remainingToWithdrawVests) : 0;
|
|
766
|
+
const hpBalance = +vestsToHp(
|
|
767
|
+
vestingShares,
|
|
768
|
+
dynamicProps.hivePerMVests
|
|
769
|
+
).toFixed(3);
|
|
770
|
+
const outgoingDelegationsHp = +vestsToHp(
|
|
771
|
+
delegatedVests,
|
|
772
|
+
dynamicProps.hivePerMVests
|
|
773
|
+
).toFixed(3);
|
|
774
|
+
const incomingDelegationsHp = +vestsToHp(
|
|
775
|
+
receivedVests,
|
|
776
|
+
dynamicProps.hivePerMVests
|
|
777
|
+
).toFixed(3);
|
|
778
|
+
const pendingPowerDownHp = +vestsToHp(
|
|
779
|
+
remainingToWithdrawVests,
|
|
780
|
+
dynamicProps.hivePerMVests
|
|
781
|
+
).toFixed(3);
|
|
782
|
+
const nextPowerDownHp = +vestsToHp(
|
|
783
|
+
nextWithdrawalVests,
|
|
784
|
+
dynamicProps.hivePerMVests
|
|
785
|
+
).toFixed(3);
|
|
786
|
+
const totalBalance = Math.max(hpBalance - pendingPowerDownHp, 0);
|
|
787
|
+
const availableHp = Math.max(
|
|
788
|
+
// Owned HP minus the portions already delegated away.
|
|
789
|
+
hpBalance - outgoingDelegationsHp,
|
|
790
|
+
0
|
|
791
|
+
);
|
|
737
792
|
return {
|
|
738
793
|
name: "HP",
|
|
739
794
|
title: "Hive Power",
|
|
740
795
|
price,
|
|
741
|
-
accountBalance: +
|
|
742
|
-
parseAsset(accountData.vesting_shares).amount,
|
|
743
|
-
// parseAsset(accountData.delegated_vesting_shares).amount +
|
|
744
|
-
// parseAsset(accountData.received_vesting_shares).amount -
|
|
745
|
-
// nextVestingSharesWithdrawal,
|
|
746
|
-
dynamicProps.hivePerMVests
|
|
747
|
-
).toFixed(3),
|
|
796
|
+
accountBalance: +totalBalance.toFixed(3),
|
|
748
797
|
apr: getAPR(dynamicProps),
|
|
749
798
|
parts: [
|
|
750
799
|
{
|
|
751
|
-
name: "
|
|
752
|
-
balance:
|
|
753
|
-
parseAsset(accountData.delegated_vesting_shares).amount,
|
|
754
|
-
dynamicProps.hivePerMVests
|
|
755
|
-
).toFixed(3)
|
|
800
|
+
name: "hp_balance",
|
|
801
|
+
balance: hpBalance
|
|
756
802
|
},
|
|
757
803
|
{
|
|
758
|
-
name: "
|
|
759
|
-
balance: +
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
804
|
+
name: "available",
|
|
805
|
+
balance: +availableHp.toFixed(3)
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
name: "outgoing_delegations",
|
|
809
|
+
balance: outgoingDelegationsHp
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
name: "incoming_delegations",
|
|
813
|
+
balance: incomingDelegationsHp
|
|
814
|
+
},
|
|
815
|
+
...pendingPowerDownHp > 0 ? [
|
|
816
|
+
{
|
|
817
|
+
name: "pending_power_down",
|
|
818
|
+
balance: +pendingPowerDownHp.toFixed(3)
|
|
819
|
+
}
|
|
820
|
+
] : [],
|
|
821
|
+
...nextPowerDownHp > 0 && nextPowerDownHp !== pendingPowerDownHp ? [
|
|
822
|
+
{
|
|
823
|
+
name: "next_power_down",
|
|
824
|
+
balance: +nextPowerDownHp.toFixed(3)
|
|
825
|
+
}
|
|
826
|
+
] : []
|
|
764
827
|
]
|
|
765
828
|
};
|
|
766
829
|
}
|
|
@@ -811,7 +874,7 @@ function getHbdAssetGeneralInfoQueryOptions(username) {
|
|
|
811
874
|
apr: ((dynamicProps?.hbdInterestRate ?? 0) / 100).toFixed(3),
|
|
812
875
|
parts: [
|
|
813
876
|
{
|
|
814
|
-
name: "
|
|
877
|
+
name: "current",
|
|
815
878
|
balance: parseAsset(accountData.hbd_balance).amount
|
|
816
879
|
},
|
|
817
880
|
{
|
|
@@ -1187,6 +1250,36 @@ async function transferToSavingsHive(payload) {
|
|
|
1187
1250
|
);
|
|
1188
1251
|
}
|
|
1189
1252
|
}
|
|
1253
|
+
async function transferFromSavingsHive(payload) {
|
|
1254
|
+
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1255
|
+
const operationPayload = {
|
|
1256
|
+
from: payload.from,
|
|
1257
|
+
to: payload.to,
|
|
1258
|
+
amount: payload.amount,
|
|
1259
|
+
memo: payload.memo,
|
|
1260
|
+
request_id: requestId
|
|
1261
|
+
};
|
|
1262
|
+
if (payload.type === "key" && "key" in payload) {
|
|
1263
|
+
const { key } = payload;
|
|
1264
|
+
return sdk.CONFIG.hiveClient.broadcast.sendOperations(
|
|
1265
|
+
[["transfer_from_savings", operationPayload]],
|
|
1266
|
+
key
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
if (payload.type === "keychain") {
|
|
1270
|
+
return sdk.Keychain.broadcast(
|
|
1271
|
+
payload.from,
|
|
1272
|
+
[["transfer_from_savings", operationPayload]],
|
|
1273
|
+
"Active"
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
return hs__default.default.sendOperation(
|
|
1277
|
+
["transfer_from_savings", operationPayload],
|
|
1278
|
+
{ callback: `https://ecency.com/@${payload.from}/wallet` },
|
|
1279
|
+
() => {
|
|
1280
|
+
}
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1190
1283
|
async function powerUpHive(payload) {
|
|
1191
1284
|
if (payload.type === "key" && "key" in payload) {
|
|
1192
1285
|
const { key, type, ...params } = payload;
|
|
@@ -1325,15 +1418,60 @@ function useClaimRewards(username, onSuccess) {
|
|
|
1325
1418
|
}
|
|
1326
1419
|
);
|
|
1327
1420
|
}
|
|
1421
|
+
async function claimInterestHive(payload) {
|
|
1422
|
+
const requestId = payload.request_id ?? Date.now() >>> 0;
|
|
1423
|
+
const baseOperation = {
|
|
1424
|
+
from: payload.from,
|
|
1425
|
+
to: payload.to,
|
|
1426
|
+
amount: payload.amount,
|
|
1427
|
+
memo: payload.memo,
|
|
1428
|
+
request_id: requestId
|
|
1429
|
+
};
|
|
1430
|
+
const cancelOperation = {
|
|
1431
|
+
from: payload.from,
|
|
1432
|
+
request_id: requestId
|
|
1433
|
+
};
|
|
1434
|
+
if (payload.type === "key" && "key" in payload) {
|
|
1435
|
+
const { key } = payload;
|
|
1436
|
+
return sdk.CONFIG.hiveClient.broadcast.sendOperations(
|
|
1437
|
+
[
|
|
1438
|
+
["transfer_from_savings", baseOperation],
|
|
1439
|
+
["cancel_transfer_from_savings", cancelOperation]
|
|
1440
|
+
],
|
|
1441
|
+
key
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
if (payload.type === "keychain") {
|
|
1445
|
+
return sdk.Keychain.broadcast(
|
|
1446
|
+
payload.from,
|
|
1447
|
+
[
|
|
1448
|
+
["transfer_from_savings", baseOperation],
|
|
1449
|
+
["cancel_transfer_from_savings", cancelOperation]
|
|
1450
|
+
],
|
|
1451
|
+
"Active"
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
return hs__default.default.sendOperations(
|
|
1455
|
+
[
|
|
1456
|
+
["transfer_from_savings", baseOperation],
|
|
1457
|
+
["cancel_transfer_from_savings", cancelOperation]
|
|
1458
|
+
],
|
|
1459
|
+
{ callback: `https://ecency.com/@${payload.from}/wallet` },
|
|
1460
|
+
() => {
|
|
1461
|
+
}
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1328
1464
|
|
|
1329
1465
|
// src/modules/assets/types/asset-operation.ts
|
|
1330
1466
|
var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
1331
1467
|
AssetOperation2["Transfer"] = "transfer";
|
|
1332
1468
|
AssetOperation2["TransferToSavings"] = "transfer-saving";
|
|
1469
|
+
AssetOperation2["WithdrawFromSavings"] = "withdraw-saving";
|
|
1333
1470
|
AssetOperation2["Delegate"] = "delegate";
|
|
1334
1471
|
AssetOperation2["PowerUp"] = "power-up";
|
|
1335
1472
|
AssetOperation2["PowerDown"] = "power-down";
|
|
1336
|
-
AssetOperation2["WithdrawRoutes"] = "withdraw-
|
|
1473
|
+
AssetOperation2["WithdrawRoutes"] = "withdraw-routes";
|
|
1474
|
+
AssetOperation2["ClaimInterest"] = "claim-interest";
|
|
1337
1475
|
AssetOperation2["Swap"] = "swap";
|
|
1338
1476
|
AssetOperation2["Gift"] = "gift";
|
|
1339
1477
|
AssetOperation2["Promote"] = "promote";
|
|
@@ -2989,26 +3127,86 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
2989
3127
|
return reactQuery.queryOptions({
|
|
2990
3128
|
queryKey: ["wallets", "token-operations", token, username, isForOwner],
|
|
2991
3129
|
queryFn: async () => {
|
|
3130
|
+
const queryClient = sdk.getQueryClient();
|
|
3131
|
+
const ensureAssetInfo = async () => {
|
|
3132
|
+
if (!isForOwner || !username) {
|
|
3133
|
+
return void 0;
|
|
3134
|
+
}
|
|
3135
|
+
return await queryClient.ensureQueryData(
|
|
3136
|
+
getAccountWalletAssetInfoQueryOptions(username, token)
|
|
3137
|
+
);
|
|
3138
|
+
};
|
|
2992
3139
|
switch (token) {
|
|
2993
|
-
case "HIVE" /* Hive */:
|
|
3140
|
+
case "HIVE" /* Hive */: {
|
|
3141
|
+
const assetInfo = await ensureAssetInfo();
|
|
3142
|
+
const savingsBalance = assetInfo?.parts?.find(
|
|
3143
|
+
(part) => part.name === "savings"
|
|
3144
|
+
)?.balance;
|
|
3145
|
+
const pendingSavingsWithdrawAmount = await (async () => {
|
|
3146
|
+
if (!isForOwner || !username) {
|
|
3147
|
+
return 0;
|
|
3148
|
+
}
|
|
3149
|
+
try {
|
|
3150
|
+
const response = await sdk.CONFIG.hiveClient.database.call(
|
|
3151
|
+
"get_savings_withdraw_from",
|
|
3152
|
+
[username]
|
|
3153
|
+
);
|
|
3154
|
+
return response.reduce((total, request) => {
|
|
3155
|
+
const parsed = parseAsset(request.amount);
|
|
3156
|
+
return parsed.symbol === "HIVE" /* HIVE */ ? total + parsed.amount : total;
|
|
3157
|
+
}, 0);
|
|
3158
|
+
} catch {
|
|
3159
|
+
return 0;
|
|
3160
|
+
}
|
|
3161
|
+
})();
|
|
3162
|
+
const hasAvailableSavingsWithdraw = typeof savingsBalance === "number" && savingsBalance - pendingSavingsWithdrawAmount > 1e-6;
|
|
2994
3163
|
return [
|
|
2995
3164
|
"transfer" /* Transfer */,
|
|
2996
3165
|
...isForOwner ? [
|
|
3166
|
+
...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
|
|
2997
3167
|
"transfer-saving" /* TransferToSavings */,
|
|
2998
3168
|
"power-up" /* PowerUp */,
|
|
2999
3169
|
"swap" /* Swap */
|
|
3000
3170
|
] : []
|
|
3001
3171
|
];
|
|
3172
|
+
}
|
|
3002
3173
|
case "HP" /* HivePower */:
|
|
3003
3174
|
return [
|
|
3004
3175
|
"delegate" /* Delegate */,
|
|
3005
|
-
...isForOwner ? ["power-down" /* PowerDown */, "withdraw-
|
|
3176
|
+
...isForOwner ? ["power-down" /* PowerDown */, "withdraw-routes" /* WithdrawRoutes */] : ["power-up" /* PowerUp */]
|
|
3006
3177
|
];
|
|
3007
|
-
case "HBD" /* HiveDollar */:
|
|
3178
|
+
case "HBD" /* HiveDollar */: {
|
|
3179
|
+
const assetInfo = await ensureAssetInfo();
|
|
3180
|
+
const savingsBalance = assetInfo?.parts?.find(
|
|
3181
|
+
(part) => part.name === "savings"
|
|
3182
|
+
)?.balance;
|
|
3183
|
+
const pendingSavingsWithdrawAmount = await (async () => {
|
|
3184
|
+
if (!isForOwner || !username) {
|
|
3185
|
+
return 0;
|
|
3186
|
+
}
|
|
3187
|
+
try {
|
|
3188
|
+
const response = await sdk.CONFIG.hiveClient.database.call(
|
|
3189
|
+
"get_savings_withdraw_from",
|
|
3190
|
+
[username]
|
|
3191
|
+
);
|
|
3192
|
+
return response.reduce((total, request) => {
|
|
3193
|
+
const parsed = parseAsset(request.amount);
|
|
3194
|
+
return parsed.symbol === "HBD" /* HBD */ ? total + parsed.amount : total;
|
|
3195
|
+
}, 0);
|
|
3196
|
+
} catch {
|
|
3197
|
+
return 0;
|
|
3198
|
+
}
|
|
3199
|
+
})();
|
|
3200
|
+
const hasAvailableSavingsWithdraw = typeof savingsBalance === "number" && savingsBalance - pendingSavingsWithdrawAmount > 1e-6;
|
|
3008
3201
|
return [
|
|
3009
3202
|
"transfer" /* Transfer */,
|
|
3010
|
-
...isForOwner ? [
|
|
3203
|
+
...isForOwner ? [
|
|
3204
|
+
...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
|
|
3205
|
+
"transfer-saving" /* TransferToSavings */,
|
|
3206
|
+
"swap" /* Swap */
|
|
3207
|
+
] : []
|
|
3011
3208
|
];
|
|
3209
|
+
}
|
|
3012
3210
|
case "POINTS" /* Points */:
|
|
3013
3211
|
return [
|
|
3014
3212
|
"gift" /* Gift */,
|
|
@@ -3042,7 +3240,6 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
3042
3240
|
if (!username) {
|
|
3043
3241
|
return ["transfer" /* Transfer */];
|
|
3044
3242
|
}
|
|
3045
|
-
const queryClient = sdk.getQueryClient();
|
|
3046
3243
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
3047
3244
|
const balances = await queryClient.ensureQueryData(balancesListQuery);
|
|
3048
3245
|
const tokensQuery = getHiveEngineTokensMetadataQueryOptions(
|
|
@@ -3409,16 +3606,19 @@ var operationToFunctionMap = {
|
|
|
3409
3606
|
HIVE: {
|
|
3410
3607
|
["transfer" /* Transfer */]: transferHive,
|
|
3411
3608
|
["transfer-saving" /* TransferToSavings */]: transferToSavingsHive,
|
|
3609
|
+
["withdraw-saving" /* WithdrawFromSavings */]: transferFromSavingsHive,
|
|
3412
3610
|
["power-up" /* PowerUp */]: powerUpHive
|
|
3413
3611
|
},
|
|
3414
3612
|
HBD: {
|
|
3415
3613
|
["transfer" /* Transfer */]: transferHive,
|
|
3416
|
-
["transfer-saving" /* TransferToSavings */]: transferToSavingsHive
|
|
3614
|
+
["transfer-saving" /* TransferToSavings */]: transferToSavingsHive,
|
|
3615
|
+
["withdraw-saving" /* WithdrawFromSavings */]: transferFromSavingsHive,
|
|
3616
|
+
["claim-interest" /* ClaimInterest */]: claimInterestHive
|
|
3417
3617
|
},
|
|
3418
3618
|
HP: {
|
|
3419
3619
|
["power-down" /* PowerDown */]: powerDownHive,
|
|
3420
3620
|
["delegate" /* Delegate */]: delegateHive,
|
|
3421
|
-
["withdraw-
|
|
3621
|
+
["withdraw-routes" /* WithdrawRoutes */]: withdrawVestingRouteHive
|
|
3422
3622
|
},
|
|
3423
3623
|
POINTS: {
|
|
3424
3624
|
["gift" /* Gift */]: transferPoint
|
|
@@ -3496,6 +3696,7 @@ exports.buildPsbt = buildPsbt;
|
|
|
3496
3696
|
exports.buildSolTx = buildSolTx;
|
|
3497
3697
|
exports.buildTonTx = buildTonTx;
|
|
3498
3698
|
exports.buildTronTx = buildTronTx;
|
|
3699
|
+
exports.claimInterestHive = claimInterestHive;
|
|
3499
3700
|
exports.decryptMemoWithAccounts = decryptMemoWithAccounts;
|
|
3500
3701
|
exports.decryptMemoWithKeys = decryptMemoWithKeys;
|
|
3501
3702
|
exports.delay = delay;
|
|
@@ -3553,6 +3754,7 @@ exports.signTx = signTx;
|
|
|
3553
3754
|
exports.signTxAndBroadcast = signTxAndBroadcast;
|
|
3554
3755
|
exports.stakeEngineToken = stakeEngineToken;
|
|
3555
3756
|
exports.transferEngineToken = transferEngineToken;
|
|
3757
|
+
exports.transferFromSavingsHive = transferFromSavingsHive;
|
|
3556
3758
|
exports.transferHive = transferHive;
|
|
3557
3759
|
exports.transferLarynx = transferLarynx;
|
|
3558
3760
|
exports.transferPoint = transferPoint;
|