Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

var WSB;(function(n){const

h=2,c=5,i=200,e=864e5,l="/msrewards/api/v1/getuserinfo",a="https://
account.microsoft.com/rewards?ref=WSB",v=n=>{return"https://account.microsoft.com/
rewards/createuser?publ=CORTIP&crea=MY019H&pn=MULTIWSBACQ201910&returnUrl=
%2Frewards%2Fredirect%3Flink%3D%252Frewards%26id%3Dbingtrial_250%26channel%3Dwsb
%26type%3D16%26amount%3D"+n+"%26hash
%3Db3bc83aeabe24a90fade4e7e81e00d5fda4aeb66abe9f569a27c5a97a75e8f57"},o="RewardsBad
geNotificationLastShownDate",u="RewardsBadgeNotificationTimesShown";class
y{constructor(i,u){this._page=i;this._accessTokenManager=u;this._balance=new
s;this._rewardsBadgeUpdatedHandlers=[];this._retryAttempted=0;r.init();t.init();con
st f=()=>{this._currentConversationId||
(this._currentConversationId=n.Host.getConversationId(),this.isFeatureEnabled()&&th
is._msaAccount&&this.refreshBalance())};n.Host.bindConversationStart(()=>f());n.Hos
t.bindQueryChangedOrInitialized(()=>f());n.Host.bindDismissed(()=>{this.clear(),thi
s._msaAccount=null,this._currentConversationId=null,t.onDismiss(),n.config.enableEd
uFlyoutRewardsSystem&&this._flyout&&this._flyout.hide(),this.shouldShowRewardsFlyou
t()&&n.RewardsFlyoutViewModel&&n.RewardsFlyoutViewModel.hideRewardsFlyout()});u.bin
dSelectedAccountChanged(n=>{if(this.isFeatureEnabled()){let
t=n&&n.accountProviderAuthority=="consumers"?
n:null;this.handleNewAccountAvailable(t)}});u.bindAccountTypesChanged(()=>{if(this.
isFeatureEnabled()){let
t=u.getCachedAccountInfo(0);this.handleNewAccountAvailable(t,(n.Host===null||
n.Host===void 0?void 0:n.Host.isAuthInvestigation())?
["MSFTRewardsViewsModel::handleAccountTypeChanged"]:undefined)}});u.bindAccessToken
Available((n,t)=>{if(n==0&&this.isFeatureEnabled())if(this._msaAccount)this.refresh
Balance();else{let
n=u.getCachedAccountInfo(0);this.handleNewAccountAvailable(n)}})}shouldShowBadgeNot
ification(){if(!this.shouldShowRewardsFlyout()||!
n.config.rewardsFlyoutNotification||!this._userIsRewardsMember&&!
n.config.rewardsFlyoutNotifNonMember)return!1;const
t=Number(n.LightweightStorage.getItem(o))||0;if(this._userIsRewardsMember)return
t==0||t+e<=n.getCurrentTime();const i=parseInt(n.LightweightStorage.getItem(u))||
0,r=i<3,f=t==0||t+e*7<=n.getCurrentTime();return f&&r}onBadgeNotificationShown()
{const t=parseInt(n.LightweightStorage.getItem(u))||
0;n.LightweightStorage.setItem(o,n.getCurrentTime().toString());n.LightweightStorag
e.setItem(u,
(t+1).toString());this.fireRewardsBadgeUpdated()}initializeEducationExperience()
{if(this._page!
=null&&n.RewardsFlyoutViewModel.EnabledMarketAndRegion()&&n.RuntimeConfig.QfMode==1
){const t=_ge("rewardsBadgeButton");if(!this._flyout)
{if(this._flyout=this._page.createFlyout("RewardsMain"),!
this._flyout)return;this._flyout.addMessage(n.Host.getLocString("RewardsEducationMa
inNewUserText")).button(n.Host.getLocString("RewardsEducationMainButtonMessage"),
(n,t)=>{this.getDataModel().click(n,t)},0,"&#xE970").icon("Rewards").setClass("mini
flyout").setSticky().isLinkTextButton(!0).target(t,"Left").showButton(!
0)}this._flyout.target(t,"Left").show()}}isFeatureEnabled(){return
n.contains(n.config.rewardsLanguageEnabled||
[],n.uiLanguageCache.toLowerCase())}isCounterFactualLoggingEnabled(){return
n.contains(n.config.rewardsCounterFactualLoggingLanguageEnabled||
[],n.uiLanguageCache.toLowerCase())}handleNewAccountAvailable(n,t)
{t=t&&[...t,"MSFTRewardsViewsModel::handleNewAccountAvailable"];const
i=this._msaAccount;i!
=n&&this._currentConversationId&&(this._msaAccount=n,this._msaAccount?
i&&this._msaAccount.accountId==i.accountId||
(this.clearCurrentBadge(),this.refreshBalance(null,t)):this.clearCurrentBadge())}cl
earCurrentBadge(){let
n=this._balance.isSet();this.clear();n&&this.fireRewardsBadgeUpdated()}clear()
{this._rewardsEnabled=!1;this._userIsRewardsMember=!0;this._userIsGiving=!
1;this._fetchInProgress=!1;this._balance=new
s;this._retryAttempted=0}refreshBalance(t,i)
{if(i=i&&[...i,"MSFTRewardsViewsModel::refreshBalance"],!this._fetchInProgress&&(!
this._currentConversationId||this._userIsRewardsMember)){const
o=this._currentConversationId,u=()=>o==this._currentConversationId,e=t=>{f.getBalan
ceAsyncRpsToken(t,t=>{this._fetchInProgress=!1,u()&&(t.IsRewardsUser||
n.config.rewardsAnidAccrualEnabled)&&(this._rewardsEnabled=!
0,this._userIsRewardsMember=t.IsRewardsUser,t.IsRewardsUser?
(this._userIsGiving=t.IsGiveUser,this.setNewBalance(t.Balance)):
(this._userIsGiving=!
1,this.setNewBalance(r.getBalance(this._msaAccount)),n.config.enableEduFlyoutReward
sSystem&&this.initializeEducationExperience()))},n=>{this._fetchInProgress=!
1,u()&&this.handleError(t,n)})};this._fetchInProgress=!0;t?
e(t):this._accessTokenManager.getAccount(0,n.getBingResourceOrScope(0),!1,!
0,t=>{let r=t&&t.Token;r?e(r):
(n.logAuthRelatedInfo("getAccountOnFailure",`authenticate failed for MSA account.
CallStack: ${i===null||i===void 0?void 0:i.join(" -> ")}`),this._fetchInProgress=!
1)},undefined,i)}}handleError(n,t){t&&t.Retryable&&this._retryAttempted<h&&(+
+this._retryAttempted,this.refreshBalance(n))}shouldShowRewardsFlyout(){const
t=n.config.enableEduFlyoutRewardsSystem&&!
this._userIsRewardsMember&&n.RewardsFlyoutViewModel.EnabledMarketAndRegion()&&n.Run
timeConfig.QfMode==1,i=n.RuntimeConfig.QfMode===0||n.RuntimeConfig.QfMode===4||
n.RuntimeConfig.QfMode===11;return t||n.config.rewFly&&!
i&&n.RewardsFlyoutViewModel.EnabledMarketAndRegion()&&(n.config.nonMemberRewFly||
this._userIsRewardsMember)}hide()
{n.RewardsFlyoutViewModel.hideRewardsFlyout()}getDataModel(){if(!
this._balance.isSet())return null;let
r=this._balance.getValue(),u=this._userIsRewardsMember?
this._userIsGiving?"RWBG":"RWBD":"RWBN",f;f=this.shouldShowRewardsFlyout()?
()=>{this._flyout&&this._flyout.dismiss(),n.RewardsFlyoutViewModel.toggleRewardsFly
out(()=>t.instrumentFlyoutClick(),
(n,i)=>t.instrumentClickOnBadge(u,n,i)),this.shouldShowBadgeNotification()&&this.on
BadgeNotificationShown()}:(i,f)=>{n.config.rewFly&&!
n.RewardsFlyoutViewModel.EnabledMarketAndRegion()&&t.instrumentRewardsFlyoutMarketB
lock();t.instrumentClickOnBadge(u,i,f);let e=this._userIsRewardsMember?
a:v(r);n.Host.launchUri(e)};let
o=""+r,s=this._userIsRewardsMember?1:r/i,e=t.instrumentBadge(u);return
e.setProperty("Balance",o),
{counterFactualLoggingEnabled:this.isCounterFactualLoggingEnabled(),balance:r,userI
sRewardsMember:this._userIsRewardsMember,userIsGiving:this._userIsGiving,click:f,in
stItem:e,badgeFillupPercentage:s,showNotification:this.shouldShowBadgeNotification(
)}}fireRewardsBadgeUpdated()
{this._rewardsBadgeUpdatedHandlers.forEach(n=>n())}isRewardsEnabled(){return
this.isCounterFactualLoggingEnabled()?!
1:this._rewardsEnabled}notifyPointsRewarded(n){const t="notifyPointsRewarded";if(!
this.isRewardsEnabled()){SharedLogHelper.LogError(t,null,new Error("Rewards not
enabled"));return}if(!this._userIsRewardsMember)if(n<=0)n=this._balance.getValue()
+c;else{SharedLogHelper.LogError(t,""+n,new Error("Invalid non rewards member new
balance"));return}if(n<0){SharedLogHelper.LogError(t,""+n,new Error("Invalid
rewards new balance"));return}this.setNewBalance(n)}setNewBalance(n)
{this._userIsRewardsMember||
(n>i&&(n=i),r.setNewBalance(this._msaAccount,n));this._balance.getValue()!
=n&&(this._balance.setValue(n),this.fireRewardsBadgeUpdated())}bindRewardsBadgeUpda
ted(n,t)
{this._rewardsBadgeUpdatedHandlers.push(n);t&&this._balance.isSet()&&n()}}n.Microso
ftRewardsViewModel=y;class s{getValue(){return this._value}setValue(n)
{this._value=typeof n=="number"?n:undefined}isSet(){return typeof
this._value=="number"}}let f;(function(t){function i(n,t,i){if(n)if(n.RewardsUser)
{let r=n.Balance&&n.Balance.Available;if(typeof r=="number"){const
i=n.UserProfileAttributes&&n.UserProfileAttributes.give_user&&n.UserProfileAttribut
es.give_user.toLowerCase()=="true";t({IsRewardsUser:!
0,Balance:r,IsGiveUser:i})}else i(n.ErrorDetail)}else
n.ErrorDetail&&n.ErrorDetail.ErrorCode===5003?t({IsRewardsUser:!
1}):i(n.ErrorDetail);else i(null)}function r(t,r,f){let e={};e["X-Search-
RPSToken"]=t;n.fetchUrlJson(l,e,u(),n=>i(n,r,f))}function u(n){let
t={PartnerId:"WSB",Channel:"WSB"};return
n&&(t.UserId=n),JSON.stringify(t)}t.getBalanceAsyncRpsToken=r})(f||(f={}));let r;
(function(t){function f(){}function r(n)
{return"RewardsPoints_"+n.accountUserName}function u(t){let
e=r(t),u=n.LightweightStorage.getItem(e),f=u?+u:0;return f>i?i:f}function e(t,f)
{if(f>i&&(f=i),u(t)!=f){let i=r(t);return f?
n.LightweightStorage.setItem(i,""+f):n.LightweightStorage.removeItem(i),!0}return!
1}t.init=f;t.getBalance=u;t.setNewBalance=e})(r||(r={}));let t;(function(t)
{function e(){}function o(){i=null;r=-1}function u(t){return i||
(i=n.InstrumentedItem.getNonSuggestionInstrumentedItem(t,n.SyntheticQSCodesMaps.KVa
lues,1)),i}function f(t){let
i=n.SequenceNumberManager.getSequenceNumber(),f=u(t);return
r<i&&(n.InstrumentationHelper.instrumentSyntheticInstrumentedItem(i,t,f),r=i),f}fun
ction s(t,i,e){let
o=n.SequenceNumberManager.getSequenceNumber();r<o&&f(t);n.InstrumentationHelper.ins
trumentItemClick(i,u(t),o,null,e,null)}function h(){const
t=n.SequenceNumberManager.getSequenceNumber();n.InstrumentationHelper.logClientInst
Event("Select","RewardsFlyoutOpen",t)}function c(){const
t=n.SequenceNumberManager.getSequenceNumber(),i={revIp:n.revIpRegionCache,language:
n.getCurrentLanguage()};n.InstrumentationHelper.logClientInstEvent("Select","Reward
sFlyoutMarketBlock",t,i)}let i,r=-
1;t.init=e;t.onDismiss=o;t.instrumentBadge=f;t.instrumentClickOnBadge=s;t.instrumen
tFlyoutClick=h;t.instrumentRewardsFlyoutMarketBlock=c})(t||(t={}))})(WSB||(WSB={}))

You might also like