Skip to content

Commit fd9c415

Browse files
authored
Merge 0b2c402 into d2cd2f3
2 parents d2cd2f3 + 0b2c402 commit fd9c415

File tree

6 files changed

+94
-3
lines changed

6 files changed

+94
-3
lines changed

packages/api/src/hooks/useTradingAccountsList.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const useTradingAccountsList = () => {
1717
const modified_accounts = useMemo(() => {
1818
return filtered_accounts?.map(trading => ({
1919
...trading,
20+
first_real_loginid: filtered_accounts?.find(account => account.account_type === 'real')?.loginid[0],
21+
demo_loginid: filtered_accounts?.find(account => account.account_type === 'demo')?.loginid,
2022
}));
2123
}, [filtered_accounts]);
2224

packages/tradershub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
},
1515
"dependencies": {
1616
"@deriv/api": "^1.0.0",
17-
"@deriv/library": "^1.0.0",
1817
"@deriv/integration": "^1.0.0",
18+
"@deriv/library": "^1.0.0",
1919
"@deriv/quill-design": "^1.3.2",
2020
"@deriv/quill-icons": "^1.0.10",
2121
"@deriv/react-joyride": "^2.6.2",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React, { useCallback, useEffect, useState } from 'react';
2+
import { Button, qtMerge, Text } from '@deriv/quill-design';
3+
import { LabelPairedChevronDownSmRegularIcon } from '@deriv/quill-icons';
4+
5+
type TAccount = {
6+
label: string;
7+
value: string;
8+
};
9+
10+
const accountTypes = [
11+
{ label: 'Demo', value: 'demo' },
12+
{ label: 'Real', value: 'real' },
13+
];
14+
15+
const DemoRealSwitcher = () => {
16+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
17+
const [selected, setSelected] = useState(accountTypes[0]);
18+
const { label, value } = selected;
19+
20+
useEffect(() => {
21+
setIsDropdownOpen(false);
22+
}, [selected]);
23+
24+
const toggleDropdown = useCallback(() => {
25+
setIsDropdownOpen(prevState => !prevState);
26+
}, []);
27+
28+
const selectAccount = useCallback((account: TAccount) => {
29+
setSelected(account);
30+
}, []);
31+
32+
return (
33+
<div className='relative inline-block w-auto'>
34+
<Button
35+
className={qtMerge(
36+
'cursor-pointer w-full py-[3px] px-400 border-75 rounded-200 [&>span]:flex [&>span]:items-center [&>span]:text-[14px]',
37+
value === 'demo'
38+
? 'border-status-light-information text-status-light-information'
39+
: 'border-status-light-success text-status-light-success'
40+
)}
41+
colorStyle='white'
42+
iconPosition='end'
43+
onClick={toggleDropdown}
44+
size='sm'
45+
variant='secondary'
46+
>
47+
{label}
48+
<LabelPairedChevronDownSmRegularIcon
49+
className={qtMerge(
50+
'transform transition duration-200 ease-in-out ml-400',
51+
value === 'demo' ? 'fill-status-light-information' : 'fill-status-light-success',
52+
isDropdownOpen && '-rotate-180'
53+
)}
54+
/>
55+
</Button>
56+
{isDropdownOpen && (
57+
<div className='absolute top-1400 z-10 rounded-200 bg-system-light-primary-background shadow-320 w-full'>
58+
{accountTypes.map(account => (
59+
<div
60+
className={qtMerge(
61+
'cursor-pointer hover:bg-system-light-hover-background',
62+
account.value === value && 'bg-system-light-active-background'
63+
)}
64+
key={account.value}
65+
onClick={() => selectAccount(account)}
66+
onKeyDown={event => {
67+
if (event.key === 'Enter') {
68+
selectAccount(account);
69+
}
70+
}}
71+
role='button'
72+
>
73+
<Text bold={account.value === value} className='px-800 py-300 text-center' size='sm'>
74+
{account.label}
75+
</Text>
76+
</div>
77+
))}
78+
</div>
79+
)}
80+
</div>
81+
);
82+
};
83+
84+
export default DemoRealSwitcher;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as DemoRealSwitcher } from './DemoRealSwitcher';

packages/tradershub/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './ButtonGroup';
44
export * from './Clipboard';
55
export * from './ContentSwitcher';
66
export * from './CurrencySwitcher';
7+
export * from './DemoRealSwitcher';
78
export * from './Dialog';
89
export * from './GetADerivAccountBanner';
910
export * from './Modal';

packages/tradershub/src/routes/TradersHubRoute/TradersHubRoute.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import React, { FC } from 'react';
22
import { Button, Heading, Text } from '@deriv/quill-design';
3-
import { OptionsAndMultipliersSection, StaticLink, TotalAssets } from '../../components';
3+
import { DemoRealSwitcher, OptionsAndMultipliersSection, StaticLink, TotalAssets } from '../../components';
44
import { CTraderList } from '../../features/cfd/components/CTraderList';
55
import { OtherCFDPlatformsList } from '../../features/cfd/components/OtherCFDPlatformsList';
66

77
const TradersHubRoute: FC = () => {
88
return (
99
<div className='flex flex-col gap-1200'>
1010
<div className='flex items-center justify-between align-start gap-100'>
11-
<Heading.H3>Trader&apos;s Hub</Heading.H3>
11+
<div className='flex flex-row gap-600'>
12+
<Heading.H3>Trader&apos;s Hub</Heading.H3>
13+
<DemoRealSwitcher />
14+
</div>
1215
<TotalAssets />
1316
</div>
1417
<OptionsAndMultipliersSection />

0 commit comments

Comments
 (0)