-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shontzu/WALL-865/Incorrect-total-asset-amount #9217
Changes from 7 commits
362602e
c84aaba
18115a3
fcc6413
90ad533
ed620a9
f31277b
4678543
6c99640
3ab5a76
78d9185
d4625c1
83b11d1
faea6de
f407aff
82c8ca2
202d5e8
8624ae2
a5e7e5b
5f3ec8c
1fa3dc1
4a51fd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
shontzu-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,22 +1,23 @@ | ||||||||||
import useRealTotalAssetCurrency from './useTotalAssetCurrency'; | ||||||||||
import useExchangeRate from './useExchangeRate'; | ||||||||||
|
||||||||||
import { useStore } from '@deriv/stores'; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
/** | ||||||||||
* we can use this hook to get the total balance of the given accounts list. | ||||||||||
* it loops through the accounts list and adds the balance of each account | ||||||||||
* to the total balance, it also converts the balance to the currency of the | ||||||||||
* first account in the list | ||||||||||
*/ | ||||||||||
|
||||||||||
const useTotalAccountBalance = (accounts: { balance?: number; currency?: string }[]) => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
const { traders_hub } = useStore(); | ||||||||||
const { is_demo } = traders_hub; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
const total_assets_real_currency = useRealTotalAssetCurrency(); | ||||||||||
const { getRate } = useExchangeRate(); | ||||||||||
|
||||||||||
if (!accounts.length) return { balance: 0, currency: total_assets_real_currency }; | ||||||||||
|
||||||||||
const balance = accounts.reduce((total, account) => { | ||||||||||
const base_rate = getRate(total_assets_real_currency || ''); | ||||||||||
const rate = getRate(account.currency || total_assets_real_currency || ''); | ||||||||||
shontzu-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
const base_rate = is_demo ? getRate('USD') : getRate(total_assets_real_currency || ''); | ||||||||||
const rate = getRate(total_assets_real_currency || ''); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
const exchange_rate = base_rate / rate; | ||||||||||
|
||||||||||
return total + (account.balance || 0) * exchange_rate; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shontzu-deriv I don't think we need to change the existing tests, I think you should add a new test case for the new scenario 🤔