fix:(dashboard) pending difference rounding on order details page (#11336)
**Why** - if pending difference is lass then the rounding threshold for currency the page would show for example "Refund -0.00$" **What** - example: hide the refund button if the pending difference in USD is -0.004 - example: show refund button if pending difference on USD is -0.007 --- CLOSES SUP-811 CLOSES https://github.com/medusajs/medusa/issues/11331
This commit is contained in:
@@ -44,10 +44,32 @@ export const getStylizedAmount = (amount: number, currencyCode: string) => {
|
||||
const symbol = getNativeSymbol(currencyCode)
|
||||
const decimalDigits = getDecimalDigits(currencyCode)
|
||||
|
||||
const lessThanRoundingPrecission = isAmountLessThenRoundingError(
|
||||
amount,
|
||||
currencyCode
|
||||
)
|
||||
|
||||
const total = amount.toLocaleString(undefined, {
|
||||
minimumFractionDigits: decimalDigits,
|
||||
maximumFractionDigits: decimalDigits,
|
||||
signDisplay: lessThanRoundingPrecission ? "exceptZero" : "auto",
|
||||
})
|
||||
|
||||
return `${symbol} ${total} ${currencyCode.toUpperCase()}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the amount is less than the rounding error for the currency
|
||||
* @param amount - The amount to check
|
||||
* @param currencyCode - The currency code to check the amount in
|
||||
* @returns - True if the amount is less than the rounding error, false otherwise
|
||||
*
|
||||
* For example returns true if amount is < 0.005 for a USD | EUR etc.
|
||||
*/
|
||||
export const isAmountLessThenRoundingError = (
|
||||
amount: number,
|
||||
currencyCode: string
|
||||
) => {
|
||||
const decimalDigits = getDecimalDigits(currencyCode)
|
||||
return Math.abs(amount) < 1 / 10 ** decimalDigits / 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user