forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
farzin/feat: add
useTradingAccountsList
, useActiveTradingAccount
,…
… and `useActiveAccount` hooks (binary-com#9824) * refactor(api): ♻️ clean-up * feat(api): ✨ add `useTradingAccountsList`, `useActiveTradingAccount`, and `useActiveAccount` hooks --------- Co-authored-by: Farzin Mirzaie <farzin@deriv.com>
- Loading branch information
1 parent
04eebe8
commit 7e84c1c
Showing
12 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
export { default as useAccountsList } from './useAccountsList'; | ||
export { default as useActiveWalletAccounts } from './useActiveWalletAccounts'; | ||
export { default as useActiveAccount } from './useActiveAccount'; | ||
export { default as useActiveTradingAccount } from './useActiveTradingAccount'; | ||
export { default as useActiveWalletAccount } from './useActiveWalletAccount'; | ||
export { default as useAuthorize } from './useAuthorize'; | ||
export { default as useBalance } from './useBalance'; | ||
export { default as useCurrencyConfig } from './useCurrencyConfig'; | ||
export { default as useGetAccountStatus } from './useGetAccountStatus'; | ||
export { default as useLandingCompany } from './useLandingCompany'; | ||
export { default as useMT5LoginList } from './useMT5LoginList'; | ||
export { default as useSettings } from './useSettings'; | ||
export { default as useTradingAccountsList } from './useTradingAccountsList'; | ||
export { default as useTradingPlatformAccounts } from './useTradingPlatformAccounts'; | ||
export { default as useWalletAccountsList } from './useWalletAccountsList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useMemo } from 'react'; | ||
import useAccountsList from './useAccountsList'; | ||
|
||
/** A custom hook that returns the account object for the current active account. */ | ||
const useActiveAccount = () => { | ||
const { data, ...rest } = useAccountsList(); | ||
const active_account = useMemo(() => data?.find(account => account.is_active), [data]); | ||
|
||
return { | ||
/** User's current active account. */ | ||
data: active_account, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useActiveAccount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useMemo } from 'react'; | ||
import useTradingAccountsList from './useTradingAccountsList'; | ||
|
||
/** A custom hook that returns the trading object for the current active trading. */ | ||
const useActiveTradingAccount = () => { | ||
const { data, ...rest } = useTradingAccountsList(); | ||
const active_trading = useMemo(() => data?.find(trading => trading.is_active), [data]); | ||
|
||
return { | ||
/** User's current active trading. */ | ||
data: active_trading, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useActiveTradingAccount; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMemo } from 'react'; | ||
import useAccountsList from './useAccountsList'; | ||
|
||
/** A custom hook that gets the list of all trading accounts for the current user. */ | ||
const useTradingAccountsList = () => { | ||
const { data: account_list_data, ...rest } = useAccountsList(); | ||
|
||
// Filter out non-trading accounts. | ||
const filtered_accounts = useMemo( | ||
() => account_list_data?.filter(account => account.is_trading), | ||
[account_list_data] | ||
); | ||
|
||
// Add additional information to each trading account. | ||
const modified_accounts = useMemo(() => { | ||
return filtered_accounts?.map(trading => ({ ...trading })); | ||
}, [filtered_accounts]); | ||
|
||
return { | ||
/** The list of trading accounts for the current user. */ | ||
data: modified_accounts, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useTradingAccountsList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.