Skip to content
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

Conversation

shontzu-deriv
Copy link
Contributor

@shontzu-deriv shontzu-deriv commented Jul 4, 2023

Changes:

MT5 accounts can have non-USD balance.
In Demo tab, total assets are in USD
MT5's non-USD balance must be converted first

Screenshots:

image
image

@vercel
Copy link

vercel bot commented Jul 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
deriv-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2023 8:38am

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

A production App ID was automatically generated for this PR. (log)

Click here to copy & paste above information.
- **PR**: [https://github.com/binary-com/deriv-app/pull/9217](https://github.com/binary-com/deriv-app/pull/9217)
- **URLs**:
    - **w/ App ID + Server**: https://deriv-app-git-fork-shontzu-deriv-shontzu-wall-865incorre-7cf99c.binary.sx?qa_server=red.binaryws.com&app_id=31478
    - **Original**: https://deriv-app-git-fork-shontzu-deriv-shontzu-wall-865incorre-7cf99c.binary.sx
- **App ID**: `31478`

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

🚨 Lighthouse report for the changes in this PR:

Category Score
🔺 Performance 21
🟧 Accessibility 75
🟢 Best practices 92
🟧 SEO 85
🟢 PWA 90

Lighthouse ran with https://deriv-app-git-fork-shontzu-deriv-shontzu-wall-865incorre-7cf99c.binary.sx/

@shontzu-deriv shontzu-deriv changed the title fix: attemp #3 shontzu/WALL-865/Incorrect-total-asset-amount Jul 4, 2023
@coveralls
Copy link

coveralls commented Jul 5, 2023

Coverage Status

coverage: 8.879% (+0.002%) from 8.877% when pulling 4a51fd6 on shontzu-deriv:shontzu/WALL-865/Incorrect-total-asset-amount into 8623b8a on binary-com:master.

Copy link
Member

@shayan-deriv shayan-deriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shontzu-deriv using const { is_demo } = traders_hub; just checks if you switch to demo account or not. but you need to check if the passed cfd accounts are demo or not. that's why you need to check account?.account_type .
please apply my changes and also revert back all changes in the test file and check it the tests are passing as before 🙏

@@ -1,22 +1,23 @@
import useRealTotalAssetCurrency from './useTotalAssetCurrency';
import useExchangeRate from './useExchangeRate';

import { useStore } from '@deriv/stores';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { useStore } from '@deriv/stores';

Comment on lines 11 to 12
const { traders_hub } = useStore();
const { is_demo } = traders_hub;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { traders_hub } = useStore();
const { is_demo } = traders_hub;

Comment on lines 19 to 20
const base_rate = is_demo ? getRate('USD') : getRate(total_assets_real_currency || '');
const rate = getRate(total_assets_real_currency || '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const base_rate = is_demo ? getRate('USD') : getRate(total_assets_real_currency || '');
const rate = getRate(total_assets_real_currency || '');
const base_rate = account?.account_type === 'demo' ? 1 : getRate(total_assets_real_currency || '');
const rate = getRate(account.currency || total_assets_real_currency || '');

/**
* 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 }[]) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const useTotalAccountBalance = (accounts: { balance?: number; currency?: string }[]) => {
const useTotalAccountBalance = (accounts: { balance?: number; currency?: string; account_type?: string; }[]) => {

Copy link
Contributor

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 🤔

/**
* 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 }[]) => {
const useTotalAccountBalance = (accounts: { balance?: number; currency?: string; account_type?: string }[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const useTotalAccountBalance = (accounts: { balance?: number; currency?: string; account_type?: string }[]) => {
type TAccounts = {
balance?: number;
currency?: string;
account_type?: string
};
const useTotalAccountBalance = (accounts: TAccounts[]) => {

@shontzu-deriv Please extract it into a type above the function 🙏🏻

packages/hooks/src/useTotalAccountBalance.ts Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

Copy link
Member

@shayan-deriv shayan-deriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@farzin-deriv farzin-deriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shontzu-deriv Please update the test file with the new added case 🙏🏻

packages/hooks/src/useTotalAccountBalance.ts Show resolved Hide resolved
mahdiyeh-deriv
mahdiyeh-deriv previously approved these changes Jul 10, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2023

Generating Lighthouse report...

@ali-hosseini-deriv
Copy link
Member

👌 Pull request has been updated with the base branch by Paimon the Release Bot

@sonarcloud
Copy link

sonarcloud bot commented Jul 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
5.5% 5.5% Duplication

@ali-hosseini-deriv ali-hosseini-deriv merged commit 7b4ba8f into binary-com:master Jul 21, 2023
4 checks passed
@ali-hosseini-deriv
Copy link
Member

✨ PR has been merged by Paimon the Release Bot

vinu-deriv pushed a commit that referenced this pull request Jul 24, 2023
* shontzu/WALL-865/Incorrect-total-asset-amount (#9217)

* fix: attemp #3

* chore: remove irrelevant check

* chore: unit test

* chore: unit test fail

* chore: fixes based on review

* chore: empty commit

* chore: code revie fixes

* chore: revert test case changes

* chore: rename type to TUseTotalAccountBalance

* chore: format doc and added test case for multiple accounts in different currencies

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>

* Farabi/bot 317/translation fixes for dbot homepage (#9108)

* fix: translation issues

* redeploy: vercel retrigger

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>

* shahzaib / KYC-270 / fix POI flow after IDV failure and retries (#9222)

* chore: fix POI flow after IDV failure and retries

* chore: fix onfido infinite trigger for nigeria clients

* chore: fix onfido trigger if submission left is zero or less

* style: fix manual upload card content alignment

* chore: rename prop to default_enabled

* fix: nimc slip document step check

* chore: add comment to define the use of added prop

* maryia/DTRA-297/fix: Crypto profit text & Hide barriers in case of trade params errors (#9347)

* chore: remove animation correction

* feat: clear barriers upon errors

* fix: profit text & hide it for crypto with more than 2 decimals

* test: AccumulatorsProfitLossText

* Revert "chore: remove animation correction"

This reverts commit f9bb5ec.

* fix: not hide barriers for ongoing contract in case of trade params error

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>

* Kate / DTRA-175 / Enable 'Only ups/downs' in reports and contract details page (#8883)

* refactor: move trade type from un to supported

* feat: ad contract type check func and add to contract details

* feat: add chart markers settings for contract type

* chore: add style for mobile

* chore: remove gradient

* chore: empty commit

* chore: add gradient for contract details card for desktop

* feat: add chart markers setings and update style

* refactor: apply suggestions

* chore: empty commit

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>

* fix: token leakage to third party api (#9000)

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>

---------

Co-authored-by: shontzu <108507236+shontzu-deriv@users.noreply.github.com>
Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
Co-authored-by: Farabi <102643568+farabi-deriv@users.noreply.github.com>
Co-authored-by: Shahzaib <shahzaib@deriv.com>
Co-authored-by: Maryia <103177211+maryia-deriv@users.noreply.github.com>
Co-authored-by: kate-deriv <121025168+kate-deriv@users.noreply.github.com>
Co-authored-by: Sui Sin <103026762+suisin-deriv@users.noreply.github.com>
mahdiyeh-deriv pushed a commit to mahdiyeh-deriv/deriv-app that referenced this pull request Jul 25, 2023
* fix: attemp #3

* chore: remove irrelevant check

* chore: unit test

* chore: unit test fail

* chore: fixes based on review

* chore: empty commit

* chore: code revie fixes

* chore: revert test case changes

* chore: rename type to TUseTotalAccountBalance

* chore: format doc and added test case for multiple accounts in different currencies

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
mahdiyeh-deriv pushed a commit to mahdiyeh-deriv/deriv-app that referenced this pull request Jul 25, 2023
* fix: attemp #3

* chore: remove irrelevant check

* chore: unit test

* chore: unit test fail

* chore: fixes based on review

* chore: empty commit

* chore: code revie fixes

* chore: revert test case changes

* chore: rename type to TUseTotalAccountBalance

* chore: format doc and added test case for multiple accounts in different currencies

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
mahdiyeh-deriv pushed a commit to mahdiyeh-deriv/deriv-app that referenced this pull request Jul 25, 2023
* fix: attemp #3

* chore: remove irrelevant check

* chore: unit test

* chore: unit test fail

* chore: fixes based on review

* chore: empty commit

* chore: code revie fixes

* chore: revert test case changes

* chore: rename type to TUseTotalAccountBalance

* chore: format doc and added test case for multiple accounts in different currencies

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
mahdiyeh-deriv pushed a commit to mahdiyeh-deriv/deriv-app that referenced this pull request Jul 25, 2023
* fix: attemp #3

* chore: remove irrelevant check

* chore: unit test

* chore: unit test fail

* chore: fixes based on review

* chore: empty commit

* chore: code revie fixes

* chore: revert test case changes

* chore: rename type to TUseTotalAccountBalance

* chore: format doc and added test case for multiple accounts in different currencies

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
matin-deriv pushed a commit to matin-deriv/deriv-app that referenced this pull request Aug 2, 2023
* fix: attemp #3

* chore: remove irrelevant check

* chore: unit test

* chore: unit test fail

* chore: fixes based on review

* chore: empty commit

* chore: code revie fixes

* chore: revert test case changes

* chore: rename type to TUseTotalAccountBalance

* chore: format doc and added test case for multiple accounts in different currencies

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants