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
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)==n