diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c34b2420..82616abcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ All notable, unreleased changes to this project will be documented in this file. - Display Cloud limits - #1004 by @dominik-zeglen - Add shipping method description - #1058 by @jwm0 - Fix voucher and sales sorting errors - #1063 by @orzechdev +- Fix custom currency formatting - #1067 by @orzechdev # 2.11.1 diff --git a/src/components/Money/Money.tsx b/src/components/Money/Money.tsx index f7de8e879..3f28cf3b3 100644 --- a/src/components/Money/Money.tsx +++ b/src/components/Money/Money.tsx @@ -10,15 +10,22 @@ export interface MoneyProps { money: IMoney | null; } +export const formatMoney = (money: IMoney, locale: string) => { + try { + const formattedMoney = money.amount.toLocaleString(locale, { + currency: money.currency, + style: "currency" + }); + return formattedMoney; + } catch (error) { + return `${money.amount} ${money.currency}`; + } +}; + export const Money: React.FC = ({ money }) => money ? ( - {({ locale }) => - money.amount.toLocaleString(locale, { - currency: money.currency, - style: "currency" - }) - } + {({ locale }) => formatMoney(money, locale)} ) : ( <>- diff --git a/src/components/MoneyRange/MoneyRange.tsx b/src/components/MoneyRange/MoneyRange.tsx index 4e154ba7e..e738c8148 100644 --- a/src/components/MoneyRange/MoneyRange.tsx +++ b/src/components/MoneyRange/MoneyRange.tsx @@ -2,19 +2,13 @@ import React from "react"; import { useIntl } from "react-intl"; import { LocaleConsumer } from "../Locale"; -import { IMoney } from "../Money"; +import { formatMoney, IMoney } from "../Money"; export interface MoneyRangeProps { from?: IMoney; to?: IMoney; } -const formatMoney = (money: IMoney, locale: string) => - money.amount.toLocaleString(locale, { - currency: money.currency, - style: "currency" - }); - export const MoneyRange: React.FC = ({ from, to }) => { const intl = useIntl(); diff --git a/src/shipping/handlers.ts b/src/shipping/handlers.ts index d2131d5ab..33ca7e27f 100644 --- a/src/shipping/handlers.ts +++ b/src/shipping/handlers.ts @@ -14,7 +14,7 @@ import { ShippingPostalCodeRulesCreateInputRange } from "@saleor/types/globalTypes"; import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc"; -import { diff } from "fast-array-diff"; +import { differenceBy } from "lodash"; import { useIntl } from "react-intl"; import { @@ -178,9 +178,7 @@ export function getShippingMethodChannelVariables( prevChannels?: ChannelShippingData[] ): ShippingMethodChannelListingUpdateVariables { const removeChannels = prevChannels - ? diff(prevChannels, formChannels, (a, b) => a.id === b.id).removed?.map( - removedChannel => removedChannel.id - ) + ? differenceBy(prevChannels, formChannels, "id").map(({ id }) => id) : []; return {