Files
discord-decomp/modules/quests/BountyActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

236 lines
7.0 KiB
TypeScript

// Metro module 10885 (f10886).
import NetworkStore from "../../stores/NetworkStore";
import BountyStore from "./BountyStore";
import { Endpoints } from "../../Constants";
import Dispatcher from "../../Dispatcher";
import { AdCreativeType } from "../../_bundle/Module6013";
import { bountyFromServer } from "../ads/BountyTypes";
import { questAdDecisionFromAdDecision } from "../ads/utils/AdDecisionUtils";
import APIError from "../../errors/APIError";
import { getSession } from "../analytics_sessions/SessionHeartbeatScheduler";
import { getOrRefreshAdSession, getCurrentAdSession } from "../analytics_sessions/SessionAdGenerator";
import { HTTP } from "../../_bundle/sendRequest";
import { getAdMetadataSealed, getAdTrafficMetadataSealed } from "./utils/QuestDataUtils";
import { HermesBuiltin } from "../../_hermes/prelude";
function $mk116053($env) {
return (a0) => {
if (a0.creative != null) {
const creative_type = a0.creative.creative_type;
if (creative_type === AdCreativeType.BOUNTY) {
const r15 = $env;
const r19 = bountyFromServer(a0.creative.creative_content);
r15[3].set(r19.id, questAdDecisionFromAdDecision(a0, {
fetchedAt: r15[1],
requestId: r15[2].request_id,
adCreativeId: r19.id
}));
return [r19];
}
}
return [];
};
}
let env7324 = {};
const fetchBountiesAndDispatch = async function fetchBountiesAndDispatch(c26829_0, c26829_1) {
let c26829_2, c26829_3, c26829_4;
let c26829_5 = 0;
const r12 = env7324;
L10: {
try {
let env30292;
c26829_3 = r12;
const r16 = env30292 = {
$parent: r12
};
c26829_2 = r16;
env30292[0] = c26829_0;
env30292[1] = void 0;
env30292[2] = void 0;
env30292[3] = void 0;
env30292[4] = void 0;
Dispatcher.dispatch({
type: "BOUNTIES_FETCH_QUEST_HOME_BOUNTIES_BEGIN"
});
c26829_5 = 1;
env30292[1] = Date.now();
const r23 = await c26829_1();
const r55 = c26829_2;
env30292[2] = r23;
env30292[3] = new Map();
env30292[4] = env30292[2].decisions.flatMap($mk116053(r55));
Dispatcher.dispatch({
type: "BOUNTIES_FETCH_QUEST_HOME_BOUNTIES_SUCCESS",
bounties: env30292[4],
placement: env30292[0],
adDecisionsByAdCreativeId: env30292[3],
fetchedAt: env30292[1]
});
c26829_5 = 0;
} catch ($e) {
const r27 = $e;
let r8 = r27;
c26829_4 = r27;
if (c26829_5 !== 0) {
while (true) {
try {
const r85 = c26829_4;
c26829_5 = 0;
env30292[5] = r85;
Dispatcher.dispatch({
type: "BOUNTIES_FETCH_QUEST_HOME_BOUNTIES_FAILURE",
placement: env30292[0],
error: new APIError(env30292[5])
});
break L10;
} catch (r81) {
r8 = r81;
c26829_4 = r81;
if (c26829_5 === 0) {
break;
}
}
}
}
throw r8;
}
}
};
export async function fetchQuestHomeBounties(c26830_0) {
L11: {
let c30293_0 = c26830_0;
if (BountyStore.isFetchingQuestHomeBounties) {
break L11;
}
await fetchBountiesAndDispatch(c26830_0, async () => {
let c31592_1;
c31592_1 = void 0;
let c32021_0 = await getSession();
let client_heartbeat_session_id = void 0;
let c32021_1 = getOrRefreshAdSession();
if (c32021_0 != null) {
client_heartbeat_session_id = c32021_0.uuid;
}
return (await HTTP.get({
url: Endpoints.QUESTS_GET_DECISIONS,
query: {
placement: c30293_0,
client_ad_session_id: c32021_1.uuid,
client_heartbeat_session_id,
num_decisions_requested: 5
},
rejectWithError: false,
context: {
connection_type: NetworkStore.getType()
}
})).body;
});
return void 0;
}
}
export async function fetchBountyPreview(c26831_0, c26831_1) {
L11: {
let c30294_0 = c26831_0;
let c30294_1 = c26831_1;
if (BountyStore.isFetchingQuestHomeBounties) {
break L11;
}
await fetchBountiesAndDispatch(c26831_1, async () => {
const r13 = URLSearchParams;
let c31593_0 = 0;
const r17 = c30294_0.map((item) => ["ad_creative_ids", item]);
const r29 = [,];
c31593_0 = HermesBuiltin.arraySpread(r29, r17, c31593_0);
r29[c31593_0] = ["placement", String(c30294_1)];
c31593_0 = c31593_0 + 1;
return (await HTTP.get({
url: `${Endpoints.QUESTS_CREATIVE_PREVIEW}?${new r13(r29).toString()}`,
rejectWithError: false
})).body;
});
return void 0;
}
}
export function setBountyVideoProgress(a0, a1) {
if (getCurrentAdSession() != null) {
getOrRefreshAdSession(true);
Dispatcher.dispatch({
type: "BOUNTIES_VIDEO_PROGRESS_UPDATE",
bountyId: a0,
timestampSec: a1.timestampSec,
maxTimestampSec: a1.maxTimestampSec,
duration: a1.duration
});
}
}
export async function claimBountyReward(bountyId, c26832_1) {
let c26832_4;
let c26832_5 = 0;
let c30295_0, c30295_1, c30295_2, c30295_3, c30295_4, c30295_5, c30295_6, c30295_7;
L21: {
try {
c30295_0 = bountyId;
c30295_1 = c26832_1;
c30295_2 = void 0;
c30295_3 = void 0;
c30295_4 = void 0;
c30295_5 = void 0;
c30295_6 = void 0;
if (BountyStore.isClaimingBountyReward(bountyId)) {
break L21;
}
Dispatcher.dispatch({
type: "BOUNTIES_CLAIM_REWARD_BEGIN",
bountyId
});
c26832_5 = 1;
c30295_2 = await getSession();
c30295_3 = getOrRefreshAdSession();
c30295_4 = getAdMetadataSealed(c30295_1, c30295_0);
c30295_5 = getAdTrafficMetadataSealed(c30295_1, void 0, c30295_0);
await HTTP.post({
url: Endpoints.QUESTS_CREATIVES_CLAIM_REWARD(c30295_0),
body: {
decision_metadata_sealed: c30295_4 != null ? c30295_4 : null,
traffic_metadata_sealed: c30295_5 != null ? c30295_5 : null,
client_ad_session_id: c30295_3.uuid,
client_heartbeat_session_id: c30295_2?.uuid
},
rejectWithError: false
});
Dispatcher.dispatch({
type: "BOUNTIES_CLAIM_REWARD_SUCCESS",
bountyId: c30295_0
});
c26832_5 = 0;
} catch ($e) {
const r32 = $e;
let r8 = r32;
c26832_4 = r32;
if (c26832_5 !== 0) {
while (true) {
try {
const r150 = c26832_4;
c26832_5 = 0;
c30295_7 = r150;
c30295_6 = new APIError(c30295_7);
Dispatcher.dispatch({
type: "BOUNTIES_CLAIM_REWARD_FAILURE",
bountyId: c30295_0,
error: c30295_6
});
throw c30295_6;
} catch (r146) {
r8 = r146;
c26832_4 = r146;
if (c26832_5 === 0) {
break;
}
}
}
}
throw r8;
}
return void 0;
}
}