diff --git a/stores/PosStore.ts b/stores/PosStore.ts index b4efd0667..a45ade8db 100644 --- a/stores/PosStore.ts +++ b/stores/PosStore.ts @@ -178,24 +178,20 @@ export default class PosStore { let totalSats = new BigNumber(0); this.currentOrder.line_items.forEach((item) => { if (item.base_price_money.sats! > 0) { - totalSats = totalSats.plus( - (item.base_price_money.sats || 0) * item.quantity - ); + const addedAmount = new BigNumber( + item.base_price_money.sats || 0 + ).times(item.quantity); + totalSats = totalSats.plus(addedAmount); totalFiat = totalFiat.plus( - this.calcFiatAmountFromSats( - (item.base_price_money.sats || 0) * item.quantity - ) + this.calcFiatAmountFromSats(addedAmount.toNumber()) ); } else { - totalFiat = totalFiat.plus( - (item.base_price_money.amount || 0) * - item.quantity * - 100 - ); + const addedAmount = new BigNumber( + item.base_price_money.amount || 0 + ).times(item.quantity); + totalFiat = totalFiat.plus(addedAmount.times(100)); totalSats = totalSats.plus( - this.calcSatsAmountFromFiat( - (item.base_price_money.amount || 0) * item.quantity - ) + this.calcSatsAmountFromFiat(addedAmount.toNumber()) ); } }); diff --git a/stores/UnitsStore.ts b/stores/UnitsStore.ts index 0b1680eaf..771af098d 100644 --- a/stores/UnitsStore.ts +++ b/stores/UnitsStore.ts @@ -237,7 +237,10 @@ export default class UnitsStore { const { symbol, space, rtl, separatorSwap } = this.fiatStore.symbolLookup(code); - const amount = value; + // handle amounts passed in with commas + const amount = Number( + value.toString().replace(/,/g, '.') + ).toFixed(2); const formattedAmount = separatorSwap ? this.fiatStore.numberWithDecimals(amount) diff --git a/views/Order.tsx b/views/Order.tsx index 83df8eb89..27a96399c 100644 --- a/views/Order.tsx +++ b/views/Order.tsx @@ -531,11 +531,13 @@ export default class OrderView extends React.Component { let unitDisplayValue, totalDisplayValue; if (fiatPriced) { unitDisplayValue = UnitsStore.getFormattedAmount( - unitPrice, + new BigNumber(unitPrice).toFixed(2), 'fiat' ); totalDisplayValue = UnitsStore.getFormattedAmount( - unitPrice * item.quantity, + new BigNumber(unitPrice) + .multipliedBy(item.quantity) + .toFixed(2), 'fiat' ); } else { @@ -544,7 +546,9 @@ export default class OrderView extends React.Component { 'sats' ); totalDisplayValue = UnitsStore.getFormattedAmount( - unitPrice * item.quantity, + new BigNumber(unitPrice) + .multipliedBy(item.quantity) + .toString(), 'sats' ); } diff --git a/views/POS/ProductDetails.tsx b/views/POS/ProductDetails.tsx index 67d12b44d..c850ca0a7 100644 --- a/views/POS/ProductDetails.tsx +++ b/views/POS/ProductDetails.tsx @@ -212,7 +212,12 @@ export default class ProductDetails extends React.Component< isValid = () => { const { product } = this.state; - return product && product?.name !== '' && product.price > 0; + return ( + product && + product?.name !== '' && + product?.price && + Number(product?.price.toString().replace(',', '.')) > 0 + ); }; render() { @@ -342,11 +347,11 @@ export default class ProductDetails extends React.Component< /> item.name === product.name && - (item.base_price_money.amount === product.price || - item.base_price_money.sats === product.price) + (item.base_price_money.amount === productCalcPrice || + item.base_price_money.sats === productCalcPrice) ); if (item) { @@ -310,12 +315,14 @@ export default class StandalonePosPane extends React.PureComponent< quantity: 1, base_price_money: { amount: - product.pricedIn === PricedIn.Fiat ? product.price : 0, + product.pricedIn === PricedIn.Fiat + ? productCalcPrice + : 0, sats: product.pricedIn === PricedIn.Sats - ? product.price + ? productCalcPrice : product.pricedIn === PricedIn.Bitcoin - ? product.price * SATS_PER_BTC + ? productCalcPrice * SATS_PER_BTC : 0 } }); @@ -443,7 +450,7 @@ export default class StandalonePosPane extends React.PureComponent< InventoryStore, navigation } = this.props; - const { search, selectedIndex } = this.state; + const { search, selectedIndex, productsList, itemQty } = this.state; const { setFiltersPos } = ActivityStore; const { getOrders, @@ -662,8 +669,8 @@ export default class StandalonePosPane extends React.PureComponent< {!loading && ((selectedIndex === 0 && - this.state.productsList && - this.state.productsList.length > 0) || + productsList && + productsList.length > 0) || (orders && orders.length > 0 && selectedIndex !== 0)) && ( @@ -699,8 +706,8 @@ export default class StandalonePosPane extends React.PureComponent< {!loading && selectedIndex === 0 && - this.state.productsList && - this.state.productsList.length === 0 && ( + productsList && + productsList.length === 0 && ( 0 - ? `${this.state.itemQty} - ` - : '') + + ? (itemQty > 0 ? `${itemQty} - ` : '') + (this.state.totalMoneyDisplay || 0) : '0' })`}