Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

likhith/create floating-rate ad #4964

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
0cb4788
Floating-rate Ui created
likhith-deriv Feb 18, 2022
5751994
Added validations to floating-rate component
likhith-deriv Feb 21, 2022
2d3d600
Implemented Floating rate component
likhith-deriv Feb 22, 2022
d01c0af
Merge branch 'master' into floating-rate_component
likhith-deriv Feb 22, 2022
f83552a
Added default values for floating rates based on ad type
likhith-deriv Feb 22, 2022
e670b1d
fixed lint issues
likhith-deriv Feb 22, 2022
0619504
Minor bug fixes
likhith-deriv Feb 28, 2022
7652940
Added store subscriptions
likhith-deriv Mar 1, 2022
d002832
Enhanced InputField component and added floating rate store
likhith-deriv Mar 2, 2022
a4ef4f0
Merge master into floating-rate_component
likhith-deriv Mar 2, 2022
8c99860
Resolved lint errors
likhith-deriv Mar 2, 2022
49dccb0
Added changes for My Ad screen
likhith-deriv Mar 3, 2022
afef5ff
Added floate-rate
likhith-deriv Mar 3, 2022
856599d
Added exisiting user update
likhith-deriv Mar 3, 2022
bfbb63c
Added reaction to my-ad store
likhith-deriv Mar 4, 2022
77ab388
Edit form
likhith-deriv Mar 4, 2022
3bb733a
Added edit ad section
likhith-deriv Mar 4, 2022
6980ea9
Added switch rate modal
likhith-deriv Mar 5, 2022
e8713c4
Added switch ad dialog
likhith-deriv Mar 7, 2022
23addfb
Added banner condition
likhith-deriv Mar 7, 2022
b618b8b
Added banner condition
likhith-deriv Mar 7, 2022
4e07c77
Empty commit
likhith-deriv Mar 7, 2022
7122a80
Integrated floating rate into create ad
likhith-deriv Mar 7, 2022
6da086d
Minor bug fixes
likhith-deriv Mar 8, 2022
d402276
Minor bug fixes
likhith-deriv Mar 8, 2022
6d6777a
removed console logs
likhith-deriv Mar 8, 2022
0769a69
Incorporated API changes
likhith-deriv Mar 9, 2022
80509c4
Incorporated review comments
likhith-deriv Mar 10, 2022
47b3d25
Removed duplication
likhith-deriv Mar 16, 2022
0c73e36
Integrated API with create floting rate ad
likhith-deriv Mar 22, 2022
bf7e356
Incorporated review comments
likhith-deriv Mar 22, 2022
75aebfc
Added floating rate error messages
likhith-deriv Mar 23, 2022
a63385b
Resolved lint error
likhith-deriv Mar 23, 2022
fd74cb3
Merge branch 'floating-rate' of github.com:binary-com/deriv-app into …
likhith-deriv Mar 23, 2022
b563eb3
Added styling as per UX
likhith-deriv Mar 24, 2022
c1ce381
Minor bug fix in create ad form
likhith-deriv Mar 25, 2022
838d968
Changes CSS as per BEM
likhith-deriv Mar 28, 2022
fa90407
Resolved lint error
likhith-deriv Mar 28, 2022
067528f
Added current_focus to input field
likhith-deriv Apr 1, 2022
8cf21a3
Merge branch 'floating-rate' of github.com:binary-com/deriv-app into …
likhith-deriv Apr 1, 2022
605b8d6
Minor bug fixes for Create ad
likhith-deriv Apr 1, 2022
6ea3617
Merge branch 'floating-rate' of github.com:binary-com/deriv-app into …
likhith-deriv Apr 1, 2022
21e03d3
Incorporated review comments
likhith-deriv Apr 5, 2022
24f45c2
Minor bug fix
likhith-deriv Apr 5, 2022
21ecc4b
Removed empty structure
likhith-deriv Apr 5, 2022
006a882
Removed additional switch state
likhith-deriv Apr 5, 2022
3403a6f
Fixed issue with date banner
likhith-deriv Apr 5, 2022
40da3db
Added test cases for Floating rate component
likhith-deriv Apr 6, 2022
a4d8dcc
Removed the empty element and replaced with null
likhith-deriv Apr 6, 2022
765cd43
Incorporated the changes
likhith-deriv Apr 7, 2022
38aa0d9
fixed incorrect file name
likhith-deriv Apr 7, 2022
f2845e7
Trigger Build
likhith-deriv Apr 7, 2022
ce807aa
Added as per naming
likhith-deriv Apr 7, 2022
2362071
Removed localize of 1
likhith-deriv Apr 7, 2022
4289aef
Added review comments
likhith-deriv Apr 8, 2022
4a1af77
Incorporated changes
likhith-deriv Apr 12, 2022
8851da8
Replaced string with constant
likhith-deriv Apr 13, 2022
9f33cb9
Incorporated review comments
likhith-deriv Apr 13, 2022
faafeca
Removed un-necessary div
likhith-deriv Apr 13, 2022
a87d8a2
Removed css
likhith-deriv Apr 13, 2022
6da74dc
Renamed function
likhith-deriv Apr 13, 2022
9b6ec45
Minor bug fixes and incorporated comments
likhith-deriv Apr 14, 2022
26bb2c7
Added fallback
likhith-deriv Apr 14, 2022
f113fc9
alphabetize observables
likhith-deriv Apr 14, 2022
9ef8b0f
Replaced CSS for Ad status
likhith-deriv Apr 14, 2022
0328e3c
Resoled CSS and functionality bugs
likhith-deriv Apr 19, 2022
322c636
Fixed lint errors
likhith-deriv Apr 19, 2022
d4e6226
Resolved lint erros
likhith-deriv Apr 20, 2022
40bcd3e
Incorporated review comments
likhith-deriv Apr 20, 2022
be702f4
Reduced spacing between the banner
likhith-deriv Apr 21, 2022
0ac00f1
Formatted user input
likhith-deriv Apr 21, 2022
f9a3a65
Fixed failing test case
likhith-deriv Apr 21, 2022
27d786d
Added comments to explain functionality
likhith-deriv Apr 22, 2022
c5a3792
Fetching date and time from server
likhith-deriv Apr 22, 2022
cd23156
Renamed function
likhith-deriv Apr 22, 2022
1ce88cd
Refactored code
likhith-deriv Apr 22, 2022
e67ab7c
Added review comments
likhith-deriv Apr 22, 2022
1f015b3
Resolved decimal round off issue
likhith-deriv Apr 25, 2022
fa5d21d
Fixed Rounding off of decimal digits
likhith-deriv Apr 25, 2022
05a32bc
Regex change in psoitive integer check
likhith-deriv Apr 26, 2022
7e02ea1
Resolved issue with round off to decimal point
likhith-deriv Apr 27, 2022
9ee2c26
Re-arranged imports
likhith-deriv Apr 27, 2022
9ef574e
Fixed the testcase
likhith-deriv Apr 27, 2022
92b00d6
Fixed floating_rate input check
likhith-deriv Apr 28, 2022
8732f94
Removed Math.sign
likhith-deriv Apr 28, 2022
a6a381c
Reverted decimal change
likhith-deriv Apr 28, 2022
86c988b
Implemented round of logic for decimal places
likhith-deriv Apr 29, 2022
12a7913
refactor: Renamed variables
likhith-deriv May 5, 2022
ff7475a
fix: Round off issue in Create Ad summary
likhith-deriv May 9, 2022
49c16f6
fix: resolved decimal point to 2 digits
likhith-deriv May 9, 2022
0795723
Merged changes from upstream floating rate into local
likhith-deriv May 9, 2022
365c319
Resolved lint errors
likhith-deriv May 9, 2022
fbad030
fix: Renamed the function
likhith-deriv May 10, 2022
d43c7fb
chore: Ad display table rate will be calculated from
likhith-deriv May 10, 2022
ef9cd4a
fix: test color in dark theme
likhith-deriv May 10, 2022
6e8fbd0
fix: label changes b/w fixed and floating
likhith-deriv May 11, 2022
b53693d
fix: invoking api call to fetch the changes
likhith-deriv May 11, 2022
707ffb9
fix: rate synced b/w myads and buy/sell
likhith-deriv May 11, 2022
29c1ebe
fix: range offset validation
May 12, 2022
f121bfb
fix: modified rate property in edit ads
May 13, 2022
ca583d1
fix: Float rate input suffix
May 13, 2022
a07495c
fix: code formatted
May 13, 2022
5ec20ce
fix: setting floating rate to 2 decimals on blur
May 13, 2022
6d6d9af
fix: spacing issue with floating rate input
May 13, 2022
b768974
Trigger build
May 16, 2022
b1565eb
Trigger build
May 17, 2022
28a3f77
Merge remote-tracking branch 'upstream/floating-rate' into floating-r…
May 17, 2022
55fa824
Merge remote-tracking branch 'upstream/floating-rate' into floating-r…
May 17, 2022
2f66cb7
fix: removed unwanted padding
May 17, 2022
fb5268a
fix: added ellipse to fix over lapping
May 17, 2022
2ad028f
fix: removed disabling of floating rate field buttons
May 18, 2022
131ab0c
fix: resolved issue with error message
May 18, 2022
67eef42
fix: Overlapping CSS issues in Mobile
May 18, 2022
3c03e02
fix: added missing background color for dark theme
May 18, 2022
ee1a7ce
fix: removed button highlight in mobile
May 18, 2022
708b8cf
fix: button higlight issue
May 18, 2022
1eb0d53
fix: display of cursor pointer on scroll
May 18, 2022
65cfd33
fix: resolved issue with message
May 18, 2022
dcbbefd
fix: Ad change warning message
May 19, 2022
da36456
fix: color for dark mode
May 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions packages/components/src/components/input-field/input-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const InputField = ({
ariaLabel,
checked,
className,
classNameDynamicSuffix,
classNameInlinePrefix,
classNameInput,
classNamePrefix,
classNameWrapper,
currency,
current_focus,
data_tip,
Expand Down Expand Up @@ -45,6 +47,7 @@ const InputField = ({
min_value,
name,
format,
onBlur,
onChange,
onClick,
onClickInputWrapper,
Expand Down Expand Up @@ -184,10 +187,13 @@ const InputField = ({
};

const updateValue = (new_value, is_long_press) => {
const formatted_value = format ? format(new_value) : new_value;
let formatted_value = format ? format(new_value) : new_value;
if (is_long_press) {
setLocalValue(formatted_value);
} else {
if (is_signed && /^\d+/.test(formatted_value) && formatted_value > 0) {
formatted_value = `+${formatted_value}`;
}
onChange({ target: { value: formatted_value, name } });
}
};
Expand Down Expand Up @@ -226,6 +232,7 @@ const InputField = ({
{ 'input--error': has_error },
classNameInput
)}
classNameDynamicSuffix={classNameDynamicSuffix}
classNameInlinePrefix={classNameInlinePrefix}
data_tip={data_tip}
data_value={data_value}
Expand All @@ -241,6 +248,7 @@ const InputField = ({
is_read_only={is_read_only}
max_length={max_length}
name={name}
onBlur={onBlur}
onClick={onClick}
onKeyPressed={onKeyPressed}
placeholder={placeholder}
Expand Down Expand Up @@ -285,9 +293,13 @@ const InputField = ({
)}
{is_increment_input ? (
<div
className={classNames('dc-input-wrapper', {
'dc-input-wrapper--disabled': !!is_disabled,
})}
className={classNames(
'dc-input-wrapper',
{
'dc-input-wrapper--disabled': !!is_disabled,
},
classNameWrapper
)}
>
{increment_buttons}
{input}
Expand Down Expand Up @@ -324,7 +336,9 @@ InputField.propTypes = {
className: PropTypes.string,
classNameInlinePrefix: PropTypes.string,
classNameInput: PropTypes.string,
classNameDynamicSuffix: PropTypes.string,
classNamePrefix: PropTypes.string,
classNameWrapper: PropTypes.string, // CSS class for the component wrapper
currency: PropTypes.string,
current_focus: PropTypes.string,
decimal_point_change: PropTypes.number, // Specify which decimal point must be updated when the increment/decrement button is pressed
Expand All @@ -349,6 +363,7 @@ InputField.propTypes = {
label: PropTypes.string,
max_length: PropTypes.number,
name: PropTypes.string,
onBlur: PropTypes.func,
onChange: PropTypes.func,
onClick: PropTypes.func,
onClickInputWrapper: PropTypes.func,
Expand Down
18 changes: 14 additions & 4 deletions packages/components/src/components/input-field/input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Input = ({
checked,
className,
classNameInlinePrefix,
classNameDynamicSuffix,
current_focus,
data_value,
data_tip,
Expand All @@ -24,6 +25,7 @@ const Input = ({
is_read_only,
max_length,
name,
onBlur,
onClick,
onKeyPressed,
placeholder,
Expand All @@ -38,7 +40,12 @@ const Input = ({
}
}, [current_focus, name]);

const onBlur = () => setCurrentFocus(null);
const onBlurHandler = e => {
setCurrentFocus(null);
if (onBlur) {
onBlur(e);
}
};
const onFocus = () => setCurrentFocus(name);

const onChange = e => {
Expand All @@ -59,7 +66,7 @@ const Input = ({
};

return (
<React.Fragment>
<div className={classNameDynamicSuffix}>
{!!inline_prefix && (
<div className={classNameInlinePrefix}>
<span
Expand All @@ -83,7 +90,7 @@ const Input = ({
id={id}
maxLength={fractional_digits ? max_length + fractional_digits + 1 : max_length}
name={name}
onBlur={onBlur}
onBlur={onBlurHandler}
onChange={onChange}
onClick={onClick}
onFocus={onFocus}
Expand All @@ -96,8 +103,9 @@ const Input = ({
type={type === 'number' ? 'text' : type}
value={display_value || ''}
aria-label={ariaLabel}
data-lpignore={type !== 'password'}
/>
</React.Fragment>
</div>
);
};

Expand All @@ -107,6 +115,7 @@ Input.propTypes = {
checked: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
className: PropTypes.string,
classNameInlinePrefix: PropTypes.string,
classNameDynamicSuffix: PropTypes.string,
current_focus: PropTypes.string,
data_tip: PropTypes.string,
data_value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
Expand All @@ -121,6 +130,7 @@ Input.propTypes = {
is_read_only: PropTypes.bool,
max_length: PropTypes.number,
name: PropTypes.string,
onBlur: PropTypes.func,
onClick: PropTypes.func,
onKeyPressed: PropTypes.func,
placeholder: PropTypes.string,
Expand Down
4 changes: 3 additions & 1 deletion packages/p2p/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { setLanguage } from './i18next';
import './app.scss';

const App = props => {
const { general_store, order_store } = useStores();
const { floating_rate_store, general_store, order_store } = useStores();
const { className, history, lang, order_id, server_time, websocket_api } = props;

React.useEffect(() => {
Expand Down Expand Up @@ -43,6 +43,8 @@ const App = props => {
}
});
general_store.setP2PConfig();
const { currency, local_currency_config } = general_store.client;
floating_rate_store.setExchangeRate(currency, local_currency_config.currency);
return () => general_store.onUnmount();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
13 changes: 9 additions & 4 deletions packages/p2p/src/components/buy-sell/buy-sell-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Table, Text, Button, Icon } from '@deriv/components';
import { isMobile } from '@deriv/shared';
import { formatMoney, isMobile } from '@deriv/shared';
import { observer } from 'mobx-react-lite';
import { buy_sell } from 'Constants/buy-sell';
import { Localize, localize } from 'Components/i18next';
import UserAvatar from 'Components/user/user-avatar';
import { ad_type } from 'Constants/floating-rate';
import { useStores } from 'Stores';
import './buy-sell-row.scss';
import TradeBadge from '../trade-badge';

const BuySellRow = ({ row: advert }) => {
const { buy_sell_store, general_store } = useStores();
const { buy_sell_store, floating_rate_store, general_store } = useStores();

if (advert.id === 'WATCH_THIS_SPACE') {
// This allows for the sliding animation on the Buy/Sell toggle as it pushes
Expand Down Expand Up @@ -41,11 +42,15 @@ const BuySellRow = ({ row: advert }) => {
min_order_amount_limit_display,
payment_method_names,
price_display,
rate_type,
rate,
} = advert;

const is_my_advert = advert.advertiser_details.id === general_store.advertiser_id;
const is_buy_advert = counterparty_type === buy_sell.BUY;
const { name: advertiser_name } = advert.advertiser_details;
const display_effective_rate =
rate_type === ad_type.FIXED ? price_display : parseFloat(floating_rate_store.exchange_rate * (1 + rate / 100));

if (isMobile()) {
return (
Expand Down Expand Up @@ -88,7 +93,7 @@ const BuySellRow = ({ row: advert }) => {
/>
</Text>
<Text as='div' color='profit-success' line_height='m' size='s' weight='bold'>
{price_display} {local_currency}
{formatMoney(local_currency, display_effective_rate, true)} {local_currency}
</Text>
<Text as='div' color='less-prominent' line_height='m' size='xxs'>
<Localize
Expand Down Expand Up @@ -169,7 +174,7 @@ const BuySellRow = ({ row: advert }) => {
</Table.Cell>
<Table.Cell>
<Text color='profit-success' size='xs' line-height='m' weight='bold'>
{price_display} {local_currency}
{formatMoney(local_currency, display_effective_rate, true)} {local_currency}
</Text>
</Table.Cell>
<Table.Cell>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import FloatingRate from '../floating-rate.jsx';

jest.mock('Stores', () => ({
...jest.requireActual('Stores'),
useStores: jest.fn().mockReturnValue({
general_store: {
current_focus: '',
client: { local_currency_config: { decimal_places: 2 } },
setCurrentFocus: jest.fn(),
},
}),
}));

describe('<FloatingRate/>', () => {
it('should render default state of the component with hint message and increment, decrement buttons', () => {
render(<FloatingRate />);

expect(screen.getByText('of the market rate')).toBeInTheDocument();
expect(screen.getAllByRole('button').length).toBe(2);
});

it('should display error messages when error is passed as props', () => {
render(<FloatingRate error_messages='Floating rate error' />);

expect(screen.getByText('Floating rate error')).toBeInTheDocument();
});

it('should render market rate feed based on the floating rate value passed', () => {
render(<FloatingRate value='+2' exchange_rate='100' />);

expect(screen.getByText('Your rate is = 102.00')).toBeInTheDocument();
});

it('should render the exchange rate in hint', () => {
render(<FloatingRate exchange_rate='20' fiat_currency='AED' local_currency='INR' />);

expect(screen.getByText('1 AED = 20.00 INR')).toBeInTheDocument();
});
});
Loading