edge-currency-accountbased 4.40.0 → 4.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[9415],{62351:function(Te,X,D){"use strict";D.d(X,{Nn:function(){return f},Nt:function(){return I},fi:function(){return y},zp:function(){return te}});var R=D(14171),ee=D(44276),w=(b,x,O)=>new Promise((L,J)=>{var d=q=>{try{V(O.next(q))}catch(U){J(U)}},H=q=>{try{V(O.throw(q))}catch(U){J(U)}},V=q=>q.done?L(q.value):Promise.resolve(q.value).then(d,H);V((O=O.apply(b,x)).next())});const ce=["https://info1.edge.app","https://info2.edge.app"];function N(b,x,O){return w(this,arguments,function*(L,J,d,H=5e3,V=fetch){const q=L.map(U=>()=>w(this,null,function*(){const ne=yield V(U+"/"+J,d);if(typeof ne!="object"){const se=`Invalid return value ${J} in ${U}`;throw console.log(se),new Error(se)}return ne}));return yield(0,R.NN)(q,H)})}function te(b,x,O,L,J=5e3,d){return w(this,null,function*(){const H=yield N((0,ee.R3)(x),O,L,J,d);if(!H.ok){const U=yield H.text();throw console.error(U),new Error(`Error fetching ${O}: ${U}`)}const V=yield H.json();return b(V)})}function F(b,x,O,L=5e3,J){return w(this,null,function*(){return yield N((0,ee.R3)(b),x,O,L,J)})}const f=(b,x,O,L)=>w(void 0,null,function*(){return yield F(ce,b,x,O,L)}),I=b=>Object.keys(b).map(x=>{const O=b[x];return O==null?x:`${x}=${encodeURIComponent(O)}`}).join("&"),y=(b,x=5e3)=>b+Math.random()*x*2-x},97734:function(Te,X,D){"use strict";D.r(X),D.d(X,{FioTools:function(){return Pe},checkAddress:function(){return he},makeCurrencyEngine:function(){return Le},makeCurrencyTools:function(){return Ze},updateInfoPayload:function(){return Qe}});var R=D(67190),ee=D(57458),w=D(66001),ce=D(90749),N=D(14171),te=D(96542),F=D(44276),f=D(99553),I=D(27980),y=D(54567),b=D(70531),x=D(75753),O=D(23857),L=D(25568),J=D.n(L),d=D(42704),H=D(82671),V=D(26277),q=D(62351);const U=(0,d.eB)({fio_addresses:(0,d._j)((0,d.eB)({fio_address:d.oJ,remaining_bundled_tx:d.i}))}),ne=(0,d.eB)({fio_domains:(0,d._j)((0,d.eB)({fio_domain:d.oJ,expiration:d.oJ,is_public:d.i}))}),se=(0,d.HS)((0,d.E8)("unstakefio","stakefio","transfer","regaddress","trnsfiopubky"),null),pe=(0,d.eB)({account_action_seq:d.i,block_num:d.i,block_time:d.oJ,action_trace:(0,d.eB)({receiver:d.oJ,act:(0,d.eB)({account:d.oJ,name:se,authorization:(0,d._j)((0,d.eB)({actor:d.oJ,permission:d.oJ})),data:(0,d.eB)({payee_public_key:(0,d.H7)(d.oJ),amount:(0,d.H7)(d.i),max_fee:(0,d.H7)(d.i),actor:(0,d.H7)(d.oJ),tpid:(0,d.H7)(d.oJ),quantity:(0,d.H7)(d.oJ),memo:(0,d.H7)(d.oJ),to:(0,d.H7)(d.oJ),from:(0,d.H7)(d.oJ)}),hex_data:d.oJ}),trx_id:d.oJ,block_num:d.i,block_time:d.oJ,producer_block_id:d.oJ})}),Ee=(0,d.eB)({actions:(0,d._j)(pe)}),ge=(0,d.eB)({balance:d.i,available:d.i,staked:d.i,srps:d.i,roe:d.oJ});var Re=Object.defineProperty,xe=Object.defineProperties,Ce=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertySymbols,Oe=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,Ke=Reflect.get,we=(u,e,t)=>e in u?Re(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t,S=(u,e)=>{for(var t in e||(e={}))be.call(e,t)&&we(u,t,e[t]);if(oe)for(var t of oe(e))_e.call(e,t)&&we(u,t,e[t]);return u},W=(u,e)=>xe(u,Ce(e)),Ne=(u,e)=>{var t={};for(var n in u)be.call(u,n)&&e.indexOf(n)<0&&(t[n]=u[n]);if(u!=null&&oe)for(var n of oe(u))e.indexOf(n)<0&&_e.call(u,n)&&(t[n]=u[n]);return t},ve=(u,e,t)=>Ke(Oe(u),t,e),k=(u,e,t)=>new Promise((n,s)=>{var i=r=>{try{l(t.next(r))}catch(o){s(o)}},a=r=>{try{l(t.throw(r))}catch(o){s(o)}},l=r=>r.done?n(r.value):Promise.resolve(r.value).then(i,a);l((t=t.apply(u,e)).next())});const qe=(0,q.fi)(2e4),Be=(0,q.fi)(2e4),$e=(0,q.fi)(2e4),je=(0,q.fi)(2e4);class ie extends V.k{constructor(e,t,n,s,i){super(e,t,n,s),this.defaultGetEncryptKey=a=>k(this,null,function*(){return{encrypt_public_key:this.walletInfo.keys.publicKey}}),this.fioRequestsListChanged=(a,l)=>{function r(o,c){for(const h of o)if(c.findIndex(_=>_.fio_request_id===h.fio_request_id)<0)return!0;return!1}return!!(r(a,l)||r(l,a))},this.removeFioRequest=(a,l)=>{const r=this.otherData.fioRequests[l].findIndex(o=>o.fio_request_id===`${a}`);r>-1&&this.otherData.fioRequests[l].splice(r,1)},this.fetchCors=(0,F.CY)(e.io),this.tpid=i,this.networkInfo=e.networkInfo,this.refBlock={expiration:"",ref_block_num:0,ref_block_prefix:0},this.fees=new Map,this.actor=R.TQ.accountHash(this.walletInfo.keys.publicKey).accountnm,this.otherMethods={fioAction:(a,l)=>k(this,null,function*(){return yield this.multicastServers(a,l)}),fetchFioAddresses:()=>k(this,null,function*(){return yield this.refreshFioAddresses(),this.otherData.fioAddresses}),fetchFioDomains:()=>k(this,null,function*(){return yield this.refreshFioDomains(),this.otherData.fioDomains}),getFioAddresses:()=>k(this,null,function*(){return this.otherData.fioAddresses}),getFioAddressNames:()=>k(this,null,function*(){return this.otherData.fioAddresses.map(a=>a.name)}),getFioDomains:()=>k(this,null,function*(){return this.otherData.fioDomains}),getFioRequests:(a,l,r=50)=>k(this,null,function*(){const o=r*(l-1),c=r*l;return this.otherData.fioRequests[a].sort((h,_)=>h.time_stamp<_.time_stamp?1:-1).slice(o,c)})},this.otherMethodsWithKeys={fetchObtData:(a,...l)=>k(this,null,function*(){const r=new R.TQ(a.fioKey,this.walletInfo.keys.publicKey,this.networkInfo.historyNodeUrls,this.fetchCors),o=100;let c=o,h=1;const _=[];for(;c===o;){let v;try{v=yield r.getObtData({limit:o,offset:(h-1)*o,includeEncrypted:!0});const g=(0,y.JC)(v),{obt_data_records:K,more:m}=g;if(_.push(...K),m===0)break;h++,c=K.length}catch(g){const K=(0,d.HS)(y.Dr)(g.json);(K==null?void 0:K.message)!=="No FIO Requests"&&this.error("fetchDecryptedObtData error: ",g);break}}return _})}}localDataDirty(){this.walletLocalDataDirty=!0}setOtherData(e){this.otherData=(0,f.s0)(e)}checkBlockchainInnerLoop(){return k(this,null,function*(){try{const e=yield this.multicastServers("getChainInfo"),t=e.head_block_num;this.walletLocalData.blockHeight!==t&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=t,this.localDataDirty(),this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const n=yield this.multicastServers("getBlock",e),s=new Date(`${e.head_block_time}Z`);s.setSeconds(s.getSeconds()+180);const i=s.toISOString();this.refBlock={expiration:i.substring(0,i.length-1),ref_block_num:n.block_num&65535,ref_block_prefix:n.ref_block_prefix}}catch(e){this.error("checkBlockchainInnerLoop Error fetching height: ",e)}})}getBalance(e){return super.getBalance(e)}doInitialBalanceCallback(){super.doInitialBalanceCallback();try{this.currencyEngineCallbacks.onStakingStatusChanged(S({},this.otherData.stakingStatus))}catch(e){this.error("doInitialBalanceCallback onStakingStatusChanged",e)}}updateStakingStatus(e){if(this.otherData.stakingStatus.stakedAmounts[0]={nativeAmount:this.otherData.lockedBalances.locked,unlockDate:void 0,otherParams:{type:"LOCKED"}},this.otherData.stakingStatus.stakedAmounts[1]={nativeAmount:this.otherData.lockedBalances.staked,unlockDate:void 0,otherParams:{type:"STAKED"}},e!=null){const{nativeAmount:t,blockTime:n,txId:s,txName:i}=e,a=Ae(new Date(De(n))),l=this.otherData.stakingStatus.stakedAmounts.findIndex(r=>{var o;return((o=r.unlockDate)==null?void 0:o.getTime())===a.getTime()});if(l<0){const r=this.otherData.stakingStatus.stakedAmounts.findIndex(c=>{var h,_;return a.getTime()>=((_=(h=c.unlockDate)==null?void 0:h.getTime())!=null?_:1/0)}),o=r<0?this.otherData.stakingStatus.stakedAmounts.length:r;this.otherData.stakingStatus.stakedAmounts.splice(o,0,{nativeAmount:t,unlockDate:a,otherParams:{date:new Date(n),txs:[{txId:s,nativeAmount:t,blockTime:n,txName:i}]}})}else{const r=W(S({},this.otherData.stakingStatus.stakedAmounts[l]),{nativeAmount:"0"}),o=r.otherParams.txs.findIndex(({txId:c,txName:h})=>c===s&&h===i);o<0?r.otherParams.txs.push({txId:s,nativeAmount:t,blockTime:n,txName:i}):r.otherParams.txs[o]={txId:s,nativeAmount:t,blockTime:n,txName:i};for(const c of r.otherParams.txs)r.nativeAmount=(0,w.add)(r.nativeAmount,c.nativeAmount);this.otherData.stakingStatus.stakedAmounts[l]=r}}this.localDataDirty();try{this.currencyEngineCallbacks.onStakingStatusChanged(S({},this.otherData.stakingStatus))}catch{this.error("onStakingStatusChanged error")}}getStakingStatus(){return k(this,null,function*(){return S({},this.otherData.stakingStatus)})}processTransaction(e,t,n=this.currencyInfo.currencyCode){const s=(0,F._r)(n,this.currencyInfo,this.allTokensMap);if(s==null)return this.error(`Received unsupported currencyCode: ${n}`),0;const{blockNum:i,transaction:a,updateStakingStatus:l}=Je({action:e,actor:t,currencyCode:n,denom:s,highestTxHeight:this.otherData.highestTxHeight,publicKey:this.walletInfo.keys.publicKey,walletId:this.walletId,findTransaction:(r,o)=>this.findTransaction(r,o),getTransactionList:r=>this.transactionList[r]});return l!=null&&this.updateStakingStatus(l),a!=null&&this.addTransaction(n,a),i}getSortedHistoryNodesLastActionSeqNumbers(){return k(this,null,function*(){const e=this.networkInfo.historyNodeUrls.map((n,s)=>k(this,null,function*(){var i;try{const a=yield this.requestHistory(s,{account_name:this.actor,pos:-1},f.m6.getActions);return((i=a==null?void 0:a.error)==null?void 0:i.noNodeForIndex)!=null?{nodeIndex:s,seqNumber:-1}:(Ee(a),a.actions.length===0?{nodeIndex:s,seqNumber:-1}:{nodeIndex:s,seqNumber:a.actions[a.actions.length-1].account_action_seq})}catch{return{nodeIndex:s,seqNumber:-1}}})),t=yield Promise.all(e);return t.sort((n,s)=>s.seqNumber-n.seqNumber),t})}checkTransactions(e){return k(this,null,function*(){var t,n;if((e==null?void 0:e.length)===0)return!1;if(e=e!=null?e:yield this.getSortedHistoryNodesLastActionSeqNumbers(),e.reduce((o,c)=>o+c.seqNumber,0)===-e.length)return!0;let s=this.otherData.highestTxHeight;const i=e[0].seqNumber,a=e[0].nodeIndex;let l=Math.max(0,i-f.y$+1),r=!1;for(;!r;){let o;try{if(o=yield this.requestHistory(a,{account_name:this.actor,pos:l,offset:f.y$-1},f.m6.getActions),((t=o.error)==null?void 0:t.noNodeForIndex)!=null)return!1;let c=[];if(((n=o.actions)==null?void 0:n.length)>0)c=o.actions;else break;for(let h=c.length-1;h>-1;h--){const _=pe(c[h]),v=this.processTransaction(_,this.actor);if(v>s)s=v;else if(v===s&&h===f.y$-1||v<this.otherData.highestTxHeight){r=!0;break}}if(l===0)break;l=Math.max(0,l-f.y$);continue}catch{return yield this.checkTransactions(e.slice(1))}}return s>this.otherData.highestTxHeight&&(this.otherData.highestTxHeight=s,this.localDataDirty()),!0})}checkTransactionsInnerLoop(){return k(this,null,function*(){let e;try{e=yield this.checkTransactions()}catch(t){this.error("checkTransactionsInnerLoop fetches failed with error: ",t);return}e&&(this.tokenCheckTransactionsStatus.FIO=1,this.updateOnAddressesChecked()),this.updateTransactionEvents()})}requestHistory(e,t,n){return k(this,null,function*(){if(this.networkInfo.historyNodeUrls[e]==null)return{error:{noNodeForIndex:!0}};const s=this.networkInfo.historyNodeUrls[e],i=JSON.stringify(t);return yield(yield fetch(`${s}history/${n}`,{method:"POST",headers:{"Content-Length":(i.length*2).toString(),Accept:"application/json","Content-Type":"application/json"},body:i})).json()})}fioApiRequest(e,t,n,s=!1){return k(this,null,function*(){var i,a,l,r;const o=new R.TQ("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,s);let c;try{switch(t){case"getChainInfo":c=yield o.transactions.getChainInfo();break;case"getBlock":c=yield o.transactions.getBlock(n);break;case"getObtData":case"getPendingFioRequests":case"getSentFioRequests":{const{endpoint:h,body:_}=n;c=yield o.transactions.executeCall({baseUrl:e,endPoint:h,body:JSON.stringify(_),signal:new(J())().signal});break}case"getCurrencyBalance":{c=yield(yield this.fetchCors(`${e}chain/get_currency_balance`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(n)})).json();break}default:c=yield o.genericAction(t,n)}}catch(h){if(h.errorCode!=null&&I.RF.includes(h.errorCode))((l=(a=(i=h.json)==null?void 0:i.fields)==null?void 0:a[0])==null?void 0:l.error)!=null&&(h.message=h.json.fields[0].error),c={isError:!0,data:{code:h.errorCode,message:(r=h.message)!=null?r:(0,F.Jo)(h),json:h.json,list:h.list}},h.errorCode!==404&&this.log(`fioApiRequest error. actionName: ${t} - apiUrl: ${e} - message: ${JSON.stringify(h.json)}`);else throw this.log(`fioApiRequest error. actionName: ${t} - apiUrl: ${e} - message: `,h),h}return c})}executePreparedTrx(e,t,n){return k(this,null,function*(){var s,i,a;const l=new R.TQ("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,!0);let r;this.warn(`executePreparedTrx. preparedTrx: ${JSON.stringify(n)} - apiUrl: ${e}`);try{r=yield l.executePreparedTrx(t,n),this.warn(`executePreparedTrx. res: ${JSON.stringify(r)} - apiUrl: ${e} - endpoint: ${t}`)}catch(o){throw o.errorCode!=null&&I.RF.includes(o.errorCode)?(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(n)} - apiUrl: ${e} - endpoint: ${t} - message: ${JSON.stringify(o.json)}`),((a=(i=(s=o.json)==null?void 0:s.fields)==null?void 0:i[0])==null?void 0:a.error)!=null&&(o.message=o.json.fields[0].error),o):(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(n)} - apiUrl: ${e} - endpoint: ${t} - message: `,o),o)}return r})}multicastServers(e,t){return k(this,null,function*(){var n,s,i,a,l,r;let o;if(f.iu[e]){const c=(0,y.VM)(t);if(this.warn(`multicastServers executePreparedTrx. actionName: ${e} - res: ${JSON.stringify(c)}`),o=yield(0,N.tQ)((0,N.QR)((0,F.R3)(this.networkInfo.apiUrls.map(h=>k(this,null,function*(){return yield(0,N.wR)(this.executePreparedTrx(h,b.EndPoint[f.Un[e]],c),1e4)})))),"Broadcast failed:"),this.warn(`multicastServers res. actionName: ${e} - res: ${JSON.stringify(o)}`),o==null)throw new Error("Service is unavailable")}else if(e==="getFioNames")o=yield(0,N.rn)(this.networkInfo.apiUrls.map(c=>k(this,null,function*(){return yield(0,N.wR)(this.fioApiRequest(c,e,t),1e4)})),c=>{const h=(0,y.lc)(f.s7)(c);return h!=null?h.data.json.message:(0,y.w7)(c)},2),((s=(n=o==null?void 0:o.data)==null?void 0:n.json)==null?void 0:s.message)===f.s7&&(o={fio_domains:[],fio_addresses:[]});else if(e==="getCurrencyBalance"){o=yield(0,N.rn)(this.networkInfo.apiUrls.map(v=>k(this,null,function*(){return yield(0,N.wR)(this.fioApiRequest(v,"getCurrencyBalance",{code:"fio.token",account:this.actor,symbol:"FIO"}),1e4)})),v=>JSON.stringify(v),2),((a=(i=o==null?void 0:o.data)==null?void 0:i.json)==null?void 0:a.message)===f.J2&&(o={balance:0,available:0,staked:0,srps:0,roe:""});const h=(0,d.VA)(d.oJ)(o)[0].split(" ")[0],_=(0,w.mul)(h,(l=this.currencyInfo.denominations[0].multiplier)!=null?l:"1000000000");o={balance:parseInt(_),available:0,staked:0,srps:0,roe:"0"}}else e==="getFioBalance"?o=yield(0,N.rn)(this.networkInfo.apiUrls.map(c=>k(this,null,function*(){return yield(0,N.wR)(this.fioApiRequest(c,e,t),1e4)})),c=>(0,y.Rf)(c),2):e==="getFees"?o=yield(0,N.NN)((0,F.R3)(this.networkInfo.apiUrls.map(c=>()=>k(this,null,function*(){const h=new R.TQ("",this.walletInfo.keys.publicKey,c,this.fetchCors,void 0,this.tpid),{endpoint:_,param:v}=t,g=yield h.getFee(_,v);return(0,y.LM)(g).fee.toString()})))):o=yield(0,N.NN)((0,F.R3)(this.networkInfo.apiUrls.map(c=>()=>k(this,null,function*(){return yield this.fioApiRequest(c,e,t)}))));if(o.isError!=null){const c=new I.PZ((r=o.errorMessage)!=null?r:o.data.message);throw c.json=o.data.json,c.list=o.data.list,c.errorCode=o.data.code,c}return o})}refreshFioAddresses(){return k(this,null,function*(){const e=U(yield this.multicastServers("getFioAddresses",{fioPublicKey:this.walletInfo.keys.publicKey}));let t=!1;if(e.fio_addresses.length!==this.otherData.fioAddresses.length)t=!0;else{for(const n of e.fio_addresses){const s=this.otherData.fioAddresses.find(i=>i.name===n.fio_address);if(s!=null){if(s.bundledTxs!==n.remaining_bundled_tx){t=!0;break}}else{t=!0;break}}if(!t){for(const n of this.otherData.fioAddresses)if(e.fio_addresses.findIndex(s=>s.fio_address===n.name)<0){t=!0;break}}}return t?(this.otherData.fioAddresses=e.fio_addresses.map(n=>({name:n.fio_address,bundledTxs:n.remaining_bundled_tx})),!0):!1})}refreshFioDomains(){return k(this,null,function*(){const e=ne(yield this.multicastServers("getFioDomains",{fioPublicKey:this.walletInfo.keys.publicKey}));let t=!1;if(e.fio_domains.length!==this.otherData.fioDomains.length)t=!0;else{for(const n of e.fio_domains){const s=this.otherData.fioDomains.find(i=>i.name===n.fio_domain);if(s!=null){if(s.expiration!==n.expiration){t=!0;break}if(s.isPublic!==(n.is_public===1)){t=!0;break}}else{t=!0;break}}if(!t){for(const n of this.otherData.fioDomains)if(e.fio_domains.findIndex(s=>s.fio_domain===n.name)<0){t=!0;break}}}return t?(this.otherData.fioDomains=e.fio_domains.map(n=>({name:n.fio_domain,expiration:n.expiration,isPublic:n.is_public===1})),!0):!1})}checkAccountInnerLoop(){return k(this,null,function*(){var e,t;const n=this.currencyInfo.currencyCode;typeof this.walletLocalData.totalBalances[n]>"u"&&this.updateBalance(n,"0");try{const a={staked:"0",locked:"0"};let l;try{l=ge(yield this.multicastServers("getFioBalance"))}catch(g){if(((e=g==null?void 0:g.json)==null?void 0:e.message)===f.XR)l=ge(yield this.multicastServers("getCurrencyBalance")),this.log.warn("Returning FIO balance only due to chain bug");else if(((t=g==null?void 0:g.json)==null?void 0:t.message)===f.J2)l={balance:0,available:0,staked:0,srps:0,roe:""};else throw g}const{balance:r,available:o,staked:c,srps:h,roe:_}=l,v=String(r);a.staked=String(c),a.locked=(0,w.sub)(v,String(o)),this.otherData.srps=h,this.otherData.stakingRoe=_,this.updateBalance(n,v),(a.staked!==this.otherData.lockedBalances.staked||a.locked!==this.otherData.lockedBalances.locked)&&(this.otherData.lockedBalances=a,this.localDataDirty(),this.updateStakingStatus())}catch(a){this.log.warn("checkAccountInnerLoop getFioBalance error: ",String(a))}const s=yield this.refreshFioAddresses().catch(a=>console.warn("checkAccountInnerLoop getFioAddresses error:",String(a))),i=yield this.refreshFioDomains().catch(a=>console.warn("checkAccountInnerLoop getFioDomains error:",String(a)));(s===!0||i===!0)&&this.localDataDirty()})}fetchEncryptedFioRequests(e,t){return k(this,null,function*(){const s=e==="PENDING"?"getPendingFioRequests":"getSentFioRequests";let i=100,a=1;const l=[];for(;i===100;)try{const r=yield this.multicastServers(s,{endpoint:t.getEndPoint(),body:{fio_public_key:this.walletInfo.keys.publicKey,limit:100,offset:(a-1)*100}}),o=(0,y.g2)(r),{requests:c,more:h}=o;if(l.push(...c),h===0)break;a++,i=c.length}catch(r){const o=(0,d.HS)(y.Dr)(r.json);(o==null?void 0:o.message)!=="No FIO Requests"&&this.error("fetchEncryptedFioRequests error: ",r);break}return l})}syncNetwork(e){return k(this,null,function*(){const t=(0,y._g)(e==null?void 0:e.privateKeys);let n=!1;const s=(i,a)=>k(this,null,function*(){var l;const r=yield this.fetchEncryptedFioRequests(i,a);a.privateKey=t.fioKey,a.publicKey=this.walletInfo.keys.publicKey;const o=(l=yield a.decrypt({requests:r}))!=null?l:{requests:[]},{requests:c}=o;this.fioRequestsListChanged(this.otherData.fioRequests[i],c)&&(this.otherData.fioRequests[i]=[...c],n=!0)});return yield s("PENDING",new x.PendingFioRequests({fioPublicKey:this.walletInfo.keys.publicKey,getEncryptKey:this.defaultGetEncryptKey})),yield s("SENT",new x.SentFioRequests({fioPublicKey:this.walletInfo.keys.publicKey,getEncryptKey:this.defaultGetEncryptKey})),n&&this.localDataDirty(),je})}getFee(e,t){return k(this,null,function*(){let n=this.fees.get(e);if(n==null||n.expiration+30*1e3<Date.now()){const i={fee:yield this.multicastServers("getFees",{endpoint:e,param:t}),expiration:Date.now()};this.fees.set(e,i),n=i}return n.fee})}startEngine(){return k(this,null,function*(){this.addToLoop("checkBlockchainInnerLoop",Be),this.addToLoop("checkAccountInnerLoop",qe),this.addToLoop("checkTransactionsInnerLoop",$e),yield ve(ie.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return k(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(e){return k(this,null,function*(){const{tokenId:t}=e,n=this.getBalance({tokenId:t}),s=this.otherData.lockedBalances.locked;e.spendTargets[0].nativeAmount="1";const i=yield this.makeSpend(e),a=(0,w.sub)((0,w.sub)(n,i.networkFee),s);if((0,w.lt)(a,"0"))throw new H.k5({networkFee:i.networkFee,tokenId:t});return a})}makeSpend(e){return k(this,null,function*(){const{edgeSpendInfo:t,nativeBalance:n,currencyCode:s}=this.makeSpendCheck(e),{memos:i=[],tokenId:a}=t,l=this.otherData.lockedBalances.locked,r=(0,w.sub)(n,l),o=t.spendTargets[0],{publicAddress:c}=o,{nativeAmount:h}=o;if(c==null)throw new Error("makeSpend Missing publicAddress");if(h==null)throw new H.ef;let{otherParams:_}=t;(_==null||Object.keys(_).length===0)&&(_={action:{name:f.kl.transferTokens,params:{payeeFioPublicKey:c,amount:h,maxFee:0}}});const{name:v,params:g}=(0,y.Vf)(_.action);let K=h,m,A;switch(v){case f.kl.transferTokens:{m=yield this.getFee(b.EndPoint.transferTokens),A={account:"fio.token",action:f.i7[f.kl.transferTokens],data:{payee_public_key:c,amount:h,max_fee:m}};break}case f.kl.stakeFioTokens:{const{fioAddress:p}=(0,y.ie)(g);K="0",m=yield this.getFee(b.EndPoint.stakeFioTokens,p),A={account:"fio.staking",action:f.i7[v],data:{amount:h,fio_address:p,actor:this.actor,max_fee:m}};break}case f.kl.unStakeFioTokens:{const{fioAddress:p}=(0,y.ie)(g);K="0",m=yield this.getFee(b.EndPoint.unStakeFioTokens,p),A={account:"fio.staking",action:f.i7[v],data:{amount:h,fio_address:p,actor:this.actor,max_fee:m}};const P=Ae(new Date),G=this.otherData.lockedBalances.staked;if((0,w.gt)(h,G)||(0,w.gt)(`${m}`,r))throw new H.k5({tokenId:a});const Z=(0,w.mul)((0,w.mul)((0,w.div)(h,G,18),`${this.otherData.srps}`),this.otherData.stakingRoe),M=(0,w.max)((0,w.sub)(Z,h),"0");_.ui={accrued:Z,estReward:M,unlockDate:P};break}case f.kl.transferFioAddress:{const{fioAddress:p}=(0,y.ie)(g);m=yield this.getFee(b.EndPoint.transferFioAddress,p),A={account:"fio.address",action:"xferaddress",data:{fio_address:p,new_owner_fio_public_key:c,actor:this.actor,max_fee:m}};break}case f.kl.transferFioDomain:{const{fioDomain:p}=(0,y.qC)(g);m=yield this.getFee(b.EndPoint.transferFioDomain),A={account:"fio.address",action:"xferdomain",data:{fio_domain:p,new_owner_fio_public_key:c,actor:this.actor,max_fee:m}};break}case f.kl.addPublicAddresses:{const{fioAddress:p,publicAddresses:P}=(0,y.TV)(g);m=yield this.getFee(b.EndPoint.addPubAddress,p),A={account:"fio.address",action:"addaddress",data:{fio_address:p,public_addresses:P,actor:this.actor,max_fee:m}};break}case f.kl.removePublicAddresses:{const{fioAddress:p,publicAddresses:P}=(0,y.TV)(g);m=yield this.getFee(b.EndPoint.removePubAddress,p),A={account:"fio.address",action:"remaddress",data:{fio_address:p,public_addresses:P,actor:this.actor,max_fee:m}};break}case f.kl.registerFioAddress:{const{fioAddress:p}=(0,y.ie)(g);m=yield this.getFee(b.EndPoint.registerFioAddress),A={account:"fio.address",action:"regaddress",data:{fio_address:p,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:m,actor:this.actor}};break}case f.kl.registerFioDomain:{const{fioDomain:p}=(0,y.q$)(g);m=yield this.getFee(b.EndPoint.registerFioDomain),A={account:"fio.address",action:"regdomain",data:{fio_domain:p,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:m,actor:this.actor}};break}case f.kl.renewFioDomain:{const{fioDomain:p}=(0,y.q$)(g);m=yield this.getFee(b.EndPoint.renewFioDomain),A={account:"fio.address",action:"renewdomain",data:{fio_domain:p,max_fee:m,actor:this.actor}};break}case f.kl.addBundledTransactions:{const{bundleSets:p,fioAddress:P}=(0,y.Zq)(g);m=yield this.getFee(b.EndPoint.addBundledTransactions,P),A={account:"fio.address",action:"addbundles",data:{fio_address:P,bundle_sets:p,actor:this.actor,max_fee:m}};break}case f.kl.setFioDomainPublic:{const{fioDomain:p,isPublic:P}=(0,y.Vj)(g);m=yield this.getFee(b.EndPoint.setFioDomainPublic),A={account:"fio.address",action:"setdomainpub",data:{fio_domain:p,is_public:P?1:0,max_fee:m,actor:this.actor}};break}case f.kl.rejectFundsRequest:{const{fioRequestId:p,payerFioAddress:P}=(0,y.f4)(g);m=yield this.getFee(b.EndPoint.rejectFundsRequest,P),A={account:"fio.reqobt",action:"rejectfndreq",data:{fio_request_id:p,max_fee:m,actor:this.actor}};break}case f.kl.cancelFundsRequest:{const{fioAddress:p,fioRequestId:P}=(0,y.K3)(g);m=yield this.getFee(b.EndPoint.cancelFundsRequest,p),A={account:"fio.reqobt",action:"cancelfndreq",data:{fio_request_id:P,max_fee:m,actor:this.actor}};break}case f.kl.recordObtData:{const{payerFioAddress:p}=(0,y.DC)(g);m=yield this.getFee(b.EndPoint.recordObtData,p);break}case f.kl.requestFunds:{const{payeeFioAddress:p}=(0,y.Wg)(g);m=yield this.getFee(b.EndPoint.newFundsRequest,p);break}default:throw new Error("Unrecognized FIO action")}return{blockHeight:0,currencyCode:s,date:0,isSend:!0,memos:i,nativeAmount:`-${(0,w.add)(K,m)}`,networkFee:`${m}`,networkFees:[],otherParams:W(S({},_),{txParams:A}),ourReceiveAddresses:[],signedTx:"",tokenId:a,txid:"",walletId:this.walletId}})}signTx(e,t){return k(this,null,function*(){const n=(0,y._g)(t),s=(0,F.Je)(e);let i=(0,d.HS)(y.zc)(s.txParams);const a=new O.Transactions;if(i==null){const{name:v,params:g}=(0,y.Vf)(s.action),{networkFee:K}=e;switch(v){case f.kl.recordObtData:{const{payerFioAddress:m,payeeFioAddress:A,payerPublicAddress:z,payeePublicAddress:p,amount:P,tokenCode:G,chainCode:Z,obtId:M,memo:B,status:Y,fioRequestId:fe}=(0,y.DC)(g),C={payer_public_address:z,payee_public_address:p,amount:P,chain_code:Z,token_code:G,status:Y,obt_id:M,memo:B,hash:void 0,offline_url:void 0},re=new R.TQ(t.fioKey,this.walletInfo.keys.publicKey,this.networkInfo.historyNodeUrls,this.fetchCors),{encrypt_public_key:$}=yield re.getEncryptKey(A),Q=a.getCipherContent("record_obt_data_content",C,n.fioKey,$);i={account:"fio.reqobt",action:"recordobt",data:{payer_fio_address:m,payee_fio_address:A,content:Q,fio_request_id:fe,max_fee:K,actor:this.actor}};break}case f.kl.requestFunds:{const{payerFioAddress:m,payerFioPublicKey:A,payeeFioAddress:z,payeeTokenPublicAddress:p,amount:P,chainCode:G,tokenCode:Z,memo:M}=(0,y.Wg)(g),B={payee_public_address:p,amount:P,chain_code:G,token_code:Z,memo:M,hash:void 0,offline_url:void 0},Y=a.getCipherContent("new_funds_content",B,n.fioKey,A);i={account:"fio.reqobt",action:"newfundsreq",data:{payer_fio_address:m,payee_fio_address:z,content:Y,max_fee:K,actor:this.actor}};break}default:throw new Error("Unknown FIO action")}}const l=yield this.getBalance({tokenId:null}),r=(0,w.lte)(l,"0")&&!this.transactionList.FIO.some(v=>(0,w.gt)(v.nativeAmount,"0"))?void 0:this.tpid,o=yield a.createRawTransaction({action:i.action,account:i.account,data:W(S({},i.data),{tpid:r}),publicKey:this.walletInfo.keys.publicKey,chainData:this.refBlock}),{serializedContextFreeData:c,serializedTransaction:h}=yield a.serialize({chainId:this.networkInfo.chainId,transaction:o}),_=yield a.sign({chainId:this.networkInfo.chainId,privateKeys:[n.fioKey],transaction:o,serializedTransaction:h,serializedContextFreeData:c});return e.otherParams=W(S({},e.otherParams),{signedTx:_}),e})}broadcastTx(e){return k(this,null,function*(){var t;const n=(0,F.Je)(e);if(((t=n.action)==null?void 0:t.name)==null)throw new Error('Action is not set, "action" prop of otherParams is required for FIO actions');const s=(0,y.VM)(n.signedTx),i=yield this.multicastServers(n.action.name,s),a=(0,y.FC)(i);e.metadata={notes:a.transaction_id},e.txid=a.transaction_id,e.date=Date.now()/1e3,e.blockHeight=a.block_num,this.warn(`SUCCESS broadcastTx
|
|
2
|
-
${(0,F.T5)(e)}`);const l=a,{block_num:r,block_time:o,transaction_id:c}=l,h=Ne(l,["block_num","block_time","transaction_id"]);return e.otherParams=W(S({},n),{broadcastResult:h}),e})}saveTx(e){return k(this,null,function*(){var t;const n=(0,F.Je)(e),{broadcastResult:s={},action:i}=n,{name:a,params:l}=(0,y.Vf)(i);try{switch(a){case f.kl.transferFioDomain:{const r=this.otherData.fioDomains.findIndex(({name:o})=>o===l.fioDomain);r>=0&&(this.otherData.fioDomains.splice(r,1),this.localDataDirty());break}case f.kl.transferFioAddress:{const r=this.otherData.fioAddresses.findIndex(({name:o})=>o===l.fioAddress);r>=0&&(this.otherData.fioAddresses.splice(r,1),this.localDataDirty());break}case f.kl.registerFioAddress:{const{fioAddress:r}=(0,y.ie)(l);this.otherData.fioAddresses.find(({name:c})=>c===r)==null&&(this.otherData.fioAddresses.push({name:r,bundledTxs:void 0}),this.localDataDirty());break}case f.kl.registerFioDomain:{const{fioDomain:r}=(0,y.q$)(l);if(s.expiration==null)throw new Error("expiration not present");const o=this.otherData.fioDomains.find(({name:c})=>c===r);o!=null&&(o.expiration=s.expiration,this.localDataDirty());break}case f.kl.renewFioDomain:{const{fioDomain:r}=(0,y.q$)(l);if(s.expiration==null)throw new Error("expiration not present");const o=this.otherData.fioDomains.find(({name:c})=>c===r);o!=null&&(o.expiration=s.expiration,this.localDataDirty());break}case f.kl.addBundledTransactions:{const{fioAddress:r}=(0,y.Zq)(l),o=this.otherData.fioAddresses.find(({name:c})=>c===r);if(o==null)throw new I.PZ("Fio Address is not found in engine");o.bundledTxs=((t=o.bundledTxs)!=null?t:0)+f.mA,this.localDataDirty();break}case f.kl.rejectFundsRequest:{const{fioRequestId:r}=(0,y.f4)(l);typeof r=="string"&&(this.removeFioRequest(r,"PENDING"),this.localDataDirty());break}case f.kl.cancelFundsRequest:{const{fioRequestId:r}=(0,y.K3)(l);typeof r=="string"&&(this.removeFioRequest(r,"SENT"),this.localDataDirty());break}case f.kl.recordObtData:{const{fioRequestId:r}=(0,y.DC)(l);r!=null&&s.status==="sent_to_blockchain"&&(this.removeFioRequest(r,"PENDING"),this.localDataDirty());break}}}catch(r){this.log.warn(`Error attempting post-broadcast action ${a}:`,r)}yield ve(ie.prototype,this,"saveTx").call(this,e)})}getFreshAddress(e){return k(this,null,function*(){return{publicAddress:this.walletInfo.keys.publicKey}})}}function Le(u,e,t,n){return k(this,null,function*(){const{tpid:s="finance@edge"}=u.initOptions,i=(0,y.Te)(t),a=new ie(u,e,i,n,s);return yield a.loadEngine(),a})}const De=u=>{const e=new Date(u);return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds())},Ae=u=>{const e=Math.floor(u.getTime()/f.JH)*f.JH;return new Date(e+f.O_)},Je=({action:u,actor:e,currencyCode:t,denom:n,highestTxHeight:s,publicKey:i,walletId:a,findTransaction:l,getTransactionList:r})=>{var o,c,h,_,v,g,K,m,A,z,p,P,G,Z;const{act:{name:M,data:B,account:Y,authorization:fe}}=u.action_trace;if(u.block_num<=s)return{blockNum:u.block_num};let C={account:Y,name:M,authorization:fe,data:B,meta:{}};const re=l(t,u.action_trace.trx_id);let $;if(re>-1&&($=r(t)[re],((c=(o=$.otherParams)==null?void 0:o.meta)==null?void 0:c.isTransferProcessed)!=null))return{blockNum:u.block_num};const Q=(_=(h=B.max_fee)==null?void 0:h.toString())!=null?_:"0",ye=(g=(v=B.amount)==null?void 0:v.toString())!=null?g:"0",We=(m=(K=B.quantity)==null?void 0:K.split(" ")[0])!=null?m:"0",me=(0,w.mul)(We,n.multiplier),Se=[];let E="0",j="0",ke,ae;switch(M){case"trnsfiopubky":if(B.payee_public_key===i)Se.push(i),B.actor===e?(E=Q,j=`-${E}`):(j=ye,E="0");else if(B.actor===e)E=Q,j=`-${(0,w.add)(ye,E)}`;else return{blockNum:u.block_num};C.meta.isTransferProcessed=!0;break;case"stakefio":{E=Q,j=`-${E}`,C.meta.isTransferProcessed=!0,ae={assetActionType:"stake"};break}case"unstakefio":ke={nativeAmount:ye,blockTime:u.block_time,txId:u.action_trace.trx_id,txName:M},E=Q,$!=null?(C=W(S(S({},$.otherParams),C),{data:S(S({},(A=$.otherParams)==null?void 0:A.data),B),meta:S(S({},(z=$.otherParams)==null?void 0:z.meta),C.meta)}),j=(0,w.sub)($.nativeAmount,E)):j=`-${E}`,C.meta.isTransferProcessed=!0,ae={assetActionType:"unstakeOrder"};break;case"regaddress":u.action_trace.act.authorization.some(le=>le.actor===e)&&(E=Q,j=`-${E}`),C.meta.isTransferProcessed=!0;break;case"transfer":{const le=C.data!=null&&C.data.memo===f.HC;if(le)ke={nativeAmount:me,blockTime:u.block_time,txId:u.action_trace.trx_id,txName:M},E="0",j=me,ae={assetActionType:"unstake"};else{const Fe=B.to===e;E=Fe?"0":me,j=Fe?"0":`-${E}`}if($!=null)if(C=W(S(S({},C),$.otherParams),{data:S(S({},C.data),(P=(p=$.otherParams)==null?void 0:p.data)!=null?P:{}),meta:S(S({},C.meta),(Z=(G=$.otherParams)==null?void 0:G.meta)!=null?Z:{}),name:le?"unstakefio":C.name}),C.meta.isTransferProcessed!=null)B.to!==e?(E=Q,j=(0,w.sub)($.nativeAmount,E)):E="0";else throw new Error("processTransaction error - existing spend transaction should have isTransferProcessed set")}break;default:return{blockNum:u.block_num}}const ze={assetAction:ae,blockHeight:u.block_num>0?u.block_num:0,currencyCode:t,date:De(u.block_time)/1e3,isSend:j.startsWith("-"),memos:[],nativeAmount:j,networkFee:E,networkFees:[],otherParams:C,ourReceiveAddresses:Se,signedTx:"",tokenId:null,txid:u.action_trace.trx_id,walletId:a};return{blockNum:u.block_num,transaction:ze,updateStakingStatus:ke}};var He=D(48287).Buffer,Ie=Object.getOwnPropertySymbols,Ue=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,Ve=(u,e)=>{var t={};for(var n in u)Ue.call(u,n)&&e.indexOf(n)<0&&(t[n]=u[n]);if(u!=null&&Ie)for(var n of Ie(u))e.indexOf(n)<0&&Me.call(u,n)&&(t[n]=u[n]);return t},T=(u,e,t)=>new Promise((n,s)=>{var i=r=>{try{l(t.next(r))}catch(o){s(o)}},a=r=>{try{l(t.throw(r))}catch(o){s(o)}},l=r=>r.done?n(r.value):Promise.resolve(r.value).then(i,a);l((t=t.apply(u,e)).next())});const de="FIO",ue="fio",Ge="";function he(u){const e=u.startsWith(de),t=u.length===53;return e&&t}class Pe{constructor(e){const{builtinTokens:t,currencyInfo:n,initOptions:s,io:i,networkInfo:a}=e;this.builtinTokens=t,this.currencyInfo=n,this.io=i,this.networkInfo=a;const{tpid:l="finance@edge",fioRegApiToken:r=Ge}=s;this.fetchCors=(0,F.CY)(e.io),this.fioRegApiToken=r,this.tpid=l;for(const o of this.networkInfo.apiUrls)new R.TQ("","",o,this.fetchCors,void 0,l)}getDisplayPrivateKey(e){return T(this,null,function*(){return(0,y._g)(e.keys).fioKey})}getDisplayPublicKey(e){return T(this,null,function*(){const{keys:t}=(0,y.Te)(e);return t.publicKey})}importPrivateKey(e){return T(this,null,function*(){const{pluginId:t}=this.currencyInfo,n={};if(/[0-9a-zA-Z]{51}$/.test(e))ee.ZD.fromString(e),n.fioKey=e;else{if(!(0,ce.validateMnemonic)(e))throw new Error("Invalid input");const i=yield R.TQ.createPrivateKeyMnemonic(e);n.fioKey=i.fioKey,n.mnemonic=i.mnemonic}const s=yield this.derivePublicKey({type:`wallet:${t}`,id:"fake",keys:n});return n.publicKey=s.publicKey,n})}createPrivateKey(e){return T(this,null,function*(){if(e.replace("wallet:","")===ue){const n=He.from(this.io.random(32));return yield R.TQ.createPrivateKey(n)}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return T(this,null,function*(){if(e.type.replace("wallet:","")===ue)return R.TQ.derivedPublicKey(e.keys.fioKey);throw new Error("InvalidWalletType")})}parseUri(e){return T(this,null,function*(){var t;const{edgeParsedUri:n}=yield(0,te.x)({currencyInfo:this.currencyInfo,uri:e,networks:{fio:!0},builtinTokens:this.builtinTokens,currencyCode:de});if(!he((t=n.publicAddress)!=null?t:""))throw new Error("InvalidPublicAddressError");return n})}encodeUri(e){return T(this,arguments,function*(t,n=[]){if(!he(t.publicAddress))throw new Error("InvalidPublicAddressError");let i;if(typeof t.nativeAmount=="string"){const l=de,r=t.nativeAmount,o=(0,F.FQ)(l,this.currencyInfo,n,this.builtinTokens);if(o==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,w.div)(r,o.multiplier,16)}return(0,te.m)(t,ue,i)})}getConnectedPublicAddress(e,t,n){return T(this,null,function*(){var s;try{R.TQ.isFioAddressValid(e)}catch{throw new I.PZ("",400,this.networkInfo.errorCodes.INVALID_FIO_ADDRESS)}try{if((yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0)throw new I.PZ("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_EXIST)}catch(i){throw i.name==="FioError"&&((s=i.json)==null?void 0:s.fields)!=null&&i.errorCode===400&&(i.labelCode=this.networkInfo.errorCodes.INVALID_FIO_ADDRESS),i}try{const i=yield this.multicastServers("getPublicAddress",{fioAddress:e,chainCode:t,tokenCode:n});if(i.public_address==null||i.public_address==="0")throw new I.PZ("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED);return i}catch(i){throw i.name==="FioError"&&i.labelCode===this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED||i.errorCode===404?new I.PZ("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED):i}})}isFioAddressValid(e){return T(this,null,function*(){try{return R.TQ.isFioAddressValid(e)}catch{return!1}})}validateAccount(e,t=!1){return T(this,null,function*(){var n;try{if(t){if(!R.TQ.isFioDomainValid(e))return!1}else if(!R.TQ.isFioAddressValid(e))return!1}catch{throw new I.PZ("",400,this.networkInfo.errorCodes.INVALID_FIO_ADDRESS)}try{return(yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0}catch(s){throw s.name==="FioError"&&((n=s.json)==null?void 0:n.fields)!=null&&s.errorCode===400&&(s.labelCode=this.networkInfo.errorCodes.INVALID_FIO_ADDRESS),s}})}isDomainPublic(e){return T(this,null,function*(){if((yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0)throw new I.PZ("",400,this.networkInfo.errorCodes.FIO_DOMAIN_IS_NOT_EXIST);const n=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${f.KV.isDomainPublic}/${e}`,{method:"GET"});if(!n.ok){const i=yield n.json();throw new I.PZ("",n.status,this.networkInfo.errorCodes.IS_DOMAIN_PUBLIC_ERROR,i)}const{isPublic:s}=yield n.json();return s})}doesAccountExist(e){return T(this,null,function*(){try{if(!R.TQ.isFioAddressValid(e))return!1}catch{return!1}try{return(yield this.multicastServers("isAvailable",{fioName:e})).is_registered===1}catch(t){return this.error("doesAccountExist error: ",t),!1}})}buyAddressRequest(e,t=!1){return T(this,null,function*(){const n={Accept:"application/json","Content-Type":"application/json"};t&&(e.apiToken=this.fioRegApiToken);try{const s=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${f.KV.buyAddress}`,{method:"POST",headers:n,body:JSON.stringify(e)});if(!s.ok){const i=yield s.json();throw this.networkInfo.errorCodes[i.errorCode]!=null?new I.PZ(i.error,s.status,this.networkInfo.errorCodes[i.errorCode],i):i.error==="Already registered"?new I.PZ(i.error,s.status,this.networkInfo.errorCodes.ALREADY_REGISTERED,i):new Error(i.error)}return yield s.json()}catch(s){throw s.labelCode!=null?s:new I.PZ((0,F.Jo)(s),500,this.networkInfo.errorCodes.SERVER_ERROR)}})}getDomains(e=""){return T(this,null,function*(){e==null&&(e=this.networkInfo.defaultRef);try{const t=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${f.KV.getDomains}/${e}`,{method:"GET"}),n=yield t.json();if(!t.ok)throw this.networkInfo.errorCodes[n.errorCode]!=null?new I.PZ(n.error,t.status,this.networkInfo.errorCodes[n.errorCode],n):new Error(n.error);return n.domains}catch(t){throw t.labelCode!=null?t:new I.PZ((0,F.Jo)(t),500,this.networkInfo.errorCodes.SERVER_ERROR)}})}getStakeEstReturn(){return T(this,null,function*(){try{const e=yield this.fetchCors(`${this.networkInfo.fioStakingApyUrl}`,{method:"GET"}),t=yield e.json();if(!e.ok)throw new Error(this.networkInfo.errorCodes.SERVER_ERROR);const n=t.historical_apr["7day"];return n!=null&&n>f.a4||n==null?f.a4:n}catch(e){throw e.labelCode!=null?e:new I.PZ(e.message,500,this.networkInfo.errorCodes.SERVER_ERROR)}})}multicastServers(e,t){return T(this,null,function*(){const n=yield(0,N.NN)((0,F.R3)(this.networkInfo.apiUrls.map(s=>()=>T(this,null,function*(){let i;const a=new R.TQ("","",s,this.fetchCors,void 0,this.tpid);try{i=yield a.genericAction(e,t)}catch(l){if(l.errorCode!=null&&I.RF.includes(l.errorCode))i={isError:!0,data:{code:l.errorCode,message:(0,F.Jo)(l),json:l.json,list:l.list}};else throw l}return i}))));if(n.isError!=null){const s=new I.PZ(n.errorMessage);throw s.json=n.data.json,s.list=n.data.list,s.errorCode=n.data.code,s}return n})}}function Ze(u){return T(this,null,function*(){return new Pe(u)})}function Qe(u,e){return T(this,null,function*(){const t=Ve(e,[]);u.networkInfo=(0,F.wy)(u.networkInfo,t)})}},73776:function(){},15340:function(){},79838:function(){}}]);
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[9415],{62351:function(Ce,X,D){"use strict";D.d(X,{Nn:function(){return h},Nt:function(){return I},fi:function(){return y},zp:function(){return te}});var E=D(14171),ee=D(44276),w=(b,x,O)=>new Promise((L,J)=>{var u=q=>{try{V(O.next(q))}catch(U){J(U)}},H=q=>{try{V(O.throw(q))}catch(U){J(U)}},V=q=>q.done?L(q.value):Promise.resolve(q.value).then(u,H);V((O=O.apply(b,x)).next())});const de=["https://info1.edge.app","https://info2.edge.app"];function N(b,x,O){return w(this,arguments,function*(L,J,u,H=5e3,V=fetch){const q=L.map(U=>()=>w(this,null,function*(){const se=yield V(U+"/"+J,u);if(typeof se!="object"){const ne=`Invalid return value ${J} in ${U}`;throw console.log(ne),new Error(ne)}return se}));return yield(0,E.NN)(q,H)})}function te(b,x,O,L,J=5e3,u){return w(this,null,function*(){const H=yield N((0,ee.R3)(x),O,L,J,u);if(!H.ok){const U=yield H.text();throw console.error(U),new Error(`Error fetching ${O}: ${U}`)}const V=yield H.json();return b(V)})}function F(b,x,O,L=5e3,J){return w(this,null,function*(){return yield N((0,ee.R3)(b),x,O,L,J)})}const h=(b,x,O,L)=>w(void 0,null,function*(){return yield F(de,b,x,O,L)}),I=b=>Object.keys(b).map(x=>{const O=b[x];return O==null?x:`${x}=${encodeURIComponent(O)}`}).join("&"),y=(b,x=5e3)=>b+Math.random()*x*2-x},97734:function(Ce,X,D){"use strict";D.r(X),D.d(X,{FioTools:function(){return Se},checkAddress:function(){return he},makeCurrencyEngine:function(){return Me},makeCurrencyTools:function(){return et},updateInfoPayload:function(){return tt}});var E=D(67190),ee=D(57458),w=D(66001),de=D(90749),N=D(14171),te=D(96542),F=D(44276),h=D(99553),I=D(27980),y=D(54567),b=D(70531),x=D(75753),O=D(23857),L=D(25568),J=D.n(L),u=D(42704),H=D(82671),V=D(26277),q=D(62351);const U=(0,u.eB)({fio_addresses:(0,u._j)((0,u.eB)({fio_address:u.oJ,remaining_bundled_tx:u.i}))}),se=(0,u.eB)({fio_domains:(0,u._j)((0,u.eB)({fio_domain:u.oJ,expiration:u.oJ,is_public:u.i}))}),ne=(0,u.HS)((0,u.E8)("unstakefio","stakefio","transfer","regaddress","trnsfiopubky"),null),ge=(0,u.eB)({account_action_seq:u.i,block_num:u.i,block_time:u.oJ,action_trace:(0,u.eB)({receiver:u.oJ,act:(0,u.eB)({account:u.oJ,name:ne,authorization:(0,u._j)((0,u.eB)({actor:u.oJ,permission:u.oJ})),data:(0,u.eB)({payee_public_key:(0,u.H7)(u.oJ),amount:(0,u.H7)(u.i),max_fee:(0,u.H7)(u.i),actor:(0,u.H7)(u.oJ),tpid:(0,u.H7)(u.oJ),quantity:(0,u.H7)(u.oJ),memo:(0,u.H7)(u.oJ),to:(0,u.H7)(u.oJ),from:(0,u.H7)(u.oJ)}),hex_data:u.oJ}),trx_id:u.oJ,block_num:u.i,block_time:u.oJ,producer_block_id:u.oJ})}),Oe=(0,u.eB)({actions:(0,u._j)(ge)}),be=(0,u.eB)({balance:u.i,available:u.i,staked:u.i,srps:u.i,roe:u.oJ});var Ke=Object.defineProperty,Ne=Object.defineProperties,qe=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertySymbols,Be=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable,je=Reflect.get,ve=(d,e,t)=>e in d?Ke(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t,T=(d,e)=>{for(var t in e||(e={}))_e.call(e,t)&&ve(d,t,e[t]);if(oe)for(var t of oe(e))we.call(e,t)&&ve(d,t,e[t]);return d},W=(d,e)=>Ne(d,qe(e)),$e=(d,e)=>{var t={};for(var s in d)_e.call(d,s)&&e.indexOf(s)<0&&(t[s]=d[s]);if(d!=null&&oe)for(var s of oe(d))e.indexOf(s)<0&&we.call(d,s)&&(t[s]=d[s]);return t},De=(d,e,t)=>je(Be(d),t,e),k=(d,e,t)=>new Promise((s,n)=>{var r=i=>{try{l(t.next(i))}catch(o){n(o)}},a=i=>{try{l(t.throw(i))}catch(o){n(o)}},l=i=>i.done?s(i.value):Promise.resolve(i.value).then(r,a);l((t=t.apply(d,e)).next())});const Le=(0,q.fi)(2e4),Je=(0,q.fi)(2e4),He=(0,q.fi)(2e4),Ue=(0,q.fi)(2e4);class re extends V.k{constructor(e,t,s,n,r){super(e,t,s,n),this.defaultGetEncryptKey=a=>k(this,null,function*(){return{encrypt_public_key:this.walletInfo.keys.publicKey}}),this.fioRequestsListChanged=(a,l)=>{function i(o,c){for(const f of o)if(c.findIndex(_=>_.fio_request_id===f.fio_request_id)<0)return!0;return!1}return!!(i(a,l)||i(l,a))},this.removeFioRequest=(a,l)=>{const i=this.otherData.fioRequests[l].findIndex(o=>o.fio_request_id===`${a}`);i>-1&&this.otherData.fioRequests[l].splice(i,1)},this.fetchCors=(0,F.CY)(e.io),this.tpid=r,this.networkInfo=e.networkInfo,this.refBlock={expiration:"",ref_block_num:0,ref_block_prefix:0},this.fees=new Map,this.actor=E.TQ.accountHash(this.walletInfo.keys.publicKey).accountnm,this.otherMethods={fioAction:(a,l)=>k(this,null,function*(){return yield this.multicastServers(a,l)}),fetchFioAddresses:()=>k(this,null,function*(){return yield this.refreshFioAddresses(),this.otherData.fioAddresses}),fetchFioDomains:()=>k(this,null,function*(){return yield this.refreshFioDomains(),this.otherData.fioDomains}),getFioAddresses:()=>k(this,null,function*(){return this.otherData.fioAddresses}),getFioAddressNames:()=>k(this,null,function*(){return this.otherData.fioAddresses.map(a=>a.name)}),getFioDomains:()=>k(this,null,function*(){return this.otherData.fioDomains}),getFioRequests:(a,l,i=50)=>k(this,null,function*(){const o=i*(l-1),c=i*l;return this.otherData.fioRequests[a].sort((f,_)=>f.time_stamp<_.time_stamp?1:-1).slice(o,c)})},this.otherMethodsWithKeys={fetchObtData:(a,...l)=>k(this,null,function*(){const i=new E.TQ(a.fioKey,this.walletInfo.keys.publicKey,this.networkInfo.historyNodeUrls,this.fetchCors),o=100;let c=o,f=1;const _=[];for(;c===o;){let v;try{v=yield i.getObtData({limit:o,offset:(f-1)*o,includeEncrypted:!0});const g=(0,y.JC)(v),{obt_data_records:K,more:m}=g;if(_.push(...K),m===0)break;f++,c=K.length}catch(g){const K=(0,u.HS)(y.Dr)(g.json);(K==null?void 0:K.message)!=="No FIO Requests"&&this.error("fetchDecryptedObtData error: ",g);break}}return _})}}localDataDirty(){this.walletLocalDataDirty=!0}setOtherData(e){this.otherData=(0,h.s0)(e)}checkBlockchainInnerLoop(){return k(this,null,function*(){try{const e=yield this.multicastServers("getChainInfo"),t=e.head_block_num;this.walletLocalData.blockHeight!==t&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=t,this.localDataDirty(),this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const s=yield this.multicastServers("getBlock",e),n=new Date(`${e.head_block_time}Z`);n.setSeconds(n.getSeconds()+180);const r=n.toISOString();this.refBlock={expiration:r.substring(0,r.length-1),ref_block_num:s.block_num&65535,ref_block_prefix:s.ref_block_prefix}}catch(e){this.error("checkBlockchainInnerLoop Error fetching height: ",e)}})}getBalance(e){return super.getBalance(e)}doInitialBalanceCallback(){super.doInitialBalanceCallback();try{this.currencyEngineCallbacks.onStakingStatusChanged(T({},this.otherData.stakingStatus))}catch(e){this.error("doInitialBalanceCallback onStakingStatusChanged",e)}}updateStakingStatus(e){if(this.otherData.stakingStatus.stakedAmounts[0]={nativeAmount:this.otherData.lockedBalances.locked,unlockDate:void 0,otherParams:{type:"LOCKED"}},this.otherData.stakingStatus.stakedAmounts[1]={nativeAmount:this.otherData.lockedBalances.staked,unlockDate:void 0,otherParams:{type:"STAKED"}},e!=null){const{nativeAmount:t,blockTime:s,txId:n,txName:r}=e,a=Ie(new Date(Ae(s))),l=this.otherData.stakingStatus.stakedAmounts.findIndex(i=>{var o;return((o=i.unlockDate)==null?void 0:o.getTime())===a.getTime()});if(l<0){const i=this.otherData.stakingStatus.stakedAmounts.findIndex(c=>{var f,_;return a.getTime()>=((_=(f=c.unlockDate)==null?void 0:f.getTime())!=null?_:1/0)}),o=i<0?this.otherData.stakingStatus.stakedAmounts.length:i;this.otherData.stakingStatus.stakedAmounts.splice(o,0,{nativeAmount:t,unlockDate:a,otherParams:{date:new Date(s),txs:[{txId:n,nativeAmount:t,blockTime:s,txName:r}]}})}else{const i=W(T({},this.otherData.stakingStatus.stakedAmounts[l]),{nativeAmount:"0"}),o=i.otherParams.txs.findIndex(({txId:c,txName:f})=>c===n&&f===r);o<0?i.otherParams.txs.push({txId:n,nativeAmount:t,blockTime:s,txName:r}):i.otherParams.txs[o]={txId:n,nativeAmount:t,blockTime:s,txName:r};for(const c of i.otherParams.txs)i.nativeAmount=(0,w.add)(i.nativeAmount,c.nativeAmount);this.otherData.stakingStatus.stakedAmounts[l]=i}}this.localDataDirty();try{this.currencyEngineCallbacks.onStakingStatusChanged(T({},this.otherData.stakingStatus))}catch{this.error("onStakingStatusChanged error")}}getStakingStatus(){return k(this,null,function*(){return T({},this.otherData.stakingStatus)})}processTransaction(e,t,s=this.currencyInfo.currencyCode){const n=(0,F._r)(s,this.currencyInfo,this.allTokensMap);if(n==null)return this.error(`Received unsupported currencyCode: ${s}`),0;const{blockNum:r,transaction:a,updateStakingStatus:l}=Ve({action:e,actor:t,currencyCode:s,denom:n,highestTxHeight:this.otherData.highestTxHeight,publicKey:this.walletInfo.keys.publicKey,walletId:this.walletId,findTransaction:(i,o)=>this.findTransaction(i,o),getTransactionList:i=>this.transactionList[i]});return l!=null&&this.updateStakingStatus(l),a!=null&&this.addTransaction(s,a),r}getSortedHistoryNodesLastActionSeqNumbers(){return k(this,null,function*(){const e=this.networkInfo.historyNodeUrls.map((s,n)=>k(this,null,function*(){var r;try{const a=yield this.requestHistory(n,{account_name:this.actor,pos:-1},h.m6.getActions);return((r=a==null?void 0:a.error)==null?void 0:r.noNodeForIndex)!=null?{nodeIndex:n,seqNumber:-1}:(Oe(a),a.actions.length===0?{nodeIndex:n,seqNumber:-1}:{nodeIndex:n,seqNumber:a.actions[a.actions.length-1].account_action_seq})}catch{return{nodeIndex:n,seqNumber:-1}}})),t=yield Promise.all(e);return t.sort((s,n)=>n.seqNumber-s.seqNumber),t})}checkTransactions(e){return k(this,null,function*(){var t,s;if((e==null?void 0:e.length)===0)return!1;if(e=e!=null?e:yield this.getSortedHistoryNodesLastActionSeqNumbers(),e.reduce((o,c)=>o+c.seqNumber,0)===-e.length)return!0;let n=this.otherData.highestTxHeight;const r=e[0].seqNumber,a=e[0].nodeIndex;let l=Math.max(0,r-h.y$+1),i=!1;for(;!i;){let o;try{if(o=yield this.requestHistory(a,{account_name:this.actor,pos:l,offset:h.y$-1},h.m6.getActions),((t=o.error)==null?void 0:t.noNodeForIndex)!=null)return!1;let c=[];if(((s=o.actions)==null?void 0:s.length)>0)c=o.actions;else break;for(let f=c.length-1;f>-1;f--){const _=ge(c[f]),v=this.processTransaction(_,this.actor);if(v>n)n=v;else if(v===n&&f===h.y$-1||v<this.otherData.highestTxHeight){i=!0;break}}if(l===0)break;l=Math.max(0,l-h.y$);continue}catch{return yield this.checkTransactions(e.slice(1))}}return n>this.otherData.highestTxHeight&&(this.otherData.highestTxHeight=n,this.localDataDirty()),!0})}checkTransactionsInnerLoop(){return k(this,null,function*(){let e;try{e=yield this.checkTransactions()}catch(t){this.error("checkTransactionsInnerLoop fetches failed with error: ",t);return}e&&(this.tokenCheckTransactionsStatus.FIO=1,this.updateOnAddressesChecked()),this.updateTransactionEvents()})}requestHistory(e,t,s){return k(this,null,function*(){if(this.networkInfo.historyNodeUrls[e]==null)return{error:{noNodeForIndex:!0}};const n=this.networkInfo.historyNodeUrls[e],r=JSON.stringify(t);return yield(yield fetch(`${n}history/${s}`,{method:"POST",headers:{"Content-Length":(r.length*2).toString(),Accept:"application/json","Content-Type":"application/json"},body:r})).json()})}fioApiRequest(e,t,s,n=!1){return k(this,null,function*(){var r,a,l,i;const o=new E.TQ("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,n);let c;try{switch(t){case"getChainInfo":c=yield o.transactions.getChainInfo();break;case"getBlock":c=yield o.transactions.getBlock(s);break;case"getObtData":case"getPendingFioRequests":case"getSentFioRequests":{const{endpoint:f,body:_}=s;c=yield o.transactions.executeCall({baseUrl:e,endPoint:f,body:JSON.stringify(_),signal:new(J())().signal});break}case"getCurrencyBalance":{c=yield(yield this.fetchCors(`${e}chain/get_currency_balance`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(s)})).json();break}default:c=yield o.genericAction(t,s)}}catch(f){if(f.errorCode!=null&&I.RF.includes(f.errorCode))((l=(a=(r=f.json)==null?void 0:r.fields)==null?void 0:a[0])==null?void 0:l.error)!=null&&(f.message=f.json.fields[0].error),c={isError:!0,data:{code:f.errorCode,message:(i=f.message)!=null?i:(0,F.Jo)(f),json:f.json,list:f.list}},f.errorCode!==404&&this.log(`fioApiRequest error. actionName: ${t} - apiUrl: ${e} - message: ${JSON.stringify(f.json)}`);else throw this.log(`fioApiRequest error. actionName: ${t} - apiUrl: ${e} - message: `,f),f}return c})}executePreparedTrx(e,t,s){return k(this,null,function*(){var n,r,a;const l=new E.TQ("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,!0);let i;this.warn(`executePreparedTrx. preparedTrx: ${JSON.stringify(s)} - apiUrl: ${e}`);try{i=yield l.executePreparedTrx(t,s),this.warn(`executePreparedTrx. res: ${JSON.stringify(i)} - apiUrl: ${e} - endpoint: ${t}`)}catch(o){throw o.errorCode!=null&&I.RF.includes(o.errorCode)?(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(s)} - apiUrl: ${e} - endpoint: ${t} - message: ${JSON.stringify(o.json)}`),((a=(r=(n=o.json)==null?void 0:n.fields)==null?void 0:r[0])==null?void 0:a.error)!=null&&(o.message=o.json.fields[0].error),o):(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(s)} - apiUrl: ${e} - endpoint: ${t} - message: `,o),o)}return i})}multicastServers(e,t){return k(this,null,function*(){var s,n,r,a,l,i;let o;if(h.iu[e]){const c=(0,y.VM)(t);if(this.warn(`multicastServers executePreparedTrx. actionName: ${e} - res: ${JSON.stringify(c)}`),o=yield(0,N.tQ)((0,N.QR)((0,F.R3)(this.networkInfo.apiUrls.map(f=>k(this,null,function*(){return yield(0,N.wR)(this.executePreparedTrx(f,b.EndPoint[h.Un[e]],c),1e4)})))),"Broadcast failed:"),this.warn(`multicastServers res. actionName: ${e} - res: ${JSON.stringify(o)}`),o==null)throw new Error("Service is unavailable")}else if(e==="getFioNames")o=yield(0,N.rn)(this.networkInfo.apiUrls.map(c=>k(this,null,function*(){return yield(0,N.wR)(this.fioApiRequest(c,e,t),1e4)})),c=>{const f=(0,y.lc)(h.s7)(c);return f!=null?f.data.json.message:(0,y.w7)(c)},2),((n=(s=o==null?void 0:o.data)==null?void 0:s.json)==null?void 0:n.message)===h.s7&&(o={fio_domains:[],fio_addresses:[]});else if(e==="getCurrencyBalance"){o=yield(0,N.rn)(this.networkInfo.apiUrls.map(v=>k(this,null,function*(){return yield(0,N.wR)(this.fioApiRequest(v,"getCurrencyBalance",{code:"fio.token",account:this.actor,symbol:"FIO"}),1e4)})),v=>JSON.stringify(v),2),((a=(r=o==null?void 0:o.data)==null?void 0:r.json)==null?void 0:a.message)===h.J2&&(o={balance:0,available:0,staked:0,srps:0,roe:""});const f=(0,u.VA)(u.oJ)(o)[0].split(" ")[0],_=(0,w.mul)(f,(l=this.currencyInfo.denominations[0].multiplier)!=null?l:"1000000000");o={balance:parseInt(_),available:0,staked:0,srps:0,roe:"0"}}else e==="getFioBalance"?o=yield(0,N.rn)(this.networkInfo.apiUrls.map(c=>k(this,null,function*(){return yield(0,N.wR)(this.fioApiRequest(c,e,t),1e4)})),c=>(0,y.Rf)(c),2):e==="getFees"?o=yield(0,N.NN)((0,F.R3)(this.networkInfo.apiUrls.map(c=>()=>k(this,null,function*(){const f=new E.TQ("",this.walletInfo.keys.publicKey,c,this.fetchCors,void 0,this.tpid),{endpoint:_,param:v}=t,g=yield f.getFee(_,v);return(0,y.LM)(g).fee.toString()})))):o=yield(0,N.NN)((0,F.R3)(this.networkInfo.apiUrls.map(c=>()=>k(this,null,function*(){return yield this.fioApiRequest(c,e,t)}))));if(o.isError!=null){const c=new I.PZ((i=o.errorMessage)!=null?i:o.data.message);throw c.json=o.data.json,c.list=o.data.list,c.errorCode=o.data.code,c}return o})}refreshFioAddresses(){return k(this,null,function*(){const e=U(yield this.multicastServers("getFioAddresses",{fioPublicKey:this.walletInfo.keys.publicKey}));let t=!1;if(e.fio_addresses.length!==this.otherData.fioAddresses.length)t=!0;else{for(const s of e.fio_addresses){const n=this.otherData.fioAddresses.find(r=>r.name===s.fio_address);if(n!=null){if(n.bundledTxs!==s.remaining_bundled_tx){t=!0;break}}else{t=!0;break}}if(!t){for(const s of this.otherData.fioAddresses)if(e.fio_addresses.findIndex(n=>n.fio_address===s.name)<0){t=!0;break}}}return t?(this.otherData.fioAddresses=e.fio_addresses.map(s=>({name:s.fio_address,bundledTxs:s.remaining_bundled_tx})),!0):!1})}refreshFioDomains(){return k(this,null,function*(){const e=se(yield this.multicastServers("getFioDomains",{fioPublicKey:this.walletInfo.keys.publicKey}));let t=!1;if(e.fio_domains.length!==this.otherData.fioDomains.length)t=!0;else{for(const s of e.fio_domains){const n=this.otherData.fioDomains.find(r=>r.name===s.fio_domain);if(n!=null){if(n.expiration!==s.expiration){t=!0;break}if(n.isPublic!==(s.is_public===1)){t=!0;break}}else{t=!0;break}}if(!t){for(const s of this.otherData.fioDomains)if(e.fio_domains.findIndex(n=>n.fio_domain===s.name)<0){t=!0;break}}}return t?(this.otherData.fioDomains=e.fio_domains.map(s=>({name:s.fio_domain,expiration:s.expiration,isPublic:s.is_public===1})),!0):!1})}checkAccountInnerLoop(){return k(this,null,function*(){var e,t;const s=this.currencyInfo.currencyCode;typeof this.walletLocalData.totalBalances[s]>"u"&&this.updateBalance(s,"0");try{const a={staked:"0",locked:"0"};let l;try{l=be(yield this.multicastServers("getFioBalance"))}catch(g){if(((e=g==null?void 0:g.json)==null?void 0:e.message)===h.XR)l=be(yield this.multicastServers("getCurrencyBalance")),this.log.warn("Returning FIO balance only due to chain bug");else if(((t=g==null?void 0:g.json)==null?void 0:t.message)===h.J2)l={balance:0,available:0,staked:0,srps:0,roe:""};else throw g}const{balance:i,available:o,staked:c,srps:f,roe:_}=l,v=String(i);a.staked=String(c),a.locked=(0,w.sub)(v,String(o)),this.otherData.srps=f,this.otherData.stakingRoe=_,this.updateBalance(s,v),(a.staked!==this.otherData.lockedBalances.staked||a.locked!==this.otherData.lockedBalances.locked)&&(this.otherData.lockedBalances=a,this.localDataDirty(),this.updateStakingStatus())}catch(a){this.log.warn("checkAccountInnerLoop getFioBalance error: ",String(a))}const n=yield this.refreshFioAddresses().catch(a=>console.warn("checkAccountInnerLoop getFioAddresses error:",String(a))),r=yield this.refreshFioDomains().catch(a=>console.warn("checkAccountInnerLoop getFioDomains error:",String(a)));(n===!0||r===!0)&&this.localDataDirty()})}fetchEncryptedFioRequests(e,t){return k(this,null,function*(){const n=e==="PENDING"?"getPendingFioRequests":"getSentFioRequests";let r=100,a=1;const l=[];for(;r===100;)try{const i=yield this.multicastServers(n,{endpoint:t.getEndPoint(),body:{fio_public_key:this.walletInfo.keys.publicKey,limit:100,offset:(a-1)*100}}),o=(0,y.g2)(i),{requests:c,more:f}=o;if(l.push(...c),f===0)break;a++,r=c.length}catch(i){const o=(0,u.HS)(y.Dr)(i.json);(o==null?void 0:o.message)!=="No FIO Requests"&&this.error("fetchEncryptedFioRequests error: ",i);break}return l})}syncNetwork(e){return k(this,null,function*(){const t=(0,y._g)(e==null?void 0:e.privateKeys);let s=!1;const n=(r,a)=>k(this,null,function*(){var l;const i=yield this.fetchEncryptedFioRequests(r,a);a.privateKey=t.fioKey,a.publicKey=this.walletInfo.keys.publicKey;const o=(l=yield a.decrypt({requests:i}))!=null?l:{requests:[]},{requests:c}=o;this.fioRequestsListChanged(this.otherData.fioRequests[r],c)&&(this.otherData.fioRequests[r]=[...c],s=!0)});return yield n("PENDING",new x.PendingFioRequests({fioPublicKey:this.walletInfo.keys.publicKey,getEncryptKey:this.defaultGetEncryptKey})),yield n("SENT",new x.SentFioRequests({fioPublicKey:this.walletInfo.keys.publicKey,getEncryptKey:this.defaultGetEncryptKey})),s&&this.localDataDirty(),Ue})}getFee(e,t){return k(this,null,function*(){let s=this.fees.get(e);if(s==null||s.expiration+30*1e3<Date.now()){const r={fee:yield this.multicastServers("getFees",{endpoint:e,param:t}),expiration:Date.now()};this.fees.set(e,r),s=r}return s.fee})}startEngine(){return k(this,null,function*(){this.addToLoop("checkBlockchainInnerLoop",Je),this.addToLoop("checkAccountInnerLoop",Le),this.addToLoop("checkTransactionsInnerLoop",He),yield De(re.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return k(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(e){return k(this,null,function*(){const{tokenId:t}=e,s=this.getBalance({tokenId:t}),n=this.otherData.lockedBalances.locked;e.spendTargets[0].nativeAmount="1";const r=yield this.makeSpend(e),a=(0,w.sub)((0,w.sub)(s,r.networkFee),n);if((0,w.lt)(a,"0"))throw new H.k5({networkFee:r.networkFee,tokenId:t});return a})}makeSpend(e){return k(this,null,function*(){const{edgeSpendInfo:t,nativeBalance:s,currencyCode:n}=this.makeSpendCheck(e),{memos:r=[],tokenId:a}=t,l=this.otherData.lockedBalances.locked,i=(0,w.sub)(s,l),o=t.spendTargets[0],{publicAddress:c}=o,{nativeAmount:f}=o;if(c==null)throw new Error("makeSpend Missing publicAddress");if(f==null)throw new H.ef;let{otherParams:_}=t;(_==null||Object.keys(_).length===0)&&(_={action:{name:h.kl.transferTokens,params:{payeeFioPublicKey:c,amount:f,maxFee:0}}});const{name:v,params:g}=(0,y.Vf)(_.action);let K=f,m,A;switch(v){case h.kl.transferTokens:{m=yield this.getFee(b.EndPoint.transferTokens),A={account:"fio.token",action:h.i7[h.kl.transferTokens],data:{payee_public_key:c,amount:f,max_fee:m}};break}case h.kl.stakeFioTokens:{const{fioAddress:p}=(0,y.ie)(g);K="0",m=yield this.getFee(b.EndPoint.stakeFioTokens,p),A={account:"fio.staking",action:h.i7[v],data:{amount:f,fio_address:p,actor:this.actor,max_fee:m}};break}case h.kl.unStakeFioTokens:{const{fioAddress:p}=(0,y.ie)(g);K="0",m=yield this.getFee(b.EndPoint.unStakeFioTokens,p),A={account:"fio.staking",action:h.i7[v],data:{amount:f,fio_address:p,actor:this.actor,max_fee:m}};const P=Ie(new Date),G=this.otherData.lockedBalances.staked;if((0,w.gt)(f,G)||(0,w.gt)(`${m}`,i))throw new H.k5({tokenId:a});const Z=(0,w.mul)((0,w.mul)((0,w.div)(f,G,18),`${this.otherData.srps}`),this.otherData.stakingRoe),M=(0,w.max)((0,w.sub)(Z,f),"0");_.ui={accrued:Z,estReward:M,unlockDate:P};break}case h.kl.transferFioAddress:{const{fioAddress:p}=(0,y.ie)(g);m=yield this.getFee(b.EndPoint.transferFioAddress,p),A={account:"fio.address",action:"xferaddress",data:{fio_address:p,new_owner_fio_public_key:c,actor:this.actor,max_fee:m}};break}case h.kl.transferFioDomain:{const{fioDomain:p}=(0,y.qC)(g);m=yield this.getFee(b.EndPoint.transferFioDomain),A={account:"fio.address",action:"xferdomain",data:{fio_domain:p,new_owner_fio_public_key:c,actor:this.actor,max_fee:m}};break}case h.kl.addPublicAddresses:{const{fioAddress:p,publicAddresses:P}=(0,y.TV)(g);m=yield this.getFee(b.EndPoint.addPubAddress,p),A={account:"fio.address",action:"addaddress",data:{fio_address:p,public_addresses:P,actor:this.actor,max_fee:m}};break}case h.kl.removePublicAddresses:{const{fioAddress:p,publicAddresses:P}=(0,y.TV)(g);m=yield this.getFee(b.EndPoint.removePubAddress,p),A={account:"fio.address",action:"remaddress",data:{fio_address:p,public_addresses:P,actor:this.actor,max_fee:m}};break}case h.kl.registerFioAddress:{const{fioAddress:p}=(0,y.ie)(g);m=yield this.getFee(b.EndPoint.registerFioAddress),A={account:"fio.address",action:"regaddress",data:{fio_address:p,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:m,actor:this.actor}};break}case h.kl.registerFioDomain:{const{fioDomain:p}=(0,y.q$)(g);m=yield this.getFee(b.EndPoint.registerFioDomain),A={account:"fio.address",action:"regdomain",data:{fio_domain:p,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:m,actor:this.actor}};break}case h.kl.renewFioDomain:{const{fioDomain:p}=(0,y.q$)(g);m=yield this.getFee(b.EndPoint.renewFioDomain),A={account:"fio.address",action:"renewdomain",data:{fio_domain:p,max_fee:m,actor:this.actor}};break}case h.kl.addBundledTransactions:{const{bundleSets:p,fioAddress:P}=(0,y.Zq)(g);m=yield this.getFee(b.EndPoint.addBundledTransactions,P),A={account:"fio.address",action:"addbundles",data:{fio_address:P,bundle_sets:p,actor:this.actor,max_fee:m}};break}case h.kl.setFioDomainPublic:{const{fioDomain:p,isPublic:P}=(0,y.Vj)(g);m=yield this.getFee(b.EndPoint.setFioDomainPublic),A={account:"fio.address",action:"setdomainpub",data:{fio_domain:p,is_public:P?1:0,max_fee:m,actor:this.actor}};break}case h.kl.rejectFundsRequest:{const{fioRequestId:p,payerFioAddress:P}=(0,y.f4)(g);m=yield this.getFee(b.EndPoint.rejectFundsRequest,P),A={account:"fio.reqobt",action:"rejectfndreq",data:{fio_request_id:p,max_fee:m,actor:this.actor}};break}case h.kl.cancelFundsRequest:{const{fioAddress:p,fioRequestId:P}=(0,y.K3)(g);m=yield this.getFee(b.EndPoint.cancelFundsRequest,p),A={account:"fio.reqobt",action:"cancelfndreq",data:{fio_request_id:P,max_fee:m,actor:this.actor}};break}case h.kl.recordObtData:{const{payerFioAddress:p}=(0,y.DC)(g);m=yield this.getFee(b.EndPoint.recordObtData,p);break}case h.kl.requestFunds:{const{payeeFioAddress:p}=(0,y.Wg)(g);m=yield this.getFee(b.EndPoint.newFundsRequest,p);break}default:throw new Error("Unrecognized FIO action")}return{blockHeight:0,currencyCode:n,date:0,isSend:!0,memos:r,nativeAmount:`-${(0,w.add)(K,m)}`,networkFee:`${m}`,networkFees:[],otherParams:W(T({},_),{txParams:A}),ourReceiveAddresses:[],signedTx:"",tokenId:a,txid:"",walletId:this.walletId}})}signTx(e,t){return k(this,null,function*(){const s=(0,y._g)(t),n=(0,F.Je)(e);let r=(0,u.HS)(y.zc)(n.txParams);const a=new O.Transactions;if(r==null){const{name:v,params:g}=(0,y.Vf)(n.action),{networkFee:K}=e;switch(v){case h.kl.recordObtData:{const{payerFioAddress:m,payeeFioAddress:A,payerPublicAddress:z,payeePublicAddress:p,amount:P,tokenCode:G,chainCode:Z,obtId:M,memo:B,status:Y,fioRequestId:ye}=(0,y.DC)(g),C={payer_public_address:z,payee_public_address:p,amount:P,chain_code:Z,token_code:G,status:Y,obt_id:M,memo:B,hash:void 0,offline_url:void 0},ae=new E.TQ(t.fioKey,this.walletInfo.keys.publicKey,this.networkInfo.historyNodeUrls,this.fetchCors),{encrypt_public_key:j}=yield ae.getEncryptKey(A),Q=a.getCipherContent("record_obt_data_content",C,s.fioKey,j);r={account:"fio.reqobt",action:"recordobt",data:{payer_fio_address:m,payee_fio_address:A,content:Q,fio_request_id:ye,max_fee:K,actor:this.actor}};break}case h.kl.requestFunds:{const{payerFioAddress:m,payerFioPublicKey:A,payeeFioAddress:z,payeeTokenPublicAddress:p,amount:P,chainCode:G,tokenCode:Z,memo:M}=(0,y.Wg)(g),B={payee_public_address:p,amount:P,chain_code:G,token_code:Z,memo:M,hash:void 0,offline_url:void 0},Y=a.getCipherContent("new_funds_content",B,s.fioKey,A);r={account:"fio.reqobt",action:"newfundsreq",data:{payer_fio_address:m,payee_fio_address:z,content:Y,max_fee:K,actor:this.actor}};break}default:throw new Error("Unknown FIO action")}}const l=yield this.getBalance({tokenId:null}),i=(0,w.lte)(l,"0")&&!this.transactionList.FIO.some(v=>(0,w.gt)(v.nativeAmount,"0"))?void 0:this.tpid,o=yield a.createRawTransaction({action:r.action,account:r.account,data:W(T({},r.data),{tpid:i}),publicKey:this.walletInfo.keys.publicKey,chainData:this.refBlock}),{serializedContextFreeData:c,serializedTransaction:f}=yield a.serialize({chainId:this.networkInfo.chainId,transaction:o}),_=yield a.sign({chainId:this.networkInfo.chainId,privateKeys:[s.fioKey],transaction:o,serializedTransaction:f,serializedContextFreeData:c});return e.otherParams=W(T({},e.otherParams),{signedTx:_}),e})}broadcastTx(e){return k(this,null,function*(){var t;const s=(0,F.Je)(e);if(((t=s.action)==null?void 0:t.name)==null)throw new Error('Action is not set, "action" prop of otherParams is required for FIO actions');const n=(0,y.VM)(s.signedTx),r=yield this.multicastServers(s.action.name,n),a=(0,y.FC)(r);e.metadata={notes:a.transaction_id},e.txid=a.transaction_id,e.date=Date.now()/1e3,e.blockHeight=a.block_num,this.warn(`SUCCESS broadcastTx
|
|
2
|
+
${(0,F.T5)(e)}`);const l=a,{block_num:i,block_time:o,transaction_id:c}=l,f=$e(l,["block_num","block_time","transaction_id"]);return e.otherParams=W(T({},s),{broadcastResult:f}),e})}saveTx(e){return k(this,null,function*(){var t;const s=(0,F.Je)(e),{broadcastResult:n={},action:r}=s,{name:a,params:l}=(0,y.Vf)(r);try{switch(a){case h.kl.transferFioDomain:{const i=this.otherData.fioDomains.findIndex(({name:o})=>o===l.fioDomain);i>=0&&(this.otherData.fioDomains.splice(i,1),this.localDataDirty());break}case h.kl.transferFioAddress:{const i=this.otherData.fioAddresses.findIndex(({name:o})=>o===l.fioAddress);i>=0&&(this.otherData.fioAddresses.splice(i,1),this.localDataDirty());break}case h.kl.registerFioAddress:{const{fioAddress:i}=(0,y.ie)(l);this.otherData.fioAddresses.find(({name:c})=>c===i)==null&&(this.otherData.fioAddresses.push({name:i,bundledTxs:void 0}),this.localDataDirty());break}case h.kl.registerFioDomain:{const{fioDomain:i}=(0,y.q$)(l);if(n.expiration==null)throw new Error("expiration not present");const o=this.otherData.fioDomains.find(({name:c})=>c===i);o!=null&&(o.expiration=n.expiration,this.localDataDirty());break}case h.kl.renewFioDomain:{const{fioDomain:i}=(0,y.q$)(l);if(n.expiration==null)throw new Error("expiration not present");const o=this.otherData.fioDomains.find(({name:c})=>c===i);o!=null&&(o.expiration=n.expiration,this.localDataDirty());break}case h.kl.addBundledTransactions:{const{fioAddress:i}=(0,y.Zq)(l),o=this.otherData.fioAddresses.find(({name:c})=>c===i);if(o==null)throw new I.PZ("Fio Address is not found in engine");o.bundledTxs=((t=o.bundledTxs)!=null?t:0)+h.mA,this.localDataDirty();break}case h.kl.rejectFundsRequest:{const{fioRequestId:i}=(0,y.f4)(l);typeof i=="string"&&(this.removeFioRequest(i,"PENDING"),this.localDataDirty());break}case h.kl.cancelFundsRequest:{const{fioRequestId:i}=(0,y.K3)(l);typeof i=="string"&&(this.removeFioRequest(i,"SENT"),this.localDataDirty());break}case h.kl.recordObtData:{const{fioRequestId:i}=(0,y.DC)(l);i!=null&&n.status==="sent_to_blockchain"&&(this.removeFioRequest(i,"PENDING"),this.localDataDirty());break}}}catch(i){this.log.warn(`Error attempting post-broadcast action ${a}:`,i)}yield De(re.prototype,this,"saveTx").call(this,e)})}getFreshAddress(e){return k(this,null,function*(){return{publicAddress:this.walletInfo.keys.publicKey}})}}function Me(d,e,t,s){return k(this,null,function*(){const{tpid:n="finance@edge"}=d.initOptions,r=(0,y.Te)(t),a=new re(d,e,r,s,n);return yield a.loadEngine(),a})}const Ae=d=>{const e=new Date(d);return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds())},Ie=d=>{const e=Math.floor(d.getTime()/h.JH)*h.JH;return new Date(e+h.O_)},Ve=({action:d,actor:e,currencyCode:t,denom:s,highestTxHeight:n,publicKey:r,walletId:a,findTransaction:l,getTransactionList:i})=>{var o,c,f,_,v,g,K,m,A,z,p,P,G,Z;const{act:{name:M,data:B,account:Y,authorization:ye}}=d.action_trace;if(d.block_num<=n)return{blockNum:d.block_num};let C={account:Y,name:M,authorization:ye,data:B,meta:{}};const ae=l(t,d.action_trace.trx_id);let j;if(ae>-1&&(j=i(t)[ae],((c=(o=j.otherParams)==null?void 0:o.meta)==null?void 0:c.isTransferProcessed)!=null))return{blockNum:d.block_num};const Q=(_=(f=B.max_fee)==null?void 0:f.toString())!=null?_:"0",me=(g=(v=B.amount)==null?void 0:v.toString())!=null?g:"0",st=(m=(K=B.quantity)==null?void 0:K.split(" ")[0])!=null?m:"0",ke=(0,w.mul)(st,s.multiplier),Ee=[];let S="0",$="0",pe,le;switch(M){case"trnsfiopubky":if(B.payee_public_key===r)Ee.push(r),B.actor===e?(S=Q,$=`-${S}`):($=me,S="0");else if(B.actor===e)S=Q,$=`-${(0,w.add)(me,S)}`;else return{blockNum:d.block_num};C.meta.isTransferProcessed=!0;break;case"stakefio":{S=Q,$=`-${S}`,C.meta.isTransferProcessed=!0,le={assetActionType:"stake"};break}case"unstakefio":pe={nativeAmount:me,blockTime:d.block_time,txId:d.action_trace.trx_id,txName:M},S=Q,j!=null?(C=W(T(T({},j.otherParams),C),{data:T(T({},(A=j.otherParams)==null?void 0:A.data),B),meta:T(T({},(z=j.otherParams)==null?void 0:z.meta),C.meta)}),$=(0,w.sub)(j.nativeAmount,S)):$=`-${S}`,C.meta.isTransferProcessed=!0,le={assetActionType:"unstakeOrder"};break;case"regaddress":d.action_trace.act.authorization.some(ce=>ce.actor===e)&&(S=Q,$=`-${S}`),C.meta.isTransferProcessed=!0;break;case"transfer":{const ce=C.data!=null&&C.data.memo===h.HC;if(ce)pe={nativeAmount:ke,blockTime:d.block_time,txId:d.action_trace.trx_id,txName:M},S="0",$=ke,le={assetActionType:"unstake"};else{const xe=B.to===e;S=xe?"0":ke,$=xe?"0":`-${S}`}if(j!=null)if(C=W(T(T({},C),j.otherParams),{data:T(T({},C.data),(P=(p=j.otherParams)==null?void 0:p.data)!=null?P:{}),meta:T(T({},C.meta),(Z=(G=j.otherParams)==null?void 0:G.meta)!=null?Z:{}),name:ce?"unstakefio":C.name}),C.meta.isTransferProcessed!=null)B.to!==e?(S=Q,$=(0,w.sub)(j.nativeAmount,S)):S="0";else throw new Error("processTransaction error - existing spend transaction should have isTransferProcessed set")}break;default:return{blockNum:d.block_num}}const nt={assetAction:le,blockHeight:d.block_num>0?d.block_num:0,currencyCode:t,date:Ae(d.block_time)/1e3,isSend:$.startsWith("-"),memos:[],nativeAmount:$,networkFee:S,networkFees:[],otherParams:C,ourReceiveAddresses:Ee,signedTx:"",tokenId:null,txid:d.action_trace.trx_id,walletId:a};return{blockNum:d.block_num,transaction:nt,updateStakingStatus:pe}};var Ge=D(48287).Buffer,Ze=Object.defineProperty,Qe=Object.defineProperties,We=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertySymbols,Pe=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,Fe=(d,e,t)=>e in d?Ze(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t,ze=(d,e)=>{for(var t in e||(e={}))Pe.call(e,t)&&Fe(d,t,e[t]);if(ie)for(var t of ie(e))Te.call(e,t)&&Fe(d,t,e[t]);return d},Ye=(d,e)=>Qe(d,We(e)),Xe=(d,e)=>{var t={};for(var s in d)Pe.call(d,s)&&e.indexOf(s)<0&&(t[s]=d[s]);if(d!=null&&ie)for(var s of ie(d))e.indexOf(s)<0&&Te.call(d,s)&&(t[s]=d[s]);return t},R=(d,e,t)=>new Promise((s,n)=>{var r=i=>{try{l(t.next(i))}catch(o){n(o)}},a=i=>{try{l(t.throw(i))}catch(o){n(o)}},l=i=>i.done?s(i.value):Promise.resolve(i.value).then(r,a);l((t=t.apply(d,e)).next())});const ue="FIO",fe="fio",Re="";function he(d){const e=d.startsWith(ue),t=d.length===53;return e&&t}class Se{constructor(e){const{builtinTokens:t,currencyInfo:s,initOptions:n,io:r,networkInfo:a}=e;this.builtinTokens=t,this.currencyInfo=s,this.io=r,this.networkInfo=a;const{tpid:l="finance@edge",fioRegApiToken:i=Re,freeRegApiToken:o=Re,freeRegRefCode:c="edgeFree"}=n;this.fetchCors=(0,F.CY)(e.io),this.fioRegApiToken=i,this.freeRegApiToken=o,this.freeRegRefCode=c,this.tpid=l;for(const f of this.networkInfo.apiUrls)new E.TQ("","",f,this.fetchCors,void 0,l)}getDisplayPrivateKey(e){return R(this,null,function*(){return(0,y._g)(e.keys).fioKey})}getDisplayPublicKey(e){return R(this,null,function*(){const{keys:t}=(0,y.Te)(e);return t.publicKey})}importPrivateKey(e){return R(this,null,function*(){const{pluginId:t}=this.currencyInfo,s={};if(/[0-9a-zA-Z]{51}$/.test(e))ee.ZD.fromString(e),s.fioKey=e;else{if(!(0,de.validateMnemonic)(e))throw new Error("Invalid input");const r=yield E.TQ.createPrivateKeyMnemonic(e);s.fioKey=r.fioKey,s.mnemonic=r.mnemonic}const n=yield this.derivePublicKey({type:`wallet:${t}`,id:"fake",keys:s});return s.publicKey=n.publicKey,s})}createPrivateKey(e){return R(this,null,function*(){if(e.replace("wallet:","")===fe){const s=Ge.from(this.io.random(32));return yield E.TQ.createPrivateKey(s)}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return R(this,null,function*(){if(e.type.replace("wallet:","")===fe)return E.TQ.derivedPublicKey(e.keys.fioKey);throw new Error("InvalidWalletType")})}parseUri(e){return R(this,null,function*(){var t;const{edgeParsedUri:s}=yield(0,te.x)({currencyInfo:this.currencyInfo,uri:e,networks:{fio:!0},builtinTokens:this.builtinTokens,currencyCode:ue});if(!he((t=s.publicAddress)!=null?t:""))throw new Error("InvalidPublicAddressError");return s})}encodeUri(e){return R(this,arguments,function*(t,s=[]){if(!he(t.publicAddress))throw new Error("InvalidPublicAddressError");let r;if(typeof t.nativeAmount=="string"){const l=ue,i=t.nativeAmount,o=(0,F.FQ)(l,this.currencyInfo,s,this.builtinTokens);if(o==null)throw new Error("InternalErrorInvalidCurrencyCode");r=(0,w.div)(i,o.multiplier,16)}return(0,te.m)(t,fe,r)})}getConnectedPublicAddress(e,t,s){return R(this,null,function*(){var n;try{E.TQ.isFioAddressValid(e)}catch{throw new I.PZ("",400,this.networkInfo.errorCodes.INVALID_FIO_ADDRESS)}try{if((yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0)throw new I.PZ("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_EXIST)}catch(r){throw r.name==="FioError"&&((n=r.json)==null?void 0:n.fields)!=null&&r.errorCode===400&&(r.labelCode=this.networkInfo.errorCodes.INVALID_FIO_ADDRESS),r}try{const r=yield this.multicastServers("getPublicAddress",{fioAddress:e,chainCode:t,tokenCode:s});if(r.public_address==null||r.public_address==="0")throw new I.PZ("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED);return r}catch(r){throw r.name==="FioError"&&r.labelCode===this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED||r.errorCode===404?new I.PZ("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED):r}})}isFioAddressValid(e){return R(this,null,function*(){try{return E.TQ.isFioAddressValid(e)}catch{return!1}})}validateAccount(e,t=!1){return R(this,null,function*(){var s;try{if(t){if(!E.TQ.isFioDomainValid(e))return!1}else if(!E.TQ.isFioAddressValid(e))return!1}catch{throw new I.PZ("",400,this.networkInfo.errorCodes.INVALID_FIO_ADDRESS)}try{return(yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0}catch(n){throw n.name==="FioError"&&((s=n.json)==null?void 0:s.fields)!=null&&n.errorCode===400&&(n.labelCode=this.networkInfo.errorCodes.INVALID_FIO_ADDRESS),n}})}isDomainPublic(e){return R(this,null,function*(){if((yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0)throw new I.PZ("",400,this.networkInfo.errorCodes.FIO_DOMAIN_IS_NOT_EXIST);const s=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${h.KV.isDomainPublic}/${e}`,{method:"GET"});if(!s.ok){const r=yield s.json();throw new I.PZ("",s.status,this.networkInfo.errorCodes.IS_DOMAIN_PUBLIC_ERROR,r)}const{isPublic:n}=yield s.json();return n})}doesAccountExist(e){return R(this,null,function*(){try{if(!E.TQ.isFioAddressValid(e))return!1}catch{return!1}try{return(yield this.multicastServers("isAvailable",{fioName:e})).is_registered===1}catch(t){return this.error("doesAccountExist error: ",t),!1}})}buyAddressRequest(e,t=!1){return R(this,null,function*(){if(t&&this.freeRegApiToken===""||!t&&this.fioRegApiToken==="")throw new Error("FIO: buyAddressRequest requires API tokens to be configured");const s={Accept:"application/json","Content-Type":"application/json"};try{const n=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${h.KV.buyAddress}`,{method:"POST",headers:s,body:JSON.stringify(Ye(ze({},e),{apiToken:t?this.freeRegApiToken:this.fioRegApiToken}))});if(!n.ok){const r=yield n.json();throw this.networkInfo.errorCodes[r.errorCode]!=null?new I.PZ(r.error,n.status,this.networkInfo.errorCodes[r.errorCode],r):r.error==="Already registered"?new I.PZ(r.error,n.status,this.networkInfo.errorCodes.ALREADY_REGISTERED,r):new Error(r.error)}return yield n.json()}catch(n){throw n.labelCode!=null?n:new I.PZ((0,F.Jo)(n),500,this.networkInfo.errorCodes.SERVER_ERROR)}})}getDomains(e=""){return R(this,null,function*(){e==null&&(e=this.networkInfo.defaultRef);try{const t=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${h.KV.getDomains}/${e}`,{method:"GET"}),s=yield t.json();if(!t.ok)throw this.networkInfo.errorCodes[s.errorCode]!=null?new I.PZ(s.error,t.status,this.networkInfo.errorCodes[s.errorCode],s):new Error(s.error);return s.domains}catch(t){throw t.labelCode!=null?t:new I.PZ((0,F.Jo)(t),500,this.networkInfo.errorCodes.SERVER_ERROR)}})}getStakeEstReturn(){return R(this,null,function*(){try{const e=yield this.fetchCors(`${this.networkInfo.fioStakingApyUrl}`,{method:"GET"}),t=yield e.json();if(!e.ok)throw new Error(this.networkInfo.errorCodes.SERVER_ERROR);const s=t.historical_apr["7day"];return s!=null&&s>h.a4||s==null?h.a4:s}catch(e){throw e.labelCode!=null?e:new I.PZ(e.message,500,this.networkInfo.errorCodes.SERVER_ERROR)}})}multicastServers(e,t){return R(this,null,function*(){const s=yield(0,N.NN)((0,F.R3)(this.networkInfo.apiUrls.map(n=>()=>R(this,null,function*(){let r;const a=new E.TQ("","",n,this.fetchCors,void 0,this.tpid);try{r=yield a.genericAction(e,t)}catch(l){if(l.errorCode!=null&&I.RF.includes(l.errorCode))r={isError:!0,data:{code:l.errorCode,message:(0,F.Jo)(l),json:l.json,list:l.list}};else throw l}return r}))));if(s.isError!=null){const n=new I.PZ(s.errorMessage);throw n.json=s.data.json,n.list=s.data.list,n.errorCode=s.data.code,n}return s})}}function et(d){return R(this,null,function*(){return new Se(d)})}function tt(d,e){return R(this,null,function*(){const t=Xe(e,[]);d.networkInfo=(0,F.wy)(d.networkInfo,t)})}},73776:function(){},15340:function(){},79838:function(){}}]);
|
package/lib/fio/FioTools.js
CHANGED
|
@@ -58,6 +58,8 @@ const FIO_REG_SITE_API_KEY = ''
|
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
|
|
61
|
+
|
|
62
|
+
|
|
61
63
|
|
|
62
64
|
constructor(env) {
|
|
63
65
|
const { builtinTokens, currencyInfo, initOptions, io, networkInfo } = env
|
|
@@ -66,11 +68,17 @@ const FIO_REG_SITE_API_KEY = ''
|
|
|
66
68
|
this.io = io
|
|
67
69
|
this.networkInfo = networkInfo
|
|
68
70
|
|
|
69
|
-
const {
|
|
70
|
-
|
|
71
|
+
const {
|
|
72
|
+
tpid = 'finance@edge',
|
|
73
|
+
fioRegApiToken = FIO_REG_SITE_API_KEY,
|
|
74
|
+
freeRegApiToken = FIO_REG_SITE_API_KEY,
|
|
75
|
+
freeRegRefCode = 'edgeFree'
|
|
76
|
+
} = initOptions
|
|
71
77
|
|
|
72
78
|
this.fetchCors = _utils.getFetchCors.call(void 0, env.io)
|
|
73
79
|
this.fioRegApiToken = fioRegApiToken
|
|
80
|
+
this.freeRegApiToken = freeRegApiToken
|
|
81
|
+
this.freeRegRefCode = freeRegRefCode
|
|
74
82
|
this.tpid = tpid
|
|
75
83
|
|
|
76
84
|
// The sdk constructor will fetch and store abi definitions for future instances
|
|
@@ -372,24 +380,31 @@ const FIO_REG_SITE_API_KEY = ''
|
|
|
372
380
|
|
|
373
381
|
|
|
374
382
|
|
|
375
|
-
|
|
376
383
|
,
|
|
377
384
|
isFree = false
|
|
378
385
|
) {
|
|
386
|
+
if (
|
|
387
|
+
(isFree && this.freeRegApiToken === '') ||
|
|
388
|
+
(!isFree && this.fioRegApiToken === '')
|
|
389
|
+
)
|
|
390
|
+
throw new Error(
|
|
391
|
+
'FIO: buyAddressRequest requires API tokens to be configured'
|
|
392
|
+
)
|
|
393
|
+
|
|
379
394
|
const headers = {
|
|
380
395
|
Accept: 'application/json',
|
|
381
396
|
'Content-Type': 'application/json'
|
|
382
397
|
}
|
|
383
|
-
if (isFree) {
|
|
384
|
-
options.apiToken = this.fioRegApiToken
|
|
385
|
-
}
|
|
386
398
|
try {
|
|
387
399
|
const result = await this.fetchCors(
|
|
388
400
|
`${this.networkInfo.fioRegApiUrl}${_fioConst.FIO_REG_API_ENDPOINTS.buyAddress}`,
|
|
389
401
|
{
|
|
390
402
|
method: 'POST',
|
|
391
403
|
headers,
|
|
392
|
-
body: JSON.stringify(
|
|
404
|
+
body: JSON.stringify({
|
|
405
|
+
...options,
|
|
406
|
+
apiToken: isFree ? this.freeRegApiToken : this.fioRegApiToken
|
|
407
|
+
})
|
|
393
408
|
}
|
|
394
409
|
)
|
|
395
410
|
if (!result.ok) {
|