Build 562131stable
Module 470285
3,777 characters · in 7878ea948ef67e52.jsDependencies
Source Raw
function(t,e,i){i.d(e,{x:()=>y,j:()=>g});var r=i(64700),s=i(636537),l=i(228366),n=i(615405),a=i(927813),u=i(561573);i(321073);var o=i(17928);let d={};class c extends o.Ay.Store{static displayName="StorefrontPromotionStore";getFetchState(t){return d[t]?.state}getFetchedAt(t){let e=d[t];if(e?.state==="success"||e?.state==="error")return e.fetchedAt}getPromotionsForApplication(t){let e=d[t];return e?.state==="success"||e?.state==="loading"?e.promotions??null:null}}new c(l.h,{LOGOUT:function(){d={}},STOREFRONT_PROMOTIONS_FETCH_START:function(t){let{applicationIds:e}=t;for(let t of e){let e=d[t];d[t]={state:"loading",promotions:e?.state==="success"?[...e.promotions]:void 0}}},STOREFRONT_PROMOTIONS_FETCH_SUCCESS:function(t){let{applicationIds:e,promotions:i}=t,r=Date.now(),s={...d};for(let t of e)s[t]={state:"success",promotions:[],fetchedAt:r};for(let t of i){let e=t.applicationId;s[e]?.state==="success"&&s[e].promotions.push(t)}d=s},STOREFRONT_PROMOTIONS_FETCH_FAIL:function(t){let{applicationIds:e}=t,i=Date.now();for(let t of e)d[t]={state:"error",fetchedAt:i}}});var p=i(723090),S=i(315069);class h extends S.A{id;applicationId;displayName;rewardType;rewardConfig;skuIds;appliesToAllSkus;startsAt;endsAt;static createFromServer(t){var e;return new h({id:t.id,applicationId:t.application_id,displayName:t.display_name??null,rewardType:t.reward_type,rewardConfig:null!=t.reward_config?null==(e=t.reward_config)?null:{discount:null!=e.discount?{id:e.discount.id,type:e.discount.type,amount:e.discount.amount}:null}:null,skuIds:function(t){if(null==t)return null;let e={};for(let[i,r]of Object.entries(t))e[i]={priceTiers:r.price_tiers};return e}(t.sku_ids),appliesToAllSkus:t.applies_to_all_skus,startsAt:null!=t.starts_at?new Date(t.starts_at):null,endsAt:null!=t.ends_at?new Date(t.ends_at):null})}constructor(t){super(),this.id=t.id,this.applicationId=t.applicationId,this.displayName=t.displayName,this.rewardType=t.rewardType,this.rewardConfig=t.rewardConfig,this.skuIds=t.skuIds,this.appliesToAllSkus=t.appliesToAllSkus,this.startsAt=t.startsAt,this.endsAt=t.endsAt}}var I=i(652215);a.A.Millis.HOUR;let f=10*a.A.Millis.MINUTE,A=a.A.Millis.MINUTE;function _(t){return t?.type==="error"?f:A}async function E(t){let{applicationId:e}=t;await T({type:"application",applicationId:e})}async function m(t){let{skuIds:e}=t;await T({type:"skus",skuIds:e})}async function T(t){let{shouldFetch:e,filteredSkuIds:i,applicationId:r}=function(t){if("application"===t.type){let e=u.A.getFetchStateForApplicationId(t.applicationId),i=_(e);return null!=e&&("loading"===e.type||e.fetchedAt>Date.now()-i)?{shouldFetch:!1,filteredSkuIds:[],applicationId:t.applicationId}:{shouldFetch:!0,filteredSkuIds:[],applicationId:t.applicationId}}{let e=t.skuIds.filter(t=>{let e=u.A.getFetchStateForSkuId(t);if(null==e)return!0;let i=_(e);return"loading"!==e.type&&e.fetchedAt<Date.now()-i}).sort((t,e)=>{let i=u.A.getFetchStateForSkuId(t),r=u.A.getFetchStateForSkuId(e);return null==i&&null!=r?-1:+(null!=i&&null==r)});return 0===e.length?{shouldFetch:!1,filteredSkuIds:[],applicationId:null}:{shouldFetch:!0,filteredSkuIds:e.slice(0,50),applicationId:null}}}(t);if(!e)return;let a=null!=r?{type:"application",applicationId:r}:{type:"skus",skuIds:i};try{l.h.dispatch({type:"SKUS_PRICING_FETCH_START",priceId:a});let t=(await s.Bo.get({url:I.Rsh.STOREFRONT_PRICES,query:{...null!=r?{application_id:r}:{sku_ids:i},country_code:n.A.ipCountryCode??void 0},rejectWithError:!0})).body;l.h.dispatch({type:"SKUS_PRICING_FETCH_SUCCESS",priceId:a,data:(0,p.Oj)(t)})}catch{l.h.dispatch({type:"SKUS_PRICING_FETCH_FAIL",priceId:a})}}function y(t){let{applicationId:e}=t;r.useEffect(()=>{null!=e&&E({applicationId:e})},[e])}function g(t){let{skuIds:e}=t;r.useEffect(()=>{0!==e.length&&m({skuIds:e})},[e])}}