decord/source/utils/PriceUtils.tsx

155 lines
5.5 KiB
TypeScript
Raw Normal View History

2026-08-25 06:04:03 +00:00
// Module ID: 5962
// Function ID: 5963
2026-07-20 16:05:17 +00:00
// Name: formatSingleCurrencyPrice
2026-08-25 06:04:03 +00:00
// Dependencies: [1996, 4045, 1924, 505, 500, 5963, 5965, 5967, 1236, 4043, 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-25 06:04:03 +00:00
// Module 5962 (formatSingleCurrencyPrice)
2026-08-24 06:08:38 +00:00
import set from "set" /* 500 */;
import getSystemLocale from "getSystemLocale" /* 1236 */;
2026-08-25 06:04:03 +00:00
import getPremiumPlanItem from "getPremiumPlanItem" /* 4043 */;
import CurrencyCodes2 from "CurrencyCodes" /* 5963 */;
import closure_2 from "_getSystemLocale" /* 1996 */;
import closure_3 from "handlePaymentSourceCreateEnd" /* 4045 */;
2026-08-24 06:08:38 +00:00
import { SubscriptionIntervalTypes } from "GuildFeatures" /* 1924 */;
import { CurrencyCodes } from "sum" /* 505 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
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) {
2026-08-24 06:08:38 +00:00
localeOverride = closure_2.locale;
2026-07-20 16:05:17 +00:00
}
let isWindowsResult = "en-US" === localeOverride;
let hasItem = isWindowsResult;
if (isWindowsResult) {
2026-08-24 06:08:38 +00:00
hasItem = closure_6.includes(closure_2.systemLocale);
2026-07-20 16:05:17 +00:00
}
if (hasItem) {
obj.currencyDisplay = "code";
}
if (isWindowsResult) {
2026-08-24 06:08:38 +00:00
isWindowsResult = set.isWindows();
const obj3 = set;
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
2026-08-24 06:08:38 +00:00
isWindowsResult = "en-GB" === closure_2.systemLocale;
2026-07-20 16:05:17 +00:00
}
if (isWindowsResult) {
obj.currencyDisplay = "code";
}
if (tmp11) {
obj.minimumFractionDigits = 0;
}
2026-08-24 06:08:38 +00:00
return CurrencyCodes2.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-08-24 06:08:38 +00:00
const platformName = set.getPlatformName();
2026-07-20 16:05:17 +00:00
if ("android" === platformName) {
2026-08-25 06:04:03 +00:00
let ipCountryCode = tmp2(5965).default.getUserCountry();
const _default2 = tmp2(5965).default;
2026-07-20 16:05:17 +00:00
} else if ("ios" === platformName) {
2026-08-25 06:04:03 +00:00
const storeFront = tmp2(5967).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-25 06:04:03 +00:00
const _default = tmp2(5967).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;
2026-08-24 06:08:38 +00:00
const obj2 = 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-08-24 06:08:38 +00:00
const intl3 = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
let obj = { price: null };
obj[0] = priceString;
2026-08-24 06:08:38 +00:00
return intl3.formatToPlainString(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-08-24 06:08:38 +00:00
const intl2 = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
obj = { price: null };
obj[0] = priceString;
2026-08-24 06:08:38 +00:00
return intl2.formatToPlainString(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-08-24 06:08:38 +00:00
const intl = getSystemLocale.intl;
2026-07-29 08:29:29 +00:00
obj = { price: null, intervalCount: null };
obj[0] = priceString;
obj[1] = intervalCount;
2026-08-24 06:08:38 +00:00
return intl.formatToPlainString(getSystemLocale.t["Qc+9ww"], obj);
2026-07-20 16:05:17 +00:00
}
}
const _Error = Error;
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
error = new Error("Unsupported interval type: " + interval + ", and interval count: " + intervalCount);
2026-07-20 16:05:17 +00:00
throw error;
}
}
2026-07-23 10:11:24 +00:00
let closure_6 = Object.freeze(["en-CA", "en-AU", "en-NZ"]);
2026-08-24 06:08:38 +00:00
const result = require("set").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-24 06:08:38 +00:00
const price = 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
};