PageSourceSearch

https://aircoinhaven.app/assets/ShoutboxCard-BO95gCxZ.js

js aircoinhaven.app collected 2026-10-08 12:43:11 UTC 15,877 bytes, 21 lines download raw bytes

1import{c as X,aq as x,ar as ge,as as ye,at as be,au as se,av as ve,aw as ae,ax as A,ay as we,u as Ne,a as je,a3 as _e,r as d,p as O,h as Me,w as re,s as w,t as h,j as s,C as ke,b as De,d as Se,B,az as Ce,e as Re,I as Te,L as Y,y as Ee,n as Ie,aA as qe,aB as Fe,aC as $e,ag as Le,X as Ae,aD as Oe}from"./bootstrap-ChjklGIm.js";import"./index-B73HoOBj.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Pe=X("CircleUser",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662",key:"154egf"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const ne=X("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const ie=X("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Xe=X("SmilePlus",[["path",{d:"M22 11v1a10 10 0 1 1-9-10",key:"ew0xw9"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}],["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}]]);function P(l,i){const r=x(l),a=x(i),n=r.getTime()-a.getTime();return n<0?-1:n>0?1:n}function He(l){return ge(l,Date.now())}function ze(l){return i=>{const a=(l?Math[l]:Math.trunc)(i);return a===0?0:a}}function Ke(l,i){return+x(l)-+x(i)}function Qe(l){const i=x(l);return i.setHours(23,59,59,999),i}function Be(l){const i=x(l);return+Qe(i)==+ye(i)}function Ye(l,i){const r=x(l),a=x(i),n=P(r,a),p=Math.abs(be(r,a));let b;if(p<1)b=0;else{r.getMonth()===1&&r.getDate()>27&&r.setDate(30),r.setMonth(r.getMonth()-n*p);let c=P(r,a)===-n;Be(x(l))&&p===1&&P(l,a)===1&&(c=!1),b=n*(p-Number(c))}return b===0?0:b}function Ue(l,i,r){const a=Ke(l,i)/1e3;return ze(r==null?void 0:r.roundingMethod)(a)}function We(l,i,r){const a=we(),n=(r==null?void 0:r.locale)??a.locale??ve,p=2520,b=P(l,i);if(isNaN(b))throw new RangeError("Invalid time value");const c=Object.assign({},r,{addSuffix:r==null?void 0:r.addSuffix,comparison:b});let M,k;b>0?(M=x(i),k=x(l)):(M=x(l),k=x(i));const N=Ue(k,M),C=(se(k)-se(M))/1e3,u=Math.round((N-C)/60);let g;if(u<2)return r!=null&&r.includeSeconds?N<5?n.formatDistance("lessThanXSeconds",5,c):N<10?n.formatDistance("lessThanXSeconds",10,c):N<20?n.formatDistance("lessThanXSeconds",20,c):N<40?n.formatDistance("halfAMinute",0,c):N<60?n.formatDistance("lessThanXMinutes",1,c):n.formatDistance("xMinutes",1,c):u===0?n.formatDistance("lessThanXMinutes",1,c):n.formatDistance("xMinutes",u,c);if(u<45)return n.formatDistance("xMinutes",u,c);if(u<90)return n.formatDistance("aboutXHours",1,c);if(u<ae){const v=Math.round(u/60);return n.formatDistance("aboutXHours",v,c)}else{if(u<p)return n.formatDistance("xDays",1,c);if(u<A){const v=Math.round(u/ae);return n.formatDistance("xDays",v,c)}else if(u<A*2)return g=Math.round(u/A),n.formatDistance("aboutXMonths",g,c)}if(g=Ye(k,M),g<12){const v=Math.round(u/A);return n.formatDistance("xMonths",v,c)}else{const v=g%12,y=Math.trunc(g/12);return v<3?n.formatDistance("aboutXYears",y,c):v<9?n.formatDistance("overXYears",y,c):n.formatDistance("almostXYears",y+1,c)}}function Je(l,i){return We(l,He(l),i)}const oe=["👍","🔥","🚀","❤️","😄","🤣"],Ge=()=>{const{publicKey:l}=Ne(),{walletSignature:i,walletSignedMessage:r}=je(),a=l==null?void 0:l.toBase58(),n=_e(),[p,b]=d.useState(""),[c,M]=d.useState(!1),[k,N]=d.useState(!1),[C,u]=d.useState(""),[g,v]=d.useState(!1),[y,H]=d.useState(null),[T,U]=d.use
21State(null),[E,W]=d.useState(null),le=d.useRef(null),J=d.useRef(null),I=d.useRef(null),{data:D,isLoading:ce}=O({queryKey:["shoutbox"],queryFn:async()=>{const{data:e,error:t}=await w.from("shoutbox_messages").select("*").order("created_at",{ascending:!1}).limit(50);if(t)throw t;return e.reverse()},staleTime:3e4}),{data:q}=O({queryKey:["shoutbox-reactions"],queryFn:async()=>{const{data:e,error:t}=await w.from("shoutbox_reactions").select("*");if(t)throw t;return e},staleTime:3e4}),de=d.useMemo(()=>{const e={};return q==null||q.forEach(t=>{e[t.message_id]||(e[t.message_id]={}),e[t.message_id][t.emoji]||(e[t.message_id][t.emoji]={count:0,hasReacted:!1}),e[t.message_id][t.emoji].count++,t.wallet_address===a&&(e[t.message_id][t.emoji].hasReacted=!0)}),e},[q,a]),{data:F}=O({queryKey:["shoutbox-leaderboard"],queryFn:async()=>{const{data:e}=await w.from("holder_leaderboard").select("snapshot_at").order("snapshot_at",{ascending:!1}).limit(1);if(!e||e.length===0)return[];const{data:t,error:o}=await w.from("holder_leaderboard").select("wallet_address, balance").eq("snapshot_at",e[0].snapshot_at).order("rank",{ascending:!0});if(o)throw o;return t},staleTime:6e4}),{data:$}=O({queryKey:["holder-profiles"],queryFn:async()=>{const{data:e,error:t}=await w.from("holder_profiles").select("wallet_address, display_name");if(t)throw t;return e},staleTime:3e4}),ue=d.useMemo(()=>{const e={};return F==null||F.forEach(t=>{e[t.wallet_address]=Number(t.balance)}),e},[F]),V=d.useMemo(()=>{const e={};return $==null||$.forEach(t=>{e[t.wallet_address]=t.display_name}),e},[$]),{balance:R}=Me(),S=re(R),z=a?V[a]:void 0;d.useEffect(()=>{const e=w.channel("shoutbox-realtime").on("postgres_changes",{event:"INSERT",schema:"public",table:"shoutbox_messages"},t=>{n.setQueryData(["shoutbox"],o=>o?[...o,t.new].slice(-50):[t.new])}).on("postgres_changes",{event:"DELETE",schema:"public",table:"shoutbox_messages"},t=>{var m;const o=(m=t.old)==null?void 0:m.id;o&&n.setQueryData(["shoutbox"],j=>j?j.filter(_=>_.id!==o):[])}).on("postgres_changes",{event:"INSERT",schema:"public",table:"shoutbox_reactions"},t=>{n.setQueryData(["shoutbox-reactions"],o=>o?[...o,t.new]:[t.new])}).on("postgres_changes",{event:"DELETE",schema:"public",table:"shoutbox_reactions"},t=>{var m;const o=(m=t.old)==null?void 0:m.id;o&&n.setQueryData(["shoutbox-reactions"],j=>j?j.filter(_=>_.id!==o):[])}).subscribe();return()=>{w.removeChannel(e)}},[n]),d.useEffect(()=>{var t;const e=(t=J.current)==null?void 0:t.closest("[data-radix-scroll-area-viewport]");e&&(e.scrollTop=e.scrollHeight)},[D==null?void 0:D.length]);const me=d.useCallback(e=>{const t=e.target.value.slice(0,280);b(t);const o=e.target;o.style.height="auto",o.style.height=Math.min(o.scrollHeight,80)+"px"},[]),L=d.useCallback(async e=>{if(!(!a||!e.trim()||c)){if(!i||!r){h({title:"Sign-in required",description:"Please sign the wallet message to post.",variant:"destructive"});return}M(!0);try{const{data:t,error:o}=await w.functions.invoke("shoutbox-post",{body:{wallet_address:a,message:e.trim(),...y?{reply_to_id:y.id}:{},...i&&r?{signature:i,signed_message:r}:{}}});if(o){const m=typeof t=="object"&&(t!=null&&t.error)?t.error:"Failed to send message";h({title:"Error",description:m,variant:"destructive"});return}if(t!=null&&t.error){h({title:"Error",description:t.error,variant:"destructive"});return}b(""),H(null),I.current&&(I.current.style.height="auto")}catch{h({title:"Error",description:"Failed to send message",variant:"destructive"})}finally{M(!1)}}},[a,c,i,r,y]),Z=d.useCallback(()=>L(p),[L,p]),fe=d.useCallback(()=>{if(!S||c)return;const e=R>=1e6?`${(R/1e6).toFixed(2)}M`:R>=1e3?`${(R/1e3).toFixed(1)}K`:R.toLocaleString();L(`${S.emoji} I'm a ${S.name}! Holding ${e} AIRCOIN 🚀`)},[S,R,c,L]),he=d.useCallback(async e=>{if(!(!a||T)){if(!i||!r){h({title:"Sign-in required",description:"Please sign the wallet message to delete.",variant:"destructive"});return}U(e);try{const{data:t,error:o}=await w.functions.invoke("shoutbox-delete",{body:{wallet_address:a,message_id:e,...i&&r?{signature:i,signed_message:r}:{}}});if(o||t!=null&&t.error){h({title:"Error",description:(t==null?void 0:t.error)||"Failed to delete",variant:"destructive"});return}n.setQueryData(["shoutbox"],m=>m?m.filter(j=>j.id!==e):[])}catch{h({title:"Error",description:"Failed to delete message",variant:"destructive"})}finally{U(null)}}},[a,T,i,r,n]),G=d.useCallback(async(e,t)=>{if(!(!a||E)){if(!i||!r){h({title:"Sign-in required",description:"Please sign the wallet message to react.",variant:"destructive"});return}W(`${e}-${t}`);try{const{data:o,error:m}=await w.functions.invoke("shoutbox-react",{body:{wallet_address:a,message_id:e,emoji:t,signature:i,signed_message:r}});if(m||o!=null&&o.error){h({title:"Error",description:(o==null?void 0:o.error)||"Failed to react",variant:"destructive"});return}n.invalidateQueries({queryKey:["shoutbox-reactions"]})}catch{h({title:"Error",description:"Failed to react",variant:"destructive"})}finally{W(null)}}},[a,E,n,i,r]),ee=d.useCallback(async()=>
21{if(!(!a||!C.trim()||g)){if(!i||!r){h({title:"Sign-in required",description:"Please sign the wallet message to set a display name.",variant:"destructive"});return}v(!0);try{const{data:e,error:t}=await w.functions.invoke("set-display-name",{body:{wallet_address:a,display_name:C.trim(),...i&&r?{signature:i,signed_message:r}:{}}});if(t||e!=null&&e.error){h({title:"Error",description:(e==null?void 0:e.error)||"Failed to set name",variant:"destructive"});return}h({title:"Name set!",description:`You're now known as "${e.display_name}"`}),N(!1),u(""),n.invalidateQueries({queryKey:["holder-profiles"]})}catch{h({title:"Error",description:"Failed to set name",variant:"destructive"})}finally{v(!1)}}},[a,C,g,n,i,r]),K=(e,t)=>{const o=V[e];return t?o||"You":o||"Anon"},xe=e=>!e||!D?null:D.find(t=>t.id===e)||null;return s.jsxs(ke,{className:"glass-card gradient-border sonic-glow h-full",children:[s.jsx(De,{className:"pb-2",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs(Se,{className:"flex items-center gap-2 text-lg",children:[s.jsx("span",{className:`inline-flex ${a&&S?"cursor-pointer hover:scale-110 transition-transform":""}`,onClick:a&&S?fe:void 0,title:S?`Share your ${S.name} rank`:void 0,children:s.jsx(ne,{className:"h-5 w-5 text-primary"})}),"Community Chat"]}),a&&s.jsxs(B,{variant:"ghost",size:"sm",className:"text-xs gap-1 h-7",onClick:()=>{N(!k),u(z||"")},children:[z?s.jsx(Ce,{className:"h-3 w-3"}):s.jsx(Pe,{className:"h-3 w-3"}),z||"Set Name"]})]})}),s.jsxs(Re,{className:"pt-0 flex flex-col gap-3",children:[k&&a&&s.jsxs("div",{className:"flex gap-2 p-2 rounded-lg bg-secondary/30 border border-primary/20",children:[s.jsx(Te,{placeholder:"Username (2-20 chars, a-z 0-9 _)",value:C,onChange:e=>u(e.target.value.slice(0,20)),onKeyDown:e=>e.key==="Enter"&&ee(),disabled:g,className:"flex-1 h-8 text-xs"}),s.jsx(B,{size:"sm",onClick:ee,disabled:!C.trim()||g,className:"h-8",children:g?s.jsx(Y,{className:"h-3 w-3 animate-spin"}):"Save"})]}),s.jsx(Ee,{className:"h-[300px]",ref:le,children:ce?s.jsx("div",{className:"space-y-2",children:Array.from({length:6}).map((e,t)=>s.jsx(Ie,{className:"h-10 w-full"},t))}):!D||D.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground text-sm py-12",children:[s.jsx(ne,{className:"h-8 w-8 mb-2 opacity-50"}),s.jsx("p",{children:"No messages yet."}),s.jsx("p",{className:"text-xs",children:"Be the first to say something!"})]}):s.jsxs("div",{className:"space-y-2 pr-3",children:[D.map(e=>{const t=e.wallet_address===a,o=ue[e.wallet_address]||0,m=re(o),j=K(e.wallet_address,t),_=xe(e.reply_to_id),Q=de[e.id]||{},pe=Object.keys(Q).length>0;return s.jsxs("div",{className:`rounded-lg p-2.5 group ${t?"bg-primary/10 border border-primary/20":"bg-secondary/30"}`,children:[_&&s.jsxs("div",{className:"mb-1.5 pl-2 border-l-2 border-primary/30 text-[11px] text-muted-foreground/70 truncate",children:[s.jsx("span",{className:"font-medium",children:K(_.wallet_address,_.wallet_address===a)}),": ",_.message.slice(0,60),_.message.length>60?"…":""]}),s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:[m?`${m.emoji} `:"",j]}),s.jsxs("div",{className:"flex items-center gap-1",children:[a&&s.jsxs(qe,{children:[s.jsx(Fe,{asChild:!0,children:s.jsx("button",{className:"opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-primary/10",title:"React",children:s.jsx(Xe,{className:"h-3 w-3 text-muted-foreground"})})}),s.jsx($e,{className:"w-auto p-1.5 flex gap-1",side:"top",align:"end",children:oe.map(f=>s.jsx("button",{onClick:()=>G(e.id,f),disabled:E===`${e.id}-${f}`,className:"text-base hover:scale-125 transition-transform p-1 rounded hover:bg-secondary/50 disabled:opacity-50",children:f},f))})]}),a&&s.jsx("button",{onClick:()=>{var f;H(e),(f=I.current)==null||f.focus()},className:"opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-primary/10",title:"Reply",children:s.jsx(ie,{className:"h-3 w-3 text-muted-foreground"})}),t&&s.jsx("button",{onClick:()=>he(e.id),disabled:T===e.id,className:"opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-destructive/10",title:"Delete message",children:T===e.id?s.jsx(Y,{className:"h-3 w-3 animate-spin text-destructive"}):s.jsx(Le,{className:"h-3 w-3 text-destructive"})}
21),s.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:Je(new Date(e.created_at),{addSuffix:!0})})]})]}),s.jsx("p",{className:"text-sm break-words",children:e.message}),pe&&s.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:oe.filter(f=>Q[f]).map(f=>{const te=Q[f];return s.jsxs("button",{onClick:()=>a&&G(e.id,f),disabled:!a||E===`${e.id}-${f}`,className:`inline-flex items-center gap-0.5 text-xs px-1.5 py-0.5 rounded-full border transition-colors disabled:opacity-50 ${te.hasReacted?"bg-primary/20 border-primary/40 text-foreground":"bg-secondary/30 border-border/50 text-muted-foreground hover:bg-secondary/50"}`,children:[s.jsx("span",{children:f}),s.jsx("span",{className:"text-[10px] font-medium",children:te.count})]},f)})})]},e.id)}),s.jsx("div",{ref:J})]})}),y&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-md bg-secondary/40 border border-primary/20 text-xs text-muted-foreground",children:[s.jsx(ie,{className:"h-3 w-3 text-primary shrink-0"}),s.jsxs("span",{className:"truncate flex-1",children:["Replying to ",s.jsx("span",{className:"font-medium",children:K(y.wallet_address,y.wallet_address===a)}),": ",y.message.slice(0,50),y.message.length>50?"…":""]}),s.jsx("button",{onClick:()=>H(null),className:"shrink-0 p-0.5 rounded hover:bg-secondary",children:s.jsx(Ae,{className:"h-3 w-3"})})]}),s.jsxs("div",{className:"flex gap-2 items-end",children:[s.jsx("textarea",{ref:I,placeholder:a?"Type a message...":"Connect wallet to chat",value:p,onChange:me,onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Z())},disabled:!a||c,spellCheck:!0,autoCapitalize:"sentences",rows:1,className:"flex-1 resize-none rounded-md border border-input bg-background px-3 py-2 text-sm r
21ing-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",style:{minHeight:"40px",maxHeight:"80px"}}),s.jsx(B,{size:"icon",onClick:Z,disabled:!a||!p.trim()||c,className:"shrink-0",children:c?s.jsx(Y,{className:"h-4 w-4 animate-spin"}):s.jsx(Oe,{className:"h-4 w-4"})})]}),s.jsxs("p",{className:"text-[10px] text-muted-foreground/60 text-right",children:[p.length,"/280"]})]})]})};export{Ge 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.