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

Rostislav / WALL-361 / Cashier Fiat Transfer amount input field #8442

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0683e6e
refactor: init pr
rostislav-deriv May 3, 2023
9bf3f9e
feat: transfer amount input field core logic
rostislav-deriv May 9, 2023
9e1c2ee
refactor: core logic changed a bit
rostislav-deriv May 9, 2023
28ac0e4
refactor: basic styles
rostislav-deriv May 10, 2023
d4f32e8
refactor: basic styles (the right one)
rostislav-deriv May 10, 2023
951a19b
refactor: tests
rostislav-deriv May 10, 2023
f760c63
refactor: backspacing test
rostislav-deriv May 10, 2023
166c389
refactor: fireEvent -> userEvent
rostislav-deriv May 10, 2023
c5ee462
refactor: add the export in index.js
rostislav-deriv May 10, 2023
f914f71
refactor: currency issue fixed
rostislav-deriv May 10, 2023
2d7b9ec
refactor: tests fix
rostislav-deriv May 10, 2023
14defb1
Update packages/components/src/components/transfer-amount-input/__tes…
rostislav-deriv May 10, 2023
d5bd8a5
refactor: TransferAmountInput -> AmountInput
rostislav-deriv May 10, 2023
f9031eb
refactor: remove redundant {}
rostislav-deriv May 10, 2023
605c462
Merge branch 'feature/wallets_with_traders_hub' into rostislav/WALL-3…
rostislav-deriv May 10, 2023
d9f4107
refactor: onChange prop added to AmountInput
rostislav-deriv May 11, 2023
b12b56b
Merge remote-tracking branch 'origin/rostislav/WALL-361/cashier-fiat-…
rostislav-deriv May 11, 2023
462fe2c
Update packages/components/src/components/amount-input/amount-input.tsx
rostislav-deriv May 11, 2023
d7728bc
refactor: suggestions
rostislav-deriv May 11, 2023
a35d1a4
Merge remote-tracking branch 'origin/rostislav/WALL-361/cashier-fiat-…
rostislav-deriv May 11, 2023
10b50b4
refactor: suggestions
rostislav-deriv May 11, 2023
fd9b68e
Update packages/components/src/components/amount-input/amount-input.scss
rostislav-deriv May 11, 2023
7a08621
refactor: props naming
rostislav-deriv May 11, 2023
f6a82c7
Merge remote-tracking branch 'origin/rostislav/WALL-361/cashier-fiat-…
rostislav-deriv May 11, 2023
66ded48
Update packages/components/src/components/amount-input/amount-input.tsx
rostislav-deriv May 11, 2023
8ee09bf
fix: import added
rostislav-deriv May 11, 2023
21a0cf5
refactor: removed redundant Input prop for max_characters
rostislav-deriv May 11, 2023
676836c
refactor: useCallback
rostislav-deriv May 11, 2023
cfad245
fix: tests and logic as well
rostislav-deriv May 11, 2023
68a9f90
refactor: using isMobile() for responsive design for AmountInput
rostislav-deriv May 11, 2023
d2577f4
refactor: toLocaleString locale changed to `undefined`
rostislav-deriv May 11, 2023
37b4ac3
refactor: test
rostislav-deriv May 11, 2023
bf1107c
Update packages/components/src/components/amount-input/amount-input.tsx
rostislav-deriv May 12, 2023
f3eb394
feat: amount-input-for-testing.tsx
rostislav-deriv May 12, 2023
9b78680
fix: amount-input-for-testing.tsx
rostislav-deriv May 12, 2023
d960fd2
fix: amount-input-for-testing.tsx
rostislav-deriv May 12, 2023
73eccc6
Update packages/components/src/components/amount-input/amount-input.tsx
rostislav-deriv May 12, 2023
fd93683
fix: tests fix by rollback
rostislav-deriv May 12, 2023
9254d04
refactor: cursor/caret issue resolved
rostislav-deriv May 12, 2023
875ebdc
refactor: pasting behavior resolved
rostislav-deriv May 12, 2023
cfaaebd
refactor: separators on paste should remain now
rostislav-deriv May 13, 2023
1ce7ef1
fix: fixed the behaviour except ctrl + a; added comments
rostislav-deriv May 13, 2023
e6a118e
refactor: isPasting -> is_pasting
rostislav-deriv May 13, 2023
431e8d4
fix: all behaviour seems to be as expected now
rostislav-deriv May 13, 2023
c339fd5
test: added more tests
rostislav-deriv May 13, 2023
f5967fa
Merge branch 'feature/wallets_with_traders_hub' into rostislav/WALL-3…
rostislav-deriv May 16, 2023
ddb5f56
refactor: input type changed to number
rostislav-deriv May 16, 2023
65ee80f
refactor: minor tests changes; also inputMode added to force keyboard…
rostislav-deriv May 16, 2023
0f8ecf4
refactor: toggles
rostislav-deriv May 16, 2023
6d47160
refactor: cursor/caret fix using state
rostislav-deriv May 17, 2023
70ead4c
fix: wring pasting behaviour fixed
rostislav-deriv May 18, 2023
d8be587
refactor: naming change for clarity
rostislav-deriv May 18, 2023
a778bc0
refactor: added a handler and comments
rostislav-deriv May 18, 2023
6fad876
fix: tests and a logical flaw
rostislav-deriv May 18, 2023
98ad866
refactor: added deps to useEffect
rostislav-deriv May 18, 2023
75116fa
refactor: ChatGPT's solution to the type thing
rostislav-deriv May 19, 2023
e181832
refactor: newValue -> new_value as @heorhi-deriv suggested
rostislav-deriv May 19, 2023
e18ce83
refactor: remove the demo component for QA
rostislav-deriv May 23, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import TransferAmountInput from '../transfer-amount-input';

