Skip to content

Commit

Permalink
fix replace value with const
Browse files Browse the repository at this point in the history
  • Loading branch information
daledah committed Sep 27, 2024
1 parent 15e2cea commit eb41706
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function convertAmountToDisplayString(amount = 0, currency: string = CONST.CURRE
return NumberFormatUtils.format(BaseLocaleListener.getPreferredLocale(), convertedAmount, {
style: 'currency',
currency,
minimumFractionDigits: 4,
minimumFractionDigits: CONST.MAX_TAX_RATE_DECIMAL_PLACES,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/PolicyDistanceRatesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function validateRateValue(values: FormOnyxValues<RateValueForm>, currency: stri
const decimalSeparator = toLocaleDigit('.');

// Allow one more decimal place for accuracy
const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{0,4})?$`, 'i');
const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{0,${CONST.MAX_TAX_RATE_DECIMAL_PLACES}})?$`, 'i');
if (!rateValueRegex.test(parsedRate) || parsedRate === '') {
errors.rate = Localize.translateLocal('common.error.invalidRateError');
} else if (NumberUtils.parseFloatAnyLocale(parsedRate) <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function CreateDistanceRatePage({route}: CreateDistanceRatePageProps) {
<InputWrapperWithRef
InputComponent={AmountForm}
inputID={INPUT_IDS.RATE}
fixedDecimals={4}
fixedDecimals={CONST.MAX_TAX_RATE_DECIMAL_PLACES}
isCurrencyPressable={false}
currency={currency}
ref={inputCallbackRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ function PolicyDistanceRateEditPage({route}: PolicyDistanceRateEditPageProps) {

const policyID = route.params.policyID;
const rateID = route.params.rateID;

const policy = usePolicy(policyID);
const customUnits = policy?.customUnits ?? {};
const customUnit = customUnits[Object.keys(customUnits)[0]];
const rate = customUnit?.rates[rateID];
const currency = rate?.currency ?? CONST.CURRENCY.USD;
const currentRateValue = (parseFloat((rate?.rate ?? 0).toString()) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET).toFixed(4);
const currentRateValue = (parseFloat((rate?.rate ?? 0).toString()) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET).toFixed(CONST.MAX_TAX_RATE_DECIMAL_PLACES);

const submitRate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.POLICY_DISTANCE_RATE_EDIT_FORM>) => {
if (currentRateValue === values.rate) {
Expand Down Expand Up @@ -89,7 +88,7 @@ function PolicyDistanceRateEditPage({route}: PolicyDistanceRateEditPageProps) {
<InputWrapperWithRef
InputComponent={AmountForm}
inputID={INPUT_IDS.RATE}
fixedDecimals={4}
fixedDecimals={CONST.MAX_TAX_RATE_DECIMAL_PLACES}
defaultValue={currentRateValue}
isCurrencyPressable={false}
currency={currency}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function PolicyDistanceRateTaxReclaimableEditPage({route, policy}: PolicyDistanc
const customUnit = customUnits[Object.keys(customUnits)[0]];
const rate = customUnit.rates[rateID];
const currency = rate.currency ?? CONST.CURRENCY.USD;
const currentTaxReclaimableOnValue = rate.attributes?.taxClaimablePercentage && rate.rate ? ((rate.attributes.taxClaimablePercentage * rate.rate) / 100).toFixed(4) : '';
const currentTaxReclaimableOnValue =
rate.attributes?.taxClaimablePercentage && rate.rate ? ((rate.attributes.taxClaimablePercentage * rate.rate) / 100).toFixed(CONST.MAX_TAX_RATE_DECIMAL_PLACES) : '';

const submitTaxReclaimableOn = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.POLICY_DISTANCE_RATE_TAX_RECLAIMABLE_ON_EDIT_FORM>) => {
if (values.taxClaimableValue === currentTaxReclaimableOnValue) {
Expand Down Expand Up @@ -85,7 +86,7 @@ function PolicyDistanceRateTaxReclaimableEditPage({route, policy}: PolicyDistanc
<InputWrapperWithRef
InputComponent={AmountForm}
inputID={INPUT_IDS.TAX_CLAIMABLE_VALUE}
fixedDecimals={4}
fixedDecimals={CONST.MAX_TAX_RATE_DECIMAL_PLACES}
defaultValue={currentTaxReclaimableOnValue?.toString() ?? ''}
isCurrencyPressable={false}
currency={currency}
Expand Down

0 comments on commit eb41706

Please sign in to comment.