Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): format prices with the pricing country

Hampus6105ad763b25
diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/hooks/usePremiumData.ts b/fluxer_app/src/features/app/components/dialogs/components/plutonium/hooks/usePremiumData.ts
index e6c214e3e..b40cd28d1 100644
--- a/fluxer_app/src/features/app/components/dialogs/components/plutonium/hooks/usePremiumData.ts
+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/hooks/usePremiumData.ts
@@ -2,8 +2,8 @@
import DeveloperOptions from '@app/features/devtools/state/DeveloperOptions';
import type {CurrentSubscriptionPrice, PriceIds} from '@app/features/premium/commands/PremiumCommands';
-import {formatMinorUnitPrice} from '@app/features/premium/utils/PricingUtils';
import * as LocaleUtils from '@app/features/user/utils/LocaleUtils';
+import {formatMinorUnitPrice} from '@fluxer/number_utils/src/PriceFormatting';
import type {PremiumStateResponse} from '@fluxer/schema/src/domains/premium/PremiumSchemas';
import {useMemo} from 'react';
@@ -12,15 +12,17 @@ const formatPriceLabel = (
amountMinor: number | null | undefined,
currency: string | null | undefined,
locale: string,
+ countryCode: string | null | undefined,
): string => {
- const formatted = formatMinorUnitPrice(amountMinor, currency, locale);
+ const formatted = formatMinorUnitPrice(amountMinor, currency, locale, countryCode);
return formatted == null ? PRICE_PLACEHOLDER : formatted;
};
const formatOptionalPriceLabel = (
amountMinor: number | null | undefined,
currency: string | null | undefined,
locale: string,
-): string | null => formatMinorUnitPrice(amountMinor, currency, locale);
+ countryCode: string | null | undefined,
+): string | null => formatMinorUnitPrice(amountMinor, currency, locale, countryCode);
const hasDeveloperPremiumStateOverride = (): boolean =>
DeveloperOptions.premiumScenarioOverride !== null ||
DeveloperOptions.premiumTypeOverride !== null ||
@@ -48,33 +50,40 @@ export const usePremiumData = ({
} = {}): PremiumData => {
const locale = LocaleUtils.getCurrentLocale();
const priceIds = premiumState?.pricing.localized ?? null;
+ const countryCode = premiumState?.pricing.country_code ?? null;
const monthlyPrice = useMemo(() => {
- return formatPriceLabel(priceIds?.monthly_amount_minor, priceIds?.currency, locale);
- }, [locale, priceIds?.currency, priceIds?.monthly_amount_minor]);
+ return formatPriceLabel(priceIds?.monthly_amount_minor, priceIds?.currency, locale, countryCode);
+ }, [countryCode, locale, priceIds?.currency, priceIds?.monthly_amount_minor]);
const yearlyPrice = useMemo(() => {
- return formatPriceLabel(priceIds?.yearly_amount_minor, priceIds?.currency, locale);
- }, [locale, priceIds?.currency, priceIds?.yearly_amount_minor]);
+ return formatPriceLabel(priceIds?.yearly_amount_minor, priceIds?.currency, locale, countryCode);
+ }, [countryCode, locale, priceIds?.currency, priceIds?.yearly_amount_minor]);
const giftMonthlyPrice = useMemo(() => {
- return formatPriceLabel(priceIds?.gift_1_month_amount_minor, priceIds?.gift_currency, locale);
- }, [locale, priceIds?.gift_1_month_amount_minor, priceIds?.gift_currency]);
+ return formatPriceLabel(priceIds?.gift_1_month_amount_minor, priceIds?.gift_currency, locale, countryCode);
+ }, [countryCode, locale, priceIds?.gift_1_month_amount_minor, priceIds?.gift_currency]);
const giftYearlyPrice = useMemo(() => {
- return formatPriceLabel(priceIds?.gift_1_year_amount_minor, priceIds?.gift_currency, locale);
- }, [locale, priceIds?.gift_1_year_amount_minor, priceIds?.gift_currency]);
+ return formatPriceLabel(priceIds?.gift_1_year_amount_minor, priceIds?.gift_currency, locale, countryCode);
+ }, [countryCode, locale, priceIds?.gift_1_year_amount_minor, priceIds?.gift_currency]);
const currentSubscriptionPrice: CurrentSubscriptionPrice | null = hasDeveloperPremiumStateOverride()
? null
: (premiumState?.billing.current_subscription_price ?? null);
const currentSubscriptionPriceLabel = useMemo(() => {
if (!currentSubscriptionPrice) return null;
- return formatOptionalPriceLabel(currentSubscriptionPrice.amount_minor, currentSubscriptionPrice.currency, locale);
- }, [currentSubscriptionPrice, locale]);
+ return formatOptionalPriceLabel(
+ currentSubscriptionPrice.amount_minor,
+ currentSubscriptionPrice.currency,
+ locale,
+ countryCode,
+ );
+ }, [countryCode, currentSubscriptionPrice, locale]);
const currentSubscriptionListPriceLabel = useMemo(() => {
if (!currentSubscriptionPrice || currentSubscriptionPrice.list_amount_minor == null) return null;
return formatOptionalPriceLabel(
currentSubscriptionPrice.list_amount_minor,
currentSubscriptionPrice.currency,
locale,
+ countryCode,
);
- }, [currentSubscriptionPrice, locale]);
+ }, [countryCode, currentSubscriptionPrice, locale]);
return {
priceIds,
monthlyPrice,
diff --git a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/LegacyPriceOptInNagbar.tsx b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/LegacyPriceOptInNagbar.tsx
index a7e0aa1c6..5382d7f08 100644
--- a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/LegacyPriceOptInNagbar.tsx
+++ b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/LegacyPriceOptInNagbar.tsx
@@ -9,11 +9,11 @@ import {resolvePriceAnnouncementCampaign} from '@app/features/premium/config/Pri
import PremiumState from '@app/features/premium/state/PremiumState';
import {MANAGE_SUBSCRIPTION_DESCRIPTOR} from '@app/features/premium/utils/PremiumMessageDescriptors';
import {getPremiumProductName} from '@app/features/premium/utils/PremiumUtils';
-import {formatMinorUnitPrice} from '@app/features/premium/utils/PricingUtils';
import NagbarState from '@app/features/ui/state/Nagbar';
import Users from '@app/features/user/state/Users';
import * as LocaleUtils from '@app/features/user/utils/LocaleUtils';
import {getFormattedLongDate} from '@fluxer/date_utils/src/DateFormatting';
+import {formatMinorUnitPrice} from '@fluxer/number_utils/src/PriceFormatting';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {useCallback} from 'react';
@@ -37,8 +37,18 @@ export const LegacyPriceOptInNagbar = observer(function LegacyPriceOptInNagbar({
if (listPriceSwitch.currency !== resolved.currency || listPriceSwitch.effective_at == null) return null;
if (listPriceSwitch.billing_cycle == null) return null;
const locale = LocaleUtils.getCurrentLocale();
- const currentPrice = formatMinorUnitPrice(listPriceSwitch.current_amount_minor, listPriceSwitch.currency, locale);
- const newPrice = formatMinorUnitPrice(listPriceSwitch.list_amount_minor, listPriceSwitch.currency, locale);
+ const currentPrice = formatMinorUnitPrice(
+ listPriceSwitch.current_amount_minor,
+ listPriceSwitch.currency,
+ locale,
+ premiumState.pricing.country_code,
+ );
+ const newPrice = formatMinorUnitPrice(
+ listPriceSwitch.list_amount_minor,
+ listPriceSwitch.currency,
+ locale,
+ premiumState.pricing.country_code,
+ );
if (currentPrice == null || newPrice == null) return null;
return (
<Nagbar
diff --git a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/PriceAnnouncementNagbar.tsx b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/PriceAnnouncementNagbar.tsx
index 956961b8b..bd50da392 100644
--- a/fluxer_app/src/features/app/components/layout/app_layout/nagbars/PriceAnnouncementNagbar.tsx
+++ b/fluxer_app/src/features/app/components/layout/app_layout/nagbars/PriceAnnouncementNagbar.tsx
@@ -9,10 +9,10 @@ import {resolvePriceAnnouncementCampaign} from '@app/features/premium/config/Pri
import PremiumState from '@app/features/premium/state/PremiumState';
import {VIEW_PLANS_DESCRIPTOR} from '@app/features/premium/utils/PremiumMessageDescriptors';
import {getPremiumProductName} from '@app/features/premium/utils/PremiumUtils';
-import {formatMinorUnitPrice} from '@app/features/premium/utils/PricingUtils';
import NagbarState from '@app/features/ui/state/Nagbar';
import Users from '@app/features/user/state/Users';
import * as LocaleUtils from '@app/features/user/utils/LocaleUtils';
+import {formatMinorUnitPrice} from '@fluxer/number_utils/src/PriceFormatting';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {useCallback} from 'react';
@@ -35,8 +35,18 @@ export const PriceAnnouncementNagbar = observer(function PriceAnnouncementNagbar
}, [campaignId]);
if (!premiumState || !resolved || premiumState.actual.has_active_paid_premium) return null;
const locale = LocaleUtils.getCurrentLocale();
- const monthlyPrice = formatMinorUnitPrice(resolved.monthlyAmountMinor, resolved.currency, locale);
- const yearlyPrice = formatMinorUnitPrice(resolved.yearlyAmountMinor, resolved.currency, locale);
+ const monthlyPrice = formatMinorUnitPrice(
+ resolved.monthlyAmountMinor,
+ resolved.currency,
+ locale,
+ premiumState.pricing.country_code,
+ );
+ const yearlyPrice = formatMinorUnitPrice(
+ resolved.yearlyAmountMinor,
+ resolved.currency,
+ locale,
+ premiumState.pricing.country_code,
+ );
if (monthlyPrice == null || yearlyPrice == null) return null;
return (
<Nagbar