Skip to content

Commit

Permalink
Remove decimal constraint for split (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
argaen authored Jun 25, 2024
1 parent 7af45ac commit edfc019
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 43 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@fontsource/inter": "^5.0.18",
"@hookform/resolvers": "^3.6.0",
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-query-devtools": "^5.40.0",
"@tanstack/react-query-devtools": "^5.45.1",
"@tanstack/react-table": "^8.17.3",
"@testing-library/jest-dom": "^6.4.6",
"axios": "^1.7.2",
Expand Down Expand Up @@ -115,7 +115,7 @@
"@types/jest": "^29.5.12",
"@types/lodash.debounce": "^4.0.9",
"@types/luxon": "^3.4.2",
"@types/node": "^20.14.6",
"@types/node": "^20.14.8",
"@types/pako": "^2.0.3",
"@types/react": "18.3.3",
"@types/react-dom": "^18.2.24",
Expand All @@ -141,7 +141,7 @@
"prettier-plugin-tailwindcss": "^0.6.5",
"snapshot-diff": "^0.10.0",
"tailwindcss": "^3.4.4",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"webpack-filter-warnings-plugin": "^1.2.1"
}
}
10 changes: 5 additions & 5 deletions src/__tests__/components/forms/transaction/SplitField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ describe('SplitField', () => {
expect(q1).toBeVisible();
expect(v1).toBeVisible();
await user.type(v1, '200');
await waitFor(() => expect(q1).toHaveValue(202.634));
await waitFor(() => expect(q1).toHaveValue(202.634245));
});

