decord/alpha/source/utils/PriceUtils.tsx

163 lines
5.9 KiB
TypeScript
Raw Normal View History

2026-10-03 08:58:59 +00:00
// Module ID: 6736
// Function ID: 6737
// Name: PriceUtils
2026-10-03 08:58:59 +00:00
// Dependencies: [2116, 4530, 1379, 1096, 1369, 6737, 6739, 6741, 1126, 4528, 2]
2026-07-29 08:29:29 +00:00
// Exports: formatDualPriceForBG, formatPercent, formatSubscriptionPlanRate, maybeShortenPrice, shortenAndFormatPrice
2026-07-20 16:05:17 +00:00
2026-10-03 08:58:59 +00:00
// Module 6736 (PriceUtils)
import Constants from "Constants" /* 1096 */;
import intl4 from "intl" /* 1126 */;
import PlatformUtils from "PlatformUtils" /* 1369 */;
import PremiumConstants from "PremiumConstants" /* 1379 */;
import PremiumUtils from "PremiumUtils" /* 4528 */;
import utils_PriceUtils from "utils/PriceUtils" /* 6737 */;
import IAPStore from "IAPStore" /* 6739 */;
import GenericIAPStore from "GenericIAPStore" /* 6741 */;
import LocaleStore from "LocaleStore" /* 2116 */;
import BillingInfoStore from "BillingInfoStore" /* 4530 */;
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
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;
2026-10-03 08:58:59 +00:00
const hasItem = isWindowsResult && 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) {
2026-10-03 08:58:59 +00:00
const obj3 = PlatformUtils;
isWindowsResult = obj3.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
}
2026-10-03 08:58:59 +00:00
const tmp11 = 0 === obj2.maximumFractionDigits && null == obj2.minimumFractionDigits;
2026-07-20 16:05:17 +00:00
if (tmp11) {
obj2.minimumFractionDigits = 0;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const obj4 = utils_PriceUtils;
return obj4.formatPrice(result, BGN, localeOverride, obj2);
2026-07-20 16:05:17 +00:00
}
function formatPrice(amount, currency, localeOverride) {
2026-10-03 08:58:59 +00:00
let combined;
2026-07-20 16:05:17 +00:00
const timestamp = Date.now();
let flag = false;
2026-10-03 08:58:59 +00:00
const date = new Date("2026-08-05T22:00:00Z");
2026-07-20 16:05:17 +00:00
if (timestamp < date.getTime()) {
2026-10-03 08:58:59 +00:00
let ipCountryCode;
const obj2 = PlatformUtils;
const platformName = obj2.getPlatformName();
2026-07-20 16:05:17 +00:00
if ("android" === platformName) {
2026-10-03 08:58:59 +00:00
const _default2 = IAPStore.default;
ipCountryCode = _default2.getUserCountry();
2026-07-20 16:05:17 +00:00
} else if ("ios" === platformName) {
2026-10-03 08:58:59 +00:00
const _default = GenericIAPStore.default;
const storeFront = _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;
} 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 _HermesInternal = HermesInternal;
2026-10-03 08:58:59 +00:00
const tmp13Result = formatSingleCurrencyPrice(amount, CurrencyCodes.EUR, localeOverride);
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-10-03 08:58:59 +00:00
const intl3 = intl4.intl;
const obj2 = { price: priceString };
2026-10-03 08:58:59 +00:00
return intl3.formatToPlainString(intl4.t["rS8FA+"], obj2);
2026-07-20 16:05:17 +00:00
} else {
2026-10-03 08:58:59 +00:00
if (interval === SubscriptionIntervalTypes.MONTH) {
2026-07-20 16:05:17 +00:00
if (1 === intervalCount) {
2026-10-03 08:58:59 +00:00
const intl2 = intl4.intl;
const obj3 = { price: priceString };
2026-10-03 08:58:59 +00:00
return intl2.formatToPlainString(intl4.t.AbOLNu, obj3);
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
if (interval === SubscriptionIntervalTypes.MONTH) {
2026-07-20 16:05:17 +00:00
if (intervalCount > 1) {
2026-10-03 08:58:59 +00:00
const intl = intl4.intl;
const obj = { price: priceString, intervalCount };
2026-10-03 08:58:59 +00:00
return intl.formatToPlainString(intl4.t["Qc+9ww"], obj);
2026-07-20 16:05:17 +00:00
}
}
const _Error = Error;
const _HermesInternal = HermesInternal;
2026-10-03 08:58:59 +00:00
const self = this;
const self2 = this;
const error = new Error("Unsupported interval type: " + interval + ", and interval count: " + intervalCount);
2026-07-20 16:05:17 +00:00
throw error;
}
}
2026-10-03 08:58:59 +00:00
const SubscriptionIntervalTypes = PremiumConstants.SubscriptionIntervalTypes;
const CurrencyCodes = Constants.CurrencyCodes;
2026-07-23 10:11:24 +00:00
let closure_6 = Object.freeze(["en-CA", "en-AU", "en-NZ"]);
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) {
2026-10-03 08:58:59 +00:00
const tmp = formatSingleCurrencyPrice(result, CurrencyCodes.EUR, localeOverride);
return "" + tmp + " (" + formatSingleCurrencyPrice(1.95583 * result, CurrencyCodes.BGN, localeOverride) + ")";
2026-07-29 08:29:29 +00:00
};
2026-07-20 16:05:17 +00:00
export { formatPrice };
export { formatRate };
export const formatPercent = function formatPercent(arg0, arg1) {
2026-10-03 08:58:59 +00:00
const NumberFormatResult = Intl.NumberFormat(arg0, { style: "percent", minimumFractionDigits: 0 });
return NumberFormatResult.format(arg1);
2026-07-20 16:05:17 +00:00
};
export const formatSubscriptionPlanRate = function formatSubscriptionPlanRate(interval_count) {
2026-10-03 08:58:59 +00:00
const tmp = "interval_count" in interval_count ? interval_count.interval_count : interval_count.intervalCount;
const obj = PremiumUtils;
const price = obj.getPrice(interval_count.id);
return formatRate(formatPrice(price.amount, price.currency), interval_count.interval, tmp);
2026-07-20 16:05:17 +00:00
};
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
};