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.
1 lines
6.9 KiB
1 lines
6.9 KiB
var x=Object.defineProperty;var D=(e,t,r)=>t in e?x(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var s=(e,t,r)=>D(e,typeof t!="symbol"?t+"":t,r);import{aa as $,C as S,V as T,f as j,e as P,_ as k,g as b,x as E,h as U,j as a,t as y,m as I,s as C,i as m,w as G,k as w,l as O}from"./index-BLqts8WY.js";import{l as M,e as V,h as N,ar as A,at as R}from"./index-MyY_xqVN.js";var F=Object.defineProperty,H=Object.getOwnPropertyDescriptor,v=(e,t,r,i)=>{for(var o=i>1?void 0:i?H(t,r):t,l=e.length-1,n;l>=0;l--)(n=e[l])&&(o=(i?n(t,r,o):n(o))||o);return i&&o&&F(t,r,o),o};let f=class extends T{constructor(){super(...arguments);s(this,"$notify");s(this,"fromProjectId","");s(this,"toProjectId","");s(this,"activeDid","");s(this,"allContacts",[]);s(this,"allMyDids",[]);s(this,"apiServer","");s(this,"amountInput","0");s(this,"callbackOnSuccess",()=>{});s(this,"customTitle");s(this,"description","");s(this,"giver");s(this,"isTrade",!1);s(this,"offerId","");s(this,"prompt","");s(this,"receiver");s(this,"unitCode","HUR");s(this,"visible",!1);s(this,"libsUtil",M)}async open(r,i,o,l,n,c){this.customTitle=l,this.giver=r,this.prompt=n||"",this.receiver=i,this.amountInput="0",this.callbackOnSuccess=c,this.offerId=o||"";try{const d=await j();this.apiServer=d.apiServer||"",this.activeDid=d.activeDid||"",this.allContacts=await P.contacts.toArray(),this.allMyDids=await V(),this.giver&&!this.giver.name&&(this.giver.name=N(this.giver.did,this.activeDid,this.allMyDids,this.allContacts))}catch(d){console.error("Error retrieving settings from database:",d),this.$notify({group:"alert",type:"danger",title:"Error",text:d.message||"There was an error retrieving your settings."},-1)}this.visible=!0}close(){this.visible=!1}changeUnitCode(){const r=Object.keys(this.libsUtil.UNIT_SHORT),i=r.indexOf(this.unitCode);this.unitCode=r[(i+1)%r.length]}increment(){this.amountInput=`${(parseFloat(this.amountInput)||0)+1}`}decrement(){this.amountInput=`${Math.max(0,(parseFloat(this.amountInput)||1)-1)}`}cancel(){this.close(),this.eraseValues()}eraseValues(){this.description="",this.giver=void 0,this.amountInput="0",this.prompt="",this.unitCode="HUR"}async confirm(){var r,i;if(!this.activeDid){this.$notify({group:"alert",type:"danger",title:"Error",text:"You must select an identifier before you can record a give."},3e3);return}if(parseFloat(this.amountInput)<0){this.$notify({group:"alert",type:"danger",text:"You may not send a negative number.",title:""},2e3);return}if(!this.description&&!parseFloat(this.amountInput)){this.$notify({group:"alert",type:"danger",title:"Error",text:`You must enter a description or some number of ${this.libsUtil.UNIT_LONG[this.unitCode]}.`},2e3);return}this.close(),this.$notify({group:"alert",type:"toast",text:"Recording the give...",title:""},1e3),await this.recordGive(((r=this.giver)==null?void 0:r.did)||null,((i=this.receiver)==null?void 0:i.did)||null,this.description,parseFloat(this.amountInput),this.unitCode).then(()=>{this.eraseValues()})}async recordGive(r,i,o,l,n="HUR"){var c,d,g;try{const u=await A(this.axios,this.apiServer,this.activeDid,r,i,o,l,n,this.toProjectId,this.offerId,this.isTrade,void 0,this.fromProjectId);if(u.type==="error"||this.isGiveCreationError(u.response)){const h=this.getGiveCreationErrorMessage(u);console.error("Error with give creation result:",u),this.$notify({group:"alert",type:"danger",title:"Error",text:h||"There was an error creating the give."},-1)}else this.$notify({group:"alert",type:"success",title:"Success",text:`That ${this.isTrade?"trade":"gift"} was recorded.`},7e3),this.callbackOnSuccess&&this.callbackOnSuccess(l)}catch(u){console.error("Error with give recordation caught:",u);const h=u.userMessage||((g=(d=(c=u.response)==null?void 0:c.data)==null?void 0:d.error)==null?void 0:g.message)||"There was an error recording the give.";this.$notify({group:"alert",type:"danger",title:"Error",text:h},-1)}}isGiveCreationError(r){var i;return r.status!==201||((i=r.data)==null?void 0:i.error)}getGiveCreationErrorMessage(r){var i,o,l,n,c;return((i=r.error)==null?void 0:i.userMessage)||((o=r.error)==null?void 0:o.error)||((c=(n=(l=r.response)==null?void 0:l.data)==null?void 0:n.error)==null?void 0:c.message)}explainData(){this.$notify({group:"alert",type:"success",title:"Data Sharing",text:R},-1)}};v([$],f.prototype,"fromProjectId",2);v([$],f.prototype,"toProjectId",2);f=v([S],f);const Y={key:0,class:"dialog-overlay"},B={class:"dialog"},q={class:"text-xl font-bold text-center mb-4"},L=["placeholder"],W={class:"flex flex-row justify-center"},z={class:"mt-4 flex justify-center"},J={class:"text-center mb-2 mt-6 italic"},K={class:"grid grid-cols-1 sm:grid-cols-2 gap-2"};function Q(e,t,r,i,o,l){var d,g,u,h;const n=b("fa"),c=b("router-link");return e.visible?(E(),U("div",Y,[a("div",B,[a("h1",q,y(e.customTitle),1),I(a("input",{type:"text",class:"block w-full rounded border border-slate-400 mb-2 px-3 py-2",placeholder:e.prompt||"What was given?","onUpdate:modelValue":t[0]||(t[0]=p=>e.description=p)},null,8,L),[[C,e.description]]),a("div",W,[a("span",{class:"rounded-l border border-r-0 border-slate-400 bg-slate-200 text-center text-blue-500 px-2 py-2 w-20",onClick:t[1]||(t[1]=p=>e.changeUnitCode())},y(e.libsUtil.UNIT_SHORT[e.unitCode]||e.unitCode),1),a("div",{class:"border border-r-0 border-slate-400 bg-slate-200 px-4 py-2",onClick:t[2]||(t[2]=p=>e.amountInput==="0"?null:e.decrement())},[m(n,{icon:"chevron-left"})]),I(a("input",{id:"inputGivenAmount",type:"number",class:"border border-r-0 border-slate-400 px-2 py-2 text-center w-20","onUpdate:modelValue":t[3]||(t[3]=p=>e.amountInput=p)},null,512),[[C,e.amountInput]]),a("div",{class:"rounded-r border border-slate-400 bg-slate-200 px-4 py-2",onClick:t[4]||(t[4]=p=>e.increment())},[m(n,{icon:"chevron-right"})])]),a("div",z,[a("span",null,[m(c,{to:{name:"gifted-details",query:{amountInput:e.amountInput,description:e.description,giverDid:(d=e.giver)==null?void 0:d.did,giverName:(g=e.giver)==null?void 0:g.name,offerId:e.offerId,fulfillsProjectId:e.toProjectId,providerProjectId:e.fromProjectId,recipientDid:(u=e.receiver)==null?void 0:u.did,recipientName:(h=e.receiver)==null?void 0:h.name,unitCode:e.unitCode}},class:"text-blue-500"},{default:G(()=>t[8]||(t[8]=[w(" Photo & more options ... ")])),_:1},8,["to"])])]),a("p",J,[t[9]||(t[9]=w(" Sign & Send to publish to the world ")),m(n,{icon:"circle-info",class:"pl-2 text-blue-500 cursor-pointer",onClick:t[5]||(t[5]=p=>e.explainData())})]),a("div",K,[a("button",{class:"block w-full text-center text-lg font-bold uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md",onClick:t[6]||(t[6]=(...p)=>e.confirm&&e.confirm(...p))}," Sign & Send "),a("button",{class:"block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md",onClick:t[7]||(t[7]=(...p)=>e.cancel&&e.cancel(...p))}," Cancel ")])])])):O("",!0)}const te=k(f,[["render",Q]]);export{te as G};
|
|
|