Skip to content

Commit

Permalink
Sergei / 89437 / Traders Hub: Total assets showing wrong amount when …
Browse files Browse the repository at this point in the history
…clients having multiple currency (binary-com#7728)

* fix: ad exchange rate for total assets in traders hub

* refactor: change types for setExchangeRate

---------

Co-authored-by: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com>
  • Loading branch information
2 people authored and sanjam-deriv committed Mar 13, 2023
1 parent d5dceef commit a7c0eef
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions packages/appstore/src/components/main-title-bar/asset-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './asset-summary.scss';
import TotalAssetsLoader from 'Components/pre-loader/total-assets-loader';

const AssetSummary = () => {
const { traders_hub, client } = useStores();
const { traders_hub, client, common } = useStores();
const {
selected_account_type,
platform_real_balance,
Expand All @@ -21,17 +21,48 @@ const AssetSummary = () => {
no_MF_account,
} = traders_hub;
const { is_logging_in, is_switching } = client;
const { getExchangeRate } = common;

const [exchanged_rate_cfd_real, setExchangedRateCfdReal] = React.useState(1);
const [exchanged_rate_cfd_demo, setExchangedRateCfdDemo] = React.useState(1);

React.useEffect(() => {
const getCurrentExchangeRate = (
currency: string,
setExchangeRate: React.Dispatch<React.SetStateAction<number>>,
base_currency = platform_real_balance.currency
) => {
if (currency) {
getExchangeRate(currency, base_currency).then((res: number) => {
setExchangeRate(res);
});
}
};

if (cfd_real_balance.currency !== platform_real_balance.currency) {
getCurrentExchangeRate(cfd_real_balance.currency, setExchangedRateCfdReal);
}
if (cfd_demo_balance.currency !== platform_demo_balance.currency) {
getCurrentExchangeRate(cfd_demo_balance.currency, setExchangedRateCfdDemo, platform_demo_balance.currency);
}
}, [
cfd_demo_balance.currency,
cfd_real_balance.currency,
getExchangeRate,
platform_demo_balance.currency,
platform_real_balance.currency,
]);

const getTotalBalance = () => {
if (selected_account_type === 'real') {
return {
balance: platform_real_balance.balance + cfd_real_balance.balance,
balance: platform_real_balance.balance + cfd_real_balance.balance * exchanged_rate_cfd_real,
currency: platform_real_balance.currency,
};
}

return {
balance: platform_demo_balance.balance + cfd_demo_balance.balance,
balance: platform_demo_balance.balance + cfd_demo_balance.balance * exchanged_rate_cfd_demo,
currency: platform_demo_balance.currency,
};
};
Expand Down

0 comments on commit a7c0eef

Please sign in to comment.