2 lines
8.8 KiB
JavaScript
2 lines
8.8 KiB
JavaScript
import{d as E,o as O,c as o,a as e,J as $,E as N,D as n,h as R,i as D,T as P,b as B,g as F,H as T,G as b,x as H,r as i,B as _,F as I,P as S,f as q,n as U,q as a}from"./index-DnbYEqLr.js";const A={class:"pb-16 md:pb-4"},G={class:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"},J={class:"glass-card p-4"},K={class:"text-white text-xl font-bold"},Q={class:"glass-card p-4"},W={class:"text-white text-xl font-bold"},X={class:"glass-card p-4"},Y={class:"text-white text-xl font-bold"},Z={class:"flex justify-end mb-4"},ee={key:"loading",class:"glass-card p-12 text-center"},te={key:"error",class:"glass-card p-6 text-center"},se={class:"text-red-300 mb-4"},le={key:"empty",class:"glass-card p-8 text-center"},ne={key:"channels",class:"space-y-3"},oe={class:"flex items-center justify-between mb-3"},ae={class:"flex items-center gap-2"},ie={class:"text-white/80 text-sm font-medium capitalize"},re=["onClick"],ue=["title"],de={class:"mb-2"},ce={class:"flex justify-between text-xs text-white/60 mb-1"},pe={class:"h-2 bg-white/10 rounded-full overflow-hidden flex"},me={class:"text-white/40 text-xs mt-1 text-center"},xe={class:"glass-card p-6 w-full max-w-md mx-4"},ve={class:"space-y-4"},be={key:0,class:"mt-3 p-2 bg-red-500/20 border border-red-500/30 rounded-lg"},fe={class:"text-red-300 text-xs"},he={class:"flex gap-3 mt-6"},ge=["disabled"],we={class:"glass-card p-6 w-full max-w-sm mx-4"},ye={class:"text-white/60 text-sm mb-4"},_e={key:0,class:"mb-3 p-2 bg-red-500/20 border border-red-500/30 rounded-lg"},ke={class:"text-red-300 text-xs"},Ce={class:"flex gap-3"},Me=["disabled"],Fe=E({__name:"LightningChannels",setup($e){const j=H(),w=i(!0),f=i(null),h=i([]),y=i({total_inbound:0,total_outbound:0}),c=i(!1),r=i({peerUri:"",amount:1e5}),p=i(!1),d=i(null),u=i(null),m=i(!1),x=i(null);function v(l){return l>=1e8?`${(l/1e8).toFixed(2)} BTC`:l>=1e6?`${(l/1e6).toFixed(1)}M sats`:l>=1e3?`${(l/1e3).toFixed(1)}k sats`:`${l} sats`}function k(l,t){return t<=0?0:Math.round(l/t*100)}async function g(){w.value=!0,f.value=null;try{const l=await _.call({method:"lnd.listchannels",timeout:15e3});h.value=l.channels||[],y.value={total_inbound:l.total_inbound||0,total_outbound:l.total_outbound||0}}catch(l){f.value=l instanceof Error?l.message:"Failed to load channels"}finally{w.value=!1}}async function z(){if(p.value)return;d.value=null;const l=r.value.peerUri.trim();if(!l){d.value="Peer URI is required";return}if(r.value.amount<2e4){d.value="Minimum 20,000 sats";return}const t=l.split("@"),s=t[0],C=t[1]||void 0;p.value=!0;try{await _.call({method:"lnd.openchannel",params:{pubkey:s,address:C,amount:r.value.amount},timeout:3e4}),c.value=!1,r.value={peerUri:"",amount:1e5},await g()}catch(M){d.value=M instanceof Error?M.message:"Failed to open channel"}finally{p.value=!1}}function L(l){u.value=l,x.value=null}async function V(){if(!(m.value||!u.value)){x.value=null,m.value=!0;try{await _.call({method:"lnd.closechannel",params:{channel_point:u.value.channel_point},timeout:3e4}),u.value=null,await g()}catch(l){x.value=l instanceof Error?l.message:"Failed to close channel"}finally{m.value=!1}}}return O(g),(l,t)=>(a(),o("div",A,[e("button",{onClick:t[0]||(t[0]=s=>N(j).push("/dashboard/apps/lnd")),class:"mb-6 flex items-center gap-2 text-white/70 hover:text-white transition-colors"},[...t[8]||(t[8]=[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 19l-7-7 7-7"})],-1),$(" Back to LND ",-1)])]),t[21]||(t[21]=e("h1",{class:"text-2xl font-bold text-white mb-6"},"Lightning Channels",-1)),e("div",G,[e("div",J,[t[9]||(t[9]=e("p",{class:"text-white/60 text-sm mb-1"},"Total Outbound",-1)),e("p",K,n(v(y.value.total_outbound)),1)]),e("div",Q,[t[10]||(t[10]=e("p",{class:"text-white/60 text-sm mb-1"},"Total Inbound",-1)),e("p",W,n(v(y.value.total_inbound)),1)]),e("div",X,[t[11]||(t[11]=e("p",{class:"text-white/60 text-sm mb-1"},"Channels",-1)),e("p",Y,n(h.value.length),1)])]),e("div",Z,[e("button",{onClick:t[1]||(t[1]=s=>c.value=!0),class:"glass-button px-4 py-2 rounded-lg text-sm font-medium flex items-center gap-2"},[...t[12]||(t[12]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),$(" Open Channel ",-1)])])]),R(P,{name:"content-fade",mode:"out-in"},{default:D(()=>[w.value?(a(),o("div",ee,[...t[13]||(t[13]=[e("svg",{class:"animate-spin h-8 w-8 text-blue-400 mx-auto mb-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1),e("p",{class:"text-white/70"},"Loading channels...",-1)])])):f.value?(a(),o("div",te,[e("p",se,n(f.value),1),e("button",{onClick:g,class:"glass-button px-4 py-2 rounded-lg text-sm"},"Retry")])):h.value.length===0?(a(),o("div",le,[...t[14]||(t[14]=[e("svg",{class:"w-16 h-16 text-white/20 mx-auto mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 10V3L4 14h7v7l9-11h-7z"})],-1),e("p",{class:"text-white/70 mb-2"},"No channels yet",-1),e("p",{class:"text-white/50 text-sm"},"Open a channel to start sending and receiving Lightning payments.",-1)])])):(a(),o("div",ne,[(a(!0),o(I,null,S(h.value,s=>(a(),o("div",{key:s.chan_id||s.channel_point,class:"glass-card p-4"},[e("div",oe,[e("div",ae,[e("span",{class:q(["w-2 h-2 rounded-full",{"bg-green-400":s.status==="active","bg-yellow-400":s.status==="pending_open","bg-red-400":s.status==="inactive"}])},null,2),e("span",ie,n(s.status.replace("_"," ")),1)]),s.status!=="pending_open"?(a(),o("button",{key:0,onClick:C=>L(s),class:"text-red-400/70 hover:text-red-400 text-xs transition-colors"}," Close ",8,re)):b("",!0)]),e("p",{class:"text-white/50 text-xs font-mono mb-3 truncate",title:s.remote_pubkey},n(s.remote_pubkey),9,ue),e("div",de,[e("div",ce,[e("span",null,"Local: "+n(v(s.local_balance)),1),e("span",null,"Remote: "+n(v(s.remote_balance)),1)]),e("div",pe,[e("div",{class:"bg-blue-400 h-full transition-all",style:U({width:k(s.local_balance,s.capacity)+"%"})},null,4),e("div",{class:"bg-orange-400 h-full transition-all",style:U({width:k(s.remote_balance,s.capacity)+"%"})},null,4)]),e("p",me," Capacity: "+n(v(s.capacity)),1)])]))),128))]))]),_:1}),c.value?(a(),o("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/10 backdrop-blur-md",onClick:t[5]||(t[5]=B(s=>c.value=!1,["self"]))},[e("div",xe,[t[19]||(t[19]=e("h2",{class:"text-lg font-bold text-white mb-4"},"Open Channel",-1)),e("div",ve,[e("div",null,[t[15]||(t[15]=e("label",{class:"text-white/60 text-sm block mb-1"},"Peer URI",-1)),F(e("input",{"onUpdate:modelValue":t[2]||(t[2]=s=>r.value.peerUri=s),type:"text",placeholder:"pubkey@host:port",class:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-white/30"},null,512),[[T,r.value.peerUri]]),t[16]||(t[16]=e("p",{class:"text-white/40 text-xs mt-1"},"Format: pubkey@host:port",-1))]),e("div",null,[t[17]||(t[17]=e("label",{class:"text-white/60 text-sm block mb-1"},"Amount (sats)",-1)),F(e("input",{"onUpdate:modelValue":t[3]||(t[3]=s=>r.value.amount=s),type:"number",min:"20000",placeholder:"100000",class:"w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-white/30"},null,512),[[T,r.value.amount,void 0,{number:!0}]]),t[18]||(t[18]=e("p",{class:"text-white/40 text-xs mt-1"},"Minimum 20,000 sats",-1))])]),d.value?(a(),o("div",be,[e("p",fe,n(d.value),1)])):b("",!0),e("div",he,[e("button",{onClick:t[4]||(t[4]=s=>c.value=!1),class:"flex-1 glass-button px-4 py-2 rounded-lg text-sm"},"Cancel"),e("button",{onClick:z,disabled:p.value,class:"flex-1 glass-button px-4 py-2 rounded-lg text-sm font-medium bg-blue-500/20 border-blue-500/30"},n(p.value?"Opening...":"Open Channel"),9,ge)])])])):b("",!0),u.value?(a(),o("div",{key:1,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/10 backdrop-blur-md",onClick:t[7]||(t[7]=B(s=>u.value=null,["self"]))},[e("div",we,[t[20]||(t[20]=e("h2",{class:"text-lg font-bold text-white mb-2"},"Close Channel?",-1)),e("p",ye,"This will cooperatively close the channel with peer "+n(u.value.remote_pubkey.slice(0,16))+"...",1),x.value?(a(),o("div",_e,[e("p",ke,n(x.value),1)])):b("",!0),e("div",Ce,[e("button",{onClick:t[6]||(t[6]=s=>u.value=null),class:"flex-1 glass-button px-4 py-2 rounded-lg text-sm"},"Cancel"),e("button",{onClick:V,disabled:m.value,class:"flex-1 glass-button px-4 py-2 rounded-lg text-sm font-medium bg-red-500/20 border-red-500/30"},n(m.value?"Closing...":"Close"),9,Me)])])])):b("",!0)]))}});export{Fe as default};
|