diff --git a/src/components/BookingBreakdown/BookingBreakdown.js b/src/components/BookingBreakdown/BookingBreakdown.js
index 7e38a4ee..275d4c66 100644
--- a/src/components/BookingBreakdown/BookingBreakdown.js
+++ b/src/components/BookingBreakdown/BookingBreakdown.js
@@ -68,7 +68,7 @@ export const BookingBreakdownComponent = props => {
);
const currencyConfig = config.currencyConfig;
- const formattedUnitPrice = formatMoney(intl, currencyConfig, nightPurchase.unitPrice);
+ const formattedUnitPrice = formatMoney(intl, nightPurchase.unitPrice);
// If commission is passed it will be shown as a fee already reduces from the total price
let subTotalInfo = null;
@@ -90,7 +90,7 @@ export const BookingBreakdownComponent = props => {
);
const commission = providerCommission.lineTotal;
- const formattedCommission = commission ? formatMoney(intl, currencyConfig, commission) : null;
+ const formattedCommission = commission ? formatMoney(intl, commission) : null;
commissionInfo = (
@@ -108,7 +108,7 @@ export const BookingBreakdownComponent = props => {
const totalLabel = totalLabelMessage || defaultTotalLabel;
const totalPrice = userRole === 'customer' ? payinTotal : payoutTotal;
- const formattedTotalPrice = formatMoney(intl, currencyConfig, totalPrice);
+ const formattedTotalPrice = formatMoney(intl, totalPrice);
return (
diff --git a/src/components/ListingCard/ListingCard.js b/src/components/ListingCard/ListingCard.js
index 18ffa7ce..5484f401 100644
--- a/src/components/ListingCard/ListingCard.js
+++ b/src/components/ListingCard/ListingCard.js
@@ -11,7 +11,7 @@ import css from './ListingCard.css';
const priceData = (price, currencyConfig, intl) => {
if (price && price.currency === currencyConfig.currency) {
- const formattedPrice = formatMoney(intl, currencyConfig, price);
+ const formattedPrice = formatMoney(intl, price);
return { formattedPrice, priceTitle: formattedPrice };
} else if (price) {
return {
diff --git a/src/components/SearchMapInfoCard/SearchMapInfoCard.js b/src/components/SearchMapInfoCard/SearchMapInfoCard.js
index 3daafe89..dcc23310 100644
--- a/src/components/SearchMapInfoCard/SearchMapInfoCard.js
+++ b/src/components/SearchMapInfoCard/SearchMapInfoCard.js
@@ -34,7 +34,7 @@ const ListingCard = props => {
const { title, price } = listing.attributes;
const formattedPrice = price && price.currency === config.currencyConfig.currency
- ? formatMoney(intl, config.currencyConfig, price)
+ ? formatMoney(intl, price)
: price.currency;
const firstImage = listing.images && listing.images.length > 0 ? listing.images[0] : null;
const urlToListing = createURL(flattenedRoutes, history, listing);
diff --git a/src/components/SearchMapPriceLabel/SearchMapPriceLabel.js b/src/components/SearchMapPriceLabel/SearchMapPriceLabel.js
index 42dbb26b..821a6b3a 100644
--- a/src/components/SearchMapPriceLabel/SearchMapPriceLabel.js
+++ b/src/components/SearchMapPriceLabel/SearchMapPriceLabel.js
@@ -31,7 +31,7 @@ class SearchMapPriceLabel extends Component {
// Create formatted price if currency is known or alternatively show just the unknown currency.
const formattedPrice = price && price.currency === config.currencyConfig.currency
- ? formatMoney(intl, config.currencyConfig, price)
+ ? formatMoney(intl, price)
: price.currency;
// Explicit type change to object literal for Google OverlayViews (geolocation is SDK type)
diff --git a/src/containers/InboxPage/InboxPage.js b/src/containers/InboxPage/InboxPage.js
index 8298f645..9bd1fbad 100644
--- a/src/containers/InboxPage/InboxPage.js
+++ b/src/containers/InboxPage/InboxPage.js
@@ -14,7 +14,6 @@ import {
TabNav,
Topbar,
} from '../../components';
-import config from '../../config';
import * as propTypes from '../../util/propTypes';
import { formatMoney } from '../../util/currency';
import { getMarketplaceEntities } from '../../ducks/marketplaceData.duck';
@@ -102,7 +101,7 @@ export const InboxItem = props => {
const bookingStart = formatDate(intl, booking.attributes.start);
const bookingEnd = formatDate(intl, booking.attributes.end);
const bookingPrice = isOrder ? tx.attributes.payinTotal : tx.attributes.payoutTotal;
- const price = formatMoney(intl, config.currencyConfig, bookingPrice);
+ const price = formatMoney(intl, bookingPrice);
return (
{
if (price && price.currency === currencyConfig.currency) {
- const formattedPrice = formatMoney(intl, currencyConfig, price);
+ const formattedPrice = formatMoney(intl, price);
return { formattedPrice, priceTitle: formattedPrice };
} else if (price) {
return {
diff --git a/src/util/currency.js b/src/util/currency.js
index f58fb7fd..b3b3f5a5 100644
--- a/src/util/currency.js
+++ b/src/util/currency.js
@@ -229,18 +229,17 @@ export const convertMoneyToNumber = value => {
* Format the given money to a string
*
* @param {Object} intl
- * @param {Object} currencyConfig
* @param {Money} value
*
* @return {String} formatted money value
*/
-export const formatMoney = (intl, currencyConfig, value) => {
+export const formatMoney = (intl, value) => {
if (!(value instanceof types.Money)) {
throw new Error('Value must be a Money type');
}
- if (value.currency !== currencyConfig.currency) {
+ if (value.currency !== config.currencyConfig.currency) {
throw new Error('Given currency different from marketplace currency');
}
const valueAsNumber = convertMoneyToNumber(value);
- return intl.formatNumber(valueAsNumber, currencyConfig);
+ return intl.formatNumber(valueAsNumber, config.currencyConfig);
};
diff --git a/src/util/currency.test.js b/src/util/currency.test.js
index 07659e5b..7e055fc8 100644
--- a/src/util/currency.test.js
+++ b/src/util/currency.test.js
@@ -222,18 +222,10 @@ describe('currency utils', () => {
});
it('Wrong type of a parameter', () => {
- expect(() => convertMoneyToNumber(10)).toThrowError(
- 'Value must be a Money type'
- );
- expect(() => convertMoneyToNumber('10')).toThrowError(
- 'Value must be a Money type'
- );
- expect(() => convertMoneyToNumber(true)).toThrowError(
- 'Value must be a Money type'
- );
- expect(() => convertMoneyToNumber({})).toThrowError(
- 'Value must be a Money type'
- );
+ expect(() => convertMoneyToNumber(10)).toThrowError('Value must be a Money type');
+ expect(() => convertMoneyToNumber('10')).toThrowError('Value must be a Money type');
+ expect(() => convertMoneyToNumber(true)).toThrowError('Value must be a Money type');
+ expect(() => convertMoneyToNumber({})).toThrowError('Value must be a Money type');
expect(() => convertMoneyToNumber(new Money('asdf', 'USD'))).toThrowError(
'[DecimalError] Invalid argument'
);
@@ -243,17 +235,13 @@ describe('currency utils', () => {
describe('formatMoney', () => {
it('complains about incorrect value type', () => {
const intl = null;
- const currencyConfig = {};
const value = null;
- expect(() => formatMoney(intl, currencyConfig, value)).toThrowError(
- 'Value must be a Money type'
- );
+ expect(() => formatMoney(intl, value)).toThrowError('Value must be a Money type');
});
it('complains about mismatching currencies', () => {
const intl = null;
- const currencyConfig = { currency: 'USD' };
const value = new types.Money(100, 'EUR');
- expect(() => formatMoney(intl, currencyConfig, value)).toThrowError(
+ expect(() => formatMoney(intl, value)).toThrowError(
'Given currency different from marketplace currency'
);
});