Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POS fixes #2067

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions stores/PosStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
});
Expand Down
5 changes: 4 additions & 1 deletion stores/UnitsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions views/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,13 @@ export default class OrderView extends React.Component<OrderProps, OrderState> {
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 {
Expand All @@ -544,7 +546,9 @@ export default class OrderView extends React.Component<OrderProps, OrderState> {
'sats'
);
totalDisplayValue = UnitsStore.getFormattedAmount(
unitPrice * item.quantity,
new BigNumber(unitPrice)
.multipliedBy(item.quantity)
.toString(),
'sats'
);
}
Expand Down
17 changes: 11 additions & 6 deletions views/POS/ProductDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -342,11 +347,11 @@ export default class ProductDetails extends React.Component<
/>
</View>
<AmountInput
amount={String(
product?.price == 0
? ''
: product?.price
)}
amount={
product?.price
? String(product?.price)
: ''
}
title={localeString(
'views.Settings.POS.Product.price'
)}
Expand Down
8 changes: 5 additions & 3 deletions views/Wallet/StandalonePosKeypadPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,18 @@ export default class PosKeypadPane extends React.PureComponent<

if (!order) return;

const amountCalc = amount.replace(/,/g, '.');

order.line_items.push({
name: localeString('pos.customItem'),
quantity: 1,
base_price_money: {
amount: units === PricedIn.Fiat ? Number(amount) : 0,
amount: units === PricedIn.Fiat ? Number(amountCalc) : 0,
sats:
units === PricedIn.Sats
? Number(amount)
? Number(amountCalc)
: units === PricedIn.Bitcoin
? Number(amount) * SATS_PER_BTC
? Number(amountCalc) * SATS_PER_BTC
: 0
}
});
Expand Down
33 changes: 19 additions & 14 deletions views/Wallet/StandalonePosPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,16 @@ export default class StandalonePosPane extends React.PureComponent<

if (!order) return;

// handle products with comma separator amounts
const productCalcPrice = Number(
product.price.toString().replace(/,/g, '.')
);

const item = order.line_items.find(
(item) =>
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) {
Expand All @@ -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
}
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) && (
Expand Down Expand Up @@ -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 && (
<Text
style={{
color: themeColor('secondaryText'),
Expand All @@ -717,7 +724,7 @@ export default class StandalonePosPane extends React.PureComponent<
{!loading && selectedIndex === 0 && (
<>
<SectionList
sections={this.state.productsList}
sections={productsList}
renderSectionHeader={this.renderSectionHeader}
stickySectionHeadersEnabled={false}
renderItem={this.renderSection}
Expand All @@ -739,9 +746,7 @@ export default class StandalonePosPane extends React.PureComponent<
<Button
title={`${localeString('general.charge')} (${
currentOrder
? (this.state.itemQty > 0
? `${this.state.itemQty} - `
: '') +
? (itemQty > 0 ? `${itemQty} - ` : '') +
(this.state.totalMoneyDisplay || 0)
: '0'
})`}
Expand Down
Loading