Files
discord-decomp/sources/utils/SubscriptionUtils.tsx
T
2026-07-27 16:20:00 +03:00

335 lines
14 KiB
TypeScript

/* Metro module 8457; source: utils/SubscriptionUtils.tsx; dependencies: [57, 31, 3807, 661, 1880, 44, 8458, 3802, 6847, 566, 8460, 3738, 2] */
function _fun67168(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#67168, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:6, offset: 0x01c18522, size: 350 bytes, params: 8, frame: 21
const env0_0 = require;
const _arrayLikeToArray_67171 = function(a0, a1) {
var r0;
var r1;
var r2;
var value3;
var length;
var value5;
var value = undefined;
var value2 = value == null;
reducibleJoin2: while (true) {
if (value2) {
r0 = value2;
break reducibleJoin2;
}
value3 = value > a0.length;
r0 = value3;
break reducibleJoin2;
}
reducibleJoin4: while (true) {
if (r0) {
length = a0.length;
r1 = length;
break reducibleJoin4;
}
r1 = value;
break reducibleJoin4;
}
value = (0, global.Array)(r1);
var value4 = 0;
if (value4 < r1) {
r2 = value4;
reducibleLoop5: while (true) {
value[r2] = a0[r2];
value5 = typeof r2 === 'bigint' ? r2 + 1n : +r2 + 1;
if (value5 < r1) {
r2 = value5;
continue reducibleLoop5;
}
break reducibleLoop5;
}
}
return value;
};
const closure = function({items}) {
return items.map(_fun67173);
};
const closure2 = subscriptionCanSwitchImmediately;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importDefault(57) /* metro dependency 57 */;
const env0_4 = importAll(31) /* metro dependency 31 */;
const subscriptionPlanStore = importDefault(3807) /* metro dependency 3807: SubscriptionPlanStore */;
let value = require(661) /* metro dependency 661: Constants */;
const env0_6 = value.SubscriptionStatusTypes;
const env0_7 = value.SubscriptionTypes;
value = require(1880) /* metro dependency 1880: PremiumConstants */;
const env0_8 = value.SubscriptionPlans;
const env0_9 = value.SubscriptionPlanInfo;
(require(2) /* metro dependency 2 */).fileFinishedImporting('utils/SubscriptionUtils.tsx');
exports.getSubscriptionPlans = closure;
exports.getSubscriptionSKUs = getSubscriptionSKUs;
exports.subscriptionCanSwitchImmediately = closure2;
exports.subscriptionCanDowngrade = function(a0, a1, a2) {
return !subscriptionCanSwitchImmediately(a0, a1, a2);
};
exports.getOrFetchSubscriptionPlan = getOrFetchSubscriptionPlan;
exports.useGetOrFetchSubscriptionPlan = useGetOrFetchSubscriptionPlan;
exports.getSubscriptionPauseDurations = getSubscriptionPauseDurations;
exports.didBeginPurchaseFlowOnFractionalPremium = didBeginPurchaseFlowOnFractionalPremium;
}
function _createForOfIteratorHelperLoose_67169(a0, a1) { // fn#67169, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:250, offset: 0x01c18680, size: 372 bytes, params: 3, frame: 20
var r6;
var r9;
var r5;
var value3;
var regexp;
const env0_0 = a0;
const Symbol = global.Symbol;
let value = typeof Symbol !== 'undefined';
let r1 = value && a0[global.Symbol.iterator];
r1 = !r1 ? a0['@@iterator'] : r1;
if (r1) {
value = r1.call(a0);
return value.next.bind(value);
}
const Array = global.Array;
if (Array.isArray(a0)) {
if (r1) {
}
return _fun67170;
}
value = undefined;
if (a0) {
if (typeof a0 === 'string') {
value = _arrayLikeToArray_67171(a0, value);
r5 = value;
} else {
value3 = ({}).toString.call(a0).slice(8, -1);
r6 = value3 === 'Object' && a0.constructor;
r9 = r6 ? a0.constructor.name : value3;
if (r9 === 'Map') {
r6 = global.Array.from(a0);
} else if (r9 === 'Set') {
r6 = global.Array.from(a0);
} else if (r9 === 'Arguments') {
value = _arrayLikeToArray_67171(a0, value);
r6 = value;
} else {
regexp = RegExp('^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$', '');
if (regexp.test(r9)) {
value = _arrayLikeToArray_67171(a0, value);
r6 = value;
} else {
r6 = value;
}
}
r5 = r6;
}
} else {
r5 = value;
}
if (r5) {
if (r5) {
}
return _fun67170;
}
const TypeError = global.TypeError;
throw new TypeError('Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
}
function getSubscriptionPlans({items}) { // fn#67172, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:1160, offset: 0x01c187f4, size: 30 bytes, params: 2, frame: 11
return items.map(_fun67173);
}
function subscriptionCanSwitchImmediately(a0, a1, a2) { // fn#67174, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:1291, offset: 0x01c18856, size: 274 bytes, params: 4, frame: 14
var object4;
const CheckoutError = (require(8458) /* metro dependency 8458: CheckoutError */).CheckoutError;
var object2;
var object3;
let value = a0.getCurrentSubscriptionPlanIdForGroup(a2);
const type = a0.type;
const PREMIUM = SubscriptionTypes.PREMIUM;
if (type !== PREMIUM) {
object4 = {oldPlanId: value, newPlanId: a1};
if (value == null) {
object3 = {message: 'Current subscription has no plan in group', extraSentryInformation: object4};
throw new CheckoutError();
}
if (value !== SubscriptionPlans.PREMIUM_YEAR_TIER_1) {
value = a2.indexOf(value);
return value < a2.indexOf(a1);
}
if (a1 === SubscriptionPlans.PREMIUM_MONTH_TIER_2) {
object2 = {message: 'Unexpected plan switch', extraSentryInformation: object4};
throw new CheckoutError();
}
} else {
if (value == null) {
return true;
}
object4 = {oldPlanId: value, newPlanId: a1};
if (value == null) {
object3 = {message: 'Current subscription has no plan in group', extraSentryInformation: object4};
throw new CheckoutError();
}
if (value !== SubscriptionPlans.PREMIUM_YEAR_TIER_1) {
value = a2.indexOf(value);
return value < a2.indexOf(a1);
}
if (a1 === SubscriptionPlans.PREMIUM_MONTH_TIER_2) {
object2 = {message: 'Unexpected plan switch', extraSentryInformation: object4};
throw new CheckoutError();
}
}
value = a2.indexOf(value);
return value < a2.indexOf(a1);
}
function getSubscriptionSKUs(a0) { // fn#67175, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:1901, offset: 0x01c18968, size: 38 bytes, params: 2, frame: 11
return getSubscriptionPlans(a0).map(function(a0) {
return a0.skuId;
});
}
function getOrFetchSubscriptionPlan(a0, a1) { // fn#67178, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:2199, offset: 0x01c189ac, size: 180 bytes, params: 3, frame: 19
var property;
var moduleValue;
var value4;
const value2 = SubscriptionPlanStore.get(a0);
if (value2 == null) {
property = SubscriptionPlanInfo[a0];
(importDefault(44) /* metro dependency 44 */)(property != null, 'Missing hardcoded subscriptionPlan: ' + a0);
moduleValue = require(3802) /* metro dependency 3802: PremiumUtils */;
value4 = moduleValue.castPremiumSubscriptionAsSkuId(property.skuId);
if (!SubscriptionPlanStore.isFetchingForSKU(value4)) {
(require(6847) /* metro dependency 6847: SubscriptionPlanActionCreators */).fetchSubscriptionPlansForSKU(value4,
a1);
}
}
return value2;
}
function useGetOrFetchSubscriptionPlan(a0, a1) { // fn#67179, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:2502, offset: 0x01c18a60, size: 150 bytes, params: 3, frame: 18
const env0_0 = a0;
const env0_1 = a1;
const fluxModule = require(566) /* metro dependency 566: flux */;
const useStateFromStoresArray = fluxModule.useStateFromStoresArray;
const value3 = env0_3(Reflect.apply(useStateFromStoresArray, fluxModule, [[SubscriptionPlanStore], _fun67180]), 2);
const property = value3[0];
env0_4.useEffect(_fun67181, [property, a0, a1, value3[1]]);
return property;
}
function getSubscriptionPauseDurations(a0) { // fn#67182, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:2957, offset: 0x01c18bf5, size: 327 bytes, params: 2, frame: 21
var r4;
var items;
var value4;
var value5;
var Math;
var value6;
var value7;
var value8;
var done;
var value9;
var value10;
const Object = global.Object;
const keys = Object.keys;
const PauseDuration = (require(8460) /* metro dependency 8460: PauseDuration */).PauseDuration;
const value3 = Reflect.apply(keys, Object, [PauseDuration]).filter(function(a0) {
return global.isNaN((0, global.Number)(a0));
});
const status = a0.status;
const PAUSED = SubscriptionStatusTypes.PAUSED;
if (status !== PAUSED) {
return {durations: value3, currentDaysPaused: 0};
}
if (a0.pauseEndsAt != null) {
value4 = (importDefault(3738) /* metro dependency 3738 */)(a0.currentPeriodStart);
value5 = (importDefault(3738) /* metro dependency 3738 */)(a0.pauseEndsAt);
Math = global.Math;
value6 = Math.round(value5.diff(value4, 'days', true));
items = [];
value7 = _createForOfIteratorHelperLoose_67169(value3);
value8 = value7();
done = value8.done;
if (!done) {
r4 = value8;
while (true) {
value9 = r4.value;
if (PauseDuration[value9] > value6) {
items.push(value9);
}
value10 = value7();
done = value10.done;
if (done) {
break;
}
r4 = value10;
continue;
}
}
return {durations: items, currentDaysPaused: value6};
}
return {durations: [], currentDaysPaused: 0};
}
function didBeginPurchaseFlowOnFractionalPremium(a0) { // fn#67184, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:3499, offset: 0x01c18d3c, size: 93 bytes, params: 2, frame: 14
var r0;
let value = a0 != null;
if (value) {
value = importDefault(3738) /* metro dependency 3738 */;
value = value.isMoment(a0);
r0 = value;
} else {
r0 = value;
}
r0 = r0 && a0.isSameOrAfter((importDefault(3738) /* metro dependency 3738 */)());
return r0;
}
function _fun67173({planId}) { // fn#67173, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:1213, offset: 0x01c18812, size: 68 bytes, params: 2, frame: 14
const value = environment.__proto__;
const value2 = SubscriptionPlanStore.get(planId);
(importDefault(44) /* metro dependency 44 */)(value2 != null, 'Unable to fetch plan');
return value2;
}
function _fun67180() { // fn#67180, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:2590, offset: 0x01c18af6, size: 83 bytes, params: 1, frame: 13
var r1;
const value2 = null;
const r2 = value2 != env0_0 ? SubscriptionPlanStore.get(env0_0) : value2;
const items2 = [r2];
let value = value2 != r2;
if (value) {
value = environment.__proto__;
value = SubscriptionPlanStore.isFetchingForSKU(r2.skuId);
r1 = value;
} else {
r1 = value;
}
items2[1] = r1;
return items2;
}
function _fun67181() { // fn#67181, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8642:2716, offset: 0x01c18b49, size: 172 bytes, params: 1, frame: 19
var value2;
var binding;
var property;
var moduleValue;
var fetchSubscriptionPlansForSKU;
var moduleValue2;
if (env0_2 == null) {
if (env0_0 != null) {
if (!env0_3) {
value2 = environment.__proto__;
binding = env0_0;
property = SubscriptionPlanInfo[binding];
(importDefault(44) /* metro dependency 44 */)(property != null,
'Missing hardcoded subscriptionPlan: ' + binding);
moduleValue = require(6847) /* metro dependency 6847: SubscriptionPlanActionCreators */;
fetchSubscriptionPlansForSKU = moduleValue.fetchSubscriptionPlansForSKU;
moduleValue2 = require(3802) /* metro dependency 3802: PremiumUtils */;
Reflect.apply(fetchSubscriptionPlansForSKU, moduleValue,
[moduleValue2.castPremiumSubscriptionAsSkuId(property.skuId), require]);
}
}
}
}