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.
[CFDs] Hirad/ Adding the current_list hook (binary-com#11358)
* chore: adding the current_list hook * fix: making changes based on the comments * fix: changed back to the previous state because of the type conflicts * fix: used api types instead of constant types
- Loading branch information
1 parent
acafd46
commit 479ce80
Showing
8 changed files
with
64 additions
and
11 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
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
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,51 @@ | ||
import { useStore } from '@deriv/stores'; | ||
import { useMT5AccountsList, useDxtradeAccountsList, useCtraderAccountsList } from '@deriv/api'; | ||
import { getAccountListKey, CFD_PLATFORMS, Jurisdiction } from '@deriv/shared'; | ||
|
||
type MT5AccountsList = NonNullable<ReturnType<typeof useMT5AccountsList>['data']>[number]; | ||
type DxtradeAccountsList = NonNullable<ReturnType<typeof useDxtradeAccountsList>['data']>[number]; | ||
type CtraderAccountsList = NonNullable<ReturnType<typeof useCtraderAccountsList>['data']>[number]; | ||
|
||
type TCurrentList = { | ||
[key: string]: MT5AccountsList | DxtradeAccountsList | CtraderAccountsList; | ||
}; | ||
|
||
/* | ||
This hook is used to get the existing_accounts_data | ||
*/ | ||
const useCurrentList = () => { | ||
const current_list: TCurrentList = {}; | ||
const { traders_hub } = useStore(); | ||
const { data: mt5_accounts } = useMT5AccountsList(); | ||
const { data: dxtrade_accounts } = useDxtradeAccountsList(); | ||
const { data: ctrader_accounts } = useCtraderAccountsList(); | ||
const show_eu_related_content = traders_hub.show_eu_related_content; | ||
|
||
mt5_accounts | ||
?.filter(acc => | ||
show_eu_related_content | ||
? acc.landing_company_short === Jurisdiction.MALTA_INVEST | ||
: acc.landing_company_short !== Jurisdiction.MALTA_INVEST | ||
) | ||
.forEach(account => { | ||
current_list[getAccountListKey(account, CFD_PLATFORMS.MT5, account.landing_company_short)] = { | ||
...account, | ||
}; | ||
}); | ||
|
||
dxtrade_accounts?.forEach(account => { | ||
current_list[getAccountListKey(account, CFD_PLATFORMS.DXTRADE, account.landing_company_short)] = { | ||
...account, | ||
}; | ||
}); | ||
|
||
ctrader_accounts?.forEach(account => { | ||
current_list[getAccountListKey(account, CFD_PLATFORMS.CTRADER, account.landing_company_short)] = { | ||
...account, | ||
}; | ||
}); | ||
|
||
return { current_list }; | ||
}; | ||
|
||
export default useCurrentList; |
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