@ecency/wallets 1.4.19 → 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.
@@ -727,33 +727,76 @@ function getHivePowerAssetGeneralInfoQueryOptions(username) {
727
727
  const marketTicker = await CONFIG.hiveClient.call("condenser_api", "get_ticker", []).catch(() => void 0);
728
728
  const marketPrice = Number.parseFloat(marketTicker?.latest ?? "");
729
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
+ );
730
765
  return {
731
766
  name: "HP",
732
767
  title: "Hive Power",
733
768
  price,
734
- accountBalance: +vestsToHp(
735
- parseAsset(accountData.vesting_shares).amount,
736
- // parseAsset(accountData.delegated_vesting_shares).amount +
737
- // parseAsset(accountData.received_vesting_shares).amount -
738
- // nextVestingSharesWithdrawal,
739
- dynamicProps.hivePerMVests
740
- ).toFixed(3),
769
+ accountBalance: +totalBalance.toFixed(3),
741
770
  apr: getAPR(dynamicProps),
742
771
  parts: [
743
772
  {
744
- name: "delegating",
745
- balance: +vestsToHp(
746
- parseAsset(accountData.delegated_vesting_shares).amount,
747
- dynamicProps.hivePerMVests
748
- ).toFixed(3)
773
+ name: "hp_balance",
774
+ balance: hpBalance
749
775
  },
750
776
  {
751
- name: "received",
752
- balance: +vestsToHp(
753
- parseAsset(accountData.received_vesting_shares).amount,
754
- dynamicProps.hivePerMVests
755
- ).toFixed(3)
756
- }
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
+ ] : []
757
800
  ]
758
801
  };
759
802
  }
@@ -3072,10 +3115,28 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
3072
3115
  const savingsBalance = assetInfo?.parts?.find(
3073
3116
  (part) => part.name === "savings"
3074
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;
3075
3136
  return [
3076
3137
  "transfer" /* Transfer */,
3077
3138
  ...isForOwner ? [
3078
- ...savingsBalance && savingsBalance > 0 ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3139
+ ...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3079
3140
  "transfer-saving" /* TransferToSavings */,
3080
3141
  "power-up" /* PowerUp */,
3081
3142
  "swap" /* Swap */
@@ -3092,10 +3153,28 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
3092
3153
  const savingsBalance = assetInfo?.parts?.find(
3093
3154
  (part) => part.name === "savings"
3094
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;
3095
3174
  return [
3096
3175
  "transfer" /* Transfer */,
3097
3176
  ...isForOwner ? [
3098
- ...savingsBalance && savingsBalance > 0 ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3177
+ ...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3099
3178
  "transfer-saving" /* TransferToSavings */,
3100
3179
  "swap" /* Swap */
3101
3180
  ] : []