Skip to content

Commit fcf9d9f

Browse files
authored
[TRAH] Aizad/TRAH-2693/WrongPlacementForRealAccounts (#13118)
* chore: fix Currency Switcher * chore: split component in different files * fix: change from quill to ui * fix: updated import with latest path * fix: provide fallback for undefined values
1 parent 13d0f58 commit fcf9d9f

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

packages/tradershub/src/components/CurrencySwitcher/CurrencySwitcher.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { THooks } from '@/types';
77
import { useActiveTradingAccount, useResetVirtualBalance } from '@deriv/api';
88
import { Provider } from '@deriv/library';
99
import { StandaloneChevronDownBoldIcon } from '@deriv/quill-icons';
10-
import { Button, Text } from '@deriv-com/ui';
10+
import { Button } from '@deriv-com/ui';
11+
import { DemoCurrencySwitcherAccountInfo, RealCurrencySwitcherAccountInfo } from './CurrencySwitcherAccountInfo';
1112

1213
type AccountActionButtonProps = {
1314
balance: THooks.ActiveTradingAccount['balance'];
@@ -53,25 +54,20 @@ const CurrencySwitcher = () => {
5354

5455
if (!isSuccess) return <CurrencySwitcherLoader />;
5556

57+
const { icon, text } = IconToCurrencyMapper[iconCurrency];
58+
5659
return (
5760
<div className='flex items-center justify-between w-full border-solid h-3600 p-800 rounded-400 border-75 border-system-light-active-background lg:w-auto lg:shrink-0 gap-800'>
58-
<div className='flex-none '>{IconToCurrencyMapper[iconCurrency].icon}</div>
61+
<div className='flex-none '>{icon}</div>
5962
<div className='grow'>
60-
<Text
61-
as='p'
62-
className={isDemo ? 'text-status-light-information' : 'text-system-light-less-prominent-text'}
63-
size='sm'
64-
weight={isDemo ? 'bold' : 'normal'}
65-
>
66-
{isDemo ? activeAccount.display_balance : IconToCurrencyMapper[iconCurrency].text}
67-
</Text>
68-
<Text
69-
className={!isDemo ? 'text-status-light-success' : ''}
70-
size='sm'
71-
weight={isDemo ? 'normal' : 'bold'}
72-
>
73-
{isDemo ? 'Demo' : activeAccount?.display_balance}
74-
</Text>
63+
{isDemo ? (
64+
<DemoCurrencySwitcherAccountInfo displayBalance={activeAccount?.display_balance} />
65+
) : (
66+
<RealCurrencySwitcherAccountInfo
67+
currencyText={text}
68+
displayBalance={activeAccount?.display_balance}
69+
/>
70+
)}
7571
</div>
7672
<div className='flex-none'>
7773
<AccountActionButton balance={activeAccount?.balance ?? 0} isDemo={isDemo ?? false} />
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { IconToCurrencyMapperType } from '@/constants';
3+
import { THooks } from '@/types';
4+
import { Text } from '@deriv-com/ui';
5+
6+
type DemoCurrencySwitcherAccountInfoProps = {
7+
displayBalance: THooks.ActiveTradingAccount['display_balance'];
8+
};
9+
10+
type RealCurrencySwitcherAccountInfoProps = {
11+
currencyText: IconToCurrencyMapperType['currency_text']['text'];
12+
displayBalance?: THooks.ActiveTradingAccount['display_balance'];
13+
};
14+
15+
export const DemoCurrencySwitcherAccountInfo = ({ displayBalance }: DemoCurrencySwitcherAccountInfoProps) => (
16+
<div className='flex flex-col'>
17+
<Text className='font-light text-system-light-less-prominent-text' size='sm' weight='bold'>
18+
Demo
19+
</Text>
20+
<Text className='text-status-light-information' size='sm' weight='bold'>
21+
{displayBalance}
22+
</Text>
23+
</div>
24+
);
25+
26+
export const RealCurrencySwitcherAccountInfo = ({
27+
currencyText,
28+
displayBalance,
29+
}: RealCurrencySwitcherAccountInfoProps) => (
30+
<div className='flex flex-col'>
31+
<Text className='text-status-light-success' size='sm' weight='bold'>
32+
{displayBalance ?? '0.00'}
33+
</Text>
34+
<Text className='text-system-light-less-prominent-text' size='sm'>
35+
{currencyText}
36+
</Text>
37+
</div>
38+
);

packages/tradershub/src/constants/constants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { PlatformIcon } from '../components';
1414
import { getStaticUrl, getUrlBinaryBot, getUrlSmartTrader } from '../helpers/urls';
1515

16-
type IconToCurrencyMapperType = {
16+
export type IconToCurrencyMapperType = {
1717
[key: string]: {
1818
icon: React.ReactNode;
1919
text: string;

0 commit comments

Comments
 (0)