From 22b0aa512be8d4bd0eb042ba18c603b1926a2269 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 28 Nov 2017 15:14:29 +0200 Subject: [PATCH] Don't throw error when dealing with other currencies The app can handle many currencies, and changing the default currency shouldn't break the Styleguide. --- src/util/currency.js | 7 ------- src/util/currency.test.js | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/util/currency.js b/src/util/currency.js index b1827458..0874c1b8 100644 --- a/src/util/currency.js +++ b/src/util/currency.js @@ -1,7 +1,6 @@ import { has, trimEnd } from 'lodash'; import Decimal from 'decimal.js'; import { types } from './sdkLoader'; -import config from '../config'; import { subUnitDivisors } from './currencyConfig'; // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER @@ -205,9 +204,6 @@ export const convertMoneyToNumber = value => { if (!(value instanceof types.Money)) { throw new Error('Value must be a Money type'); } - if (value.currency !== config.currency) { - throw new Error('Given currency different from marketplace currency'); - } const subUnitDivisorAsDecimal = convertDivisorToDecimal(unitDivisor(value.currency)); let amount; @@ -245,9 +241,6 @@ export const formatMoney = (intl, value) => { if (!(value instanceof types.Money)) { throw new Error('Value must be a Money type'); } - if (value.currency !== config.currency) { - throw new Error('Given currency different from marketplace currency'); - } const valueAsNumber = convertMoneyToNumber(value); // See: https://github.com/yahoo/react-intl/wiki/API#formatnumber diff --git a/src/util/currency.test.js b/src/util/currency.test.js index 7e055fc8..cd357319 100644 --- a/src/util/currency.test.js +++ b/src/util/currency.test.js @@ -238,13 +238,6 @@ describe('currency utils', () => { const value = null; expect(() => formatMoney(intl, value)).toThrowError('Value must be a Money type'); }); - it('complains about mismatching currencies', () => { - const intl = null; - const value = new types.Money(100, 'EUR'); - expect(() => formatMoney(intl, value)).toThrowError( - 'Given currency different from marketplace currency' - ); - }); // No test for that actual formatting for now. It depends on the // locale, and it doesn't really make sense to test the fake intl