import{G as v,k as w,J as u,L as k,E as B,n as e}from"../../../../../vendor-CdGQ_kNX.js";import{j as I,k as K,l as F,d as C,h as P}from"../../../../../hooks-CpKiwlXR.js";import{z as W,f as q,i as N,e as M,o as z}from"../../../../../utils-D7d4_AgI.js";import{u as Q,a as U,o as _,A as D}from"../../../../../store-CA4zKa5y.js";import"../../../ui/Copy/Style-B4KRGFC9.js";import"../../../ui/Href/Href-BgQ3YY1y.js";import{I as j}from"../../../ui/Icon/Icon-B1RuiTzs.js";import"../../../ui/Input/Style-CSjEZHkN.js";import{B as G}from"../../../ui/Button/Button-Bmos_HC5.js";import{L as J}from"../../../ui/Loader/Loader-rH-H67Hl.js";import"../../../ui/Select/Style-JIoW6bDj.js";import"../../../ui/Dropdown/Style-DCbB92PD.js";import"../../../ui/StatusTx/Style-BqGWL3dI.js";import"../../../ui/Checkbox/Style-CnodpLBl.js";import"../../../ui/BtnBurger/Style-CETsgO8g.js";import"../../Alert/Styles-DZk5HI36.js";import"../../ErrorAlert/Style-Bm_CSIde.js";import"../../CodeMirror/CodeMirror-D9BEPmHF.js";import"../../../../../context-BBqFUxjA.js";import"../../BillsTable/Style-Ba2jPwcC.js";import"../../TxIdsTable/Style-BveMwsf_.js";import"../../Promt/Style-CDvrZUqf.js";import"../../PromoCode/Style-DB63PuBp.js";import"../../CsvUpload/Style-Cb0rm0KO.js";import"../../ShowExample/Style-DbpCvgI_.js";import"../../Faq/Style-DxkXGNt5.js";import"../../TokenSelect/Style-DEUzLCeC.js";import"../../Transactions/Style--LgeQx0n.js";import"../../Verification/Style-BZte7Qws.js";import{S as H}from"../../SentTransactions/SentTransaction-CHXoJB03.js";import"../../SentTransactions/Style-DoN3Da3g.js";import"../../../../elements/Header/Style-Q6VLkei_.js";import"../../../../elements/Footer/Style-BS6teA8h.js";import"../../../../layouts/Main-XrVcJZZG.js";import"../../../../layouts/Style-CkhJeVgl.js";import"../../../../layouts/NotFoundLayout-BSHQjReB.js";import"../../../../elements/AppLoader/Style-BJMDZnm0.js";import"../Stats/Style-BvV9dnBS.js";import{T as V,L as X,a as Y,b as m,I as Z,c as T,d as $,e as ee,W as re}from"./Style-CkZVKrWn.js";import"../TopUpInfo/Style-DqdWGGmm.js";import"../AmountInfo/Style-BxjtFCxc.js";import"../BackupInfo/Style-DKIbumns.js";import"../ActionButton/Style-tD1QS4ij.js";import"../WalletVerificationMessage/Style-BRLPhw-s.js";import"../Summary/Style-vE4FPkZG.js";import"../TokenRefund/Style-D0R7HjCi.js";import"../TokenSummary/Style-vE4FPkZG.js";function Ve(){const p=Q(),{connection:o}=v(),{account:r}=U(),S=_(),R=I(),{onBurnerKeySend:l}=K(),a=P("Refund"),c=F(),{refundTransactions:f}=C(),[L,h]=w.useState(!0),y=w.useCallback(async()=>{var n;try{if(h(!0),!r)throw new Error("no account");const[t,s,b]=await Promise.all([W(o,r.publicKey),q(p,r.publicKey,"processed"),N(o)]);if(!t||r.publicKey.toBase58()===t)throw new Error("no source");if(new u(s).isLessThanOrEqualTo(0))throw new Error("Not enough SOL balance to refund");const A=c({sender:r.publicKey,bills:[{address:t,amount:s==null?void 0:s.toString()}]}),g=await M(o,A[0],1.15),O=new u(b).dividedBy(k),i=new u(s).minus(g).minus(O);if(i.isLessThanOrEqualTo(0))return h(!1),[];a("SOL refund started","send refund");const x=c({sender:r.publicKey,bills:[{address:t,amount:i==null?void 0:i.toString()}]});return await l(()=>x,D.REFUND),a("SOL successfully refunded","Send refund"),x}catch(t){throw z(t,"doRefund",{account:(n=r==null?void 0:r.publicKey)==null?void 0:n.toBase58(),analyticsId:S}),a("SOP refund Failed","Send refund"),t}},[r,p,o,c]),d=B({queryKey:["solRefund"],queryFn:y,refetchOnMount:!0,refetchOnReconnect:!1,refetchOnWindowFocus:!1}),E=async n=>{await l(()=>[n.tx],n.type),R.remove(n.id)};return e.jsxs("div",{children:[e.jsx(V,{children:"Refund details"}),d.isLoading&&e.jsxs(X,{children:[e.jsx(Y,{children:e.jsx(J,{})}),e.jsx(m,{children:"Refund transaction is being created."})]}),!L&&e.jsxs(Z,{children:[e.jsx("div",{children:e.jsx(j,{name:"info"})}),e.jsx(T,{children:e.jsx(m,{children:"Unfortunately, we cannot process the refund transaction. Please import the private key into your wallet and withdraw manually the remaining funds."})})]}),f.length>0&&e.jsx($,{children:f.map(n=>e.jsx(ee,{children:e.jsx(H,{transaction:n,onResend:E})},n.id))}),d.isError&&e.jsxs(re,{children:[e.jsx(j,{name:"danger"}),e.jsxs(T,{children:[e.jsxs(m,{children:["The refund ended with an error: ",d.error.message]}),e.jsx(G,{size:"small",onClick:y,children:"Retry"})]})]})]})}export{Ve as R};
