import{a as Te,b as Ce,c as _e}from"/build/_shared/chunk-W4ARAVNL.js";import{a as ke,b as ye,c as Ne}from"/build/_shared/chunk-NO333FYP.js";import{b as we}from"/build/_shared/chunk-O4PYWHLL.js";import{a as ge,b as M}from"/build/_shared/chunk-XOLAAALG.js";import{a as ve}from"/build/_shared/chunk-JDRDOC5G.js";import{a as G,d as J,e as be,f as K,g as Q}from"/build/_shared/chunk-3YOXUXUW.js";import{a as q}from"/build/_shared/chunk-QTPODCL2.js";import{a as xe}from"/build/_shared/chunk-DAHIBWKD.js";import{a as he}from"/build/_shared/chunk-PYDU2FCB.js";import{D as fe,u as ue,x as pe}from"/build/_shared/chunk-II7NYN3G.js";import{d as de}from"/build/_shared/chunk-XVTEUPS3.js";import{b as F}from"/build/_shared/chunk-3YCDAG7N.js";import{E as re,R as ne,q as se,w as W}from"/build/_shared/chunk-MS7LRLWT.js";import{B as A,Ba as me,J as j,ba as oe,ca as ie,j as ae,oa as H,pa as S,ta as ce,xa as le}from"/build/_shared/chunk-LQ2J2PAT.js";import{a as te,b as $}from"/build/_shared/chunk-P2E5SG33.js";import{f as w,n as O}from"/build/_shared/chunk-VBX4N7BW.js";O();var Pe=w(ae(),1);var p=w(te(),1);var e=w($(),1),Y=class extends Error{description;constructor(o,l){super(o),this.description=l}},Ae=({open:u,postagsFee:o,feeRate:l,inscriptions:T,commitOpReturnAuth:z,setOpen:C,onSuccess:X})=>{let{connectedInfo:_,connector:y}=de(),{loadSafeUTXOs:L,storeSafeTx:V}=pe(),[c,I]=(0,p.useState)(0),[P,N]=(0,p.useState)(!1),[g,f]=(0,p.useState)(),[B,h]=(0,p.useState)({}),[d,v]=(0,p.useState)(),[b,U]=(0,p.useState)([]),D=(0,p.useRef)(!1),Oe=()=>{h({}),Se()},x=[{title:"Connect Wallet",description:"Connect your wallet to get started",icon:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("img",{src:"/icons/wallet.svg",alt:"wallet",className:"dark:hidden"}),(0,e.jsx)("img",{src:"/icons/dark_wallet.svg",alt:"wallet",className:"hidden dark:inline"})]}),action:async()=>{if(!_)throw new Error("Please connect your wallet");return{connected:_}},result:({connected:s})=>(0,e.jsxs)("span",{children:["Connected to"," ",(0,e.jsx)("span",{className:"font-medium",children:S(s.account.address)})]})},{title:"Check UTXOs",description:"Check your UTXOs to see if you have enough funds",icon:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("img",{src:"/icons/check.svg",alt:"check",className:"dark:hidden"}),(0,e.jsx)("img",{src:"/icons/dark_check.svg",alt:"check",className:"hidden dark:inline"})]}),action:async({connected:s})=>{let{network:t,paymentAccount:n}=s,i=await le(t,n.address),a=await L(t,n.address,i),m=[...i,...a];if(m.length===0)throw new Error("No avaiable UTXOs found");return{connected:s,utxos:m}},result:()=>(0,e.jsx)("span",{children:"Fetch your UTXOs success"})},{title:"Build Commit Transactions",description:"Build commit transactions to send to the blockchain",icon:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("img",{src:"/icons/buildtx.svg",alt:"buildtx",className:"dark:hidden"}),(0,e.jsx)("img",{src:"/icons/dark_buildtx.svg",alt:"buildtx",className:"hidden dark:inline"})]}),action:async({connected:s,utxos:t})=>{if(!T||T.length===0||!l)throw new Error("Inscription or fee rate is empty");let{network:n,paymentAccount:i}=s,{commit_psbt:a,refund_vouts:m,reveal_tx_options:R}=await Ce({network:n,payment_account:i,fee_rate:l,postags_fee:o,inscriptions:T,utxos:t,op_return_auth:z});return{connected:s,commit_psbt:a,refund_vouts:m,reveal_tx_options:R}},result:()=>(0,e.jsx)("span",{children:"Transaction built"})},{title:"Build Reveal Transactions and Push Commit Transaction",description:"Build Reveal Transactions and Push the Commit Transaction",icon:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("img",{src:"/icons/sign.svg",alt:"sign",className:"dark:hidden"}),(0,e.jsx)("img",{src:"/icons/dark_sign.svg",alt:"sign",className:"hidden dark:inline"})]}),action:async({connected:s,commit_psbt:t,reveal_tx_options:n,refund_vouts:i})=>{if(!y)throw new Error("Please connect your wallet");let{network:a,account:m,paymentAccount:R}=s,E=await y.signPsbt(t.toHex(),{autoFinalized:!0,toSignInputs:t.data.inputs.map((We,Ee)=>({index:Ee,address:R.address}))}),Ue=Pe.Psbt.fromHex(E,{network:a}).extractTransaction().getId(),De=await _e({network:a,commit_tx_id:Ue,desitination_script:m.script.toString("hex"),postags_fee:o,reveal_tx_options:n}),ee=await j(a,E);return i&&i.length>0&&V(a,R.address,ee,i),{connected:s,reveal_psbts:De,commit_txid:ee}},result:({connected:s,commit_txid:t})=>(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:"Push commit transaction success."}),(0,e.jsxs)("a",{href:A(s.network,t),target:"_blank",className:"flex items-center space-x-2",rel:"noreferrer",children:["0x",S(t),(0,e.jsx)(W,{className:"h-4"})]})]})},{title:"Push Reveal Transactions",description:"Push the reveal transactions",icon:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("img",{src:"/icons/push.svg",alt:"push",className:"dark:hidden"}),(0,e.jsx)("img",{src:"/icons/dark_push.svg",alt:"push",className:"hidden dark:inline"})]}),action:async({commit_txid:s,reveal_psbts:t,connected:n})=>{await ce(2e3);let{network:i}=n,a=b;for(let m=0;m<t.length;m++){if(a[m])continue;let R=t[m],E=await j(i,R.toHex());window.logger?.log("reveal txid",E),a[m]=E}return U(a),{connected:n,commitTxId:s,revealTxIds:a}},result:({revealTxIds:s,network:t})=>(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:"Push reveal transaction success."}),s.map((n,i)=>(0,e.jsxs)("a",{href:A(t,n),target:"_blank",className:"flex items-center space-x-2",rel:"noreferrer",children:["0x",S(n),(0,e.jsx)(W,{className:"h-4"})]},i))]})}],Se=async()=>{window.umami?.track("inscribe");try{await Z()}catch(s){let t=s instanceof Error?s.message:"Unknown error";f(t),window.umami?.track("inscribe-failed",{error:t})}},Z=async s=>{let t=null;s&&s>0&&(t=d);for(let n=0;n<x.length;n++){if(s&&n<s)continue;let i=x[n];try{I(n),t=await i.action?.(t),v(t),i.result&&h({...B,[n]:i.result?.(t)})}catch(a){let m=a instanceof Y?a.description:a.message;throw new Error(m)}}Fe(t)},Fe=async({commitTxId:s,revealTxIds:t})=>{window.logger?.log("complete",s,t),I(x.length),U([])},Be=async()=>{f(void 0);try{await Z(c)}catch(s){f(s instanceof Error?s.message:"Unknown error")}};return(0,p.useEffect)(()=>{u&&!D.current&&(Oe(),D.current=!0)},[u]),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(G,{open:u,children:(0,e.jsxs)(Q,{className:H("inter bg-[url('/icons/bg_ripple.svg')] bg-no-repeat pt-9 dark:bg-[url('/icons/dark_bg_ripple.svg')] xs:max-w-md",{hidden:P,"bg-[url('/icons/bg-success.svg')] dark:bg-[url('/icons/bg-success.svg')]":c>=x.length}),children:[(0,e.jsxs)(J,{className:H("flex flex-row justify-between",{"xs:pl-7":c<x.length}),children:[(0,e.jsx)(K,{className:"font-bold dark:text-white-almost lg:text-xl",children:c<x.length?"Inscribe Progress":"Waiting for confirmation..."}),c<x.length&&(0,e.jsx)(ne,{className:"h-5 w-5 cursor-pointer hover:opacity-70",onClick:()=>N(!0)})]}),(0,e.jsx)(ve,{className:"scroll max-h-[70vh] w-full pr-1",children:c<x.length?(0,e.jsxs)("div",{className:" flex flex-col items-center",children:[(0,e.jsx)("ol",{className:"relative mb-8 ml-5 mt-3 flex max-w-xs flex-col space-y-7 border-l border-dashed border-gray-300 dark:border-dialog-background",children:x.map((s,t)=>(0,e.jsxs)("li",{className:"ml-7",children:[(0,e.jsx)("span",{className:H("absolute -left-[calc(1.25rem+1px)] flex h-10 w-10 items-center justify-center",{"rounded-full border border-inscribe-success bg-inscribe-success dark:border-none dark:bg-inscribe-success":t<c,"rounded-xl border border-gray-200 bg-background shadow dark:border-none dark:bg-item-foreground":t>=c,"rounded-full border border-inscribe-error bg-inscribe-error dark:border-none dark:bg-inscribe-error":t===c&&g}),children:t<c?(0,e.jsx)("img",{src:"/icons/inscribe_success.svg",alt:"inscribe_success"}):t===c?g?(0,e.jsx)("img",{src:"/icons/inscribe_error.svg",alt:"inscribe_error"}):(0,e.jsx)(re,{className:"h-5 w-5 animate-spin"}):s.icon}),(0,e.jsx)("h3",{className:"dark:text-wi text-base font-medium leading-tight",children:s.title}),(0,e.jsx)("p",{className:"text-sm text-search-placeholder dark:text-muted-background",children:t===c&&g?g:B[t]||s.description})]},t))}),g&&(0,e.jsx)(F,{className:"h-12 w-full",variant:"submit",onClick:Be,children:(0,e.jsx)("span",{children:"Retry"})})]}):(0,e.jsxs)("div",{className:"flex flex-col items-center space-y-4 py-2",children:[(0,e.jsx)(se,{className:"my-5 h-20 w-20 text-primary-green"}),(0,e.jsx)("p",{className:"text-center text-base font-medium lg:text-2xl",children:"Wallet preparing transaction submitted successfully..."}),(0,e.jsxs)("div",{className:"flex w-full flex-col items-center rounded-lg bg-item py-2",children:[(0,e.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,e.jsx)(M,{className:"text-foreground dark:text-secondary-foreground",children:"Commit Transaction:"}),(0,e.jsxs)("div",{className:"flex items-center space-x-2 px-4 py-2",children:[(0,e.jsxs)("a",{href:A(d.network,d.commitTxId),target:"_blank",className:"text-primary-blue",rel:"noreferrer",children:["0x",S(d?.commitTxId)]}),(0,e.jsx)(q,{content:d?.commitTxId,className:"h-6 p-1"})]})]}),(0,e.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,e.jsx)(M,{className:"text-foreground dark:text-secondary-foreground",children:"Reveal Transactions:"}),(0,e.jsx)("div",{className:"flex flex-col",children:d?.revealTxIds.map((s,t)=>(0,e.jsxs)("div",{className:"flex items-center space-x-2 px-4 py-2",children:[(0,e.jsxs)("a",{href:A(d.network,s),target:"_blank",className:"text-primary-blue",rel:"noreferrer",children:["0x",S(s)]}),(0,e.jsx)(q,{content:s,className:"h-6 p-1"})]},t))})]})]}),(0,e.jsxs)("div",{className:"flex w-full items-center space-x-2",children:[(0,e.jsx)(F,{onClick:()=>{D.current=!1,h({}),C(!1),X?.()},className:"h-12 w-full",variant:"submit",children:"Other"}),(0,e.jsx)(F,{onClick:()=>{D.current=!1,h({}),C(!1)},className:"h-12 w-full",variant:"submit",children:"Resume"})]})]})})]})}),(0,e.jsx)(G,{open:P,children:(0,e.jsxs)(Q,{className:"inter space-y-4 bg-[url('/icons/disclaimer.svg')] bg-no-repeat pt-20 dark:bg-[url('/icons/dark_disclaimer.svg')] xs:max-w-md",children:[(0,e.jsxs)(J,{children:[(0,e.jsx)(K,{className:"text-base font-bold md:text-xl",children:"Are you sure you want to cancel inscribe?"}),(0,e.jsx)("div",{className:"text-search-placeholder dark:text-muted-background",children:"This will cancel the inscribe process and you will have to start"})]}),(0,e.jsxs)(be,{className:"flex-row space-x-2",children:[(0,e.jsx)(F,{onClick:()=>N(!1),className:"h-12 w-full",variant:"nav",children:"Resume Inscribe"}),(0,e.jsx)(F,{className:"h-12 w-full",variant:"submit",onClick:()=>{N(!1),I(0),f(void 0),v(void 0),D.current=!1,U([]),h({}),C(!1)},children:"Cancel Inscribe"})]})]})})]})},st=Ae;O();var Re=w(ae(),1),k=w(te(),1);var r=w($(),1),Xe=({inscriptions:u,feeRate:o,postagsFee:l,onPostagsFeeChange:T,onEstimateFeeChange:z,opReturnAuth:C})=>{let X=fe(),_=u.length,{serviceFee:y,orginalServiceFee:L}=(0,k.useMemo)(()=>ue(),[]),V=L!==y,{commit_tx_vsize:c,reveal_tx_vsize:I}=(0,k.useMemo)(()=>Te({network:Re.networks.bitcoin,inscriptions:u,opReturnAuth:!!C}),[u,C]),P=(0,k.useMemo)(()=>o?Math.ceil(c*o):0,[c,o]),N=(0,k.useMemo)(()=>o?Math.ceil(I*o):0,[I,o]),g=(0,k.useMemo)(()=>l*_+P+N+y,[P,_,l,N,y]);(0,k.useEffect)(()=>{z?.(g)},[g]);let f=(d,v,b,U)=>(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"grid grid-cols-3 items-end justify-items-start gap-x-2 gap-y-5 text-sm",children:[(0,r.jsx)(ge,{className:"text-foreground dark:text-secondary-foreground",children:d}),(0,r.jsx)("div",{className:"oswald flex w-full items-center justify-end",children:U?v>0?(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"mr-1 line-through",children:L}),(0,r.jsxs)("span",{className:"text-primary-red",children:[v," ",(0,r.jsx)("span",{className:"inter",children:"sats"})," ",b&&b>1?`\xD7 ${b}`:""]})]}):(0,r.jsx)("span",{className:"inter text-primary-red",children:"Limited Free"}):(0,r.jsxs)("span",{children:[v," ",(0,r.jsx)("span",{className:"inter",children:"sats"})," ",b&&b>1?`\xD7 ${b}`:""]})}),(0,r.jsx)("span",{className:"oswald w-full text-right",children:X&&v>0?`~$${me(v*X*(b||1)/10**8)}`:"-"})]})}),B=546,h=1e4;return(0,r.jsxs)("div",{className:"inter flex flex-col space-y-5 rounded-2xl bg-accent-background p-3 text-search-icon dark:bg-item dark:text-muted md:p-6",children:[(0,r.jsxs)(ke,{children:[(0,r.jsx)("div",{className:"flex w-full justify-end",children:(0,r.jsx)(ye,{className:"pb-4 text-sm font-bold underline",children:"Custimise"})}),f("Sats In Inscription",l,_),(0,r.jsx)(Ne,{children:(0,r.jsxs)("div",{className:"mt-3 flex items-center space-x-2 py-1",children:[(0,r.jsx)(we,{step:1,max:h,min:B,value:[l],onValueChange:d=>T?.(d[0])}),(0,r.jsx)(he,{className:"oswald h-8 w-20 rounded-lg text-center",type:"number",step:1,min:B,max:h,value:l,onChange:d=>T?.(parseInt(d.target.value))})]})})]}),f("Commit Transaction Fee",P),f("Reveal Transaction Fee",N),f("Service Fee",y,void 0,V),(0,r.jsx)(xe,{orientation:"horizontal",className:"bg-muted-foreground dark:bg-dialog-foreground"}),f("Total",g)]})},ft=Xe;O();function vt(u,o="utf8"){let l=ie[o];if(l==null)throw new Error(`Unsupported encoding "${o}"`);return(o==="utf8"||o==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?oe(globalThis.Buffer.from(u,"utf-8")):l.decoder.decode(`${l.prefix}${u}`)}export{vt as a,st as b,ft as c};
