Skip to content

Commit

Permalink
fix: mt5 get more button not launching jurisdicton modal and cfd malt…
Browse files Browse the repository at this point in the history
…ainvest (binary-com#13056)
  • Loading branch information
thisyahlen-deriv committed Jan 19, 2024
1 parent 2380193 commit 6509df7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/api/src/hooks/useSortedMT5Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const useSortedMT5Accounts = (regulation?: string) => {
? all_available_mt5_accounts.filter(account => account.shortcode === 'maltainvest')
: all_available_mt5_accounts;

const filtered_mt5_accounts = mt5_accounts.filter(account => account.is_virtual === activeAccount?.is_virtual);
const filtered_mt5_accounts = mt5_accounts.filter(
account =>
account.is_virtual === activeAccount?.is_virtual &&
(isEU
? account.landing_company_short === 'maltainvest'
: account.landing_company_short !== 'maltainvest')
);

return filtered_available_accounts?.map(available_account => {
const created_account = filtered_mt5_accounts?.find(account => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useMemo } from 'react';
import { useActiveTradingAccount, useAuthorize, useInvalidateQuery, useSortedMT5Accounts } from '@deriv/api';
import { useUIContext } from '../../../../components';
import { TradingAppCardLoader } from '../../../../components/Loaders/TradingAppCardLoader';
import useRegulationFlags from '../../../../hooks/useRegulationFlags';
import { THooks } from '../../../../types';
import { PlatformDetails } from '../../constants';
import { AddedMT5AccountsList, AvailableMT5AccountsList } from '../../flows/MT5';
Expand All @@ -18,6 +19,7 @@ const MT5PlatformsList = ({ onMT5PlatformListLoaded }: TMT5PlatformsListProps) =
const activeRegulation = getUIState('regulation');
const { areAllAccountsCreated, data, isFetchedAfterMount } = useSortedMT5Accounts(activeRegulation ?? '');
const { data: activeTradingAccount } = useActiveTradingAccount();
const { isEU } = useRegulationFlags(activeRegulation);
const invalidate = useInvalidateQuery();

const hasMT5Account = useMemo(() => {
Expand All @@ -35,6 +37,9 @@ const MT5PlatformsList = ({ onMT5PlatformListLoaded }: TMT5PlatformsListProps) =
return () => onMT5PlatformListLoaded?.(false);
}, [isFetchedAfterMount, onMT5PlatformListLoaded]);

const shouldShowGetMoreMT5Accounts =
hasMT5Account && !activeTradingAccount?.is_virtual && !areAllAccountsCreated && !isEU && isFetchedAfterMount;

return (
<CFDPlatformLayout title={PlatformDetails.mt5.title}>
{!isFetchedAfterMount && <TradingAppCardLoader />}
Expand All @@ -50,7 +55,7 @@ const MT5PlatformsList = ({ onMT5PlatformListLoaded }: TMT5PlatformsListProps) =
/>
);
})}
{hasMT5Account && !activeTradingAccount?.is_virtual && !areAllAccountsCreated && <GetMoreMT5Accounts />}
{shouldShowGetMoreMT5Accounts && <GetMoreMT5Accounts />}
</CFDPlatformLayout>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React, { ComponentProps, useState } from 'react';
import { Provider } from '@deriv/library';
import { Button } from '@deriv/quill-design';
import { Button } from '@deriv-com/ui/dist/components/Button';
import { Modal } from '../../../../components';
import { MT5AccountType } from '../../screens';
import { JurisdictionModal } from '../JurisdictionModal';

type TMarketTypes = ComponentProps<typeof MT5AccountType>['selectedMarketType'];

const MT5AccountTypeModal = () => {
const [selectedMarketType, setSelectedMarketType] = useState<TMarketTypes>(undefined);
const { setCfdState } = Provider.useCFDContext();
const { show } = Provider.useModal();

return (
<Modal>
Expand All @@ -18,13 +20,12 @@ const MT5AccountTypeModal = () => {
</Modal.Content>
<Modal.Footer>
<Button
colorStyle='coral'
disabled={!selectedMarketType}
onClick={() => {
setCfdState('marketType', selectedMarketType);
show(<JurisdictionModal />);
}}
size='md'
variant='primary'
>
Next
</Button>
Expand Down

0 comments on commit 6509df7

Please sign in to comment.