From 8aba4d5b260fafdea41f7c6782be653e9de86320 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Thu, 4 Apr 2019 18:48:25 +0300 Subject: [PATCH 1/4] Add divisors for NZD and HKD and reorder --- src/util/currencyConfig.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/util/currencyConfig.js b/src/util/currencyConfig.js index d93bbf00..fe3c1b3a 100644 --- a/src/util/currencyConfig.js +++ b/src/util/currencyConfig.js @@ -1,18 +1,20 @@ // See: https://en.wikipedia.org/wiki/ISO_4217 // See: https://stripe.com/docs/currencies export const subUnitDivisors = { - EUR: 100, - USD: 100, - GBP: 100, AUD: 100, CAD: 100, - DKK: 100, - JPY: 1, - SGD: 100, - SEK: 100, CHF: 100, - INR: 100, - MXN: 100, CNY: 100, + DKK: 100, + EUR: 100, + GBP: 100, + HKD: 100, + INR: 100, + JPY: 1, + MXN: 100, NOK: 100, + NZD: 100, + SEK: 100, + SGD: 100, + USD: 100, }; From 18348a6955f538de43a76d8e6045632797bf78cb Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Thu, 4 Apr 2019 18:52:38 +0300 Subject: [PATCH 2/4] Relocate currency configuration --- src/{util/currencyConfig.js => currency-config.js} | 0 src/util/currency.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{util/currencyConfig.js => currency-config.js} (100%) diff --git a/src/util/currencyConfig.js b/src/currency-config.js similarity index 100% rename from src/util/currencyConfig.js rename to src/currency-config.js diff --git a/src/util/currency.js b/src/util/currency.js index fb09dc3d..7dc45a9c 100644 --- a/src/util/currency.js +++ b/src/util/currency.js @@ -2,7 +2,7 @@ import has from 'lodash/has'; import trimEnd from 'lodash/trimEnd'; import Decimal from 'decimal.js'; import { types as sdkTypes } from './sdkLoader'; -import { subUnitDivisors } from './currencyConfig'; +import { subUnitDivisors } from '../currency-config'; const { Money } = sdkTypes; From ea8217a6ab9a4a68b5f1d87c246579c7a9547eaf Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Thu, 4 Apr 2019 19:04:00 +0300 Subject: [PATCH 3/4] Refactor configs for currency formatting --- src/config.js | 22 ++++++---------------- src/currency-config.js | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/config.js b/src/config.js index cde88294..4b42234f 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,7 @@ import * as custom from './marketplace-custom-config.js'; import defaultLocationSearches from './default-location-searches'; import { stripePublishableKey, stripeSupportedCountries } from './stripe-config'; +import { currencyConfiguration } from './currency-config'; const env = process.env.REACT_APP_ENV; const dev = process.env.REACT_APP_ENV === 'development'; @@ -59,6 +60,10 @@ const sdkTransitVerbose = process.env.REACT_APP_SHARETRIBE_SDK_TRANSIT_VERBOSE = const currency = process.env.REACT_APP_SHARETRIBE_MARKETPLACE_CURRENCY; +// Currency formatting options. +// See: https://github.com/yahoo/react-intl/wiki/API#formatnumber +const currencyConfig = currencyConfiguration(currency); + // Listing minimum price in currency sub units, e.g. cents. // 0 means no restriction to the price const listingMinimumPriceSubUnits = 0; @@ -69,21 +74,6 @@ const sentryDsn = process.env.REACT_APP_SENTRY_DSN; // If webapp is using SSL (i.e. it's behind 'https' protocol) const usingSSL = process.env.REACT_APP_SHARETRIBE_USING_SSL === 'true'; -// Currency formatting options. -// See: https://github.com/yahoo/react-intl/wiki/API#formatnumber -// -// TODO: Remove this and hide formating within the util/currency module -const currencyConfig = { - style: 'currency', - currency, - currencyDisplay: 'symbol', - useGrouping: true, - // Note: you should change fraction digits to 0, - // if the currency is not using subunits (like JPY). - minimumFractionDigits: 2, - maximumFractionDigits: 2, -}; - // Address information is used in SEO schema for Organization (http://schema.org/PostalAddress) const addressCountry = 'FI'; const addressRegion = 'Helsinki'; @@ -205,8 +195,8 @@ const config = { }, sortSearchByDistance, currency, - listingMinimumPriceSubUnits, currencyConfig, + listingMinimumPriceSubUnits, stripe: { publishableKey: stripePublishableKey, supportedCountries: stripeSupportedCountries, diff --git a/src/currency-config.js b/src/currency-config.js index fe3c1b3a..5aefa59b 100644 --- a/src/currency-config.js +++ b/src/currency-config.js @@ -18,3 +18,30 @@ export const subUnitDivisors = { SGD: 100, USD: 100, }; + +// Currency formatting options. +// See: https://github.com/yahoo/react-intl/wiki/API#formatnumber +export const currencyConfiguration = currency => { + if (!subUnitDivisors[currency]) { + throw new Error(`Configuration missing for currency: ${currency}.`); + } + + return subUnitDivisors[currency] === 1 + ? { + style: 'currency', + currency, + currencyDisplay: 'symbol', + useGrouping: true, + // If the currency is not using subunits (like JPY), remove fractions. + minimumFractionDigits: 0, + maximumFractionDigits: 0, + } + : { + style: 'currency', + currency, + currencyDisplay: 'symbol', + useGrouping: true, + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }; +}; From 47b6a584c158d8382b9aac61499ecf584494d3fb Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Thu, 4 Apr 2019 19:34:58 +0300 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1c3c352..8b78e026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ way to update this template, but currently, we follow a pattern: ## Upcoming version 2019-XX-XX +- [add] Added NZD and HKD subunit divisors and refactored currency configuration. + [#1063](https://github.com/sharetribe/flex-template-web/pull/1063) - [add] Add support for arbitrary line items. [#1062](https://github.com/sharetribe/flex-template-web/pull/1062) - [fix] US individual accounts had a non-editable business url in PayoutDetailsForm. It was probably