/**
Expand Down Expand Up @@ -655,7 +655,7 @@ describe('SplitField', () => {
expect(q1).toBeVisible();
expect(v1).toBeVisible();
await user.type(v1, '200');
await waitFor(() => expect(q1).toHaveValue(202.634));
await waitFor(() => expect(q1).toHaveValue(202.634245));

await user.click(screen.getByLabelText('splits.1.account'));
await user.click(screen.getByText('path3'));
Expand Down Expand Up @@ -743,7 +743,7 @@ describe('SplitField', () => {
expect(q1).toBeVisible();
expect(v1).toBeVisible();
await user.type(v1, '200');
await waitFor(() => expect(q1).toHaveValue(202.634));
await waitFor(() => expect(q1).toHaveValue(202.634245));
});

it('recalculates when date changes', async () => {
Expand Down Expand Up @@ -800,11 +800,11 @@ describe('SplitField', () => {
expect(q1).toBeVisible();
expect(v1).toBeVisible();
await user.type(v1, '200');
await waitFor(() => expect(q1).toHaveValue(202.634));
await waitFor(() => expect(q1).toHaveValue(202.634245));

user.clear(dateField);
await user.type(dateField, '2023-01-11');
await waitFor(() => expect(q1).toHaveValue(190.476));
await waitFor(() => expect(q1).toHaveValue(190.47619));
await waitFor(() => expect(v1).toHaveValue(200));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ describe('TransactionForm', () => {

await waitFor(() => expect(q0).toHaveValue(-100)); // 100 EUR
await waitFor(() => expect(v1).toHaveValue(100)); // 100 EUR
await waitFor(() => expect(q1).toHaveValue(142.857)); // 142.857 SGD
await waitFor(() => expect(q1).toHaveValue(142.857143)); // 142.857 SGD

expect(screen.getByText('add')).not.toBeDisabled();
await user.click(screen.getByText('add'));
Expand Down Expand Up @@ -553,8 +553,8 @@ describe('TransactionForm', () => {
fk_account: {
guid: 'account_guid_2',
},
quantityNum: 142857,
quantityDenom: 1000,
quantityNum: 142857143,
quantityDenom: 1000000,
valueNum: 100,
valueDenom: 1,
},
Expand Down Expand Up @@ -978,9 +978,11 @@ describe('TransactionForm', () => {
// the imbalance disappear
await user.clear(v0);
await user.type(v0, '995');
await waitFor(() => expect(v0).toHaveValue(995));

expect(screen.getByText('add')).not.toBeDisabled();
await user.click(screen.getByText('add'));
const addButton = screen.getByText('add');
expect(addButton).not.toBeDisabled();
await user.click(addButton);

const tx = await Transaction.findOneOrFail({
where: { description: 'Buy TICKER' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ exports[`SplitField renders with empty data 1`] = `
aria-label="splits.1.quantity"
class="w-full text-right m-0"
name="splits.1.quantity"
step="0.001"
step="any"
type="number"
/>
<span
Expand All @@ -146,7 +146,7 @@ exports[`SplitField renders with empty data 1`] = `
aria-label="splits.1.value"
class="w-full text-right m-0"
name="splits.1.value"
step="0.001"
step="any"
type="number"
/>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ exports[`SplitsField renders with default values 1`] = `
aria-label="splits.1.quantity"
class="w-full text-right m-0"
name="splits.1.quantity"
step="0.001"
step="any"
type="number"
/>
<span
Expand All @@ -223,7 +223,7 @@ exports[`SplitsField renders with default values 1`] = `
aria-label="splits.1.value"
class="w-full text-right m-0"
name="splits.1.value"
step="0.001"
step="any"
type="number"
/>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ exports[`TransactionForm renders as expected with action add 1`] = `
aria-label="splits.1.quantity"
class="w-full text-right m-0"
name="splits.1.quantity"
step="0.001"
step="any"
type="number"
/>
<span
Expand All @@ -265,7 +265,7 @@ exports[`TransactionForm renders as expected with action add 1`] = `
aria-label="splits.1.value"
class="w-full text-right m-0"
name="splits.1.value"
step="0.001"
step="any"
type="number"
/>
<span
Expand Down Expand Up @@ -564,7 +564,7 @@ exports[`TransactionForm renders as expected with action delete 1`] = `
class="w-full text-right m-0"
disabled=""
name="splits.1.quantity"
step="0.001"
step="any"
type="number"
/>
<span
Expand All @@ -586,7 +586,7 @@ exports[`TransactionForm renders as expected with action delete 1`] = `
class="w-full text-right m-0"
disabled=""
name="splits.1.value"
step="0.001"
step="any"
type="number"
/>
<span
Expand Down Expand Up @@ -805,7 +805,7 @@ exports[`TransactionForm renders as expected with action update 1`] = `
aria-label="splits.0.quantity"
class="w-full text-right m-0"
name="splits.0.quantity"
step="0.001"
step="any"
type="number"
/>
<span
Expand All @@ -826,7 +826,7 @@ exports[`TransactionForm renders as expected with action update 1`] = `
aria-label="splits.0.value"
class="w-full text-right m-0"
name="splits.0.value"
step="0.001"
step="any"
type="number"
/>
<span
Expand Down Expand Up @@ -960,7 +960,7 @@ exports[`TransactionForm renders as expected with action update 1`] = `
aria-label="splits.1.quantity"
class="w-full text-right m-0"
name="splits.1.quantity"
step="0.001"
step="any"
type="number"
/>
<span
Expand All @@ -981,7 +981,7 @@ exports[`TransactionForm renders as expected with action update 1`] = `
aria-label="splits.1.value"
class="w-full text-right m-0"
name="splits.1.value"
step="0.001"
step="any"
type="number"
/>
<span
Expand Down
2 changes: 1 addition & 1 deletion src/components/CommodityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function CommodityCard({
!priceAvailable
&& (
<div
className="badge warning ml-auto"
className="badge bg-warning ml-auto"
data-tooltip-id={`missing-price-${guid}`}
>
!
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/transaction/MainSplit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function MainSplit({

React.useEffect(() => {
if (form.formState.isDirty && splits.length > 1) {
form.setValue('splits.0.value', toFixed(quantity * exchangeRate.value, 3));
form.setValue('splits.0.value', toFixed(quantity * exchangeRate.value, 6));
form.trigger('splits');
}
}, [quantity, exchangeRate, splits.length, form]);
Expand Down
8 changes: 4 additions & 4 deletions src/components/forms/transaction/SplitField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function SplitField({
if (value && action === 'add') {
form.setValue(
`splits.${index}.quantity`,
toFixed(value / exchangeRate.value, 3),
toFixed(value / exchangeRate.value, 6),
);
}
form.trigger('splits');
Expand Down Expand Up @@ -150,13 +150,13 @@ export default function SplitField({
aria-label={`splits.${index}.quantity`}
className="w-full text-right m-0"
type="number"
step="0.001"
step="any"
disabled={disabled}
onChange={(e) => {
const splits = form.getValues('splits');
if (!showValueField && splits.length > 1) {
const quantity = Number(e.target.value);
form.setValue(`splits.${index}.value`, toFixed(quantity * exchangeRate.value, 3));
form.setValue(`splits.${index}.value`, quantity * exchangeRate.value);
}
}}
/>
Expand All @@ -181,7 +181,7 @@ export default function SplitField({
aria-label={`splits.${index}.value`}
className="w-full text-right m-0"
type="number"
step="0.001"
step="any"
disabled={disabled}
/>
<span className="pr-2">
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1930,10 +1930,10 @@
resolved "https://registry.yarnpkg.com/@tanstack/query-devtools/-/query-devtools-5.37.1.tgz#8dcfa1488b4f2e353be7eede6691b0ad9197183b"
integrity sha512-XcG4IIHIv0YQKrexTqo2zogQWR1Sz672tX2KsfE9kzB+9zhx44vRKH5si4WDILE1PIWQpStFs/NnrDQrBAUQpg==

"@tanstack/react-query-devtools@^5.40.0":
version "5.45.0"
resolved "https://registry.yarnpkg.com/@tanstack/react-query-devtools/-/react-query-devtools-5.45.0.tgz#4e5f31b88270fbbd3c4f350943de2a074af939f4"
integrity sha512-bYHKCBQxRYQgQPPt+OdxJxoGag8SyPYxFxUsTHXERPnhD99I8iUV39XGYePyxKv5b3oME4fM1e8AgQ1aPxTQ6w==
"@tanstack/react-query-devtools@^5.45.1":
version "5.45.1"
resolved "https://registry.yarnpkg.com/@tanstack/react-query-devtools/-/react-query-devtools-5.45.1.tgz#bea7ba0ffd509f0930237c2df7feba9209f76aa6"
integrity sha512-4mrbk1g5jqlqh0pifZNsKzy7FtgeqgwzMICL4d6IJGayrrcrKq9K4N/OzRNbgRWrTn6YTY63qcAcKo+NJU2QMw==
dependencies:
"@tanstack/query-devtools" "5.37.1"

Expand Down Expand Up @@ -2228,10 +2228,10 @@
dependencies:
undici-types "~5.26.4"

"@types/node@^20.14.6":
version "20.14.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.7.tgz#342cada27f97509eb8eb2dbc003edf21ce8ab5a8"
integrity sha512-uTr2m2IbJJucF3KUxgnGOZvYbN0QgkGyWxG6973HCpMYFy2KfcgYuIwkJQMQkt1VbBMlvWRbpshFTLxnxCZjKQ==
"@types/node@^20.14.8":
version "20.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.8.tgz#45c26a2a5de26c3534a9504530ddb3b27ce031ac"
integrity sha512-DO+2/jZinXfROG7j7WKFn/3C6nFwxy2lLpgLjEXJz+0XKphZlTLJ14mo8Vfg8X5BWN6XjyESXq+LcYdT7tR3bA==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -7333,10 +7333,10 @@ typeorm@^0.3.20:
uuid "^9.0.0"
yargs "^17.6.2"

typescript@^5.4.5:
version "5.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611"
integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==
typescript@^5.5.2:
version "5.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.2.tgz#c26f023cb0054e657ce04f72583ea2d85f8d0507"
integrity sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==

unbox-primitive@^1.0.2:
version "1.0.2"
Expand Down

0 comments on commit edfc019

Please sign in to comment.