Skip to content

Commit

Permalink
fix taxAmount validation showing negative
Browse files Browse the repository at this point in the history
  • Loading branch information
teneeto committed Mar 22, 2024
1 parent c15a61c commit 9d8c337
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/TaxPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function TaxPicker({selectedTaxRate = '', policy, insets, onSubmit}: TaxPickerPr

const shouldShowTextInput = !isTaxRatesCountBelowThreshold;

const getTaxName = useCallback((key: string) => taxRates?.taxes[key].name, [taxRates?.taxes]);
const getTaxName = useCallback((key: string) => taxRates?.taxes[key]?.name, [taxRates?.taxes]);

const selectedOptions = useMemo(() => {
if (!selectedTaxRate) {
Expand Down
4 changes: 1 addition & 3 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
Navigation.dismissModal();
return;
}
// optimisticall set tax amount.
IOU.setMoneyRequestTaxAmount(transaction.transactionID, getTaxAmount(-newAmount, transactionTaxCode, taxRates));
IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, newCurrency, newAmount, policy, policyTags, policyCategories);
Navigation.dismissModal();
},
[transaction, report, policy, policyTags, policyCategories, taxRates, transactionTaxCode],
[transaction, report, policy, policyTags, policyCategories],
);

const saveTag = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/steps/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const getNewSelection = (oldSelection: Selection, prevLength: number, newLength:

const isAmountInvalid = (amount: string) => !amount.length || parseFloat(amount) < 0.01;
const isTaxAmountInvalid = (currentAmount: string, taxAmount: number, isTaxAmountForm: boolean) =>
isTaxAmountForm && Number.parseFloat(currentAmount) > CurrencyUtils.convertToFrontendAmount(taxAmount);
isTaxAmountForm && Number.parseFloat(currentAmount) > CurrencyUtils.convertToFrontendAmount(Math.abs(taxAmount));

const AMOUNT_VIEW_ID = 'amountView';
const NUM_PAD_CONTAINER_VIEW_ID = 'numPadContainerView';
Expand Down Expand Up @@ -102,7 +102,7 @@ function MoneyRequestAmountForm(

const forwardDeletePressedRef = useRef(false);

const formattedTaxAmount = CurrencyUtils.convertToDisplayString(taxAmount, currency);
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(Math.abs(taxAmount), currency);

/**
* Event occurs when a user presses a mouse button over an DOM element.
Expand Down

0 comments on commit 9d8c337

Please sign in to comment.