// Metro module 8722 (f8723). import SKUStore from "../../stores/game_store/SKUStore"; import { Endpoints } from "../../Constants"; import Logger from "../debug/Logger"; import Dispatcher from "../../Dispatcher"; import { HTTP } from "../../_bundle/sendRequest"; import { BillingError } from "../../errors/index"; import { isTestModeForApplication } from "../game_store/TestModeUtils"; import SentryUtils_native from "../../utils/SentryUtils.native"; function $mk115332($env) { return () => { Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_REDEEM_START", skuId: $env[0] }); }; } let c5686_6; let env5686 = {}; export async function fetchVirtualCurrencyBalance() { let body; let c26275_0, c26275_1, c26275_2; let c26275_3 = 0; const r11 = env5686; try { let env29973; c26275_1 = r11; const r27 = env29973 = { $parent: r11 }; c26275_0 = r27; env29973[0] = void 0; env29973[1] = void 0; env29973[2] = void 0; Dispatcher.wait(() => { Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_BALANCE_FETCH" }); }); c26275_3 = 1; env29973[0] = await HTTP.get({ url: Endpoints.VIRTUAL_CURRENCY_USER_BALANCE, rejectWithError: false }); env29973[1] = env29973[0].body.balance; Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_BALANCE_FETCH_SUCCESS", balance: env29973[1] }); body = env29973[0].body; c26275_3 = 0; } catch ($e) { const r25 = $e; let r8 = r25; c26275_2 = r25; if (c26275_3 !== 0) { while (true) { try { const r79 = c26275_2; c26275_3 = 0; env29973[3] = r79; env29973[2] = env29973[3] instanceof BillingError ? env29973[3] : new BillingError(env29973[3]); Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_BALANCE_FETCH_FAIL", error: env29973[2] }); } catch (r75) { r8 = r75; c26275_2 = r75; if (c26275_3 === 0) { break; } continue; } return void 0; } } throw r8; } return body; } c5686_6 = new Logger("VirtualCurrencyActionCreators"); export async function redeemVirtualCurrencyForSKU(c26276_0) { let r176; let c26276_1, c26276_2, c26276_3; let c26276_4 = 0; const r13 = env5686; L29: { try { let env29974; c26276_2 = r13; const r36 = env29974 = { $parent: r13 }; c26276_1 = r36; env29974[0] = void 0; env29974[1] = void 0; env29974[2] = void 0; env29974[3] = void 0; env29974[4] = void 0; env29974[5] = void 0; env29974[0] = c26276_0.skuId; env29974[1] = c26276_0.loadId; env29974[2] = c26276_0.onRedeemStart; env29974[3] = c26276_0.onRedeemSucceed; env29974[4] = c26276_0.onRedeemFail; const shouldRefetchBalance = c26276_0.shouldRefetchBalance; if (shouldRefetchBalance !== void 0) { env29974[5] = shouldRefetchBalance; env29974[6] = void 0; env29974[7] = void 0; env29974[8] = void 0; env29974[9] = void 0; env29974[10] = void 0; env29974[11] = void 0; env29974[12] = void 0; env29974[13] = void 0; } else { env29974[5] = true; env29974[6] = void 0; env29974[7] = void 0; env29974[8] = void 0; env29974[9] = void 0; env29974[10] = void 0; env29974[11] = void 0; env29974[12] = void 0; env29974[13] = void 0; } await void 0; Dispatcher.wait($mk115332(c26276_1)); const r71 = env29974[2]; if (r71 != null) { r71(); } c26276_4 = 1; env29974[6] = SKUStore.get(env29974[0]); env29974[7] = env29974[6]?.applicationId; env29974[8] = env29974[7] != null && isTestModeForApplication(env29974[7]); env29974[9] = { checkout_session_id: env29974[1] }; if (env29974[8]) { env29974[9].test_mode = true; } const r115 = await HTTP.post({ url: Endpoints.VIRTUAL_CURRENCY_SKU_REDEEM(env29974[0]), body: env29974[9], rejectWithError: false }); const r125 = "Could not read entitlements from Virtual Currency redemption response. Response: "; env29974[10] = r115.body; if (env29974[10] != null && Array.isArray(env29974[10])) { Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_REDEEM_SUCCESS", skuId: env29974[0], entitlements: env29974[10] }); if (env29974[5]) { (0, fetchVirtualCurrencyBalance)(); } const r171 = env29974[3]; if (r171 != null) { r171(env29974[10]); } r176 = env29974[10]; c26276_4 = 0; break L29; } env29974[11] = r125; env29974[12] = new Error(env29974[11], env29974[10]); c5686_6.error(env29974[11], env29974[10]); SentryUtils_native.captureException(env29974[12], { tags: { app_context: "virtual_currency" } }); throw env29974[12]; } catch ($e) { const r34 = $e; let r8 = r34; c26276_3 = r34; if (c26276_4 !== 0) { while (true) { try { const r188 = c26276_3; c26276_4 = 0; env29974[14] = r188; env29974[13] = env29974[14] instanceof BillingError ? env29974[14] : new BillingError(env29974[14]); Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_REDEEM_FAIL", skuId: env29974[0], error: env29974[13] }); if (env29974[5]) { (0, fetchVirtualCurrencyBalance)(); } const r222 = env29974[4]; if (r222 != null) { r222(env29974[13]); } } catch (r184) { r8 = r184; c26276_3 = r184; if (c26276_4 === 0) { break; } continue; } return void 0; } } throw r8; } } return r176; } export function setBalancePillOverlay(a0) { return Dispatcher.dispatch({ type: "VIRTUAL_CURRENCY_SET_BALANCE_PILL_OVERLAY", balancePillOverlay: a0 }); }