1import{an as we,r as l,N as ve,T as ye,i as J,M as Q,j as e,m as M,C as R,a as U,t as A}from"./index-g_xumml3.js";import{T as ee}from"./TokenModal-Czk3mgY6.js";import{T as Ne}from"./TxSettingsPanel-CgX_gcFQ.js";const se="0x0000000000000000000000000000000000000000";function Ce({addLiquidity:te,removeLiquidity:re,getTokenBalance:w,getPairAddress:$,getPairInfo:q,loading:I,txHash:O,error:W,isConnected:b,onConnectClick:le,initialTokenB:oe}){const{slippage:V,deadline:_,expertMode:ae}=we(),[x,X]=l.useState("add"),[t,ne]=l.useState(ve),[o,de]=l.useState(oe??ye[2]),[i,h]=l.useState(""),[c,g]=l.useState(""),[f,C]=l.useState(""),[ie,S]=l.useState(null),[Y,ce]=l.useState("0"),[D,xe]=l.useState("0"),[B,me]=l.useState(""),[r,H]=l.useState(null),[E,z]=l.useState("0"),[ue,T]=l.useState(!1),[fe,P]=l.useState(!1),[v,y]=l.useState(null),[K,pe]=l.useState(!1),j=l.useCallback(async()=>{if(!b)return;const[s,d]=await Promise.all([w(t.address),w(o.address)]);ce(s),xe(d);const a=await $(t.address,o.address);if(me(a),a&&a!==se){const m=await q(a);H(m);const u=await w(a);z(u)}else H(null),z("0")},[b,t,o,w,$,q]);l.useEffect(()=>{j()},[j]);const n=l.useMemo(()=>{if(!r)return null;const s=U.WETH.toLowerCase(),d=J(t.address)?s:t.address.toLowerCase(),a=r.token0.toLowerCase(),m=parseFloat(d===a?r.reserve0:r.reserve1),u=parseFloat(d===a?r.reserve1:r.reserve0);return!m||!u?null:{aPerB:m/u,bPerA:u/m,reserveA:m,reserveB:u}},[r,t.address]);l.useEffect(()=>{if(x!=="add"||v!=="A"||!n||!i)return;const s=parseFloat(i);!isNaN(s)&&s>0?g((s*n.bPerA).toFixed(6)):i===""&&g("")},[i,n,v,x]),l.useEffect(()=>{if(x!=="add"||v!=="B"||!n||!c)return;const s=parseFloat(c);!isNaN(s)&&s>0?h((s*n.aPerB).toFixed(6)):c===""&&h("")},[c,n,v,x]);const N=l.useMemo(()=>{if(!r||!f)return null;const s=parseFloat(f),d=parseFloat(r.totalSupply);if(!s||!d)return null;const a=s/d,m=U.WETH.toLowerCase(),u=J(t.address)?m:t.address.toLowerCase(),Z=r.token0.toLowerCase(),ge=parseFloat(u===Z?r.reserve0:r.reserve1),je=parseFloat(u===Z?r.reserve1:r.reserve0);return{outA:ge*a,outB:je*a,share:a*100}},[r,f,t.address]),p=l.useMemo(()=>{if(!n||!i||!c)return null;const s=parseFloat(i),d=parseFloat(c);if(!s||!d)return null;const a=d/s,m=n.bPerA;return Math.abs(a-m)/m*100},[n,i,c]),be=async()=>{if(!(!i||!c))try{const s=await te(t,o,i,c,parseFloat(V),parseFloat(_));A.success("Liquidity added!",{description:`${i} ${t.symbol} + ${c} ${o.symbol}`,action:{label:"View TX",onClick:()=>window.open(`${R.blockExplorer}/tx/${s}`,"_blank")}}),h(""),g(""),j()}catch(s){A.error("Add liquidity failed",{description:s.reason||s.message})}},he=async()=>{if(!(!f||!B))try{const s=await re(t,o,f,B,parseFloat(V),parseFloat(_));A.success("Liquidity removed!",{description:`Removed ${f} LP tokens`,action:{label:"View TX",onClick:()=>window.open(`${R.blockExplorer}/tx/${s}`,"_blank")}}),C(""),S(null),j()}catch(s){A.error("Remove liquidity failed",{description:s.reason||s.message})}},G=s=>{S(s);const d=parseFloat(E);if(!d)return;const a=(d*s/100).toFixed(6);C(a)},L=r&&B!==se,k=r?Q(r.token0):null,F=r?Q(r.token1):null;return e.jsxs(e.Fragment,{children:[e.jsxs(M.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"wolf-card rounded-2xl p-5 w-full max-w-lg mx-auto wolf-glow overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[e.jsxs("div",{className:"flex flex-1 bg-wolf-dark/50 rounded-xl p-1",children:[e.jsx("button",{onClick:()=>X("add"),className:`flex-1 py-2.5 rounded-lg text-sm font-semibold transition-all flex items-center justify-center gap-1.5 ${x==="add"?"bg-wolf-pink/20 text-wolf-pink border border-wolf-pink/40":"text-muted-foreground border border-transparent"}`,children:"+ Add Liquidity"}),e.jsx("button",{onClick:()=>X("remove"),className:`flex-1 py-2.5 rounded-lg text-sm font-semibold transition-all flex items-center justify-center gap-1.5 ${x==="remove"?"bg-wolf-pink/20 text-wolf-pink border border-wolf-pink/40":"text-muted-foreground border border-transparent"}`,children:"â Remove Liquidity"})]}),e.jsx("button",{onClick:()=>pe(!K),className:"p-2.5 rounded-xl bg-wolf-dark/50 hover:bg-wolf-surface border border-wolf-border/30 text-muted-foreground hover:text-wolf-pink transition-all","aria-label":"Slippage settings",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 00-2 2v.18a2 2 0 01-1 1.73l-.43.25a2 2 0 01-2 0l-.15-.08a2 2 0 00-2.73.73l-.22.38a2 2 0 00.73 2.73l.15.1a2 2 0 011 1.72v.51a2 2 0 01-1 1.74l-.15.09a2 2 0 00-.73 2.73l.22.38a2 2 0 002.73.73l.15-.08a2 2 0 012 0l.43.25a2 2 0 011 1.73V20a2 2 0 002 2h.44a2 2 0 002-2v-.18a2 2 0 011-1.73l.43-.25a2 2 0 012 0l.15.08a2 2 0 002.73-.73l.22-.39a2 2 0 00-.73-2.73l-.15-.08a2 2 0 01-1-1.74v-.5a2 2 0 011-1.74l.15-.09a2 2 0 00.73-2.73l-.22-.38a2 2 0 00-2.73-.73l-.15.08a2 2 0 01-2 0l-.43-.25a2 2 0 01-1-1.73V4a2 2 0 00-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}),e.jsx(Ne,{open:K}),x==="add"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl bg-wolf-dark/60 p-4 border border-wolf-border/20 mb-2",children:[e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mb-2",children:[e.jsx("span",{className:"uppercase tracking-wider font-medium",children:"Token A"}),e.jsxs("span",{children:["Balance: ",e.jsxs("button",{onClick:()=>{y("A"),h(Y)},className:"text-wolf-pink font-semibold",children:[parseFloat(Y).toFixed(4)," ",e.jsx("span",{className:"text-wolf-gold",children:"MAX"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"number",value:i,onChange:s=>{y("A"),h(s.target.value)},placeholder:"0.0",className:"flex-1 bg-transparent text-xl font-bold outline-none min-w-0"}),e.jsxs("button",{onClick:()=>T(!0),className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-wolf-surface hover:bg-wolf-surface-hover border border-wolf-border/40 shrink-0 transition-all",children:[e.jsx("img",{src:t.logo,alt:t.symbol,className:"w-6 h-6 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{className:"font-semibold text-sm",children:t.symbol}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]})]})]}),e.jsx("div",{className:"flex justify-center -my-1 relative z-10",children:e.jsx("div",{className:"w-8 h-8 rounded-lg bg-wolf-surface border border-wolf-border/40 flex items-center justify-center text-wolf-pink font-bold",children:"+"})}),e.jsxs("div",{className:"rounded-xl bg-wolf-dark/60 p-4 border border-wolf-border/20 mb-3",children:[e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mb-2",children:[e.jsxs("span",{className:"uppercase tracking-wider font-medium",children:["Token B ",n&&e.jsx("span",{className:"text-wolf-green/80 normal-case ml-1",children:"⢠auto"})]}),e.jsxs("span",{children:["Balance: ",e.jsxs("button",{onClick:()=>{y("B"),g(D)},className:"text-wolf-pink font-semibold",children:[parseFloat(D).toFixed(4)," ",e.jsx("span",{className:"text-wolf-gold",children:"MAX"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"number",value:c,onChange:s=>{y("B"),g(s.target.value)},placeholder:"0.0",className:"flex-1 bg-transparent text-xl font-bold outline-none min-w-0"}),e.jsxs("button",{onClick:()=>P(!0),className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-wolf-surface hover:bg-wolf-surface-hover border border-wolf-border/40 shrink-0 transition-all",children:[e.jsx("img",{src:o.logo,alt:o.symbol,className:"w-6 h-6 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{className:"font-semibold text-sm",children:o.symbol}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]})]})]}),n&&e.jsxs("div",{className:"rounded-xl bg-wolf-dark/40 p-3 border border-wolf-border/1
15 mb-3 text-xs",children:[e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:"Pool Ratio"}),e.jsxs("span",{className:"text-foreground",children:["1 ",t.symbol," â ",n.bPerA.toFixed(6)," ",o.symbol]})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground mt-1",children:[e.jsx("span",{children:"Inverse"}),e.jsxs("span",{className:"text-foreground",children:["1 ",o.symbol," â ",n.aPerB.toFixed(6)," ",t.symbol]})]})]}),!ae&&p!==null&&p>1&&e.jsxs(M.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:`rounded-xl p-3 mb-3 text-xs flex items-start gap-2 border ${p>10?"bg-destructive/10 border-destructive/40 text-destructive":p>5?"bg-yellow-500/10 border-yellow-500/40 text-yellow-500":"bg-wolf-gold/10 border-wolf-gold/30 text-wolf-gold"}`,children:[e.jsx("span",{className:"text-base leading-none",children:p>10?"ð¨":"â "}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"font-semibold mb-0.5",children:[p>10?"High price impact":p>5?"Notable price impact":"Slight price deviation"," (~",p.toFixed(2),"%)"]}),e.jsx("div",{className:"opacity-80",children:"Your input ratio differs from the pool ratio. The router will only accept the smaller paired amount and refund the rest."})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl bg-wolf-dark/60 p-4 border border-wolf-border/20 mb-3",children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium",children:"Your LP Tokens"}),e.jsx("span",{className:"text-2xl font-black text-foreground",children:parseFloat(E).toFixed(6)})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex -space-x-1.5",children:[e.jsx("img",{src:k?.logo||t.logo,alt:"",className:"w-4 h-4 rounded-full ring-1 ring-wolf-dark",onError:s=>{s.target.style.display="none"}}),e.jsx("img",{src:F?.logo||o.logo,alt:"",className:"w-4 h-4 rounded-full ring-1 ring-wolf-dark",onError:s=>{s.target.style.display="none"}})]}),e.jsxs("span",{children:[k?.symbol||t.symbol,"/",F?.symbol||o.symbol," LP"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1.5",children:"Token A"}),e.jsxs("button",{onClick:()=>T(!0),className:"w-full flex items-center gap-2 px-3 py-2.5 rounded-xl bg-wolf-surface hover:bg-wolf-surface-hover border border-wolf-border/40 transition-all",children:[e.jsx("img",{src:t.logo,alt:t.symbol,className:"w-6 h-6 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{className:"font-semibold text-sm flex-1 text-left",children:t.symbol}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1.5",children:"Token B"}),e.jsxs("button",{onClick:()=>P(!0),className:"w-full flex items-center gap-2 px-3 py-2.5 rounded-xl bg-wolf-surface hover:bg-wolf-surface-hover border border-wolf-border/40 transition-all",children:[e.jsx("img",{src:o.logo,alt:o.symbol,className:"w-6 h-6 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{className:"font-semibold text-sm flex-1 text-left",children:o.symbol}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]})]})]}),e.jsxs("div",{className:"rounded-xl bg-wolf-dark/60 p-4 border border-wolf-border/20 mb-3",children:[e.jsxs("div",{className:"flex justify-between text-xs mb-2",children:[e.jsx("span",{className:"uppercase tracking-wider font-medium text-muted-foreground",children:"Amount To Remove"}),e.jsx("button",{onClick:()=>G(100),className:"text-wolf-pink font-bold text-xs",children:"MAX"})]}),e.jsx("input",{type:"number",value:f,onChange:s=>{S(null),C(s.target.value)},placeholder:"0.0",className:"w-full bg-transparent text-2xl font-bold outline-none placeholder:text-muted-foreground
1/40"})]}),e.jsx("div",{className:"grid grid-cols-4 gap-2 mb-3",children:[25,50,75,100].map(s=>e.jsxs("button",{onClick:()=>G(s),className:`py-2.5 rounded-xl text-sm font-bold transition-all border ${ie===s?"bg-wolf-pink/20 text-wolf-pink border-wolf-pink/50":"bg-wolf-dark/60 border-wolf-border/30 text-foreground hover:bg-wolf-surface-hover"}`,children:[s,"%"]},s))}),N&&e.jsxs("div",{className:"rounded-xl bg-wolf-dark/40 p-3 border border-wolf-border/15 mb-3 space-y-1.5",children:[e.jsx("div",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-1",children:"You Will Receive"}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:t.logo,alt:"",className:"w-4 h-4 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{children:t.symbol})]}),e.jsx("span",{className:"font-bold text-wolf-green",children:N.outA.toFixed(6)})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:o.logo,alt:"",className:"w-4 h-4 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{children:o.symbol})]}),e.jsx("span",{className:"font-bold text-wolf-green",children:N.outB.toFixed(6)})]}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground border-t border-wolf-border/20 pt-1.5 mt-1",children:[e.jsx("span",{children:"Pool share"}),e.jsxs("span",{children:[N.share.toFixed(4),"%"]})]})]})]}),x==="add"&&e.jsxs("div",{className:"rounded-xl bg-wolf-dark/40 p-4 border border-wolf-border/15 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium",children:"Pool Information"}),e.jsx("div",{className:"flex items-center gap-1.5",children:L?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-wolf-green font-medium",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-wolf-green"})," Active Pool"]}):e.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-500 font-medium",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-yellow-500"})," No Pool"]})})]}),L&&r&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:k?.logo||t.logo,alt:"",className:"w-5 h-5 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{className:"text-sm",children:k?.symbol||t.symbol})]}),e.jsx("span",{className:"text-sm font-bold",children:parseFloat(r.reserve0).toFixed(4)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:F?.logo||o.logo,alt:"",className:"w-5 h-5 rounded-full",onError:s=>{s.target.style.display="none"}}),e.jsx("span",{className:"text-sm",children:F?.symbol||o.symbol})]}),e.jsx("span",{className:"text-sm font-bold",children:parseFloat(r.reserve1).toFixed(4)})]}),e.jsxs("div",{className:"border-t border-wolf-border/20 pt-2 mt-2",children:[e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Your LP"}),e.jsx("span",{className:"text-wolf-gold font-medium",children:parseFloat(E).toFixed(6)})]}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mt-1",children:[e.jsx("span",{children:"Total Supply"}),e.jsx("span",{children:parseFloat(r.totalSupply).toFixed(4)})]})]})]}),!L&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-2",children:"Be the first to add liquidity for this pair"})]}),e.jsx("button",{onClick:b?x==="add"?be:he:le,disabled:b&&(I||(x==="add"?!i||!c:!f)),className:"w-full py-4 rounded-2xl font-bold text-base wolf-btn-primary disabled:opacity-50 text-lg",children:b?I?"Processing...":x==="add"?"Add Liquidity":"Remove Liquidity":"Connect Wallet"}),e.jsx("div",{className:"flex items-center justify-center gap-4 mt-4 text-xs text-muted-foreground",children:e.jsx("button",{onClick:j,className:"flex items-center gap-1 hover:text-foreground transition-colors",children:"ð Refresh"})}),O&&e.jsxs(M.div,{initial:{opacity:0}
1,animate:{opacity:1},className:"mt-3 p-3 rounded-xl bg-green-500/10 border border-green-500/30 text-sm",children:[e.jsx("span",{className:"text-green-400",children:"â Success!"}),e.jsx("a",{href:`${R.blockExplorer}/tx/${O}`,target:"_blank",rel:"noopener noreferrer",className:"block text-xs text-wolf-gold hover:underline mt-1 truncate",children:"View on Explorer â"})]}),W&&e.jsx("div",{className:"mt-3 p-3 rounded-xl bg-destructive/10 border border-destructive/30 text-sm text-destructive",children:W})]}),e.jsx(ee,{isOpen:ue,onClose:()=>T(!1),onSelect:ne,excludeAddress:o.address}),e.jsx(ee,{isOpen:fe,onClose:()=>P(!1),onSelect:de,excludeAddress:t.address})]})}export{Ce as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.