@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.
@@ -654,11 +654,31 @@ function getHiveAssetGeneralInfoQueryOptions(username) {
654
654
  );
655
655
  const marketTicker = await CONFIG.hiveClient.call("condenser_api", "get_ticker", []).catch(() => void 0);
656
656
  const marketPrice = Number.parseFloat(marketTicker?.latest ?? "");
657
+ if (!accountData) {
658
+ return {
659
+ name: "HIVE",
660
+ title: "Hive",
661
+ price: Number.isFinite(marketPrice) ? marketPrice : dynamicProps ? dynamicProps.base / dynamicProps.quote : 0,
662
+ accountBalance: 0
663
+ };
664
+ }
665
+ const liquidBalance = parseAsset(accountData.balance).amount;
666
+ const savingsBalance = parseAsset(accountData.savings_balance).amount;
657
667
  return {
658
668
  name: "HIVE",
659
669
  title: "Hive",
660
670
  price: Number.isFinite(marketPrice) ? marketPrice : dynamicProps ? dynamicProps.base / dynamicProps.quote : 0,
661
- accountBalance: accountData ? parseAsset(accountData.balance).amount : 0
671
+ accountBalance: liquidBalance + savingsBalance,
672
+ parts: [
673
+ {
674
+ name: "current",
675
+ balance: liquidBalance
676
+ },
677
+ {
678
+ name: "savings",
679
+ balance: savingsBalance
680
+ }
681
+ ]
662
682
  };
663
683
  }
664
684
  });
@@ -707,33 +727,76 @@ function getHivePowerAssetGeneralInfoQueryOptions(username) {
707
727
  const marketTicker = await CONFIG.hiveClient.call("condenser_api", "get_ticker", []).catch(() => void 0);
708
728
  const marketPrice = Number.parseFloat(marketTicker?.latest ?? "");
709
729
  const price = Number.isFinite(marketPrice) ? marketPrice : dynamicProps.base / dynamicProps.quote;
730
+ const vestingShares = parseAsset(accountData.vesting_shares).amount;
731
+ const delegatedVests = parseAsset(accountData.delegated_vesting_shares).amount;
732
+ const receivedVests = parseAsset(accountData.received_vesting_shares).amount;
733
+ const withdrawRateVests = parseAsset(accountData.vesting_withdraw_rate).amount;
734
+ const remainingToWithdrawVests = Math.max(
735
+ (Number(accountData.to_withdraw) - Number(accountData.withdrawn)) / 1e6,
736
+ 0
737
+ );
738
+ const nextWithdrawalVests = !isEmptyDate(accountData.next_vesting_withdrawal) ? Math.min(withdrawRateVests, remainingToWithdrawVests) : 0;
739
+ const hpBalance = +vestsToHp(
740
+ vestingShares,
741
+ dynamicProps.hivePerMVests
742
+ ).toFixed(3);
743
+ const outgoingDelegationsHp = +vestsToHp(
744
+ delegatedVests,
745
+ dynamicProps.hivePerMVests
746
+ ).toFixed(3);
747
+ const incomingDelegationsHp = +vestsToHp(
748
+ receivedVests,
749
+ dynamicProps.hivePerMVests
750
+ ).toFixed(3);
751
+ const pendingPowerDownHp = +vestsToHp(
752
+ remainingToWithdrawVests,
753
+ dynamicProps.hivePerMVests
754
+ ).toFixed(3);
755
+ const nextPowerDownHp = +vestsToHp(
756
+ nextWithdrawalVests,
757
+ dynamicProps.hivePerMVests
758
+ ).toFixed(3);
759
+ const totalBalance = Math.max(hpBalance - pendingPowerDownHp, 0);
760
+ const availableHp = Math.max(
761
+ // Owned HP minus the portions already delegated away.
762
+ hpBalance - outgoingDelegationsHp,
763
+ 0
764
+ );
710
765
  return {
711
766
  name: "HP",
712
767
  title: "Hive Power",
713
768
  price,
714
- accountBalance: +vestsToHp(
715
- parseAsset(accountData.vesting_shares).amount,
716
- // parseAsset(accountData.delegated_vesting_shares).amount +
717
- // parseAsset(accountData.received_vesting_shares).amount -
718
- // nextVestingSharesWithdrawal,
719
- dynamicProps.hivePerMVests
720
- ).toFixed(3),
769
+ accountBalance: +totalBalance.toFixed(3),
721
770
  apr: getAPR(dynamicProps),
722
771
  parts: [
723
772
  {
724
- name: "delegating",
725
- balance: +vestsToHp(
726
- parseAsset(accountData.delegated_vesting_shares).amount,
727
- dynamicProps.hivePerMVests
728
- ).toFixed(3)
773
+ name: "hp_balance",
774
+ balance: hpBalance
729
775
  },
730
776
  {
731
- name: "received",
732
- balance: +vestsToHp(
733
- parseAsset(accountData.received_vesting_shares).amount,
734
- dynamicProps.hivePerMVests
735
- ).toFixed(3)
736
- }
777
+ name: "available",
778
+ balance: +availableHp.toFixed(3)
779
+ },
780
+ {
781
+ name: "outgoing_delegations",
782
+ balance: outgoingDelegationsHp
783
+ },
784
+ {
785
+ name: "incoming_delegations",
786
+ balance: incomingDelegationsHp
787
+ },
788
+ ...pendingPowerDownHp > 0 ? [
789
+ {
790
+ name: "pending_power_down",
791
+ balance: +pendingPowerDownHp.toFixed(3)
792
+ }
793
+ ] : [],
794
+ ...nextPowerDownHp > 0 && nextPowerDownHp !== pendingPowerDownHp ? [
795
+ {
796
+ name: "next_power_down",
797
+ balance: +nextPowerDownHp.toFixed(3)
798
+ }
799
+ ] : []
737
800
  ]
738
801
  };