describe('<TransferAmountInput/>', () => {
it('should render with the initial value of "0.00"', () => {
render(<TransferAmountInput currency={'USD'} />);
const input = screen.getByRole('textbox');
expect(input).toHaveDisplayValue('0.00');
});

it('should not change the value on non-numeric and non-"." inputs', () => {
render(<TransferAmountInput currency={'USD'} />);
const input = screen.getByRole('textbox');
fireEvent.change(input, { target: { value: 'abcdef!@#$%^&*()_+-={}[];\'"|\\/,.<>' } });
expect(input).toHaveDisplayValue('0.00');
});

it('should change the value like an ATM, i.e. from right to left, when entering digits', () => {
render(<TransferAmountInput currency={'USD'} />);
const input = screen.getByRole('textbox');
fireEvent.change(input, { target: { value: '1' } });
expect(input).toHaveDisplayValue('0.01');
fireEvent.change(input, { target: { value: '12' } });
expect(input).toHaveDisplayValue('0.12');
fireEvent.change(input, { target: { value: '123' } });
expect(input).toHaveDisplayValue('1.23');
});

it('should add commas for big values', () => {
render(<TransferAmountInput currency={'USD'} />);
const input = screen.getByRole('textbox');
fireEvent.change(input, { target: { value: '1234567890' } });
expect(input).toHaveDisplayValue('12,345,678.90');
});

it('should not remove "0.00" when backspacing', () => {
render(<TransferAmountInput currency={'USD'} />);
const input = screen.getByRole('textbox');
fireEvent.change(input, { target: { value: '0' } });
expect(input).toHaveDisplayValue('0.00');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import TransferAmountInput from './transfer-amount-input';
import './transfer-amount-input.scss';

export default TransferAmountInput;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.transfer-amount-input-wrapper {
display: flex;
flex-direction: column;

span {
font-size: 14px;
rostislav-deriv marked this conversation as resolved.
Show resolved Hide resolved
line-height: 20px;
}
}

.transfer-amount-input {
border: none;
line-height: 30px;
rostislav-deriv marked this conversation as resolved.
Show resolved Hide resolved

input {
font-size: 20px;
rostislav-deriv marked this conversation as resolved.
Show resolved Hide resolved
font-weight: 700;
rostislav-deriv marked this conversation as resolved.
Show resolved Hide resolved
nijil-deriv marked this conversation as resolved.
Show resolved Hide resolved
padding: 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState } from 'react';
import Input from '../input';

type TTransferAmountInput = {
className?: string;
currency: string;
disabled?: boolean;
initialValue?: number;
label?: React.ReactNode;
};

const TransferAmountInput = ({ className, currency, disabled = false, initialValue, label }: TTransferAmountInput) => {
const [value, setValue] = useState(0);

return (
<div className='transfer-amount-input-wrapper'>
<span>{label}</span>
rostislav-deriv marked this conversation as resolved.
Show resolved Hide resolved
<Input
rostislav-deriv marked this conversation as resolved.
Show resolved Hide resolved
className='transfer-amount-input'
disabled={disabled}
onChange={e => {
let input_value = e.target.value;
input_value = input_value.replace(/\D/g, '');
setValue(Number(input_value) / 100);
}}
type={'text'}
placeholder={`${value.toLocaleString('en-US', { minimumFractionDigits: 2 })} USD`}
value={value.toLocaleString('en-US', { minimumFractionDigits: 2 })}
/>
</div>
);
};

Input.displayName = 'TransferAmountInput';

export default TransferAmountInput;