Skip to content
Snippets Groups Projects
Commit 763aee67 authored by Dima Rifai's avatar Dima Rifai Committed by mcfarhat
Browse files

Issue #417 - Calculate account_value from dollars entry and pass it to formatter

parent db9b35ec
No related branches found
No related tags found
1 merge request!529Delrifai/#417 fix wallet bug
...@@ -25,6 +25,7 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea ...@@ -25,6 +25,7 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea
return formattedHP as string; return formattedHP as string;
} }
const { hiveChain } = useHiveChainContext(); const { hiveChain } = useHiveChainContext();
const {accountDetails, notFound}= useAccountDetails(accountName, liveDataEnabled); const {accountDetails, notFound}= useAccountDetails(accountName, liveDataEnabled);
if (!dynamicGlobalData || !hiveChain || !accountDetails) return {formattedAccountDetails: undefined, notFound: undefined}; if (!dynamicGlobalData || !hiveChain || !accountDetails) return {formattedAccountDetails: undefined, notFound: undefined};
...@@ -75,6 +76,7 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea ...@@ -75,6 +76,7 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea
created: formatAndDelocalizeTime(accountDetails.created), created: formatAndDelocalizeTime(accountDetails.created),
}; };
// Prepare HBD for $ display // Prepare HBD for $ display
const dollars = { const dollars = {
hbd_balance: accountDetailsForFormat.hbd_balance, hbd_balance: accountDetailsForFormat.hbd_balance,
...@@ -89,8 +91,23 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea ...@@ -89,8 +91,23 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea
vesting_shares: hiveChain.hiveToHbd(vesting_shares, rawFeedPrice, rawQuote), vesting_shares: hiveChain.hiveToHbd(vesting_shares, rawFeedPrice, rawQuote),
vesting_withdraw_rate: hiveChain.hiveToHbd(vesting_withdraw_rate, rawFeedPrice, rawQuote) vesting_withdraw_rate: hiveChain.hiveToHbd(vesting_withdraw_rate, rawFeedPrice, rawQuote)
} }
interface NaiAsset {
amount: string;
nai: string;
precision: number
}
/* Account Value Calculations */
const skipCalculation = ["delegated_vesting_shares", "received_vesting_shares"];
let totalAccountValue = Object.entries(dollars).reduce((sum, [key, value]) => {
if (value && value.hasOwnProperty('amount') && !skipCalculation.includes(key)) {
return sum + Number((value as NaiAsset).amount);
}
return sum;
}, 0);
(dollars as any)["account_value"] = hiveChain.hbd(totalAccountValue);
const formattedAccountDetails = {...hiveChain?.formatter.format({ const formattedAccountDetails = {...hiveChain?.formatter.format({
...accountDetailsForFormat, ...accountDetailsForFormat,
...@@ -98,7 +115,7 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea ...@@ -98,7 +115,7 @@ const useConvertedAccountDetails = (accountName: string, liveDataEnabled: boolea
vests, vests,
has_hbd_reward: !!accountDetails.reward_hbd_balance, has_hbd_reward: !!accountDetails.reward_hbd_balance,
has_vesting_reward: !!Number(accountDetails.reward_vesting_balance), has_vesting_reward: !!Number(accountDetails.reward_vesting_balance),
has_hive_reward: !!accountDetails.reward_hive_balance has_hive_reward: !!accountDetails.reward_hive_balance,
}), }),
} as Explorer.FormattedAccountDetails; } as Explorer.FormattedAccountDetails;
delete formattedAccountDetails.last_post; delete formattedAccountDetails.last_post;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment