Skip to content

Commit

Permalink
thisyahlen/chore: add balance to useAccountlist (binary-com#9803)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisyahlen-deriv committed Aug 24, 2023
1 parent f6556e7 commit 278eacd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/api/src/hooks/useAccountsList.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useMemo } from 'react';
import useAuthorize from './useAuthorize';
import useBalance from './useBalance';

/** A custom hook that returns the list of accounts of the logged in user. */
const useAccountsList = () => {
const { data: authorize_data, ...rest } = useAuthorize();
const { data: balance_data } = useBalance();

// Add additional information to the authorize response.
const modified_accounts = useMemo(() => {
Expand All @@ -30,9 +32,20 @@ const useAccountsList = () => {
});
}, [authorize_data.account_list, authorize_data.loginid]);

// Add balance to each account
const modified_accounts_with_balance = useMemo(
() =>
modified_accounts?.map(account => ({
...account,
/** The balance of the account. */
balance: balance_data?.accounts?.[account.loginid]?.balance || 0,
})),
[balance_data?.accounts, modified_accounts]
);

return {
/** The list of accounts. */
data: modified_accounts,
data: modified_accounts_with_balance,
...rest,
};
};
Expand Down

0 comments on commit 278eacd

Please sign in to comment.