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.
[TRAH] shontzu/TRAH-2576/MT5PlatformList-2 (binary-com#12807)
* chore: init MT5LoginList * style: fix the get more button size * style: remove scss * style: update quill button prop * chore: miscs from code review * chore: remove commented code * fix: responsive view * chore: removed sm * refactor: use market_type and shortcode as key in map function
- Loading branch information
1 parent
810e8e3
commit 6ff40ff
Showing
6 changed files
with
73 additions
and
20 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
55 changes: 55 additions & 0 deletions
55
packages/tradershub/src/features/cfd/components/MT5PlatformsList/MT5PlatformsList.tsx
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,55 @@ | ||
import React, { Fragment, useEffect, useMemo } from 'react'; | ||
import { useActiveTradingAccount, useAuthorize, useInvalidateQuery, useSortedMT5Accounts } from '@deriv/api'; | ||
import { Text } from '@deriv/quill-design'; | ||
import { THooks } from '../../../../types'; | ||
import { AddedMT5AccountsList, AvailableMT5AccountsList } from '../../flows/MT5'; | ||
import { GetMoreMT5Accounts } from '../../screens'; | ||
|
||
type TMT5PlatformsListProps = { | ||
onMT5PlatformListLoaded?: (value: boolean) => void; | ||
}; | ||
|
||
const MT5PlatformsList = ({ onMT5PlatformListLoaded }: TMT5PlatformsListProps) => { | ||
const { isFetching } = useAuthorize(); | ||
const { areAllAccountsCreated, data, isFetchedAfterMount } = useSortedMT5Accounts(); | ||
const { data: activeTradingAccount } = useActiveTradingAccount(); | ||
const invalidate = useInvalidateQuery(); | ||
|
||
const hasMT5Account = useMemo(() => { | ||
return data?.some(account => account.is_added); | ||
}, [data]); | ||
|
||
useEffect(() => { | ||
if (!isFetching) { | ||
invalidate('mt5_login_list'); | ||
} | ||
}, [invalidate, isFetching]); | ||
|
||
useEffect(() => { | ||
onMT5PlatformListLoaded?.(isFetchedAfterMount); | ||
return () => onMT5PlatformListLoaded?.(false); | ||
}, [isFetchedAfterMount, onMT5PlatformListLoaded]); | ||
|
||
return ( | ||
<Fragment> | ||
<Text bold>Deriv MT5</Text> | ||
<div className='grid grid-cols-1 lg:grid-cols-3 gap-1200'> | ||
{isFetchedAfterMount && | ||
data?.map(account => { | ||
if (account.is_added) | ||
return <AddedMT5AccountsList account={account} key={`added-mt5-list-${account.loginid}`} />; | ||
|
||
return ( | ||
<AvailableMT5AccountsList | ||
account={account as unknown as THooks.MT5AccountsList} | ||
key={`available-mt5-list-${account.market_type}-${account.shortcode}`} | ||
/> | ||
); | ||
})} | ||
{hasMT5Account && !activeTradingAccount?.is_virtual && !areAllAccountsCreated && <GetMoreMT5Accounts />} | ||
</div> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export default MT5PlatformsList; |
1 change: 1 addition & 0 deletions
1
packages/tradershub/src/features/cfd/components/MT5PlatformsList/index.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 @@ | ||
export { default as MT5PlatformsList } from './MT5PlatformsList'; |
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