mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-25 22:37:18 +10:00
Refactor configs for currency formatting
This commit is contained in:
parent
18348a6955
commit
ea8217a6ab
2 changed files with 33 additions and 16 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue