Remove currencyConfig from formatMoney params

This commit is contained in:
Kimmo Puputti 2017-08-25 09:57:39 +03:00
parent a214a04901
commit cb41d90d7b
8 changed files with 17 additions and 31 deletions

View file

@ -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 = (
<div className={css.lineItem}>
@ -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 (
<div className={classes}>

View file

@ -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 {

View file

@ -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);

View file

@ -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)

View file

@ -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 (
<NamedLink

View file

@ -36,7 +36,7 @@ const { UUID } = types;
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 {

View file

@ -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);
};

View file

@ -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'
);
});