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.
thisyahlen/chore: add useTradingPlatformAvailableAccounts to deriv api (
binary-com#9810) * chore: add useTradingPlatformAvailableAccounts to deriv api * fix: type repetition annd fallback * refactor: repetition * fix: empty commit * fix: empty commit * fix: comment
- Loading branch information
1 parent
39ce848
commit 43a4298
Showing
3 changed files
with
140 additions
and
0 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
38 changes: 38 additions & 0 deletions
38
packages/api/src/hooks/useTradingPlatformAvailableAccounts.ts
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,38 @@ | ||
import { useMemo } from 'react'; | ||
import useFetch from '../useFetch'; | ||
|
||
/** @description This hook is used to get all the available MT5 accounts. */ | ||
const useTradingPlatformAvailableAccounts = () => { | ||
const { data: mt5_available_accounts, ...rest } = useFetch('trading_platform_available_accounts', { | ||
payload: { platform: 'mt5' }, | ||
}); | ||
|
||
const modified_mt5_available_accounts = useMemo( | ||
() => | ||
mt5_available_accounts?.trading_platform_available_accounts?.map(account => { | ||
return { | ||
...account, | ||
}; | ||
}), | ||
[mt5_available_accounts?.trading_platform_available_accounts] | ||
); | ||
|
||
/** This function is used to group the available MT5 accounts by market type. */ | ||
const grouped_mt5_available_accounts = useMemo(() => { | ||
return modified_mt5_available_accounts?.reduce((acc, account) => { | ||
const { market_type } = account; | ||
const marketType = market_type as keyof typeof acc; | ||
const marketTypeArray = acc[marketType] || (acc[marketType] = []); | ||
marketTypeArray.push(account); | ||
return acc; | ||
}, {} as Record<string, typeof modified_mt5_available_accounts>); | ||
}, [modified_mt5_available_accounts]); | ||
|
||
return { | ||
/** The available MT5 accounts grouped by market type */ | ||
data: grouped_mt5_available_accounts, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useTradingPlatformAvailableAccounts; |
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