Files
discord-decomp/sources/utils/PriceUtils.tsx
T
2026-07-28 01:06:53 +03:00

164 lines
8.2 KiB
TypeScript

/* Metro module 5137; source: utils/PriceUtils.tsx; dependencies: [1949, 3804, 1880, 482, 477, 5138, 5140, 5142, 1244, 3802, 2] */
import LocaleStore from '../modules/user_settings/LocaleStore.tsx'; /* Metro dependency 1949 */
import BillingInfoStore from '../stores/billing/BillingInfoStore.tsx'; /* Metro dependency 3804 */
import * as FileImportTrackerModule from '../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */
import * as ConstantsModule from '../external/discord_common/js/shared/Constants.tsx'; /* Metro dependency 482 */
import * as IndexNativeModule from '../intl/index.native.tsx'; /* Metro dependency 1244 */
import * as PremiumConstantsModule from '../modules/premium/PremiumConstants.tsx'; /* Metro dependency 1880 */
import * as PremiumUtilsModule from './PremiumUtils.tsx'; /* Metro dependency 3802 */
import * as PriceUtilsModule from '../external/discord_common/js/shared/utils/PriceUtils.tsx'; /* Metro dependency 5138 */
function _fun45261(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#45261, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5315:6, offset: 0x01185e28, size: 304 bytes, params: 8, frame: 25
const env0_0 = require;
const formatSingleCurrencyPrice2 = formatSingleCurrencyPrice;
const formatDualPriceForBG2 = formatDualPriceForBG;
const formatPrice2 = formatPrice;
const formatRate2 = formatRate;
const closure5 = function(a0) {
var r0;
var value = a0;
if (value.length > 5) {
value = value.replace(RegExp('\\.00(?=[\\s)]|$)', 'g'), '');
r0 = value;
} else {
r0 = value;
}
return r0;
};
let Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
Object = global.Object;
const env0_6 = Object.freeze(['en-CA', 'en-AU', 'en-NZ']);
(FileImportTrackerModule).fileFinishedImporting('utils/PriceUtils.tsx');
exports.formatSingleCurrencyPrice = formatSingleCurrencyPrice2;
exports.formatDualPriceForBG = formatDualPriceForBG2;
exports.formatPrice = formatPrice2;
exports.formatRate = formatRate2;
exports.formatPercent = function(a0, a1) {
var Intl = global.Intl;
return Intl.NumberFormat(a0, {'style': 'percent', 'minimumFractionDigits': 0}).format(a1);
};
exports.formatSubscriptionPlanRate = formatSubscriptionPlanRate;
exports.maybeShortenPrice = closure5;
exports.shortenAndFormatPrice = function(a0, a1, a2) {
return maybeShortenPrice(formatPrice(a0, a1, a2));
};
function formatSingleCurrencyPrice(a0, a1, a2) { // fn#45262, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5315:219, offset: 0x01185f58, size: 273 bytes, params: 4, frame: 20
var r0;
let value = a2;
const object = {};
copyDataProperties(object, value ?? ({}), undefined);
const r4 = value?.localeOverride ?? LocaleStore.locale;
if (r4 === 'en-US' && env0_6.includes(LocaleStore.systemLocale)) {
object.currencyDisplay = 'code';
}
if (value) {
value = require(477) /* metro dependency 477: PlatformUtils */;
value = value.isWindows();
r0 = value;
} else {
r0 = value;
}
r0 = r0 && LocaleStore.systemLocale === 'en-GB';
if (r0) {
object.currencyDisplay = 'code';
}
if (object.maximumFractionDigits === 0 && object.minimumFractionDigits == null) {
object.minimumFractionDigits = 0;
}
return (PriceUtilsModule).formatPrice(a0, a1, r4, object);
}
function formatDualPriceForBG(a0, a1) { // fn#45263, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5315:633, offset: 0x01186069, size: 101 bytes, params: 3, frame: 18
const formatSingleCurrencyPriceBinding = formatSingleCurrencyPrice;
const EUR = CurrencyCodes.EUR;
const value2 = formatSingleCurrencyPriceBinding(a0, EUR, a1);
const value3 = 1.95583 * a0;
const BGN = CurrencyCodes.BGN;
return '' + value2 + ' (' + formatSingleCurrencyPriceBinding(value3, BGN, a1) + ')';
}
function formatPrice(a0, a1, a2) { // fn#45264, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5315:766, offset: 0x011860ce, size: 321 bytes, params: 4, frame: 20
var r7;
var r0;
var value5;
var platformName;
var storeFront;
let Date = global.Date;
let value = Date.now();
Date = global.Date;
const date = new Date('2026-08-05T22:00:00Z');
const getTime = date.getTime;
value = value >= Reflect.apply(getTime, date, []);
if (value) {
r0 = false;
} else {
value5 = undefined;
platformName = (require(477) /* metro dependency 477: PlatformUtils */).getPlatformName();
if (platformName === 'android') {
r7 = (require(5140) /* metro dependency 5140: IAPStoreAndroid */).default.getUserCountry();
} else if (platformName === 'ios') {
storeFront = (require(5142) /* metro dependency 5142: GenericIAPStore */).default.getStoreFront();
r7 = storeFront == null ? value5 : storeFront.country;
} else {
r7 = BillingInfoStore.ipCountryCode;
}
r0 = r7 === 'BG' && (a1 == null ? value5 : a1.toLowerCase()) === CurrencyCodes.EUR;
}
r0 = r0 ? formatDualPriceForBG(a0, a2) : formatSingleCurrencyPrice(a0, a1, a2);
return r0;
}
function formatRate(a0, a1, a2) { // fn#45265, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5315:1231, offset: 0x0118620f, size: 342 bytes, params: 4, frame: 19
var Error;
const intl = (IndexNativeModule).intl;
const t = (IndexNativeModule).t;
var value;
const YEAR = SubscriptionIntervalTypes.YEAR;
if (a1 === YEAR) {
return intl.formatToPlainString(t['rS8FA+'], {price: a0});
}
let MONTH = SubscriptionIntervalTypes.MONTH;
if (a1 !== MONTH) {
if (a1 !== SubscriptionIntervalTypes.MONTH) {
Error = global.Error;
value = 'Unsupported interval type: ' + a1 + ', and interval count: ' + a2;
throw new Error();
}
if (a2 > 1) {
return intl.formatToPlainString(t['Qc+9ww'], {price: a0, intervalCount: a2});
}
Error = global.Error;
value = 'Unsupported interval type: ' + a1 + ', and interval count: ' + a2;
throw new Error();
}
if (a2 === 1) {
return intl.formatToPlainString(t.AbOLNu, {price: a0});
}
MONTH = SubscriptionIntervalTypes.MONTH;
if (a1 !== MONTH) {
Error = global.Error;
value = 'Unsupported interval type: ' + a1 + ', and interval count: ' + a2;
throw new Error();
}
if (a2 > 1) {
return intl.formatToPlainString(t['Qc+9ww'], {price: a0, intervalCount: a2});
}
Error = global.Error;
value = 'Unsupported interval type: ' + a1 + ', and interval count: ' + a2;
const value2 = Object.create(Error.prototype, {constructor: {value: Error}});
const error = new Error();
throw error instanceof Object ? error : value2;
}
function formatSubscriptionPlanRate(a0) { // fn#45268, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5315:2057, offset: 0x011863ca, size: 110 bytes, params: 2, frame: 17
const r4 = 'interval_count' in a0 ? a0.interval_count : a0.intervalCount;
const price = (PremiumUtilsModule).getPrice(a0.id);
return formatRate(formatPrice(price.amount, price.currency), a0.interval, r4);
}
}
global.__d(_fun45261, 5137, [1949, 3804, 1880, 482, 477, 5138, 5140, 5142, 1244, 3802,
2]) /* metro module 5137, dependencies: [1949, 3804, 1880, 482, 477, 5138, 5140, 5142, 1244, 3802, 2] */;