decord/source/utils/PriceUtils.tsx

150 lines
5.3 KiB
TypeScript
Raw Normal View History

// Module ID: 7337
// Function ID: 7338
// Name: PriceUtils
// Dependencies: [2025, 4296, 1373, 1085, 1363, 7338, 7340, 7342, 1114, 4294, 2]
2026-07-29 08:29:29 +00:00
// Exports: formatDualPriceForBG, formatPercent, formatSubscriptionPlanRate, maybeShortenPrice, shortenAndFormatPrice
2026-07-20 16:05:17 +00:00
// Module 7337 (PriceUtils)
import util from "util" /* 1114 */;
import PlatformUtils from "PlatformUtils" /* 1363 */;
import PremiumUtils from "PremiumUtils" /* 4294 */;
import utils_PriceUtils from "utils/PriceUtils" /* 7338 */;
import LocaleStore from "LocaleStore" /* 2025 */;
import BillingInfoStore from "BillingInfoStore" /* 4296 */;
2026-07-23 10:11:24 +00:00
require = fn;
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 = {};
}
const obj2 = {};
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 = LocaleStore.locale;
2026-07-20 16:05:17 +00:00
}
let isWindowsResult = "en-US" === localeOverride;
let hasItem = isWindowsResult;
if (isWindowsResult) {
hasItem = closure_6.includes(LocaleStore.systemLocale);
2026-07-20 16:05:17 +00:00
}
if (hasItem) {
obj2.currencyDisplay = "code";
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
isWindowsResult = PlatformUtils.isWindows();
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
isWindowsResult = "en-GB" === LocaleStore.systemLocale;
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
obj2.currencyDisplay = "code";
2026-07-20 16:05:17 +00:00
}
if (tmp11) {
obj2.minimumFractionDigits = 0;
2026-07-20 16:05:17 +00:00
}
return utils_PriceUtils.formatPrice(result, BGN, localeOverride, obj2);
2026-07-20 16:05:17 +00:00
}
function formatPrice(amount, currency, localeOverride) {
2026-07-20 16:05:17 +00:00
const timestamp = Date.now();
let flag = false;
if (timestamp < date.getTime()) {
const platformName = PlatformUtils.getPlatformName();
2026-07-20 16:05:17 +00:00
if ("android" === platformName) {
let ipCountryCode = tmp2(7340).default.getUserCountry();
const _default2 = tmp2(7340).default;
2026-07-20 16:05:17 +00:00
} else if ("ios" === platformName) {
const storeFront = tmp2(7342).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;
const _default = tmp2(7342).default;
2026-07-20 16:05:17 +00:00
} else {
ipCountryCode = BillingInfoStore.ipCountryCode;
2026-07-20 16:05:17 +00:00
}
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;
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) {
const intl3 = util.intl;
const obj2 = { price: priceString };
return intl3.formatToPlainString(util.t["rS8FA+"], obj2);
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) {
const intl2 = util.intl;
const obj3 = { price: priceString };
return intl2.formatToPlainString(util.t.AbOLNu, obj3);
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) {
const intl = util.intl;
const obj = { price: priceString, intervalCount };
return intl.formatToPlainString(util.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);
2026-07-20 16:05:17 +00:00
throw error;
}
}
const SubscriptionIntervalTypes = fn(1373).SubscriptionIntervalTypes;
const CurrencyCodes = fn(1085).CurrencyCodes;
2026-07-23 10:11:24 +00:00
let closure_6 = Object.freeze(["en-CA", "en-AU", "en-NZ"]);
const size = fn(2);
const result = size.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) {
const price = PremiumUtils.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
};