Skip to content

Commit 2ce8ea2

Browse files
authored
Merge pull request #184 from ameerul-deriv/FEQ-2444-implement-real-time-exchange-rate
Ameerul / FEQ-2444 Implement real-time exchange rate
2 parents ec9569f + 054d896 commit 2ce8ea2

File tree

19 files changed

+492
-79
lines changed

19 files changed

+492
-79
lines changed

src/components/BuySellForm/BuySellAmount/BuySellAmount.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeEvent, useEffect, useState } from 'react';
1+
import { ChangeEvent, useEffect } from 'react';
22
import { Controller, useForm } from 'react-hook-form';
33
import { TCurrency } from 'types';
44
import { LightDivider } from '@/components';
@@ -10,52 +10,56 @@ import './BuySellAmount.scss';
1010

1111
type TBuySellAmountProps = {
1212
accountCurrency: string;
13-
amount: string;
13+
buySellAmount: string;
1414
calculatedRate: string;
1515
control: ReturnType<typeof useForm>['control'];
16+
inputValue: string;
1617
isBuy: boolean;
1718
isDisabled: boolean;
1819
localCurrency: TCurrency;
1920
maxLimit: string;
2021
minLimit: string;
2122
paymentMethodNames?: string[];
23+
setBuySellAmount: (value: string) => void;
24+
setInputValue: (value: string) => void;
2225
setValue: ReturnType<typeof useForm>['setValue'];
2326
trigger: ReturnType<typeof useForm>['trigger'];
2427
};
2528
const BuySellAmount = ({
2629
accountCurrency,
27-
amount,
30+
buySellAmount,
2831
calculatedRate,
2932
control,
33+
inputValue,
3034
isBuy,
3135
isDisabled,
3236
localCurrency,
3337
maxLimit,
3438
minLimit,
3539
paymentMethodNames,
40+
setBuySellAmount,
41+
setInputValue,
3642
setValue,
3743
trigger,
3844
}: TBuySellAmountProps) => {
3945
const { isMobile } = useDevice();
4046
const labelSize = isMobile ? 'sm' : 'xs';
41-
const [inputValue, setInputValue] = useState(minLimit);
42-
const [buySellAmount, setBuySellAmount] = useState(amount);
4347

4448
useEffect(() => {
4549
setBuySellAmount(
4650
FormatUtils.formatMoney(Number(inputValue) * Number(calculatedRate), {
4751
currency: localCurrency,
4852
})
4953
);
50-
}, [calculatedRate, inputValue, localCurrency]);
54+
}, [calculatedRate, inputValue, localCurrency, setBuySellAmount]);
5155

5256
// This is needed as minLimit can be passed as the default 0 on first time render
5357
// causing the amount to be 0
5458
useEffect(() => {
5559
setInputValue(minLimit);
5660
setValue('amount', minLimit);
5761
trigger('amount');
58-
}, [minLimit, setValue, trigger]);
62+
}, [minLimit, setInputValue, setValue, trigger]);
5963

6064
return (
6165
<div className='flex flex-col gap-[2rem] py-[1.6rem]'>

src/components/BuySellForm/BuySellData/BuySellData.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@
77
flex-direction: column;
88
gap: 1.6rem;
99
}
10+
11+
&__floating-badge {
12+
color: #1789e1;
13+
padding: 0.2rem 0.4rem;
14+
background-color: rgba(44, 154, 255, 0.08);
15+
border-radius: 0.4rem;
16+
cursor: pointer;
17+
}
1018
}
1119
}

src/components/BuySellForm/BuySellData/BuySellData.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { forwardRef } from 'react';
2+
import clsx from 'clsx';
23
import { THooks } from 'types';
34
import { PaymentMethodWithIcon } from '@/components';
5+
import { RATE_TYPE } from '@/constants';
46
import { formatTime } from '@/utils';
57
import { Localize, useTranslations } from '@deriv-com/translations';
6-
import { Text, useDevice } from '@deriv-com/ui';
8+
import { Text, Tooltip, useDevice } from '@deriv-com/ui';
79
import './BuySellData.scss';
810

911
type TBuySellDataProps = {
@@ -16,6 +18,7 @@ type TBuySellDataProps = {
1618
paymentMethodNames?: string[];
1719
paymentMethods: THooks.PaymentMethods.Get;
1820
rate: string;
21+
rateType?: string;
1922
};
2023

2124
type TType = THooks.AdvertiserPaymentMethods.Get[number]['type'];
@@ -31,6 +34,7 @@ const BuySellData = forwardRef<HTMLDivElement, TBuySellDataProps>(
3134
paymentMethodNames,
3235
paymentMethods,
3336
rate,
37+
rateType,
3438
},
3539
ref
3640
) => {
@@ -44,6 +48,7 @@ const BuySellData = forwardRef<HTMLDivElement, TBuySellDataProps>(
4448
}
4549
return acc;
4650
}, {});
51+
const isFloating = rateType === RATE_TYPE.FLOAT;
4752

4853
return (
4954
<div className='p-[1.6rem] lg:px-[2.4rem]' ref={ref}>
@@ -55,7 +60,33 @@ const BuySellData = forwardRef<HTMLDivElement, TBuySellDataProps>(
5560
<Text size={valueSize}>{name}</Text>
5661
</div>
5762
<div className='flex flex-col w-full'>
58-
<Text color='less-prominent' size={labelSize}>{`Rate (1 ${accountCurrency})`}</Text>
63+
<div className={clsx({ 'lg:hover:mb-[2.2rem]': isFloating })}>
64+
<div
65+
className={clsx('flex items-center gap-2', {
66+
'lg:hover:absolute': isFloating,
67+
})}
68+
>
69+
<Text color='less-prominent' size={labelSize}>{`Rate (1 ${accountCurrency})`}</Text>
70+
{isFloating && (
71+
<Tooltip
72+
className='w-72 mb-[-0.8rem] text-center'
73+
message={
74+
<Text size={labelSize}>
75+
<Localize i18n_default_text='Floating exchange rate shifts with market fluctuations.' />
76+
</Text>
77+
}
78+
>
79+
<Text
80+
as='div'
81+
className='buy-sell-data__details__floating-badge'
82+
size={labelSize}
83+
>
84+
<Localize i18n_default_text='Floating' />
85+
</Text>
86+
</Tooltip>
87+
)}
88+
</div>
89+
</div>
5990
<Text size={valueSize}>
6091
{rate} {localCurrency}
6192
</Text>

0 commit comments

Comments
 (0)