@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.
@@ -754,33 +754,76 @@ function getHivePowerAssetGeneralInfoQueryOptions(username) {
754
754
  const marketTicker = await sdk.CONFIG.hiveClient.call("condenser_api", "get_ticker", []).catch(() => void 0);
755
755
  const marketPrice = Number.parseFloat(marketTicker?.latest ?? "");
756
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
+ );
757
792
  return {
758
793
  name: "HP",
759
794
  title: "Hive Power",
760
795
  price,
761
- accountBalance: +vestsToHp(
762
- parseAsset(accountData.vesting_shares).amount,
763
- // parseAsset(accountData.delegated_vesting_shares).amount +
764
- // parseAsset(accountData.received_vesting_shares).amount -
765
- // nextVestingSharesWithdrawal,
766
- dynamicProps.hivePerMVests
767
- ).toFixed(3),
796
+ accountBalance: +totalBalance.toFixed(3),
768
797
  apr: getAPR(dynamicProps),
769
798
  parts: [
770
799
  {
771
- name: "delegating",
772
- balance: +vestsToHp(
773
- parseAsset(accountData.delegated_vesting_shares).amount,
774
- dynamicProps.hivePerMVests
775
- ).toFixed(3)
800
+ name: "hp_balance",
801
+ balance: hpBalance
776
802
  },
777
803
  {
778
- name: "received",
779
- balance: +vestsToHp(
780
- parseAsset(accountData.received_vesting_shares).amount,
781
- dynamicProps.hivePerMVests
782
- ).toFixed(3)
783
- }
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
+ ] : []
784
827
  ]
785
828
  };
786
829
  }
@@ -3099,10 +3142,28 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
3099
3142
  const savingsBalance = assetInfo?.parts?.find(
3100
3143
  (part) => part.name === "savings"
3101
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;
3102
3163
  return [
3103
3164
  "transfer" /* Transfer */,
3104
3165
  ...isForOwner ? [
3105
- ...savingsBalance && savingsBalance > 0 ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3166
+ ...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3106
3167
  "transfer-saving" /* TransferToSavings */,
3107
3168
  "power-up" /* PowerUp */,
3108
3169
  "swap" /* Swap */
@@ -3119,10 +3180,28 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
3119
3180
  const savingsBalance = assetInfo?.parts?.find(
3120
3181
  (part) => part.name === "savings"
3121
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;
3122
3201
  return [
3123
3202
  "transfer" /* Transfer */,
3124
3203
  ...isForOwner ? [
3125
- ...savingsBalance && savingsBalance > 0 ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3204
+ ...hasAvailableSavingsWithdraw ? ["withdraw-saving" /* WithdrawFromSavings */] : [],
3126
3205
  "transfer-saving" /* TransferToSavings */,
3127
3206
  "swap" /* Swap */
3128
3207
  ] : []