739
802
  }
@@ -784,7 +847,7 @@ function getHbdAssetGeneralInfoQueryOptions(username) {
784
847
  apr: ((dynamicProps?.hbdInterestRate ?? 0) / 100).toFixed(3),
785
848
  parts: [
786
849
  {
787
- name: "account",
850
+ name: "current",
788
851
  balance: parseAsset(accountData.hbd_balance).amount
789
852
  },
790
853
  {
@@ -1160,6 +1223,36 @@ async function transferToSavingsHive(payload) {
1160
1223
  );
1161
1224
  }
1162
1225
  }
1226
+ async function transferFromSavingsHive(payload) {
1227
+ const requestId = payload.request_id ?? Date.now() >>> 0;
1228
+ const operationPayload = {
1229
+ from: payload.from,
1230
+ to: payload.to,
1231
+ amount: payload.amount,
1232
+ memo: payload.memo,
1233
+ request_id: requestId
1234
+ };
1235
+ if (payload.type === "key" && "key" in payload) {
1236
+ const { key } = payload;
1237
+ return CONFIG.hiveClient.broadcast.sendOperations(
1238
+ [["transfer_from_savings", operationPayload]],
1239
+ key
1240
+ );
1241
+ }
1242
+ if (payload.type === "keychain") {
1243
+ return Keychain.broadcast(
1244
+ payload.from,
1245
+ [["transfer_from_savings", operationPayload]],
1246
+ "Active"
1247
+ );
1248
+ }
1249
+ return hs.sendOperation(
1250
+ ["transfer_from_savings", operationPayload],
1251
+ { callback: `https://ecency.com/@${payload.from}/wallet` },
1252
+ () => {
1253
+ }
1254
+ );
1255
+ }
1163
1256
  async function powerUpHive(payload) {
1164
1257
  if (payload.type === "key" && "key" in payload) {
1165
1258
  const { key, type, ...params } = payload;
@@ -1298,15 +1391,60 @@ function useClaimRewards(username, onSuccess) {
1298
1391
  }
1299
1392
  );
1300
1393
  }
1394
+ async function claimInterestHive(payload) {
1395
+ const requestId = payload.request_id ?? Date.now() >>> 0;
1396
+ const baseOperation = {
1397
+ from: payload.from,
1398
+ to: payload.to,
1399
+ amount: payload.amount,
1400
+ memo: payload.memo,
1401
+ request_id: requestId
1402
+ };
1403
+ const cancelOperation = {
1404
+ from: payload.from,
1405
+ request_id: requestId
1406
+ };
1407
+ if (payload.type === "key" && "key" in payload) {
1408
+ const { key } = payload;
1409
+ return CONFIG.hiveClient.broadcast.sendOperations(
1410
+ [
1411
+ ["transfer_from_savings", baseOperation],
1412
+ ["cancel_transfer_from_savings", cancelOperation]
1413
+ ],
1414
+ key
1415
+ );
1416
+ }
1417
+ if (payload.type === "keychain") {
1418
+ return Keychain.broadcast(
1419
+ payload.from,
1420
+ [
1421
+ ["transfer_from_savings", baseOperation],
1422
+ ["cancel_transfer_from_savings", cancelOperation]
1423
+ ],
1424
+ "Active"
1425
+ );
1426
+ }
1427
+ return hs.sendOperations(
1428
+ [
1429
+ ["transfer_from_savings", baseOperation],
1430
+ ["cancel_transfer_from_savings", cancelOperation]
1431
+ ],
1432
+ { callback: `https://ecency.com/@${payload.from}/wallet` },
1433
+ () => {
1434
+ }
1435
+ );
1436
+ }
1301
1437
 
1302
1438
  // src/modules/assets/types/asset-operation.ts
1303
1439
  var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
1304
1440
  AssetOperation2["Transfer"] = "transfer";
1305
1441
  AssetOperation2["TransferToSavings"] = "transfer-saving";
1442
+ AssetOperation2["WithdrawFromSavings"] = "withdraw-saving";
1306
1443
  AssetOperation2["Delegate"] = "delegate";
1307
1444
  AssetOperation2["PowerUp"] = "power-up";
1308
1445
  AssetOperation2["PowerDown"] = "power-down";
1309
- AssetOperation2["WithdrawRoutes"] = "withdraw-saving";
1446
+ AssetOperation2["WithdrawRoutes"] = "withdraw-routes";
1447
+ AssetOperation2["ClaimInterest"] = "claim-interest";
1310
1448
  AssetOperation2["Swap"] = "swap";
1311
1449
  AssetOperation2["Gift"] = "gift";
1312
1450
  AssetOperation2["Promote"] = "promote";
@@ -2962,26 +3100,86 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
2962
3100
  return queryOptions({
2963
3101
  queryKey: ["wallets", "token-operations", token, username, isForOwner],
2964
3102
  queryFn: async () => {
3103
+ const queryClient = getQueryClient();
3104
+ const ensureAssetInfo = async () => {
3105
+ if (!isForOwner || !username) {
3106
+ return void 0;
3107
+ }
3108
+ return await queryClient.ensureQueryData(
3109
+ getAccountWalletAssetInfoQueryOptions(username, token)
3110
+ );
3111
+ };
2965
3112
  switch (token) {
2966
- case "HIVE" /* Hive */:
3113
+ case "HIVE" /* Hive */: {
3114
+ const assetInfo = await ensureAssetInfo();
3115
+ const savingsBalance = assetInfo?.parts?.find(
3116
+ (part) => part.name === "savings"
3117
+ )?.balance;
3118
+ const pendingSavingsWithdrawAmount = await (async () => {
3119
+ if (!isForOwner || !username) {
3120
+ return 0;
3121
+ }
3122
+ try {
3123
+ const response = await CONFIG.hiveClient.database.call(
3124
+ "get_savings_withdraw_from",
3125
+ [username]
3126
+ );
3127
+ return response.reduce((total, request) => {
3128
+ const parsed = parseAsset(request.amount);
3129
+ return parsed.symbol === "HIVE" /* HIVE */ ? total + parsed.amount : total;
3130
+ }, 0);
3131
+ } catch {
3132
+ return 0;
3133
+ }
3134
+ })();
3135
+ const hasAvailableSavingsWithdraw = typeof savingsBalance === "number" && savingsBalance - pendingSavingsWithdrawAmount > 1e-6;
2967
3136
  return [
2968
3137
  "transfer" /* Transfer */,
2969
3138
  ...isForOwner ? [
3139
+ ...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
2970
3140
  "transfer-saving" /* TransferToSavings */,
2971
3141
  "power-up" /* PowerUp */,
2972
3142
  "swap" /* Swap */
2973
3143
  ] : []
2974
3144
  ];
3145
+ }
2975
3146
  case "HP" /* HivePower */:
2976
3147
  return [
2977
3148
  "delegate" /* Delegate */,
2978
- ...isForOwner ? ["power-down" /* PowerDown */, "withdraw-saving" /* WithdrawRoutes */] : ["power-up" /* PowerUp */]
3149
+ ...isForOwner ? ["power-down" /* PowerDown */, "withdraw-routes" /* WithdrawRoutes */] : ["power-up" /* PowerUp */]
2979
3150
  ];
2980
- case "HBD" /* HiveDollar */:
3151
+ case "HBD" /* HiveDollar */: {
3152
+ const assetInfo = await ensureAssetInfo();
3153
+ const savingsBalance = assetInfo?.parts?.find(
3154
+ (part) => part.name === "savings"
3155
+ )?.balance;
3156
+ const pendingSavingsWithdrawAmount = await (async () => {
3157
+ if (!isForOwner || !username) {
3158
+ return 0;
3159
+ }
3160
+ try {
3161
+ const response = await CONFIG.hiveClient.database.call(
3162
+ "get_savings_withdraw_from",
3163
+ [username]
3164
+ );
3165
+ return response.reduce((total, request) => {
3166
+ const parsed = parseAsset(request.amount);
3167
+ return parsed.symbol === "HBD" /* HBD */ ? total + parsed.amount : total;
3168
+ }, 0);
3169
+ } catch {
3170
+ return 0;
3171
+ }
3172
+ })();
3173
+ const hasAvailableSavingsWithdraw = typeof savingsBalance === "number" && savingsBalance - pendingSavingsWithdrawAmount > 1e-6;
2981
3174
  return [
2982
3175
  "transfer" /* Transfer */,
2983
- ...isForOwner ? ["transfer-saving" /* TransferToSavings */, "swap" /* Swap */] : []
3176
+ ...isForOwner ? [
3177
+ ...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3178
+ "transfer-saving" /* TransferToSavings */,
3179
+ "swap" /* Swap */
3180
+ ] : []
2984
3181
  ];
3182
+ }
2985
3183
  case "POINTS" /* Points */:
2986
3184
  return [
2987
3185
  "gift" /* Gift */,
@@ -3015,7 +3213,6 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
3015
3213
  if (!username) {
3016
3214
  return ["transfer" /* Transfer */];
3017
3215
  }
3018
- const queryClient = getQueryClient();
3019
3216
  const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
3020
3217
  const balances = await queryClient.ensureQueryData(balancesListQuery);
3021
3218
  const tokensQuery = getHiveEngineTokensMetadataQueryOptions(
@@ -3382,16 +3579,19 @@ var operationToFunctionMap = {
3382
3579
  HIVE: {
3383
3580
  ["transfer" /* Transfer */]: transferHive,
3384
3581
  ["transfer-saving" /* TransferToSavings */]: transferToSavingsHive,
3582
+ ["withdraw-saving" /* WithdrawFromSavings */]: transferFromSavingsHive,
3385
3583
  ["power-up" /* PowerUp */]: powerUpHive
3386
3584
  },
3387
3585
  HBD: {
3388
3586
  ["transfer" /* Transfer */]: transferHive,
3389
- ["transfer-saving" /* TransferToSavings */]: transferToSavingsHive
3587
+ ["transfer-saving" /* TransferToSavings */]: transferToSavingsHive,
3588
+ ["withdraw-saving" /* WithdrawFromSavings */]: transferFromSavingsHive,
3589
+ ["claim-interest" /* ClaimInterest */]: claimInterestHive
3390
3590
  },
3391
3591
  HP: {
3392
3592
  ["power-down" /* PowerDown */]: powerDownHive,
3393
3593
  ["delegate" /* Delegate */]: delegateHive,
3394
- ["withdraw-saving" /* WithdrawRoutes */]: withdrawVestingRouteHive
3594
+ ["withdraw-routes" /* WithdrawRoutes */]: withdrawVestingRouteHive
3395
3595
  },
3396
3596
  POINTS: {
3397
3597
  ["gift" /* Gift */]: transferPoint
@@ -3455,6 +3655,6 @@ function useWalletOperation(username, asset, operation) {
3455
3655
  // src/index.ts
3456
3656
  rememberScryptBsvVersion();
3457
3657
 
3458
- export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, NaiMap, PointTransactionType, Symbol2 as Symbol, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
3658
+ export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, NaiMap, PointTransactionType, Symbol2 as Symbol, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, claimInterestHive, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, 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 };
3459
3659
  //# sourceMappingURL=index.mjs.map
3460
3660
  //# sourceMappingURL=index.mjs.map