decord/source/utils/PriceUtils.tsx

151 lines
5.5 KiB
TypeScript
Raw Normal View History

2026-08-12 06:57:52 +00:00
// Module ID: 5894
// Function ID: 5895
2026-07-20 16:05:17 +00:00
// Name: formatSingleCurrencyPrice
2026-08-12 06:57:52 +00:00
// Dependencies: [1994, 4009, 1924, 505, 500, 5895, 5897, 5899, 1236, 4007, 2]
2026-07-29 08:29:29 +00:00
// Exports: formatDualPriceForBG, formatPercent, formatSubscriptionPlanRate, maybeShortenPrice, shortenAndFormatPrice
2026-07-20 16:05:17 +00:00
2026-08-12 06:57:52 +00:00
// Module 5894 (formatSingleCurrencyPrice)
2026-07-29 08:29:29 +00:00
import _getSystemLocale from "_getSystemLocale";
import handlePaymentSourceCreateEnd from "handlePaymentSourceCreateEnd";
2026-07-23 10:11:24 +00:00
import { SubscriptionIntervalTypes } from "GuildFeatures";
import { CurrencyCodes } from "sum";
const require = arg1;
2026-07-20 16:05:17 +00:00
function formatSingleCurrencyPrice(result, BGN, localeOverride) {
2026-07-29 08:29:29 +00:00
let obj = localeOverride;
if (localeOverride == null) {
2026-07-20 16:05:17 +00:00
obj = {};
}
2026-07-29 08:29:29 +00:00
obj = {};
2026-07-20 16:05:17 +00:00
const merged = Object.assign(obj);
localeOverride = undefined;
2026-07-29 08:29:29 +00:00
if (localeOverride != null) {
2026-07-20 16:05:17 +00:00
localeOverride = localeOverride.localeOverride;
}
2026-07-29 08:29:29 +00:00
if (localeOverride == null) {
localeOverride = _getSystemLocale.locale;
2026-07-20 16:05:17 +00:00
}
let isWindowsResult = "en-US" === localeOverride;
let hasItem = isWindowsResult;
if (isWindowsResult) {
2026-07-29 08:29:29 +00:00
hasItem = closure_6.includes(_getSystemLocale.systemLocale);
2026-07-20 16:05:17 +00:00
}
if (hasItem) {
obj.currencyDisplay = "code";
}
if (isWindowsResult) {
2026-07-29 08:29:29 +00:00
isWindowsResult = require(500) /* set */.isWindows();
const obj3 = require(500) /* set */;
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
2026-07-29 08:29:29 +00:00
isWindowsResult = "en-GB" === _getSystemLocale.systemLocale;
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
obj.currencyDisplay = "code";
}
if (tmp11) {
obj.minimumFractionDigits = 0;
}
2026-08-12 06:57:52 +00:00
return require(5895) /* CurrencyCodes */.formatPrice(result, BGN, localeOverride, obj);
2026-07-20 16:05:17 +00:00
}
function formatPrice(amount, currency, localeOverride, localeOverride) {
const timestamp = Date.now();
let flag = false;
if (timestamp < date.getTime()) {
2026-07-29 08:29:29 +00:00
const platformName = require(500) /* set */.getPlatformName();
2026-07-20 16:05:17 +00:00
if ("android" === platformName) {
2026-08-12 06:57:52 +00:00
let ipCountryCode = tmp2(5897).default.getUserCountry();
const _default2 = tmp2(5897).default;
2026-07-20 16:05:17 +00:00
} else if ("ios" === platformName) {
2026-08-12 06:57:52 +00:00
const storeFront = tmp2(5899).default.getStoreFront();
2026-07-20 16:05:17 +00:00
let country;
2026-07-29 08:29:29 +00:00
if (storeFront != null) {
2026-07-20 16:05:17 +00:00
country = storeFront.country;
}
ipCountryCode = country;
2026-08-12 06:57:52 +00:00
const _default = tmp2(5899).default;
2026-07-20 16:05:17 +00:00
} else {
ipCountryCode = ipCountryCode.ipCountryCode;
}
2026-07-29 08:29:29 +00:00
let tmp9 = "BG" === ipCountryCode;
if (tmp9) {
2026-07-20 16:05:17 +00:00
let formatted;
2026-07-29 08:29:29 +00:00
if (currency != null) {
2026-07-20 16:05:17 +00:00
formatted = currency.toLowerCase();
}
2026-07-29 08:29:29 +00:00
tmp9 = formatted === CurrencyCodes.EUR;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
flag = tmp9;
const obj2 = require(500) /* set */;
2026-07-20 16:05:17 +00:00
}
if (flag) {
2026-07-29 08:29:29 +00:00
const tmp13Result = tmp13(amount, CurrencyCodes.EUR, localeOverride);
const _HermesInternal = HermesInternal;
let combined = "" + tmp13Result + " (" + tmp13(1.95583 * amount, CurrencyCodes.BGN, localeOverride) + ")";
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
combined = tmp13(amount, currency, localeOverride);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return combined;
2026-07-20 16:05:17 +00:00
}
function formatRate(priceString, interval, intervalCount) {
if (interval === SubscriptionIntervalTypes.YEAR) {
2026-07-29 08:29:29 +00:00
const intl3 = require(1236) /* getSystemLocale */.intl;
let obj = { price: null };
obj[0] = priceString;
return intl3.formatToPlainString(require(1236) /* getSystemLocale */.t["rS8FA+"], obj);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
if (interval === tmp.MONTH) {
2026-07-20 16:05:17 +00:00
if (1 === intervalCount) {
2026-07-29 08:29:29 +00:00
const intl2 = require(1236) /* getSystemLocale */.intl;
obj = { price: null };
obj[0] = priceString;
return intl2.formatToPlainString(require(1236) /* getSystemLocale */.t.AbOLNu, obj);
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (interval === tmp.MONTH) {
2026-07-20 16:05:17 +00:00
if (intervalCount > 1) {
2026-07-29 08:29:29 +00:00
const intl = require(1236) /* getSystemLocale */.intl;
obj = { price: null, intervalCount: null };
obj[0] = priceString;
obj[1] = intervalCount;
return intl.formatToPlainString(require(1236) /* getSystemLocale */.t["Qc+9ww"], obj);
2026-07-20 16:05:17 +00:00
}
}
const _Error = Error;
const _HermesInternal = HermesInternal;
const error = new Error("Unsupported interval type: " + interval + ", and interval count: " + intervalCount);
throw error;
}
}
2026-07-23 10:11:24 +00:00
let closure_6 = Object.freeze(["en-CA", "en-AU", "en-NZ"]);
const result = require("GuildFeatures").fileFinishedImporting("utils/PriceUtils.tsx");
2026-07-20 16:05:17 +00:00
export { formatSingleCurrencyPrice };
2026-07-29 08:29:29 +00:00
export const formatDualPriceForBG = function formatDualPriceForBG(result, localeOverride) {
return "" + formatSingleCurrencyPrice(result, CurrencyCodes.EUR, localeOverride) + " (" + formatSingleCurrencyPrice(1.95583 * result, CurrencyCodes.BGN, localeOverride) + ")";
};
2026-07-20 16:05:17 +00:00
export { formatPrice };
export { formatRate };
export const formatPercent = function formatPercent(arg0, arg1) {
2026-07-23 10:11:24 +00:00
return Intl.NumberFormat(arg0, { style: "percent", minimumFractionDigits: 0 }).format(arg1);
2026-07-20 16:05:17 +00:00
};
export const formatSubscriptionPlanRate = function formatSubscriptionPlanRate(interval_count) {
2026-08-12 06:57:52 +00:00
const price = require(4007) /* getPremiumPlanItem */.getPrice(interval_count.id);
2026-07-20 16:05:17 +00:00
return formatRate(formatPrice(price.amount, price.currency), interval_count.interval, "interval_count" in interval_count ? interval_count.interval_count : interval_count.intervalCount);
};
2026-07-29 08:29:29 +00:00
export const maybeShortenPrice = function maybeShortenPrice(str) {
let replaced = str;
if (str.length > 5) {
replaced = str.replace(/\.00(?=[\s)]|$)/g, "");
}
return replaced;
};
2026-07-20 16:05:17 +00:00
export const shortenAndFormatPrice = function shortenAndFormatPrice(amount, currency, localeOverride) {
2026-07-29 08:29:29 +00:00
const arr = formatPrice(amount, currency, localeOverride);
let replaced = arr;
if (arr.length > 5) {
replaced = arr.replace(/\.00(?=[\s)]|$)/g, "");
}
return replaced;
2026-07-20 16:05:17 +00:00
};