You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
8.2 KiB

var E=Object.defineProperty;var M=(t,e,o)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var d=(t,e,o)=>M(t,typeof e!="symbol"?e+"":e,o);import{V as O,f as A,e as V,a9 as G,a as S,C as j,_ as P,g as y,h as m,i as u,j as i,l as g,F as k,z as U,k as v,t as C,m as b,o as D,s as H,x as p}from"./index-BLqts8WY.js";import{D as I}from"./datetime-BDQ5ptpc.js";import{Q as N}from"./QuickNav-DgCyvgDx.js";import{T as Q}from"./TopMessage-BE0GBIgW.js";import{g as W,a6 as x,F as _,aS as F,ar as L,aQ as $,aT as R}from"./index-MyY_xqVN.js";import"./index-CsfPLOYu.js";var Y=Object.defineProperty,z=Object.getOwnPropertyDescriptor,q=(t,e,o,a)=>{for(var r=a>1?void 0:a?z(e,o):e,s=t.length-1,l;s>=0;s--)(l=t[s])&&(r=(a?l(e,o,r):l(r))||r);return a&&r&&Y(e,o,r),r};let w=class extends O{constructor(){super(...arguments);d(this,"$notify");d(this,"activeDid","");d(this,"allContacts",[]);d(this,"allMyDids",[]);d(this,"apiServer","");d(this,"claimCountByUser",0);d(this,"claimCountWithHidden",0);d(this,"claimsToConfirm",[]);d(this,"claimsToConfirmSelected",[]);d(this,"description","breakfast");d(this,"loadingConfirms",!0);d(this,"someoneGave",!1);d(this,"supplyGiftDetails",!1)}async created(){this.loadingConfirms=!0;const e=await A();this.apiServer=e.apiServer||"",this.activeDid=e.activeDid||"",this.allContacts=await V.contacts.toArray();let o=I.now().setZone("America/Denver");o.weekday<6&&(o=o.minus({week:1}));const r=o.set({weekday:6}).set({hour:9}).startOf("hour").toISO({suppressMilliseconds:!0})||"",s=await G;await s.open();const l=await s.accounts.toArray();this.allMyDids=l.map(c=>c.did);const h=await W(this.activeDid);try{const c=await fetch(this.apiServer+"/api/claim/?issuedAt_greaterThanOrEqualTo="+encodeURIComponent(r)+"&excludeConfirmations=true",{headers:h});if(!c.ok)throw console.error("Bad response",c),new Error("Bad response when retrieving claims.");await c.json().then(n=>{const f=x(B=>B.issuer===this.activeDid,n),T=x(_,f);this.claimsToConfirm=T,this.claimCountByUser=n.length-f.length,this.claimCountWithHidden=f.length-T.length})}catch(c){console.error("Error:",c),this.$notify({group:"alert",type:"danger",title:"Error",text:"There was an error retrieving today's claims to confirm."},5e3)}this.loadingConfirms=!1}onClickLoadClaim(e){const o={path:"/claim/"+encodeURIComponent(e)};this.$router.push(o)}async record(){var e;try{this.claimsToConfirmSelected.length>0&&this.$notify({group:"alert",type:"toast",title:"Sent..."},1e3);const o=await Promise.allSettled(this.claimsToConfirmSelected.map(async s=>{const l=this.claimsToConfirm.find(h=>h.id===s);return l?F(this.activeDid,l.claim,l.id,l.handleId,this.apiServer,S):{type:"error",error:"Record not found."}})),a=o.filter(s=>s.status==="fulfilled"&&s.value.type==="success");if(a.length<this.claimsToConfirmSelected.length){console.error("Error sending confirmations:",o);const s=a.length===0?"all":"some";this.$notify({group:"alert",type:"danger",title:"Error",text:`There was an error sending ${s} of the confirmations.`},5e3)}let r=!1;if(this.someoneGave&&!this.supplyGiftDetails){const s=await L(S,this.apiServer,this.activeDid,void 0,this.activeDid,this.description,void 0,void 0,void 0,void 0,!1,void 0,$);r=s.type==="success",r||(console.error("Error sending give:",s),this.$notify({group:"alert",type:"danger",title:"Error",text:((e=s==null?void 0:s.error)==null?void 0:e.userMessage)||"There was an error sending that give."},5e3))}if(this.someoneGave&&this.supplyGiftDetails){if(a.length>0){const s=a.length===1?"Your confirmation has been recorded.":"Your confirmations have been recorded.";this.$notify({group:"alert",type:"success",title:"Success",text:s},3e3)}this.$router.push({name:"gifted-details",query:{description:this.description,destinationPathAfter:"/",providerProjectId:$,recipientDid:this.activeDid}})}else if(a.length>0||r){const s=a.length===1?"confirmation":"confirmations",l=a.length>0&&r?`Your ${s} and that give have been recorded.`:r?"That give has been recorded.":"Your "+s+" "+(a.length===1?"has":"have")+" been recorded.";this.$notify({group:"alert",type:"succ