Skip to content

Commit

Permalink
[CFDs] Hirad/ Adding the current_list hook (binary-com#11358)
Browse files Browse the repository at this point in the history
* 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
hirad-deriv committed Nov 17, 2023
1 parent acafd46 commit 479ce80
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 11 deletions.
10 changes: 6 additions & 4 deletions packages/cfd/src/Components/props.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type TCFDPlatform = 'dxtrade' | 'mt5' | 'ctrader' | 'derivez';

export type TCFDsPlatformType = 'dxtrade' | 'derivez' | 'mt5' | 'ctrader' | '';

export type TShortcode = DetailsOfEachMT5Loginid['landing_company_short'];

export type TCFDAccountCopy = {
text: string | undefined;
className: string;
Expand Down Expand Up @@ -87,10 +89,10 @@ export type TTradingPlatformAvailableAccount = {
};
signup: string[];
};
shortcode: 'bvi' | 'labuan' | 'maltainvest' | 'svg' | 'vanuatu';
shortcode?: TShortcode;
sub_account_type: string;
account_type?: 'real' | 'demo';
landing_company_short?: 'bvi' | 'labuan' | 'svg' | 'vanuatu';
landing_company_short?: TShortcode;
};

export type TModifiedTradingPlatformAvailableAccount = Omit<TTradingPlatformAvailableAccount, 'market_type'> & {
Expand Down Expand Up @@ -235,7 +237,7 @@ export type TTradingPlatformAccounts = {
/**
* Landing company shortcode of the DXTrade account.
*/
landing_company_short?: 'bvi' | 'labuan' | 'malta' | 'maltainvest' | 'svg' | 'vanuatu';
landing_company_short?: DetailsOfEachMT5Loginid['landing_company_short'];
/**
* Login of DXTrade account.
*/
Expand Down Expand Up @@ -279,7 +281,7 @@ export type TJurisdictionData = {

export type TDetailsOfEachMT5Loginid = DetailsOfEachMT5Loginid & {
display_login?: string;
landing_company_short?: string;
landing_company_short?: TShortcode;
short_code_and_region?: string;
mt5_acc_auth_status?: string | null;
selected_mt5_jurisdiction?: TOpenAccountTransferMeta &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const CFDCompareAccountsButton = observer(({ trading_platforms, is_demo }: TComp
const history = useHistory();

const market_type = getMarketType(trading_platforms);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode ?? '');
const {
modules: { cfd },
common,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { REGION } from '../../Helpers/cfd-config';

const CFDCompareAccountsDescription = ({ trading_platforms, is_demo }: TCompareAccountsCard) => {
const market_type = getMarketType(trading_platforms);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode ?? '');
const juridisction_data = getJuridisctionDescription(market_type_shortcode);
const { traders_hub } = useStore();
const { selected_region } = traders_hub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CFD_PLATFORMS, MARKET_TYPE_SHORTCODE } from '../../Helpers/cfd-config';

const CFDCompareAccountsTitleIcon = ({ trading_platforms, is_eu_user, is_demo }: TCompareAccountsCard) => {
const market_type = !is_eu_user ? getMarketType(trading_platforms) : 'CFDs';
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode ?? '');
const jurisdiction_card_icon =
trading_platforms.platform === CFD_PLATFORMS.DXTRADE || trading_platforms.platform === CFD_PLATFORMS.CTRADER
? getAccountIcon(trading_platforms.platform)
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Containers/props.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type TCFDPersonalDetailsContainerProps = {
onSubmit: (index: number, value: { [key: string]: string }) => void;
};

type CFD_Platform = 'dxtrade' | 'mt5' | 'derivez' | 'ctrader';
export type CFD_Platform = 'dxtrade' | 'mt5' | 'derivez' | 'ctrader';

export type TCFDChangePasswordConfirmationProps = {
confirm_label?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Helpers/compare-accounts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getHighlightedIconLabel = (
is_demo?: boolean
): TInstrumentsIcon[] => {
const market_type = getMarketType(trading_platforms);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode);
const market_type_shortcode = market_type.concat('_', trading_platforms.shortcode ?? '');
// Forex for these: MT5 Financial Vanuatu, MT5 Financial Labuan
const forex_label =
market_type_shortcode === MARKET_TYPE_SHORTCODE.FINANCIAL_LABUAN ||
Expand Down
51 changes: 51 additions & 0 deletions packages/cfd/src/features/hooks/useCurrentList.ts
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;
4 changes: 2 additions & 2 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type TTradingPlatformAvailableAccount = {
};
signup: string[];
};
shortcode: 'bvi' | 'labuan' | 'svg' | 'vanuatu' | 'maltainvest';
shortcode?: DetailsOfEachMT5Loginid['landing_company_short'];
sub_account_type: string;
};

Expand Down Expand Up @@ -884,7 +884,7 @@ type TTradersHubStore = {
action_type: 'get' | 'none' | 'trade' | 'dxtrade' | 'multi-action';
key: string;
name: string;
landing_company_short?: 'bvi' | 'labuan' | 'svg' | 'vanuatu' | 'maltainvest';
landing_company_short?: DetailsOfEachMT5Loginid['landing_company_short'];
platform?: TPlatform;
availability?: TRegionAvailability;
description?: string;
Expand Down

0 comments on commit 479ce80

Please sign in to comment.