diff --git a/assets/index-7e672544.js b/assets/index-403c60df.js similarity index 98% rename from assets/index-7e672544.js rename to assets/index-403c60df.js index 0da6dba..bd326c3 100644 --- a/assets/index-7e672544.js +++ b/assets/index-403c60df.js @@ -433,4 +433,4 @@ Error generating stack: `+i.message+` * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var qf=b,JG=XG;function eq(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var tq=typeof Object.is=="function"?Object.is:eq,nq=JG.useSyncExternalStore,rq=qf.useRef,oq=qf.useEffect,iq=qf.useMemo,sq=qf.useDebugValue;GP.useSyncExternalStoreWithSelector=function(e,t,n,r,o){var i=rq(null);if(i.current===null){var s={hasValue:!1,value:null};i.current=s}else s=i.current;i=iq(function(){function l(p){if(!c){if(c=!0,u=p,p=r(p),o!==void 0&&s.hasValue){var v=s.value;if(o(v,p))return d=v}return d=p}if(v=d,tq(u,p))return v;var h=r(p);return o!==void 0&&o(v,h)?v:(u=p,d=h)}var c=!1,u,d,f=n===void 0?null:n;return[function(){return l(t())},f===null?void 0:function(){return l(f())}]},[t,n,r,o]);var a=nq(e,i[0],i[1]);return oq(function(){s.hasValue=!0,s.value=a},[a]),sq(a),a};HP.exports=GP;var aq=HP.exports;const lq=Ge(aq),{useSyncExternalStoreWithSelector:cq}=lq;function uq(e,t=e.getState,n){const r=cq(e.subscribe,e.getState,e.getServerState||e.getState,t,n);return b.useDebugValue(r),r}const Cx=e=>{const t=typeof e=="function"?VG(e):e,n=(r,o)=>uq(t,r,o);return Object.assign(n,t),n},dq=e=>e?Cx(e):Cx,Ls=25,Eg={"wss://nos.lol":{read:!0,write:!1},"wss://nostr.wine":{read:!0,write:!1}};function fq(){const e=localStorage.getItem("nostr-client:keystore:keystore");if(e)if(e==="localstore"){const t=localStorage.getItem("nostr-client:keystore:public-key"),n=localStorage.getItem("nostr-client:keystore:private-key");if(t&&n)return{keystore:"localstore",publicKey:t,privateKey:n}}else{if(e==="nos2x")return{keystore:"nos2x",publicKey:void 0,privateKey:void 0};if(e==="download")return{keystore:"download",publicKey:void 0,privateKey:void 0}}return{keystore:"none",publicKey:void 0,privateKey:void 0}}function Ex(e){localStorage.setItem("nostr-client:keystore:keystore",e.keystore),e.keystore==="localstore"&&e.publicKey&&e.privateKey?(localStorage.setItem("nostr-client:keystore:public-key",e.publicKey),localStorage.setItem("nostr-client:keystore:private-key",e.privateKey)):e.keystore==="nos2x"||e.keystore}const Tx=new Worker(new URL("/nostr-ts/assets/worker-3bdd9117.js",self.location),{type:"module"});function hq(e,t){let n=null,r=[];return function(o){r.push(o),n||(n=setTimeout(()=>{e(r),r=[],n=null},t))}}const Q=dq((e,t)=>({store:VP(Tx),init:async n=>{await t().loadKeyStore(),await t().store.init(n);const o=hq(i=>{i.forEach(s=>{const a=s.data;if(a.type==="event:new"||a.type==="event:update"){const l=a.data;a.type==="event:new"?t().addEvent(l):a.type==="event:update"&&t().updateEvent(l)}else if(a.type==="relay:message"){const l=a.data;e({relayEvents:[...t().relayEvents,l]})}else a.type==="event:queue:update"&&t().updateQueueItem(a.data)})},100);Tx.addEventListener("message",o)},connected:!1,connect:async n=>{t().connected||(await t().store.connect(n),e({connected:!0}))},disconnect:async()=>{await t().store.disconnect(),e({connected:!1})},getRelays:async()=>t().store.getRelays(),updateRelay:async(n,r)=>t().store.updateRelay(n,r),relayEvents:[],getSubscriptions:async()=>t().store.getSubscriptions(),subscribe:async n=>t().store.subscribe(n),unsubscribe:async n=>(console.log(`Unsubscribing ${n}`),t().store.unsubscribe(n)),unsubscribeAll:async()=>(console.log("Unsubscribing all"),t().store.unsubscribeAll()),keystore:"none",loadKeyStore:()=>{const n=fq();e({keystore:n.keystore}),n.keystore==="localstore"&&n.publicKey&&n.privateKey&&e({keypair:{publicKey:n.publicKey,privateKey:n.privateKey},keypairIsLoaded:!0})},saveKeyStore:()=>{const n=t().keystore;if(n==="localstore"){const r=t().keypair;Ex(r?{keystore:n,publicKey:r.publicKey,privateKey:r.privateKey}:{keystore:n})}},setKeyStore:n=>{n.keystore==="localstore"?(console.log(`Setting keystore for ${n.keystore}`,n),n.publicKey&&n.privateKey&&(e({keystore:n.keystore,keypair:{publicKey:n.publicKey,privateKey:n.privateKey},keypairIsLoaded:!0}),t().saveKeyStore())):n.keystore==="nos2x"?e({keystore:n.keystore,keypair:{publicKey:n.publicKey||""}}):console.error(`Unknown keystore ${n.keystore}`)},keypair:{publicKey:"",privateKey:""},keypairIsLoaded:!1,newEvent:new rn({kind:Or.SHORT_TEXT_NOTE}),setNewEvent:n=>{e({newEvent:n})},newEventName:"NewShortTextNote",setNewEventName:n=>{e({newEventName:n})},setNewEventContent:n=>{e({newEvent:t().newEvent.setContentWithoutChecks(n)})},count:async n=>t().store.count(n),events:[],addEvent:n=>{e({events:[...t().events,n]})},updateEvent:n=>{const r=t().events.findIndex(o=>o.event.id===n.event.id);if(r!==-1){const o=[...t().events];o[r]=n,e({events:o})}},maxEvents:Ls,setMaxEvents:async n=>{await t().store.setMaxEvents(n),e({maxEvents:n})},determineApplicableRelays:async n=>{const r=await t().getRelays();return{relays:(n.relayIds?r.filter(i=>{var s;return(s=n.relayIds)==null?void 0:s.includes(i.id)}):r).filter(i=>i.isReady&&i.write===!0),pow:0}},generateQueueItems:async n=>{const{relays:r}=await t().determineApplicableRelays(n),o=[];for(const i of r)if(i.isReady&&i.write){const{relayIds:s,...a}=n,l={...a,id:PW(),relayId:i.id,send:!1};o.push(l)}return o},addQueueItems:n=>{e({eventsPublishingQueue:[...t().eventsPublishingQueue,...n]})},updateQueueItem:async n=>{const r=t().eventsPublishingQueue,o=r.findIndex(i=>i.event.id===n.event.id);if(o!==-1){const i=[...r];i[o]=n,e({eventsPublishingQueue:i})}},getUser:async n=>t().store.getUser(n),addUser:async n=>t().store.addUser(n),updateUser:async n=>t().store.updateUser(n),countUsers:async()=>t().store.countUsers(),getEventById:n=>t().store.getEventById(n),eventProofOfWork:async(n,r)=>new Promise(o=>{const i=new Worker(new URL("/nostr-ts/assets/pow-worker-46de68b7.js",self.location),{type:"module"});i.onmessage=function(s){o(s.data.result),i.terminate()},i.postMessage({event:n,bits:r})}),sendEvent:async n=>t().store.sendEvent(n),signAndSendEvent:async n=>{var d,f,p,v;const r=t().keypair;if(!r)throw new Error("Keypair not initialized");const o=t().keystore;let i=n.event;i.pubkey=r.publicKey,i.generateId();const{relays:s,pow:a}=await t().determineApplicableRelays(n);if(s.length===0)throw new Error("No (write-enabled) relays available. Check relays.");let l=n.pow;const c=a;if(l&&l!==0){if(l0){u=await t().generateQueueItems({...n,pow:l}),(f=(d=t()).addQueueItems)==null||f.call(d,u);const h=await t().eventProofOfWork(n.event,l);i=new rn(h);for(const x of u)x.event=i,x.powDone=Date.now()}if(o==="localstore")i.sign({privateKey:r.privateKey||"",publicKey:r.publicKey});else if(o==="nos2x")if(window.nostr&&window.nostr.signEvent){const h=await window.nostr.signEvent(i.ToObj());if(!h.sig)throw new Error("No signature");i.sig=h.sig}else throw new Error("Nostr not initialized");else throw new Error("Invalid keystore");if(i.isReadyToPublishOrThrow(),u.length===0)u=await t().generateQueueItems({...n,pow:l,event:i}),(v=(p=t()).addQueueItems)==null||v.call(p,u);else for(const h of u)h.event=i,t().updateQueueItem(h);return await t().store.sendQueueItems(u),i.id},eventsPublishingQueue:[],clearEvents:async()=>{await t().store.clearEvents(),e({events:[]})},followUser:async n=>{await t().store.followUser(n);const r=await t().store.getAllUsersFollowing();r&&e({followingUserIds:r.map(o=>o.user.pubkey)})},unfollowUser:async n=>{await t().store.unfollowUser(n);const r=await t().store.getAllUsersFollowing();r&&e({followingUserIds:r.map(o=>o.user.pubkey)})},followingUser:async n=>t().store.followingUser(n),followingUserIds:[],getAllUsersFollowing:async()=>t().store.getAllUsersFollowing(),updateUserFollowing:async n=>t().store.updateUserFollowing(n),requestInformation:(n,r)=>t().store.requestInformation(n,r),hasSubscriptionForEventIds:async(n,r)=>t().store.hasSubscriptionForEventIds(n,r),hasViewSubscription:async n=>(await t().getSubscriptions()).some(o=>o.options&&o.options.view===n),setViewSubscription:async(n,r)=>{const o=await t().getSubscriptions();if(o.find(a=>a.options&&a.options.view===n)){console.log(`Already subscribed to view ${n}`);return}for(const a of o)a.options&&a.options.view&&await t().unsubscribe(a.id);const s=await t().getRelays();await t().subscribe({type:H0.REQ,filters:{...r,limit:r.limit?Math.round(r.limit/s.length):void 0},options:{view:n,timeout:1e4,timeoutAt:Date.now()+1e4}}),setTimeout(async()=>{var v,h;const a=[],l=[];for(const x of t().events)(v=x.event)!=null&&v.pubkey&&!((h=x.user)!=null&&h.pubkey)&&a.push({pubkey:x.event.pubkey,relayIds:x.eventRelayIds}),x.reactions||l.push({id:x.event.id,relayIds:x.eventRelayIds});const c={};for(const x of a)for(const y of x.relayIds)c[y]||(c[y]=new Set),c[y].add(x.pubkey);const u=Object.entries(c).map(([x,y])=>({source:"users",relayId:x,idsOrKeys:[...y]})),d={};for(const x of l)for(const y of x.relayIds)d[y]||(d[y]=new Set),d[y].add(x.id);const f=Object.entries(d).map(([x,y])=>({source:"events",relayId:x,idsOrKeys:[...y]})),p=[];for(const x of[...u,...f])p.push(await t().requestInformation(x,{timeout:1e4,timeoutAt:Date.now()+1e4}))},5e3)},removeViewSubscription:async n=>{const r=await t().getSubscriptions();if(console.log(`Remove view subscription ${n}`),!n){const s=r.map(a=>t().unsubscribe(a.id));await Promise.all(s);return}const i=r.filter(s=>s.options&&s.options.view===n).map(s=>t().unsubscribe(s.id));await Promise.all(i)}}));function pq(){const[e]=Q(d=>[d.keystore]),[t]=Q(d=>[d.keypairIsLoaded]),[n]=Q(d=>[d.keypair]),[r]=Q(d=>{var f;return[((f=d==null?void 0:d.keypair)==null?void 0:f.publicKey)||""]}),[o,i]=b.useState(!1),s=Hl(),[a,l]=b.useState(!1),c=()=>{const d=rG();Q.getState().setKeyStore({keystore:"localstore",publicKey:d.publicKey,privateKey:d.privateKey})},u=async d=>{if(l(!0),window.nostr)try{const f=await window.nostr.getPublicKey();console.log(f),Q.getState().setKeyStore({keystore:"nos2x",publicKey:f,privateKey:""}),l(!1)}catch(f){console.error("Error loading public key:",f),l(!1)}else{console.log(`Nostr extention not ready, retry ${d}`);const f=d?d+1:1;if(f>2){s({title:"Error loading relays",description:"nos2x extention not available or ready.",status:"error",duration:5e3,isClosable:!0}),l(!1);return}setTimeout(()=>u(f),1e3)}};return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Account"}),t?g.jsxs(xe,{fontWeight:"bold",children:["Keypair loaded from ",e,"."]}):g.jsxs(g.Fragment,{children:[g.jsx(xe,{fontWeight:"bold",marginBottom:2,children:"Keypair is not loaded."}),g.jsx(xe,{marginBottom:2,children:"If you generate a new keypair, it will be stored in the browser local store (insecure). Alternatively get nos2x for Chrome, or nos2x-fox for Firefox, and store your keys in the extention (less insecure)."}),g.jsxs(Mn,{children:[g.jsx(Oe,{onClick:c,children:"Generate new keypair"}),g.jsx(Oe,{isLoading:a,onClick:()=>u(),children:"Load from nos2x"})]})]}),n&&g.jsxs(Se,{mt:4,children:[g.jsxs(Sl,{marginBottom:4,children:[g.jsx(kl,{children:"Public key:"}),g.jsx(li,{type:"text",value:r,isReadOnly:!0})]}),g.jsxs(Sl,{marginBottom:4,children:[g.jsx(kl,{children:"Private key:"}),g.jsxs(Mn,{spacing:2,children:[g.jsx(li,{type:o?"text":"password",value:n.privateKey,isReadOnly:!0}),g.jsx(Oe,{isDisabled:e!=="localstore",size:"sm",onClick:()=>i(!o),children:o?"Hide":"Show"})]})]})]})]})}function mq(){const[e,t]=b.useState(0),[n,r,o]=Q(l=>[l.events.length,l.maxEvents,l.relayEvents]),[i,s]=b.useState(0),a=Hl();return b.useEffect(()=>{const l=setInterval(async()=>{const c=await Q.getState().countUsers();c&&t(c)},1e3);return()=>clearInterval(l)},[]),b.useEffect(()=>{const l=o.length;if(l>0){const c=l-i;if(c>0){s(l);const u=o.slice(-c);for(const d of u){let f="";if(d.data[0]===Ea.NOTICE)f=d.data[1];else if(d.data[0]===Ea.OK)f=`${d.data[2]}. Event ${d.data[1]}: ${d.data[3]}`;else{if(d.data[0]===Ea.EOSE)return;d.data[0]===Ea.COUNT&&(f=`Relay ${d.data[1]}: ${JSON.stringify(d.data[2])} events`)}f!==""&&a({title:`Relay ${d.data[0]}`,position:"top-right",description:f,status:"info",duration:5e3,isClosable:!0})}}}},[o]),g.jsx(Se,{position:"fixed",bottom:0,left:0,right:0,bg:"white",boxShadow:"md",p:3,children:g.jsx(Mn,{spacing:4,children:g.jsxs(g.Fragment,{children:[g.jsxs(Mn,{spacing:2,children:[g.jsx(xe,{fontSize:"sm",children:"Events:"}),g.jsxs(xe,{fontSize:"xl",marginLeft:1,children:[n," (max ",r,")"]})]}),g.jsxs(Mn,{spacing:2,children:[g.jsx(xe,{fontSize:"sm",children:"Users:"}),g.jsx(xe,{fontSize:"xl",children:e})]})]})})})}function _i({label:e,value:t,to:n,leftIcon:r}){return g.jsx(X9,{as:xW,to:n,w:"100%",padding:2,border:"1px solid",borderColor:"gray.200",borderRadius:2,backgroundColor:"gray.100",_hover:{backgroundColor:"gray.300"},_activeLink:{backgroundColor:"gray.300"},children:g.jsxs(Mn,{children:[r,g.jsx(xe,{fontSize:"md",fontWeight:"bold",children:e}),t&&g.jsx(xe,{fontSize:"md",children:t})]})})}function gq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Ad=gq(b),vq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Px=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=yq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Ad.createElement("svg",vq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Ad.createElement("path",{d:"M4,1C2.89,1 2,1.89 2,3V7C2,8.11 2.89,9 4,9H1V11H13V9H10C11.11,9 12,8.11 12,7V3C12,1.89 11.11,1 10,1H4M4,3H10V7H4V3M3,13V18L3,20H10V18H5V13H3M14,13C12.89,13 12,13.89 12,15V19C12,20.11 12.89,21 14,21H11V23H23V21H20C21.11,21 22,20.11 22,19V15C22,13.89 21.11,13 20,13H14M14,15H20V19H14V15Z"}))},bq=Ad.memo?Ad.memo(Px):Px,wq=bq;const xq=Ge(wq);function Sq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var $d=Sq(b),kq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},_x=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Cq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return $d.createElement("svg",kq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),$d.createElement("path",{d:"M4,1C2.89,1 2,1.89 2,3V7C2,8.11 2.89,9 4,9H1V11H13V9H10C11.11,9 12,8.11 12,7V3C12,1.89 11.11,1 10,1H4M4,3H10V7H4V3M14,13C12.89,13 12,13.89 12,15V19C12,20.11 12.89,21 14,21H11V23H23V21H20C21.11,21 22,20.11 22,19V15C22,13.89 21.11,13 20,13H14M3.88,13.46L2.46,14.88L4.59,17L2.46,19.12L3.88,20.54L6,18.41L8.12,20.54L9.54,19.12L7.41,17L9.54,14.88L8.12,13.46L6,15.59L3.88,13.46M14,15H20V19H14V15Z"}))},Eq=$d.memo?$d.memo(_x):_x,Tq=Eq;const Pq=Ge(Tq);function _q(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Od=_q(b),Rq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Rx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Aq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Od.createElement("svg",Rq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Od.createElement("path",{d:"M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z"}))},$q=Od.memo?Od.memo(Rx):Rx,Oq=$q;const Iq=Ge(Oq);function jq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Id=jq(b),Lq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ax=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Mq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Id.createElement("svg",Lq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Id.createElement("path",{d:"M11 10V12H9V14H7V12H5.8C5.4 13.2 4.3 14 3 14C1.3 14 0 12.7 0 11S1.3 8 3 8C4.3 8 5.4 8.8 5.8 10H11M3 10C2.4 10 2 10.4 2 11S2.4 12 3 12 4 11.6 4 11 3.6 10 3 10M16 14C18.7 14 24 15.3 24 18V20H8V18C8 15.3 13.3 14 16 14M16 12C13.8 12 12 10.2 12 8S13.8 4 16 4 20 5.8 20 8 18.2 12 16 12Z"}))},Bq=Id.memo?Id.memo(Ax):Ax,zq=Bq;const Fq=Ge(zq);function Nq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var jd=Nq(b),Dq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},$x=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Vq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return jd.createElement("svg",Dq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),jd.createElement("path",{d:"M14 10H3V12H14V10M14 6H3V8H14V6M3 16H10V14H3V16M21.5 11.5L23 13L16 20L11.5 15.5L13 14L16 17L21.5 11.5Z"}))},Uq=jd.memo?jd.memo($x):$x,Wq=Uq;const Hq=Ge(Wq);function Gq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Ld=Gq(b),qq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ox=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Kq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Ld.createElement("svg",qq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Ld.createElement("path",{d:"M16 17V19H2V17S2 13 9 13 16 17 16 17M12.5 7.5A3.5 3.5 0 1 0 9 11A3.5 3.5 0 0 0 12.5 7.5M15.94 13A5.32 5.32 0 0 1 18 17V19H22V17S22 13.37 15.94 13M15 4A3.39 3.39 0 0 0 13.07 4.59A5 5 0 0 1 13.07 10.41A3.39 3.39 0 0 0 15 11A3.5 3.5 0 0 0 15 4Z"}))},Zq=Ld.memo?Ld.memo(Ox):Ox,Yq=Zq;const Qq=Ge(Yq);function Xq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Md=Xq(b),Jq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ix=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=eK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Md.createElement("svg",Jq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Md.createElement("path",{d:"M21.4 7.5C22.2 8.3 22.2 9.6 21.4 10.3L18.6 13.1L10.8 5.3L13.6 2.5C14.4 1.7 15.7 1.7 16.4 2.5L18.2 4.3L21.2 1.3L22.6 2.7L19.6 5.7L21.4 7.5M15.6 13.3L14.2 11.9L11.4 14.7L9.3 12.6L12.1 9.8L10.7 8.4L7.9 11.2L6.4 9.8L3.6 12.6C2.8 13.4 2.8 14.7 3.6 15.4L5.4 17.2L1.4 21.2L2.8 22.6L6.8 18.6L8.6 20.4C9.4 21.2 10.7 21.2 11.4 20.4L14.2 17.6L12.8 16.2L15.6 13.3Z"}))},tK=Md.memo?Md.memo(Ix):Ix,nK=tK;const rK=Ge(nK);function oK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Bd=oK(b),iK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},jx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=sK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Bd.createElement("svg",iK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Bd.createElement("path",{d:"M18 5H6V7H18M6 9H18V11H6M2 12H4V17H20V12H22V17A2 2 0 0 1 20 19H4A2 2 0 0 1 2 17M18 13H6V15H18Z"}))},aK=Bd.memo?Bd.memo(jx):jx,lK=aK;const cK=Ge(lK);function Lx(e){return Object.entries(e).map(([t,{read:n,write:r}])=>({url:t,read:n,write:r}))}function uK({isOpen:e,onClose:t}){const[n,r]=b.useState(Lx(Eg)),[o,i]=b.useState(""),[s,a]=b.useState(!1),[l,c]=b.useState(!1),u=Hl(),d=async p=>{if(a(!0),window.nostr&&window.nostr.getRelays)try{const v=await window.nostr.getRelays();r(Lx(v)),a(!1)}catch(v){console.error("Error loading relays:",v);let h="Unknown error";v instanceof Error&&(h=v.message),u({title:"Error loading relays",description:h,status:"error",duration:5e3,isClosable:!0}),a(!1)}else{console.log(`Nostr extention not ready, retry ${p}`);const v=p?p+1:1;if(v>2){u({title:"Error loading relays",description:"nos2x extention not available or ready.",status:"error",duration:5e3,isClosable:!0}),a(!1);return}setTimeout(()=>d(v),1e3)}},f=async()=>{c(!0),await Q.getState().connect(n),c(!1),t()};return g.jsxs(Us,{isOpen:e,onClose:t,children:[g.jsx(Gs,{}),g.jsxs(Ws,{children:[g.jsx(Hs,{children:"Connect to Relay(s)"}),g.jsx(Yl,{}),g.jsxs(qs,{children:[g.jsxs(xe,{children:["You can find a list of relays in the nostr-ts repository",g.jsx(sg,{marginLeft:1,href:"https://github.com/franzos/nostr-ts/blob/master/discovered-relays.json",isExternal:!0,color:"blue.500",children:"github.com/franzos/nostr-ts"}),",",g.jsx(sg,{marginLeft:1,marginRight:1,href:"https://nostr.info/relays/",isExternal:!0,color:"blue.500",children:"nostr.info"}),"and elsewhere."]}),g.jsx(Ha,{spacing:3,width:"100%",children:n&&n.map(p=>g.jsxs(pd,{width:"100%",alignItems:"center",borderBottom:"1px solid",borderColor:"gray.200",py:2,children:[g.jsx(xe,{flex:"1",marginLeft:"2",children:p.url}),g.jsx(Oe,{ml:"auto",onClick:()=>{const v=n.filter(h=>h.url!==p.url);r(v)},children:"Remove"})]},p.url))}),g.jsxs(pd,{direction:"row",alignItems:"center",children:[g.jsx(li,{flex:"1",value:o,onChange:p=>i(p.target.value),placeholder:"Enter new relay URL"}),g.jsx(Oe,{ml:2,onClick:()=>{o.trim()!==""&&(r([...n,{url:o,read:!0,write:!0}]),i(""))},children:"Add"})]}),g.jsx(Oe,{isLoading:s,onClick:()=>d(),size:"xs",marginTop:2,children:"Load from nos2x"})]}),g.jsx(R0,{children:g.jsx(Oe,{colorScheme:"green",isDisabled:n.length===0,isLoading:l,onClick:f,children:"Connect"})})]})]})}function dK(){const[e,t,n]=Q(v=>[v.connected,v.keystore,v.eventsPublishingQueue.length]),[r,o]=b.useState(0),[i,s]=b.useState([]),[a,l]=b.useState(0),{isOpen:c,onOpen:u,onClose:d}=ql(),f=async()=>{const v=await Q.getState().getAllUsersFollowing();v&&s(v);const h=await Q.getState().getSubscriptions();h&&o(h.length);const x=await Q.getState().getRelays();x&&l(x.length)};b.useEffect(()=>{(async()=>{await f()})();const h=setInterval(f,1e3);return()=>clearInterval(h)},[]);const p=g.jsxs(Ha,{align:"start",spacing:5,w:"100%",children:[g.jsx(_i,{label:"Home",to:"/",leftIcon:g.jsx($e,{as:Iq,marginRight:1})}),e&&g.jsxs(g.Fragment,{children:[g.jsx(_i,{label:"Following",value:i.length,to:"/following",leftIcon:g.jsx($e,{as:Qq,marginRight:1})}),g.jsx(_i,{label:"Subscriptions",value:r,to:"/subscriptions",leftIcon:g.jsx($e,{as:Hq,marginRight:1})}),g.jsx(_i,{label:"Relays",value:a,to:"/relays",leftIcon:g.jsx($e,{as:rK,marginRight:1})}),g.jsx(_i,{label:"Queue",value:n,to:"/queue",leftIcon:g.jsx($e,{as:cK,marginRight:1})})]}),g.jsx(_i,{label:"Account",value:t,to:"/account",leftIcon:g.jsx($e,{as:Fq,marginRight:1})}),e?g.jsxs(Oe,{w:"100%",colorScheme:"red",onClick:Q.getState().disconnect,children:[g.jsx($e,{as:Pq,marginRight:1}),"Disconnect"]}):g.jsx(Oe,{w:"100%",colorScheme:"green",onClick:u,leftIcon:g.jsx($e,{as:xq}),children:"Connect to relay(s)"})]});return g.jsxs(TT,{maxW:"8xl",p:5,children:[g.jsxs(Ha,{spacing:5,align:"stretch",children:[g.jsx(Ha,{spacing:1,align:"start",children:g.jsx(Vt,{as:"h1",size:"lg",children:"Nostr Client"})}),g.jsxs(zf,{templateColumns:["1fr","1fr 4fr"],gap:20,children:[p,g.jsx(Se,{maxHeight:"80vh",overflowY:"auto",children:g.jsx(uW,{})})]})]}),g.jsx(mq,{}),uK({isOpen:c,onOpen:u,onClose:d})]})}function fK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var zd=fK(b),hK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Mx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=pK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return zd.createElement("svg",hK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),zd.createElement("path",{d:"M23,10C23,8.89 22.1,8 21,8H14.68L15.64,3.43C15.66,3.33 15.67,3.22 15.67,3.11C15.67,2.7 15.5,2.32 15.23,2.05L14.17,1L7.59,7.58C7.22,7.95 7,8.45 7,9V19A2,2 0 0,0 9,21H18C18.83,21 19.54,20.5 19.84,19.78L22.86,12.73C22.95,12.5 23,12.26 23,12V10M1,21H5V9H1V21Z"}))},mK=zd.memo?zd.memo(Mx):Mx,gK=mK;const vK=Ge(gK);function yK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Fd=yK(b),bK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Bx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=wK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Fd.createElement("svg",bK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Fd.createElement("path",{d:"M19,15H23V3H19M15,3H6C5.17,3 4.46,3.5 4.16,4.22L1.14,11.27C1.05,11.5 1,11.74 1,12V14A2,2 0 0,0 3,16H9.31L8.36,20.57C8.34,20.67 8.33,20.77 8.33,20.88C8.33,21.3 8.5,21.67 8.77,21.94L9.83,23L16.41,16.41C16.78,16.05 17,15.55 17,15V5C17,3.89 16.1,3 15,3Z"}))},xK=Fd.memo?Fd.memo(Bx):Bx,SK=xK;const kK=Ge(SK);function CK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Nd=CK(b),EK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},zx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=TK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Nd.createElement("svg",EK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Nd.createElement("path",{d:"M17,17H7V14L3,18L7,22V19H19V13H17M7,7H17V10L21,6L17,2V5H5V11H7V7Z"}))},PK=Nd.memo?Nd.memo(zx):zx,_K=PK;const ZP=Ge(_K),RK=e=>{const t=new Date,n=new Date(e*1e3),r=t.getTime()-n.getTime(),o=Math.floor(r/1e3),i=Math.floor(o/60),s=Math.floor(i/60);return o<60?`${o} seconds ago`:i<60?`${i} minutes ago`:s<24?`${s} hours ago`:`${n.toLocaleDateString()} ${n.toLocaleTimeString()}`};function AK({userComponent:e,event:t,reactions:n,reposts:r,eventRelayIds:o}){var B;const[i]=Q($=>[$.connected&&$.keystore!=="none"]),s=Hl(),[a,l]=b.useState(0),[c,u]=b.useState(0),[d,f]=b.useState(0),[p,v]=b.useState({});b.useEffect(()=>{u((n==null?void 0:n.filter($=>$.content==="-").length)||0),l((n==null?void 0:n.filter($=>$.content==="+").length)||0),f((r==null?void 0:r.length)||0),v((n==null?void 0:n.filter($=>$.content!=="+"&&$.content!=="-").reduce(($,P)=>($[P.content]?$[P.content]+=1:$[P.content]=1,$),{}))||{})},[n]);const h=(B=t==null?void 0:t.content)==null?void 0:B.match(/\bhttps?:\/\/\S+?\.(?:jpg|jpeg|png|gif)\b/gi),{isOpen:x,onOpen:y,onClose:m}=ql(),[w,S]=b.useState(null),C=$=>{S($),y()},T=async()=>{const P=(await Q.getState().getRelays()).find(j=>j.id===o[0]);if(!P){s({title:"Error",description:`Relay ${o[0]} not found`,status:"error",duration:5e3,isClosable:!0});return}const I=kG({text:"",inResponseTo:{id:t.id,pubkey:t.pubkey},relayUrl:P.url});Q.getState().setNewEvent(I),Q.getState().setNewEventName("NewShortTextNoteResponse")},E=async($,P)=>{let I;switch($){case"quote":I=MP({inResponseTo:t,relayUrl:""});break;case"reaction":if(!P)throw new Error("Reaction is required");I=CG({text:P,inResponseTo:{id:t.id,pubkey:t.pubkey}});break;default:return}try{const j=await Q.getState().signAndSendEvent({event:I});j&&(s({title:"Success",description:`Event ${j} submitted`,status:"success",duration:5e3,isClosable:!0}),Q.getState().requestInformation({source:"events",idsOrKeys:[j],relayId:o[0]},{timeout:1e4,timeoutAt:Date.now()+1e4}))}catch(j){let V="";j instanceof Error?V=j.message:V=j?j.toString():"Unknown error",s({title:"Error",description:V,status:"error",duration:5e3,isClosable:!0});return}},_=()=>g.jsxs(Mn,{children:[g.jsx(Oe,{size:"sm",variant:"solid",colorScheme:"blue",onClick:()=>T(),isDisabled:!i,children:"Reply"}),g.jsx(Oe,{size:"sm","aria-label":"Upvote",leftIcon:g.jsx($e,{as:vK}),onClick:()=>E("reaction","+"),isDisabled:!i,children:a}),g.jsx(Oe,{size:"sm","aria-label":"Downvote",leftIcon:g.jsx($e,{as:kK}),onClick:()=>E("reaction","-"),isDisabled:!i,children:c}),g.jsx(Oe,{size:"sm","aria-label":"Repost",leftIcon:g.jsx($e,{as:ZP}),onClick:()=>E("quote"),isDisabled:!i,children:d}),p&&Object.keys(p).map($=>g.jsxs(Oe,{size:"sm","aria-label":"Repost",isDisabled:!0,children:[$," ",p[$]]},$))]});return g.jsxs(g.Fragment,{children:[g.jsxs(cD,{border:"1px solid #e1e1e1",overflow:"hidden",children:[g.jsx(lD,{p:0,children:g.jsxs(Se,{children:[h&&(h==null?void 0:h.length)>0&&g.jsx(Se,{className:"image-container",marginBottom:4,children:h.map(($,P)=>g.jsx(Ca,{src:$,fallback:g.jsx(Ca,{src:"/no-image.png"}),fallbackStrategy:"onError",alt:"",onClick:()=>C($)},P))}),g.jsx(Se,{p:4,paddingBottom:0,children:e&&e})]})}),g.jsxs(sD,{p:4,children:[g.jsx(xe,{children:t.content}),g.jsx(xe,{fontWeight:"bold",fontSize:12,marginTop:2,children:RK(t.created_at)})]}),g.jsx(aD,{p:4,children:g.jsxs(Mn,{children:[g.jsx(_,{}),g.jsxs(xe,{children:["Relay ",o[0].substring(0,5),"..."]})]})})]}),g.jsxs(Us,{isOpen:x,onClose:m,size:"full",closeOnOverlayClick:!0,children:[g.jsx(Gs,{}),g.jsxs(Ws,{children:[g.jsx(Hs,{children:e&&e}),g.jsx(qs,{children:g.jsx(Ca,{src:w||"",fallback:g.jsx(Ca,{src:"/no-image.png"}),fallbackStrategy:"onError",alt:"Enlarged view",height:"80vh",marginLeft:"auto",marginRight:"auto"})}),g.jsxs(R0,{children:[g.jsx(_,{}),g.jsx(Oe,{marginLeft:4,onClick:m,children:"Close"})]})]})]})]})}function YP(e){const[t,n]=Q(s=>[s.events,s.maxEvents]),[r,o]=b.useState(0),i=async()=>{r===0&&o(r+1),await Q.getState().setMaxEvents(n+Ls),e&&await Q.getState().setViewSubscription(e.view,e.filters)};return g.jsxs(Se,{maxHeight:"80vh",overflowY:"auto",children:[t.map(s=>g.jsx(Se,{padding:2,children:g.jsx(AK,{event:s.event,user:s.user,reactions:s.reactions,reposts:s.reposts,eventRelayIds:s.eventRelayIds,userComponent:e&&e.userComponent?s.user&&s.user.pubkey?g.jsx(e.userComponent,{user:s.user,relayId:s.eventRelayIds[0]}):g.jsx(e.userComponent,{user:{pubkey:s.event.pubkey},relayId:s.eventRelayIds[0]}):void 0},s.event.id)},s.event.id)),t.length===0&&g.jsx(xe,{children:"Waiting for fresh content ... hold on."}),t.length>=n&&g.jsxs(Se,{display:"flex",justifyContent:"space-between",padding:2,children:[g.jsxs(Oe,{flex:"1",marginRight:2,onClick:i,children:["Load ",Ls," more"]}),g.jsx(Oe,{flex:"1",marginLeft:2,onClick:async()=>Q.getState().clearEvents(),children:"Reset and load new (performance)"})]})]})}function Kf({user:e,relayId:t,hideFollow:n}){const[r]=Q(c=>[c.followingUserIds.find(u=>u===e.pubkey)]),o=e.data?e.data:null,i=o&&o.display_name?o.display_name:"Anonymous",s=o&&o.name?o.name:"Anonymous",a=o&&o.picture?o.picture:"/no-image.png",l=`/p/${t}/${e.pubkey}`;return g.jsxs(pd,{children:[g.jsx(Se,{mr:"3",children:g.jsx(FE,{size:"sm",src:a})}),g.jsx(Se,{children:g.jsxs(rP,{to:l,children:[g.jsx(Vt,{size:"sm",children:i}),g.jsx(xe,{fontSize:"sm",children:s})]})}),g.jsx(kT,{}),!n&&g.jsx(Oe,{variant:"outline",colorScheme:r?"red":"green",onClick:()=>r?Q.getState().unfollowUser(e.pubkey):Q.getState().followUser({pubkey:e.pubkey,relayId:t}),children:r?"Unfollow":"Follow"})]})}function $K(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Dd=$K(b),OK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Fx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=IK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Dd.createElement("svg",OK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Dd.createElement("path",{d:"M2,21L23,12L2,3V10L17,12L2,14V21Z"}))},jK=Dd.memo?Dd.memo(Fx):Fx,LK=jK;const MK=Ge(LK);function BK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Vd=BK(b),zK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Nx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=FK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Vd.createElement("svg",zK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Vd.createElement("path",{d:"M4,9H20V11H4V9M4,13H14V15H4V13Z"}))},NK=Vd.memo?Vd.memo(Nx):Nx,DK=NK;const VK=Ge(DK);function UK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Ud=UK(b),WK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Dx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=HK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Ud.createElement("svg",WK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Ud.createElement("path",{d:"M4,5H20V7H4V5M4,9H20V11H4V9M4,13H20V15H4V13M4,17H14V19H4V17Z"}))},GK=Ud.memo?Ud.memo(Dx):Dx,qK=GK;const KK=Ge(qK);function ZK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Wd=ZK(b),YK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Vx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=QK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Wd.createElement("svg",YK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Wd.createElement("path",{d:"M10,9V5L3,12L10,19V14.9C15,14.9 18.5,16.5 21,20C20,15 17,10 10,9Z"}))},XK=Wd.memo?Wd.memo(Vx):Vx,JK=XK;const eZ=Ge(JK);function tZ(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Hd=tZ(b),nZ=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ux=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=rZ(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Hd.createElement("svg",nZ({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Hd.createElement("path",{d:"M12,6C8.6,6 5.5,7.1 3,9L1.2,6.6C4.2,4.3 8,3 12,3C16,3 19.8,4.3 22.8,6.6L21,9C18.5,7.1 15.4,6 12,6M13,19C13,17.7 13.4,16.4 14.2,15.4C13.5,15.2 12.8,15 12,15C10.7,15 9.4,15.5 8.4,16.2L12,21L13,19.6C13,19.4 13,19.2 13,19M16.8,13.4C17.1,13.3 17.5,13.2 17.9,13.1L19.2,11.4C17.2,9.9 14.7,9 12,9C9.3,9 6.8,9.9 4.8,11.4L6.6,13.8C8.1,12.7 10,12 12,12C13.8,12 15.4,12.5 16.8,13.4M16.5,22.6L17.2,19.8L15,17.9L17.9,17.7L19,15L20.1,17.6L23,17.8L20.8,19.7L21.5,22.5L19,21.1L16.5,22.6Z"}))},oZ=Hd.memo?Hd.memo(Ux):Ux,iZ=oZ;const sZ=Ge(iZ);async function _p(e,t){try{let n=await Promise.race([fetch(e,{headers:t}),new Promise((o,i)=>setTimeout(()=>i(new Error("Timeout")),5e3))]);if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){throw new Error(`Error making request: ${n}`)}}var Tg=class extends RG{constructor(e){super(e)}async makeZapRequest(e,t){const n=this.getLud16Or06Url();if(n)try{if(!this.hasZapInfo()){const s=await _p(n.url);if(!lG(s))throw new Error("Lnurl endpoint does not allow Nostr payments. Expected to find 'allowsNostr' in response.");this.lightningZapInfo=s}console.log("LnurlEndpointResponse",this.lightningZapInfo);const r={...e,recipientPubkey:this.pubkey,lnurl:n.type==="lud16"?pG(this.getLud16()):this.getLud06()},o=PG(r,this.lightningZapInfo.callback,t),i=await _p(o.invoiceUrl);if(!cG(r,i))throw new Error("Lnurl invoice response is invalid or does not match your request.");return console.log("LnurlInvoiceResponse",i),{...i,event:o.event}}catch(r){throw new Error(`Error making zap request: ${r}`)}else throw new Error("No lud16 or lud06 url found")}async makeNIP05Request(){const e=this.getNip05Url();if(e)try{return await _p(e)}catch(t){throw new Error(`Error making NIP05 request: ${t}`)}else throw new Error("No nip05 url found")}};const QP=()=>{var y;const[e]=Q(m=>[m.connected&&m.keystore!=="none"]),[t,n]=b.useState([]),[r,o,i,s,a]=Q(m=>{var w;return[m.keystore,m.keypair,((w=m.newEvent)==null?void 0:w.kind)||0,m.newEventName,m.newEvent]}),l=Hl(),[c,u]=b.useState([]),[d]=Q(m=>{var w;return[(w=m.newEvent)==null?void 0:w.hasPublicKeyTags()]}),[f,p]=b.useState("");b.useEffect(()=>{(async()=>{const w=[];if(d)for(const S of d){S.length===2&&p(S[1]);const C=S[0],T=await Q.getState().getUser(C);T?w.push(T):w.push(new Tg({pubkey:C}))}u(w)})()},[d,s]);const v=async()=>{if(n([]),!a){n(["Event is required"]),l({title:"Error",description:"Event is required",status:"error",duration:5e3,isClosable:!0});return}if(r&&r==="none"){n(["Keystore is required"]),l({title:"Error",description:"Keystore is required",status:"error",duration:5e3,isClosable:!0});return}if(!o){n(["Keypair is required"]),l({title:"Error",description:"Keypair is required",status:"error",duration:5e3,isClosable:!0});return}if(!a.content){n(["Event content is required"]),l({title:"Error",description:"Event content is required",status:"error",duration:5e3,isClosable:!0});return}try{const m=await Q.getState().signAndSendEvent({event:a});m&&(l({title:"Success",description:`Event ${m} submitted`,status:"success",duration:5e3,isClosable:!0}),x(s,!0))}catch(m){let w="";m instanceof Error?w=m.message:w=m?m.toString():"Unknown error",n([w]),l({title:"Error",description:w,status:"error",duration:5e3,isClosable:!0});return}},h=m=>{switch(m){case"NewShortTextNote":return"Short Text Note";case"NewRecommendRelay":return"Recommend Relay";case"NewLongFormContent":return"Long Form Content";case"NewShortTextNoteResponse":return"Short Text Note Response";case"NewQuoteRepost":return"Quote Repost";default:return""}},x=(m,w=!1)=>{let S;if(!w&&m===s){console.log(`Already set to ${m}`);return}switch(m){case"NewShortTextNote":S=xG({text:""}),m="NewShortTextNote";break;case"NewRecommendRelay":S=EG({relayUrl:Object.keys(Eg)[0]}),m="NewRecommendRelay";break;case"NewLongFormContent":S=SG({text:""}),m="NewLongFormContent";break;case"NewQuoteRepost":S=MP({inResponseTo:new Tg({pubkey:""}),relayUrl:Object.keys(Eg)[0]});break;default:n(["Invalid event type"]);return}Q.getState().setNewEvent(S),Q.getState().setNewEventName(m),n([])};return g.jsxs(Se,{width:"100%",children:[g.jsxs(Sl,{marginBottom:4,children:[g.jsxs(kl,{children:["Type: ",h(s)]}),c.map(m=>g.jsx(Kf,{user:m,relayId:f},m.pubkey))]}),g.jsxs(Sl,{marginBottom:4,children:[g.jsx(kl,{children:"Content"}),g.jsx(li,{type:"text",as:i===Or.LONG_FORM_CONTENT?HT:li,value:((y=Q.getState().newEvent)==null?void 0:y.content)||"",onChange:m=>Q.getState().setNewEventContent(m.target.value),placeholder:"Enter event content"})]}),g.jsxs(Mn,{marginBottom:4,children:[g.jsx(Ai,{"aria-label":"Short Text Note",icon:g.jsx($e,{as:VK}),onClick:()=>x("NewShortTextNote"),isActive:s==="NewShortTextNote"}),g.jsx(Ai,{"aria-label":"NewLongFormContent",icon:g.jsx($e,{as:KK}),onClick:()=>x("NewLongFormContent"),isActive:s==="NewLongFormContent"}),g.jsx(Ai,{"aria-label":"NewShortTextNoteResponse",icon:g.jsx($e,{as:eZ}),onClick:()=>x("NewShortTextNoteResponse"),isActive:s==="NewShortTextNoteResponse",isDisabled:s!=="NewShortTextNoteResponse"}),g.jsx(Ai,{"aria-label":"NewRecommendRelay",icon:g.jsx($e,{as:sZ}),onClick:()=>x("NewRecommendRelay"),isActive:s==="NewRecommendRelay"}),g.jsx(Ai,{"aria-label":"NewQuoteRepost",icon:g.jsx($e,{as:ZP}),onClick:()=>x("NewQuoteRepost"),isActive:s==="NewQuoteRepost",isDisabled:s!=="NewQuoteRepost"})]}),t.map((m,w)=>g.jsx(Se,{color:"red.500",children:m},w)),g.jsx(Oe,{type:"submit",colorScheme:"blue",onClick:v,leftIcon:g.jsx($e,{as:MK}),isDisabled:!e,children:"Send"})]})};function aZ(){const[e,t]=Q(o=>[o.connected,o.events.length>=o.maxEvents]),n=new Td({kinds:[Or.SHORT_TEXT_NOTE,Or.LONG_FORM_CONTENT],limit:Ls}),r=b.useRef(!1);return b.useEffect(()=>{(async()=>{!e||r.current||(r.current=!0,await Q.getState().clearEvents(),await Q.getState().setViewSubscription("welcome",n))})()},[]),b.useEffect(()=>{(async()=>{!e||r.current||(r.current=!0,await Q.getState().setViewSubscription("welcome",n))})()},[e]),b.useEffect(()=>{t&&(async()=>{e&&await Q.getState().removeViewSubscription("welcome")})()},[t]),g.jsxs(zf,{templateColumns:["1fr","2fr 1fr"],gap:20,children:[g.jsx(Se,{maxHeight:"80vh",overflowY:"auto",children:g.jsx(Se,{children:e?g.jsx(YP,{userComponent:Kf,view:"welcome",filters:n,connected:e}):g.jsxs(Se,{maxWidth:600,children:[g.jsx(Vt,{size:"lg",children:"About Nostr"}),g.jsx(xe,{marginBottom:2,fontWeight:"bold",children:"Tldr: Nostr is a decentralized social network."}),g.jsx(xe,{marginBottom:4,children:"Nostr is anything you can imagine. A new reddit, Twitter, Facebook, Mastodon - Craigstslist or Ebay? It's only a matter of what the interface looks like, the underlying network is the same, and so is your identity - so you get to access it all, without giving up yourself."}),g.jsx(Vt,{size:"md",children:"Connect to get started"}),g.jsx(xe,{marginBottom:2,children:"You don't need an account to browse or follow users. All data is saved in your browser. To interact with events, generate or supply a keypair."}),g.jsx(xe,{children:"nos2x and nos2x-fox should be working too."})]})})}),g.jsxs(Se,{display:"flex",flexDirection:"column",children:[g.jsx(Vt,{as:"h2",size:"md",marginBottom:4,children:"Broadcast to the Network"}),g.jsx(QP,{})]})]})}function lZ(){const[e,t]=b.useState([]),n=b.useRef(!1);return b.useEffect(()=>{(async()=>{if(n.current)return;n.current=!0;const o=await Q.getState().getAllUsersFollowing();o&&t(o)})()},[]),g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Following"}),e.length>0?g.jsx(g.Fragment,{children:e.map(r=>g.jsx(Se,{mb:"3",children:g.jsx(Kf,{user:r.user,relayId:r.relayIds[0]},r.user.pubkey)},r.user.pubkey))}):g.jsxs(g.Fragment,{children:[g.jsx(xe,{children:"Follow users to subscribe to their messages. The subscription is stored in your browser and not shared with relays."}),g.jsx(xe,{fontWeight:"bold",children:"You are not following anyone."})]})]})}const XP=Object.keys(Or).map(e=>({name:e,value:Or[e]})),cZ=e=>{const t=XP.find(n=>n.value===e);return t?t.name:"Unknown"},uZ=e=>e.map(cZ).join(", ");function dZ(){const[e,t]=b.useState([]),[n,r]=b.useState(null),{isOpen:o,onOpen:i,onClose:s}=ql(),a=async()=>{const u=await Q.getState().getSubscriptions();u&&t(u)};b.useEffect(()=>{(async()=>{await a()})();const d=setInterval(a,1e3);return()=>clearInterval(d)},[]);const l=g.jsxs(Us,{isOpen:o,onClose:s,size:"xl",children:[" ",g.jsx(Gs,{}),g.jsxs(Ws,{maxHeight:"80vh",maxWidth:"80vw",children:[" ",g.jsx(Hs,{children:"Filters"}),g.jsx(Yl,{}),g.jsxs(qs,{overflowY:"auto",children:[" ",g.jsx("pre",{children:n})]})]})]}),c=u=>{const d=u.options&&u.options.view?u.options.view:"";return g.jsxs(Os,{children:[g.jsx(_t,{children:g.jsx(Rl,{label:u.id,children:`${u.id.substring(0,3)}..`})}),g.jsx(_t,{children:u.filters.kinds&&uZ(u.filters.kinds)}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>{r(JSON.stringify(u.filters,null,2)),i()},children:"Show"})}),g.jsx(_t,{children:g.jsx(Rl,{label:d,children:`${d.substring(0,4)}..`})}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>Q.getState().unsubscribe(u.id),children:"Unsubscribe"})})]},u.id)};return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Subscriptions"}),g.jsxs(Df,{variant:"simple",marginBottom:4,children:[g.jsx(A0,{children:g.jsxs(Os,{children:[g.jsx(Rt,{children:"ID"}),g.jsx(Rt,{children:"Kind"}),g.jsx(Rt,{children:"Filter"}),g.jsx(Rt,{children:"View"}),g.jsx(Rt,{children:"Action"})]})}),g.jsx($0,{children:e.map(u=>c(u))})]}),g.jsx(Vt,{size:"md",marginBottom:2,children:"Legend"}),XP.map(u=>g.jsxs(xe,{children:[u.name," - ",u.value]},u.name)),l]})}function fZ(){const[e,t]=Q(c=>[c.connected,c.events.length>=c.maxEvents]),[n,r]=b.useState(null),o=QU(),i=o.pubkey||"",s=o.relayid||"",a=`profile-${i}`,l=new Td({limit:Ls,authors:[i],kinds:[Or.SHORT_TEXT_NOTE,Or.LONG_FORM_CONTENT]});return b.useEffect(()=>{(async()=>{if(e){if(await Q.getState().clearEvents(),await Q.getState().setViewSubscription(a,l),!n){const u=await Q.getState().getUser(i);r(u||new Tg({pubkey:i}))}await Q.getState().count({type:H0.COUNT,filters:new Td({kinds:[3],"#p":[i]}),options:{timeout:1e4,timeoutAt:Date.now()+1e4}})}})()},[]),b.useEffect(()=>{t&&(async()=>{e&&await Q.getState().removeViewSubscription(a)})()},[t]),g.jsxs(zf,{templateColumns:["1fr","2fr 1fr"],gap:20,children:[g.jsxs(Se,{maxHeight:"80vh",overflowY:"auto",children:[g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Profile"}),n&&g.jsx(Kf,{user:n,relayId:s})]}),g.jsx(Se,{children:e?g.jsx(YP,{view:a,filters:l,connected:e}):g.jsx(xe,{children:"Not connected."})})]}),g.jsxs(Se,{display:"flex",flexDirection:"column",children:[g.jsx(Vt,{as:"h2",size:"md",marginBottom:4,children:"Broadcast to the Network"}),g.jsx(QP,{})]})]})}function hZ(){const[e,t]=b.useState([]),[n,r]=b.useState(null),[o,i]=b.useState(!1),{isOpen:s,onOpen:a,onClose:l}=ql(),c=async()=>{const h=await Q.getState().getRelays();h&&t(h)};b.useEffect(()=>{(async()=>{await c()})();const x=setInterval(c,2e3);return()=>clearInterval(x)},[]);const u=async h=>{i(!0);const x=!h.read;await Q.getState().updateRelay(h.id,{read:x}),await c(),i(!1)},d=async h=>{i(!0);const x=!h.write;await Q.getState().updateRelay(h.id,{write:x}),await c(),i(!1)};function f({obj:h}){return h?g.jsx("div",{children:Object.entries(h).map(([x,y])=>typeof y=="object"&&y!==null&&!Array.isArray(y)?g.jsxs("div",{children:[g.jsxs("strong",{children:[x,":"]}),g.jsx(f,{obj:y})]},x):Array.isArray(y)?g.jsxs("div",{children:[g.jsxs("strong",{children:[x,":"]}),g.jsx("ul",{children:y.map((m,w)=>g.jsx("li",{children:typeof m=="object"&&m!==null?g.jsx(f,{obj:m}):m.toString()},w))})]},x):g.jsxs("div",{children:[g.jsxs("strong",{children:[x,":"]})," ",y==null?void 0:y.toString()]},x))}):null}const p=g.jsxs(Us,{isOpen:s,onClose:l,size:"xl",children:[g.jsx(Gs,{}),g.jsxs(Ws,{maxHeight:"80vh",maxWidth:"80vw",children:[g.jsx(Hs,{children:"Relay"}),g.jsx(Yl,{}),g.jsx(qs,{overflowY:"auto",children:n&&n.info&&g.jsx(f,{obj:n.info})})]})]}),v=h=>g.jsxs(Os,{children:[g.jsx(_t,{children:g.jsx(Rl,{label:h.id,children:`${h.id.substring(0,3)}..`})}),g.jsx(_t,{children:h.url}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>{r(h),a()},children:"Show"})}),g.jsx(_t,{children:g.jsx(dg,{isChecked:h.read,onChange:()=>u(h),isDisabled:o})}),g.jsx(_t,{children:g.jsx(dg,{isChecked:h.write,onChange:()=>d(h),isDisabled:o})})]},h.id);return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Relays"}),g.jsxs(Df,{variant:"simple",marginBottom:4,children:[g.jsx(A0,{children:g.jsxs(Os,{children:[g.jsx(Rt,{children:"ID"}),g.jsx(Rt,{children:"Url"}),g.jsx(Rt,{children:"Info"}),g.jsx(Rt,{children:"Read"}),g.jsx(Rt,{children:"Write"})]})}),g.jsx($0,{children:e.map(h=>v(h))})]}),p]})}function pZ(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Gd=pZ(b),mZ=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Wx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=gZ(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Gd.createElement("svg",mZ({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Gd.createElement("path",{d:"M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"}))},vZ=Gd.memo?Gd.memo(Wx):Wx,yZ=vZ;const Rp=Ge(yZ);function bZ(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var qd=bZ(b),wZ=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Hx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=xZ(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return qd.createElement("svg",wZ({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),qd.createElement("path",{d:"M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"}))},SZ=qd.memo?qd.memo(Hx):Hx,kZ=SZ;const Ap=Ge(kZ);function CZ(){const[e]=Q(d=>[d.eventsPublishingQueue]),[t,n]=b.useState(null),r=d=>!!d.error,o=d=>d.error?d.error:"",{isOpen:i,onOpen:s,onClose:a}=ql();function l({obj:d}){return g.jsx("div",{children:Object.entries(d).map(([f,p])=>typeof p=="object"&&!Array.isArray(p)?g.jsxs("div",{children:[g.jsxs("strong",{children:[f,":"]}),g.jsx(l,{obj:p})]},f):Array.isArray(p)?g.jsxs("div",{children:[g.jsxs("strong",{children:[f,":"]}),g.jsx("ul",{children:p.map((v,h)=>g.jsx("li",{children:typeof v=="object"?g.jsx(l,{obj:v}):v},h))})]},f):g.jsxs("div",{children:[g.jsxs("strong",{children:[f,":"]})," ",p?p.toString():"null"]},f))})}const c=g.jsxs(Us,{isOpen:i,onClose:a,size:"xl",children:[g.jsx(Gs,{}),g.jsxs(Ws,{maxHeight:"80vh",maxWidth:"80vw",children:[g.jsx(Hs,{children:"Queue Item Detail"}),g.jsx(Yl,{}),g.jsx(qs,{overflowY:"auto",children:t&&g.jsx(l,{obj:t})})]})]}),u=d=>{const f=d.event.id||"";return g.jsxs(Os,{children:[g.jsx(_t,{children:g.jsx(Rl,{label:f,children:`${f.substring(0,3)}..`})}),g.jsx(_t,{children:g.jsxs(Mn,{children:[d.pow?g.jsx(xe,{children:d.pow}):g.jsx(xe,{children:"0"}),g.jsx(xe,{children:"/"}),g.jsx($e,{as:d.powDone?Rp:Ap})]})}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>{n(d),s()},children:"Show"})}),g.jsx(_t,{children:g.jsx($e,{as:d.send?Rp:Ap,marginRight:1})}),g.jsxs(_t,{children:[g.jsx($e,{as:d.accepted?Rp:Ap}),r(d)&&g.jsx(xe,{color:"red.500",children:o(d)})]})]},f)};return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Queue"}),g.jsxs(Df,{variant:"simple",marginBottom:4,children:[g.jsx(A0,{children:g.jsxs(Os,{children:[g.jsx(Rt,{children:"Event ID"}),g.jsx(Rt,{children:"POW / Done"}),g.jsx(Rt,{children:"Info"}),g.jsx(Rt,{children:"Send"}),g.jsx(Rt,{children:"Accepted"})]})}),g.jsx($0,{children:e.map(d=>u(d))})]}),c]})}const EZ=async()=>{await Q.getState().init({maxEvents:Ls})};EZ();hg.createRoot(document.getElementById("root")).render(g.jsx(ei.StrictMode,{children:g.jsx(DN,{children:g.jsx(yW,{basename:"/nostr-ts/",children:g.jsx(fW,{children:g.jsxs(dr,{element:g.jsx(dK,{}),children:[g.jsx(dr,{path:"/",element:g.jsx(aZ,{})}),g.jsx(dr,{path:"/account",element:g.jsx(pq,{})}),g.jsx(dr,{path:"/following",element:g.jsx(lZ,{})}),g.jsx(dr,{path:"/subscriptions",element:g.jsx(dZ,{})}),g.jsx(dr,{path:"/relays",element:g.jsx(hZ,{})}),g.jsx(dr,{path:"/queue",element:g.jsx(CZ,{})}),g.jsx(dr,{path:"/p/:relayid/:pubkey",element:g.jsx(fZ,{})})]})})})})})); + */var qf=b,JG=XG;function eq(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var tq=typeof Object.is=="function"?Object.is:eq,nq=JG.useSyncExternalStore,rq=qf.useRef,oq=qf.useEffect,iq=qf.useMemo,sq=qf.useDebugValue;GP.useSyncExternalStoreWithSelector=function(e,t,n,r,o){var i=rq(null);if(i.current===null){var s={hasValue:!1,value:null};i.current=s}else s=i.current;i=iq(function(){function l(p){if(!c){if(c=!0,u=p,p=r(p),o!==void 0&&s.hasValue){var v=s.value;if(o(v,p))return d=v}return d=p}if(v=d,tq(u,p))return v;var h=r(p);return o!==void 0&&o(v,h)?v:(u=p,d=h)}var c=!1,u,d,f=n===void 0?null:n;return[function(){return l(t())},f===null?void 0:function(){return l(f())}]},[t,n,r,o]);var a=nq(e,i[0],i[1]);return oq(function(){s.hasValue=!0,s.value=a},[a]),sq(a),a};HP.exports=GP;var aq=HP.exports;const lq=Ge(aq),{useSyncExternalStoreWithSelector:cq}=lq;function uq(e,t=e.getState,n){const r=cq(e.subscribe,e.getState,e.getServerState||e.getState,t,n);return b.useDebugValue(r),r}const Cx=e=>{const t=typeof e=="function"?VG(e):e,n=(r,o)=>uq(t,r,o);return Object.assign(n,t),n},dq=e=>e?Cx(e):Cx,Ls=25,Eg={"wss://nos.lol":{read:!0,write:!1},"wss://nostr.wine":{read:!0,write:!1}};function fq(){const e=localStorage.getItem("nostr-client:keystore:keystore");if(e)if(e==="localstore"){const t=localStorage.getItem("nostr-client:keystore:public-key"),n=localStorage.getItem("nostr-client:keystore:private-key");if(t&&n)return{keystore:"localstore",publicKey:t,privateKey:n}}else{if(e==="nos2x")return{keystore:"nos2x",publicKey:void 0,privateKey:void 0};if(e==="download")return{keystore:"download",publicKey:void 0,privateKey:void 0}}return{keystore:"none",publicKey:void 0,privateKey:void 0}}function Ex(e){localStorage.setItem("nostr-client:keystore:keystore",e.keystore),e.keystore==="localstore"&&e.publicKey&&e.privateKey?(localStorage.setItem("nostr-client:keystore:public-key",e.publicKey),localStorage.setItem("nostr-client:keystore:private-key",e.privateKey)):e.keystore==="nos2x"||e.keystore}const Tx=new Worker(new URL("/nostr-ts/assets/worker-3bdd9117.js",self.location),{type:"module"});function hq(e,t){let n=null,r=[];return function(o){r.push(o),n||(n=setTimeout(()=>{e(r),r=[],n=null},t))}}const Q=dq((e,t)=>({store:VP(Tx),init:async n=>{await t().loadKeyStore(),await t().store.init(n);const o=hq(i=>{i.forEach(s=>{const a=s.data;if(a.type==="event:new"||a.type==="event:update"){const l=a.data;a.type==="event:new"?t().addEvent(l):a.type==="event:update"&&t().updateEvent(l)}else if(a.type==="relay:message"){const l=a.data;e({relayEvents:[...t().relayEvents,l]})}else a.type==="event:queue:update"&&t().updateQueueItem(a.data)})},100);Tx.addEventListener("message",o)},connected:!1,connect:async n=>{t().connected||(await t().store.connect(n),e({connected:!0}))},disconnect:async()=>{await t().store.disconnect(),e({connected:!1})},getRelays:async()=>t().store.getRelays(),updateRelay:async(n,r)=>t().store.updateRelay(n,r),relayEvents:[],getSubscriptions:async()=>t().store.getSubscriptions(),subscribe:async n=>t().store.subscribe(n),unsubscribe:async n=>(console.log(`Unsubscribing ${n}`),t().store.unsubscribe(n)),unsubscribeAll:async()=>(console.log("Unsubscribing all"),t().store.unsubscribeAll()),keystore:"none",loadKeyStore:()=>{const n=fq();e({keystore:n.keystore}),n.keystore==="localstore"&&n.publicKey&&n.privateKey&&e({keypair:{publicKey:n.publicKey,privateKey:n.privateKey},keypairIsLoaded:!0})},saveKeyStore:()=>{const n=t().keystore;if(n==="localstore"){const r=t().keypair;Ex(r?{keystore:n,publicKey:r.publicKey,privateKey:r.privateKey}:{keystore:n})}},setKeyStore:n=>{n.keystore==="localstore"?(console.log(`Setting keystore for ${n.keystore}`,n),n.publicKey&&n.privateKey&&(e({keystore:n.keystore,keypair:{publicKey:n.publicKey,privateKey:n.privateKey},keypairIsLoaded:!0}),t().saveKeyStore())):n.keystore==="nos2x"?e({keystore:n.keystore,keypair:{publicKey:n.publicKey||""}}):console.error(`Unknown keystore ${n.keystore}`)},keypair:{publicKey:"",privateKey:""},keypairIsLoaded:!1,newEvent:new rn({kind:Or.SHORT_TEXT_NOTE}),setNewEvent:n=>{e({newEvent:n})},newEventName:"NewShortTextNote",setNewEventName:n=>{e({newEventName:n})},setNewEventContent:n=>{e({newEvent:t().newEvent.setContentWithoutChecks(n)})},count:async n=>t().store.count(n),events:[],addEvent:n=>{e({events:[...t().events,n]})},updateEvent:n=>{const r=t().events.findIndex(o=>o.event.id===n.event.id);if(r!==-1){const o=[...t().events];o[r]=n,e({events:o})}},maxEvents:Ls,setMaxEvents:async n=>{await t().store.setMaxEvents(n),e({maxEvents:n})},determineApplicableRelays:async n=>{const r=await t().getRelays();return{relays:(n.relayIds?r.filter(i=>{var s;return(s=n.relayIds)==null?void 0:s.includes(i.id)}):r).filter(i=>i.isReady&&i.write===!0),pow:0}},generateQueueItems:async n=>{const{relays:r}=await t().determineApplicableRelays(n),o=[];for(const i of r)if(i.isReady&&i.write){const{relayIds:s,...a}=n,l={...a,id:PW(),relayId:i.id,send:!1};o.push(l)}return o},addQueueItems:n=>{e({eventsPublishingQueue:[...t().eventsPublishingQueue,...n]})},updateQueueItem:async n=>{const r=t().eventsPublishingQueue,o=r.findIndex(i=>i.event.id===n.event.id);if(o!==-1){const i=[...r];i[o]=n,e({eventsPublishingQueue:i})}},getUser:async n=>t().store.getUser(n),addUser:async n=>t().store.addUser(n),updateUser:async n=>t().store.updateUser(n),countUsers:async()=>t().store.countUsers(),getEventById:n=>t().store.getEventById(n),eventProofOfWork:async(n,r)=>new Promise(o=>{const i=new Worker(new URL("/nostr-ts/assets/pow-worker-46de68b7.js",self.location),{type:"module"});i.onmessage=function(s){o(s.data.result),i.terminate()},i.postMessage({event:n,bits:r})}),sendEvent:async n=>t().store.sendEvent(n),signAndSendEvent:async n=>{var d,f,p,v;const r=t().keypair;if(!r)throw new Error("Keypair not initialized");const o=t().keystore;let i=n.event;i.pubkey=r.publicKey,i.generateId();const{relays:s,pow:a}=await t().determineApplicableRelays(n);if(s.length===0)throw new Error("No (write-enabled) relays available. Check relays.");let l=n.pow;const c=a;if(l&&l!==0){if(l0){u=await t().generateQueueItems({...n,pow:l}),(f=(d=t()).addQueueItems)==null||f.call(d,u);const h=await t().eventProofOfWork(n.event,l);i=new rn(h);for(const x of u)x.event=i,x.powDone=Date.now()}if(o==="localstore")i.sign({privateKey:r.privateKey||"",publicKey:r.publicKey});else if(o==="nos2x")if(window.nostr&&window.nostr.signEvent){const h=await window.nostr.signEvent(i.ToObj());if(!h.sig)throw new Error("No signature");i.sig=h.sig}else throw new Error("Nostr not initialized");else throw new Error("Invalid keystore");if(i.isReadyToPublishOrThrow(),u.length===0)u=await t().generateQueueItems({...n,pow:l,event:i}),(v=(p=t()).addQueueItems)==null||v.call(p,u);else for(const h of u)h.event=i,t().updateQueueItem(h);return await t().store.sendQueueItems(u),i.id},eventsPublishingQueue:[],clearEvents:async()=>{await t().store.clearEvents(),e({events:[]})},followUser:async n=>{await t().store.followUser(n);const r=await t().store.getAllUsersFollowing();r&&e({followingUserIds:r.map(o=>o.user.pubkey)})},unfollowUser:async n=>{await t().store.unfollowUser(n);const r=await t().store.getAllUsersFollowing();r&&e({followingUserIds:r.map(o=>o.user.pubkey)})},followingUser:async n=>t().store.followingUser(n),followingUserIds:[],getAllUsersFollowing:async()=>t().store.getAllUsersFollowing(),updateUserFollowing:async n=>t().store.updateUserFollowing(n),requestInformation:(n,r)=>t().store.requestInformation(n,r),hasSubscriptionForEventIds:async(n,r)=>t().store.hasSubscriptionForEventIds(n,r),hasViewSubscription:async n=>(await t().getSubscriptions()).some(o=>o.options&&o.options.view===n),setViewSubscription:async(n,r)=>{const o=await t().getSubscriptions();if(o.find(a=>a.options&&a.options.view===n)){console.log(`Already subscribed to view ${n}`);return}for(const a of o)a.options&&a.options.view&&await t().unsubscribe(a.id);const s=await t().getRelays();await t().subscribe({type:H0.REQ,filters:{...r,limit:r.limit?Math.round(r.limit/s.length):void 0},options:{view:n,timeout:1e4,timeoutAt:Date.now()+1e4}}),setTimeout(async()=>{var v,h;const a=[],l=[];for(const x of t().events)(v=x.event)!=null&&v.pubkey&&!((h=x.user)!=null&&h.pubkey)&&a.push({pubkey:x.event.pubkey,relayIds:x.eventRelayIds}),x.reactions||l.push({id:x.event.id,relayIds:x.eventRelayIds});const c={};for(const x of a)for(const y of x.relayIds)c[y]||(c[y]=new Set),c[y].add(x.pubkey);const u=Object.entries(c).map(([x,y])=>({source:"users",relayId:x,idsOrKeys:[...y]})),d={};for(const x of l)for(const y of x.relayIds)d[y]||(d[y]=new Set),d[y].add(x.id);const f=Object.entries(d).map(([x,y])=>({source:"events",relayId:x,idsOrKeys:[...y]})),p=[];for(const x of[...u,...f])p.push(await t().requestInformation(x,{timeout:1e4,timeoutAt:Date.now()+1e4}))},5e3)},removeViewSubscription:async n=>{const r=await t().getSubscriptions();if(console.log(`Remove view subscription ${n}`),!n){const s=r.map(a=>t().unsubscribe(a.id));await Promise.all(s);return}const i=r.filter(s=>s.options&&s.options.view===n).map(s=>t().unsubscribe(s.id));await Promise.all(i)}}));function pq(){const[e]=Q(d=>[d.keystore]),[t]=Q(d=>[d.keypairIsLoaded]),[n]=Q(d=>[d.keypair]),[r]=Q(d=>{var f;return[((f=d==null?void 0:d.keypair)==null?void 0:f.publicKey)||""]}),[o,i]=b.useState(!1),s=Hl(),[a,l]=b.useState(!1),c=()=>{const d=rG();Q.getState().setKeyStore({keystore:"localstore",publicKey:d.publicKey,privateKey:d.privateKey})},u=async d=>{if(l(!0),window.nostr)try{const f=await window.nostr.getPublicKey();console.log(f),Q.getState().setKeyStore({keystore:"nos2x",publicKey:f,privateKey:""}),l(!1)}catch(f){console.error("Error loading public key:",f),l(!1)}else{console.log(`Nostr extention not ready, retry ${d}`);const f=d?d+1:1;if(f>2){s({title:"Error loading relays",description:"nos2x extention not available or ready.",status:"error",duration:5e3,isClosable:!0}),l(!1);return}setTimeout(()=>u(f),1e3)}};return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Account"}),t?g.jsxs(xe,{fontWeight:"bold",children:["Keypair loaded from ",e,"."]}):g.jsxs(g.Fragment,{children:[g.jsx(xe,{fontWeight:"bold",marginBottom:2,children:"Keypair is not loaded."}),g.jsx(xe,{marginBottom:2,children:"If you generate a new keypair, it will be stored in the browser local store (insecure). Alternatively get nos2x for Chrome, or nos2x-fox for Firefox, and store your keys in the extention (less insecure)."}),g.jsxs(Mn,{children:[g.jsx(Oe,{onClick:c,children:"Generate new keypair"}),g.jsx(Oe,{isLoading:a,onClick:()=>u(),children:"Load from nos2x"})]})]}),n&&g.jsxs(Se,{mt:4,children:[g.jsxs(Sl,{marginBottom:4,children:[g.jsx(kl,{children:"Public key:"}),g.jsx(li,{type:"text",value:r,isReadOnly:!0})]}),g.jsxs(Sl,{marginBottom:4,children:[g.jsx(kl,{children:"Private key:"}),g.jsxs(Mn,{spacing:2,children:[g.jsx(li,{type:o?"text":"password",value:n.privateKey,isReadOnly:!0}),g.jsx(Oe,{isDisabled:e!=="localstore",size:"sm",onClick:()=>i(!o),children:o?"Hide":"Show"})]})]})]})]})}function mq(){const[e,t]=b.useState(0),[n,r,o]=Q(l=>[l.events.length,l.maxEvents,l.relayEvents]),[i,s]=b.useState(0),a=Hl();return b.useEffect(()=>{const l=setInterval(async()=>{const c=await Q.getState().countUsers();c&&t(c)},1e3);return()=>clearInterval(l)},[]),b.useEffect(()=>{const l=o.length;if(l>0){const c=l-i;if(c>0){s(l);const u=o.slice(-c);for(const d of u){let f="";if(d.data[0]===Ea.NOTICE)f=d.data[1];else if(d.data[0]===Ea.OK)f=`${d.data[2]}. Event ${d.data[1]}: ${d.data[3]}`;else{if(d.data[0]===Ea.EOSE)return;d.data[0]===Ea.COUNT&&(f=`Relay ${d.data[1]}: ${JSON.stringify(d.data[2])} events`)}f!==""&&a({title:`Relay ${d.data[0]}`,position:"top-right",description:f,status:"info",duration:5e3,isClosable:!0})}}}},[o]),g.jsx(Se,{position:"fixed",bottom:0,left:0,right:0,bg:"white",boxShadow:"md",p:3,children:g.jsx(Mn,{spacing:4,children:g.jsxs(g.Fragment,{children:[g.jsxs(Mn,{spacing:2,children:[g.jsx(xe,{fontSize:"sm",children:"Events:"}),g.jsxs(xe,{fontSize:"xl",marginLeft:1,children:[n," (max ",r,")"]})]}),g.jsxs(Mn,{spacing:2,children:[g.jsx(xe,{fontSize:"sm",children:"Users:"}),g.jsx(xe,{fontSize:"xl",children:e})]})]})})})}function _i({label:e,value:t,to:n,leftIcon:r}){return g.jsx(X9,{as:xW,to:n,w:"100%",padding:2,border:"1px solid",borderColor:"gray.200",borderRadius:2,backgroundColor:"gray.100",_hover:{backgroundColor:"gray.300"},_activeLink:{backgroundColor:"gray.300"},children:g.jsxs(Mn,{children:[r,g.jsx(xe,{fontSize:"md",fontWeight:"bold",children:e}),t&&g.jsx(xe,{fontSize:"md",children:t})]})})}function gq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Ad=gq(b),vq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Px=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=yq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Ad.createElement("svg",vq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Ad.createElement("path",{d:"M4,1C2.89,1 2,1.89 2,3V7C2,8.11 2.89,9 4,9H1V11H13V9H10C11.11,9 12,8.11 12,7V3C12,1.89 11.11,1 10,1H4M4,3H10V7H4V3M3,13V18L3,20H10V18H5V13H3M14,13C12.89,13 12,13.89 12,15V19C12,20.11 12.89,21 14,21H11V23H23V21H20C21.11,21 22,20.11 22,19V15C22,13.89 21.11,13 20,13H14M14,15H20V19H14V15Z"}))},bq=Ad.memo?Ad.memo(Px):Px,wq=bq;const xq=Ge(wq);function Sq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var $d=Sq(b),kq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},_x=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Cq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return $d.createElement("svg",kq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),$d.createElement("path",{d:"M4,1C2.89,1 2,1.89 2,3V7C2,8.11 2.89,9 4,9H1V11H13V9H10C11.11,9 12,8.11 12,7V3C12,1.89 11.11,1 10,1H4M4,3H10V7H4V3M14,13C12.89,13 12,13.89 12,15V19C12,20.11 12.89,21 14,21H11V23H23V21H20C21.11,21 22,20.11 22,19V15C22,13.89 21.11,13 20,13H14M3.88,13.46L2.46,14.88L4.59,17L2.46,19.12L3.88,20.54L6,18.41L8.12,20.54L9.54,19.12L7.41,17L9.54,14.88L8.12,13.46L6,15.59L3.88,13.46M14,15H20V19H14V15Z"}))},Eq=$d.memo?$d.memo(_x):_x,Tq=Eq;const Pq=Ge(Tq);function _q(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Od=_q(b),Rq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Rx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Aq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Od.createElement("svg",Rq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Od.createElement("path",{d:"M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z"}))},$q=Od.memo?Od.memo(Rx):Rx,Oq=$q;const Iq=Ge(Oq);function jq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Id=jq(b),Lq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ax=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Mq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Id.createElement("svg",Lq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Id.createElement("path",{d:"M11 10V12H9V14H7V12H5.8C5.4 13.2 4.3 14 3 14C1.3 14 0 12.7 0 11S1.3 8 3 8C4.3 8 5.4 8.8 5.8 10H11M3 10C2.4 10 2 10.4 2 11S2.4 12 3 12 4 11.6 4 11 3.6 10 3 10M16 14C18.7 14 24 15.3 24 18V20H8V18C8 15.3 13.3 14 16 14M16 12C13.8 12 12 10.2 12 8S13.8 4 16 4 20 5.8 20 8 18.2 12 16 12Z"}))},Bq=Id.memo?Id.memo(Ax):Ax,zq=Bq;const Fq=Ge(zq);function Nq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var jd=Nq(b),Dq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},$x=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Vq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return jd.createElement("svg",Dq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),jd.createElement("path",{d:"M14 10H3V12H14V10M14 6H3V8H14V6M3 16H10V14H3V16M21.5 11.5L23 13L16 20L11.5 15.5L13 14L16 17L21.5 11.5Z"}))},Uq=jd.memo?jd.memo($x):$x,Wq=Uq;const Hq=Ge(Wq);function Gq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Ld=Gq(b),qq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ox=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=Kq(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Ld.createElement("svg",qq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Ld.createElement("path",{d:"M16 17V19H2V17S2 13 9 13 16 17 16 17M12.5 7.5A3.5 3.5 0 1 0 9 11A3.5 3.5 0 0 0 12.5 7.5M15.94 13A5.32 5.32 0 0 1 18 17V19H22V17S22 13.37 15.94 13M15 4A3.39 3.39 0 0 0 13.07 4.59A5 5 0 0 1 13.07 10.41A3.39 3.39 0 0 0 15 11A3.5 3.5 0 0 0 15 4Z"}))},Zq=Ld.memo?Ld.memo(Ox):Ox,Yq=Zq;const Qq=Ge(Yq);function Xq(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Md=Xq(b),Jq=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ix=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=eK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Md.createElement("svg",Jq({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Md.createElement("path",{d:"M21.4 7.5C22.2 8.3 22.2 9.6 21.4 10.3L18.6 13.1L10.8 5.3L13.6 2.5C14.4 1.7 15.7 1.7 16.4 2.5L18.2 4.3L21.2 1.3L22.6 2.7L19.6 5.7L21.4 7.5M15.6 13.3L14.2 11.9L11.4 14.7L9.3 12.6L12.1 9.8L10.7 8.4L7.9 11.2L6.4 9.8L3.6 12.6C2.8 13.4 2.8 14.7 3.6 15.4L5.4 17.2L1.4 21.2L2.8 22.6L6.8 18.6L8.6 20.4C9.4 21.2 10.7 21.2 11.4 20.4L14.2 17.6L12.8 16.2L15.6 13.3Z"}))},tK=Md.memo?Md.memo(Ix):Ix,nK=tK;const rK=Ge(nK);function oK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Bd=oK(b),iK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},jx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=sK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Bd.createElement("svg",iK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Bd.createElement("path",{d:"M18 5H6V7H18M6 9H18V11H6M2 12H4V17H20V12H22V17A2 2 0 0 1 20 19H4A2 2 0 0 1 2 17M18 13H6V15H18Z"}))},aK=Bd.memo?Bd.memo(jx):jx,lK=aK;const cK=Ge(lK);function Lx(e){return Object.entries(e).map(([t,{read:n,write:r}])=>({url:t,read:n,write:r}))}function uK({isOpen:e,onClose:t}){const[n,r]=b.useState(Lx(Eg)),[o,i]=b.useState(""),[s,a]=b.useState(!1),[l,c]=b.useState(!1),u=Hl(),d=async p=>{if(a(!0),window.nostr&&window.nostr.getRelays)try{const v=await window.nostr.getRelays();r(Lx(v)),a(!1)}catch(v){console.error("Error loading relays:",v);let h="Unknown error";v instanceof Error&&(h=v.message),u({title:"Error loading relays",description:h,status:"error",duration:5e3,isClosable:!0}),a(!1)}else{console.log(`Nostr extention not ready, retry ${p}`);const v=p?p+1:1;if(v>2){u({title:"Error loading relays",description:"nos2x extention not available or ready.",status:"error",duration:5e3,isClosable:!0}),a(!1);return}setTimeout(()=>d(v),1e3)}},f=async()=>{c(!0),await Q.getState().connect(n),c(!1),t()};return g.jsxs(Us,{isOpen:e,onClose:t,children:[g.jsx(Gs,{}),g.jsxs(Ws,{children:[g.jsx(Hs,{children:"Connect to Relay(s)"}),g.jsx(Yl,{}),g.jsxs(qs,{children:[g.jsxs(xe,{children:["You can find a list of relays in the nostr-ts repository",g.jsx(sg,{marginLeft:1,href:"https://github.com/franzos/nostr-ts/blob/master/discovered-relays.json",isExternal:!0,color:"blue.500",children:"github.com/franzos/nostr-ts"}),",",g.jsx(sg,{marginLeft:1,marginRight:1,href:"https://nostr.info/relays/",isExternal:!0,color:"blue.500",children:"nostr.info"}),"and elsewhere."]}),g.jsx(Ha,{spacing:3,width:"100%",children:n&&n.map(p=>g.jsxs(pd,{width:"100%",alignItems:"center",borderBottom:"1px solid",borderColor:"gray.200",py:2,children:[g.jsx(xe,{flex:"1",marginLeft:"2",children:p.url}),g.jsx(Oe,{ml:"auto",onClick:()=>{const v=n.filter(h=>h.url!==p.url);r(v)},children:"Remove"})]},p.url))}),g.jsxs(pd,{direction:"row",alignItems:"center",children:[g.jsx(li,{flex:"1",value:o,onChange:p=>i(p.target.value),placeholder:"Enter new relay URL"}),g.jsx(Oe,{ml:2,onClick:()=>{o.trim()!==""&&(r([...n,{url:o,read:!0,write:!0}]),i(""))},children:"Add"})]}),g.jsx(Oe,{isLoading:s,onClick:()=>d(),size:"xs",marginTop:2,children:"Load from nos2x"})]}),g.jsx(R0,{children:g.jsx(Oe,{colorScheme:"green",isDisabled:n.length===0,isLoading:l,onClick:f,children:"Connect"})})]})]})}function dK(){const[e,t,n]=Q(v=>[v.connected,v.keystore,v.eventsPublishingQueue.length]),[r,o]=b.useState(0),[i,s]=b.useState([]),[a,l]=b.useState(0),{isOpen:c,onOpen:u,onClose:d}=ql(),f=async()=>{const v=await Q.getState().getAllUsersFollowing();v&&s(v);const h=await Q.getState().getSubscriptions();h&&o(h.length);const x=await Q.getState().getRelays();x&&l(x.length)};b.useEffect(()=>{(async()=>{await f()})();const h=setInterval(f,1e3);return()=>clearInterval(h)},[]);const p=g.jsxs(Ha,{align:"start",spacing:5,w:"100%",children:[g.jsx(_i,{label:"Home",to:"/",leftIcon:g.jsx($e,{as:Iq,marginRight:1})}),e&&g.jsxs(g.Fragment,{children:[g.jsx(_i,{label:"Following",value:i.length,to:"/following",leftIcon:g.jsx($e,{as:Qq,marginRight:1})}),g.jsx(_i,{label:"Subscriptions",value:r,to:"/subscriptions",leftIcon:g.jsx($e,{as:Hq,marginRight:1})}),g.jsx(_i,{label:"Relays",value:a,to:"/relays",leftIcon:g.jsx($e,{as:rK,marginRight:1})}),g.jsx(_i,{label:"Queue",value:n,to:"/queue",leftIcon:g.jsx($e,{as:cK,marginRight:1})})]}),g.jsx(_i,{label:"Account",value:t,to:"/account",leftIcon:g.jsx($e,{as:Fq,marginRight:1})}),e?g.jsxs(Oe,{w:"100%",colorScheme:"red",onClick:Q.getState().disconnect,children:[g.jsx($e,{as:Pq,marginRight:1}),"Disconnect"]}):g.jsx(Oe,{w:"100%",colorScheme:"green",onClick:u,leftIcon:g.jsx($e,{as:xq}),children:"Connect to relay(s)"})]});return g.jsxs(TT,{maxW:"8xl",p:5,children:[g.jsxs(Ha,{spacing:5,align:"stretch",children:[g.jsx(Ha,{spacing:1,align:"start",children:g.jsx(Vt,{as:"h1",size:"lg",children:"Nostr Client"})}),g.jsxs(zf,{templateColumns:["1fr","1fr 4fr"],gap:20,children:[p,g.jsx(Se,{maxHeight:"80vh",overflowY:"auto",children:g.jsx(uW,{})})]})]}),g.jsx(mq,{}),uK({isOpen:c,onOpen:u,onClose:d})]})}function fK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var zd=fK(b),hK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Mx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=pK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return zd.createElement("svg",hK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),zd.createElement("path",{d:"M23,10C23,8.89 22.1,8 21,8H14.68L15.64,3.43C15.66,3.33 15.67,3.22 15.67,3.11C15.67,2.7 15.5,2.32 15.23,2.05L14.17,1L7.59,7.58C7.22,7.95 7,8.45 7,9V19A2,2 0 0,0 9,21H18C18.83,21 19.54,20.5 19.84,19.78L22.86,12.73C22.95,12.5 23,12.26 23,12V10M1,21H5V9H1V21Z"}))},mK=zd.memo?zd.memo(Mx):Mx,gK=mK;const vK=Ge(gK);function yK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Fd=yK(b),bK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Bx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=wK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Fd.createElement("svg",bK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Fd.createElement("path",{d:"M19,15H23V3H19M15,3H6C5.17,3 4.46,3.5 4.16,4.22L1.14,11.27C1.05,11.5 1,11.74 1,12V14A2,2 0 0,0 3,16H9.31L8.36,20.57C8.34,20.67 8.33,20.77 8.33,20.88C8.33,21.3 8.5,21.67 8.77,21.94L9.83,23L16.41,16.41C16.78,16.05 17,15.55 17,15V5C17,3.89 16.1,3 15,3Z"}))},xK=Fd.memo?Fd.memo(Bx):Bx,SK=xK;const kK=Ge(SK);function CK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Nd=CK(b),EK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},zx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=TK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Nd.createElement("svg",EK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Nd.createElement("path",{d:"M17,17H7V14L3,18L7,22V19H19V13H17M7,7H17V10L21,6L17,2V5H5V11H7V7Z"}))},PK=Nd.memo?Nd.memo(zx):zx,_K=PK;const ZP=Ge(_K),RK=e=>{const t=new Date,n=new Date(e*1e3),r=t.getTime()-n.getTime(),o=Math.floor(r/1e3),i=Math.floor(o/60),s=Math.floor(i/60);return o<60?`${o} seconds ago`:i<60?`${i} minutes ago`:s<24?`${s} hours ago`:`${n.toLocaleDateString()} ${n.toLocaleTimeString()}`};function AK({userComponent:e,event:t,reactions:n,reposts:r,eventRelayIds:o}){var B;const[i]=Q($=>[$.connected&&$.keystore!=="none"]),s=Hl(),[a,l]=b.useState(0),[c,u]=b.useState(0),[d,f]=b.useState(0),[p,v]=b.useState({});b.useEffect(()=>{u((n==null?void 0:n.filter($=>$.content==="-").length)||0),l((n==null?void 0:n.filter($=>$.content==="+").length)||0),f((r==null?void 0:r.length)||0),v((n==null?void 0:n.filter($=>$.content!=="+"&&$.content!=="-").reduce(($,P)=>($[P.content]?$[P.content]+=1:$[P.content]=1,$),{}))||{})},[n]);const h=(B=t==null?void 0:t.content)==null?void 0:B.match(/\bhttps?:\/\/\S+?\.(?:jpg|jpeg|png|gif)\b/gi),{isOpen:x,onOpen:y,onClose:m}=ql(),[w,S]=b.useState(null),C=$=>{S($),y()},T=async()=>{const P=(await Q.getState().getRelays()).find(j=>j.id===o[0]);if(!P){s({title:"Error",description:`Relay ${o[0]} not found`,status:"error",duration:5e3,isClosable:!0});return}const I=kG({text:"",inResponseTo:{id:t.id,pubkey:t.pubkey},relayUrl:P.url});Q.getState().setNewEvent(I),Q.getState().setNewEventName("NewShortTextNoteResponse")},E=async($,P)=>{let I;switch($){case"quote":I=MP({inResponseTo:t,relayUrl:""});break;case"reaction":if(!P)throw new Error("Reaction is required");I=CG({text:P,inResponseTo:{id:t.id,pubkey:t.pubkey}});break;default:return}try{const j=await Q.getState().signAndSendEvent({event:I});j&&(s({title:"Success",description:`Event ${j} submitted`,status:"success",duration:5e3,isClosable:!0}),Q.getState().requestInformation({source:"events",idsOrKeys:[j],relayId:o[0]},{timeout:1e4,timeoutAt:Date.now()+1e4}))}catch(j){let V="";j instanceof Error?V=j.message:V=j?j.toString():"Unknown error",s({title:"Error",description:V,status:"error",duration:5e3,isClosable:!0});return}},_=()=>g.jsxs(Mn,{children:[g.jsx(Oe,{size:"sm",variant:"solid",colorScheme:"blue",onClick:()=>T(),isDisabled:!i,children:"Reply"}),g.jsx(Oe,{size:"sm","aria-label":"Upvote",leftIcon:g.jsx($e,{as:vK}),onClick:()=>E("reaction","+"),isDisabled:!i,children:a}),g.jsx(Oe,{size:"sm","aria-label":"Downvote",leftIcon:g.jsx($e,{as:kK}),onClick:()=>E("reaction","-"),isDisabled:!i,children:c}),g.jsx(Oe,{size:"sm","aria-label":"Repost",leftIcon:g.jsx($e,{as:ZP}),onClick:()=>E("quote"),isDisabled:!i,children:d}),p&&Object.keys(p).map($=>g.jsxs(Oe,{size:"sm","aria-label":"Repost",isDisabled:!0,children:[$," ",p[$]]},$))]});return g.jsxs(g.Fragment,{children:[g.jsxs(cD,{border:"1px solid #e1e1e1",overflow:"hidden",children:[g.jsx(lD,{p:0,children:g.jsxs(Se,{children:[h&&(h==null?void 0:h.length)>0&&g.jsx(Se,{className:"image-container",marginBottom:4,children:h.map(($,P)=>g.jsx(Ca,{src:$,fallback:g.jsx(Ca,{src:"/no-image.png"}),fallbackStrategy:"onError",alt:"",onClick:()=>C($)},P))}),g.jsx(Se,{p:4,paddingBottom:0,children:e&&e})]})}),g.jsxs(sD,{p:4,children:[g.jsx(xe,{children:t.content}),g.jsx(xe,{fontWeight:"bold",fontSize:12,marginTop:2,children:RK(t.created_at)})]}),g.jsx(aD,{p:4,children:g.jsxs(Mn,{children:[g.jsx(_,{}),g.jsxs(xe,{children:["Relay ",o[0].substring(0,5),"..."]})]})})]}),g.jsxs(Us,{isOpen:x,onClose:m,size:"full",closeOnOverlayClick:!0,children:[g.jsx(Gs,{}),g.jsxs(Ws,{children:[g.jsx(Hs,{children:e&&e}),g.jsx(qs,{children:g.jsx(Ca,{src:w||"",fallback:g.jsx(Ca,{src:"/no-image.png"}),fallbackStrategy:"onError",alt:"Enlarged view",height:"80vh",marginLeft:"auto",marginRight:"auto"})}),g.jsxs(R0,{children:[g.jsx(_,{}),g.jsx(Oe,{marginLeft:4,onClick:m,children:"Close"})]})]})]})]})}function YP(e){const[t,n]=Q(s=>[s.events,s.maxEvents]),[r,o]=b.useState(0),i=async()=>{r===0&&o(r+1),await Q.getState().setMaxEvents(n+Ls),e&&await Q.getState().setViewSubscription(e.view,e.filters)};return g.jsxs(Se,{maxHeight:"80vh",overflowY:"auto",children:[t.map(s=>g.jsx(Se,{padding:2,children:g.jsx(AK,{event:s.event,user:s.user,reactions:s.reactions,reposts:s.reposts,eventRelayIds:s.eventRelayIds,userComponent:e&&e.userComponent?s.user&&s.user.pubkey?g.jsx(e.userComponent,{user:s.user,relayId:s.eventRelayIds[0]}):g.jsx(e.userComponent,{user:{pubkey:s.event.pubkey},relayId:s.eventRelayIds[0]}):void 0},s.event.id)},s.event.id)),t.length===0&&g.jsx(xe,{children:"Waiting for fresh content ... hold on."}),t.length>=n&&g.jsxs(Se,{display:"flex",justifyContent:"space-between",padding:2,children:[g.jsxs(Oe,{flex:"1",marginRight:2,onClick:i,children:["Load ",Ls," more"]}),g.jsx(Oe,{flex:"1",marginLeft:2,onClick:async()=>Q.getState().clearEvents(),children:"Reset and load new (performance)"})]})]})}function Kf({user:e,relayId:t,hideFollow:n}){const[r]=Q(c=>[c.followingUserIds.find(u=>u===e.pubkey)]),o=e.data?e.data:null,i=o&&o.display_name?o.display_name:"Anonymous",s=o&&o.name?o.name:"Anonymous",a=o&&o.picture?o.picture:"/no-image.png",l=`/p/${t}/${e.pubkey}`;return g.jsxs(pd,{children:[g.jsx(Se,{mr:"3",children:g.jsx(FE,{size:"sm",src:a})}),g.jsx(Se,{children:g.jsxs(rP,{to:l,children:[g.jsx(Vt,{size:"sm",children:i}),g.jsx(xe,{fontSize:"sm",children:s})]})}),g.jsx(kT,{}),!n&&g.jsx(Oe,{variant:"outline",colorScheme:r?"red":"green",onClick:()=>r?Q.getState().unfollowUser(e.pubkey):Q.getState().followUser({pubkey:e.pubkey,relayId:t}),children:r?"Unfollow":"Follow"})]})}function $K(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Dd=$K(b),OK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Fx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=IK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Dd.createElement("svg",OK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Dd.createElement("path",{d:"M2,21L23,12L2,3V10L17,12L2,14V21Z"}))},jK=Dd.memo?Dd.memo(Fx):Fx,LK=jK;const MK=Ge(LK);function BK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Vd=BK(b),zK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Nx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=FK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Vd.createElement("svg",zK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Vd.createElement("path",{d:"M4,9H20V11H4V9M4,13H14V15H4V13Z"}))},NK=Vd.memo?Vd.memo(Nx):Nx,DK=NK;const VK=Ge(DK);function UK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Ud=UK(b),WK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Dx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=HK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Ud.createElement("svg",WK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Ud.createElement("path",{d:"M4,5H20V7H4V5M4,9H20V11H4V9M4,13H20V15H4V13M4,17H14V19H4V17Z"}))},GK=Ud.memo?Ud.memo(Dx):Dx,qK=GK;const KK=Ge(qK);function ZK(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Wd=ZK(b),YK=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Vx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=QK(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Wd.createElement("svg",YK({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Wd.createElement("path",{d:"M10,9V5L3,12L10,19V14.9C15,14.9 18.5,16.5 21,20C20,15 17,10 10,9Z"}))},XK=Wd.memo?Wd.memo(Vx):Vx,JK=XK;const eZ=Ge(JK);function tZ(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Hd=tZ(b),nZ=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Ux=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=rZ(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Hd.createElement("svg",nZ({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Hd.createElement("path",{d:"M12,6C8.6,6 5.5,7.1 3,9L1.2,6.6C4.2,4.3 8,3 12,3C16,3 19.8,4.3 22.8,6.6L21,9C18.5,7.1 15.4,6 12,6M13,19C13,17.7 13.4,16.4 14.2,15.4C13.5,15.2 12.8,15 12,15C10.7,15 9.4,15.5 8.4,16.2L12,21L13,19.6C13,19.4 13,19.2 13,19M16.8,13.4C17.1,13.3 17.5,13.2 17.9,13.1L19.2,11.4C17.2,9.9 14.7,9 12,9C9.3,9 6.8,9.9 4.8,11.4L6.6,13.8C8.1,12.7 10,12 12,12C13.8,12 15.4,12.5 16.8,13.4M16.5,22.6L17.2,19.8L15,17.9L17.9,17.7L19,15L20.1,17.6L23,17.8L20.8,19.7L21.5,22.5L19,21.1L16.5,22.6Z"}))},oZ=Hd.memo?Hd.memo(Ux):Ux,iZ=oZ;const sZ=Ge(iZ);async function _p(e,t){try{let n=await Promise.race([fetch(e,{headers:t}),new Promise((o,i)=>setTimeout(()=>i(new Error("Timeout")),5e3))]);if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){throw new Error(`Error making request: ${n}`)}}var Tg=class extends RG{constructor(e){super(e)}async makeZapRequest(e,t){const n=this.getLud16Or06Url();if(n)try{if(!this.hasZapInfo()){const s=await _p(n.url);if(!lG(s))throw new Error("Lnurl endpoint does not allow Nostr payments. Expected to find 'allowsNostr' in response.");this.lightningZapInfo=s}console.log("LnurlEndpointResponse",this.lightningZapInfo);const r={...e,recipientPubkey:this.pubkey,lnurl:n.type==="lud16"?pG(this.getLud16()):this.getLud06()},o=PG(r,this.lightningZapInfo.callback,t),i=await _p(o.invoiceUrl);if(!cG(r,i))throw new Error("Lnurl invoice response is invalid or does not match your request.");return console.log("LnurlInvoiceResponse",i),{...i,event:o.event}}catch(r){throw new Error(`Error making zap request: ${r}`)}else throw new Error("No lud16 or lud06 url found")}async makeNIP05Request(){const e=this.getNip05Url();if(e)try{return await _p(e)}catch(t){throw new Error(`Error making NIP05 request: ${t}`)}else throw new Error("No nip05 url found")}};const QP=()=>{var y;const[e]=Q(m=>[m.connected&&m.keystore!=="none"]),[t,n]=b.useState([]),[r,o,i,s,a]=Q(m=>{var w;return[m.keystore,m.keypair,((w=m.newEvent)==null?void 0:w.kind)||0,m.newEventName,m.newEvent]}),l=Hl(),[c,u]=b.useState([]),[d]=Q(m=>{var w;return[(w=m.newEvent)==null?void 0:w.hasPublicKeyTags()]}),[f,p]=b.useState("");b.useEffect(()=>{(async()=>{const w=[];if(d)for(const S of d){S.length===2&&p(S[1]);const C=S[0],T=await Q.getState().getUser(C);T?w.push(T):w.push(new Tg({pubkey:C}))}u(w)})()},[d,s]);const v=async()=>{if(n([]),!a){n(["Event is required"]),l({title:"Error",description:"Event is required",status:"error",duration:5e3,isClosable:!0});return}if(r&&r==="none"){n(["Keystore is required"]),l({title:"Error",description:"Keystore is required",status:"error",duration:5e3,isClosable:!0});return}if(!o){n(["Keypair is required"]),l({title:"Error",description:"Keypair is required",status:"error",duration:5e3,isClosable:!0});return}if(!a.content){n(["Event content is required"]),l({title:"Error",description:"Event content is required",status:"error",duration:5e3,isClosable:!0});return}try{const m=await Q.getState().signAndSendEvent({event:a});m&&(l({title:"Success",description:`Event ${m} submitted`,status:"success",duration:5e3,isClosable:!0}),x(s,!0))}catch(m){let w="";m instanceof Error?w=m.message:w=m?m.toString():"Unknown error",n([w]),l({title:"Error",description:w,status:"error",duration:5e3,isClosable:!0});return}},h=m=>{switch(m){case"NewShortTextNote":return"Short Text Note";case"NewRecommendRelay":return"Recommend Relay";case"NewLongFormContent":return"Long Form Content";case"NewShortTextNoteResponse":return"Short Text Note Response";case"NewQuoteRepost":return"Quote Repost";default:return""}},x=(m,w=!1)=>{let S;if(!w&&m===s){console.log(`Already set to ${m}`);return}switch(m){case"NewShortTextNote":S=xG({text:""}),m="NewShortTextNote";break;case"NewRecommendRelay":S=EG({relayUrl:Object.keys(Eg)[0]}),m="NewRecommendRelay";break;case"NewLongFormContent":S=SG({text:""}),m="NewLongFormContent";break;case"NewQuoteRepost":S=MP({inResponseTo:new Tg({pubkey:""}),relayUrl:Object.keys(Eg)[0]});break;default:n(["Invalid event type"]);return}Q.getState().setNewEvent(S),Q.getState().setNewEventName(m),n([])};return g.jsxs(Se,{width:"100%",children:[g.jsxs(Sl,{marginBottom:4,children:[g.jsxs(kl,{children:["Type: ",h(s)]}),c.map(m=>g.jsx(Kf,{user:m,relayId:f},m.pubkey))]}),g.jsxs(Sl,{marginBottom:4,children:[g.jsx(kl,{children:"Content"}),g.jsx(li,{type:"text",as:i===Or.LONG_FORM_CONTENT?HT:li,value:((y=Q.getState().newEvent)==null?void 0:y.content)||"",onChange:m=>Q.getState().setNewEventContent(m.target.value),placeholder:"Enter event content"})]}),g.jsxs(Mn,{marginBottom:4,children:[g.jsx(Ai,{"aria-label":"Short Text Note",icon:g.jsx($e,{as:VK}),onClick:()=>x("NewShortTextNote"),isActive:s==="NewShortTextNote"}),g.jsx(Ai,{"aria-label":"NewLongFormContent",icon:g.jsx($e,{as:KK}),onClick:()=>x("NewLongFormContent"),isActive:s==="NewLongFormContent"}),g.jsx(Ai,{"aria-label":"NewShortTextNoteResponse",icon:g.jsx($e,{as:eZ}),onClick:()=>x("NewShortTextNoteResponse"),isActive:s==="NewShortTextNoteResponse",isDisabled:s!=="NewShortTextNoteResponse"}),g.jsx(Ai,{"aria-label":"NewRecommendRelay",icon:g.jsx($e,{as:sZ}),onClick:()=>x("NewRecommendRelay"),isActive:s==="NewRecommendRelay"}),g.jsx(Ai,{"aria-label":"NewQuoteRepost",icon:g.jsx($e,{as:ZP}),onClick:()=>x("NewQuoteRepost"),isActive:s==="NewQuoteRepost",isDisabled:s!=="NewQuoteRepost"})]}),t.map((m,w)=>g.jsx(Se,{color:"red.500",children:m},w)),g.jsx(Oe,{type:"submit",colorScheme:"blue",onClick:v,leftIcon:g.jsx($e,{as:MK}),isDisabled:!e,children:"Send"})]})};function aZ(){const[e,t]=Q(o=>[o.connected,o.events.length>=o.maxEvents]),n=new Td({kinds:[Or.SHORT_TEXT_NOTE,Or.LONG_FORM_CONTENT],limit:Ls}),r=b.useRef(!1);return b.useEffect(()=>{(async()=>{!e||r.current||(r.current=!0,await Q.getState().clearEvents(),await Q.getState().setViewSubscription("welcome",n))})()},[]),b.useEffect(()=>{(async()=>{!e||r.current||(r.current=!0,await Q.getState().setViewSubscription("welcome",n))})()},[e]),b.useEffect(()=>{t&&(async()=>{e&&await Q.getState().removeViewSubscription("welcome")})()},[t]),g.jsxs(zf,{templateColumns:["1fr","2fr 1fr"],gap:20,children:[g.jsx(Se,{maxHeight:"80vh",overflowY:"auto",children:g.jsx(Se,{children:e?g.jsx(YP,{userComponent:Kf,view:"welcome",filters:n,connected:e}):g.jsxs(Se,{maxWidth:600,children:[g.jsx(Vt,{size:"lg",children:"About Nostr"}),g.jsx(xe,{marginBottom:2,fontWeight:"bold",children:"Tldr: Nostr is a decentralized social network."}),g.jsx(xe,{marginBottom:4,children:"Nostr is anything you can imagine. A new reddit, Twitter, Facebook, Mastodon - Craigstslist or Ebay? It's only a matter of what the interface looks like, the underlying network is the same, and so is your identity - so you get to access it all, without giving up yourself."}),g.jsx(Vt,{size:"md",children:"Connect to get started"}),g.jsx(xe,{marginBottom:2,children:"You don't need an account to browse or follow users. All data is saved in your browser. To interact with events, generate or supply a keypair."}),g.jsx(xe,{children:"nos2x and nos2x-fox should be working too."})]})})}),g.jsxs(Se,{display:"flex",flexDirection:"column",children:[g.jsx(Vt,{as:"h2",size:"md",marginBottom:4,children:"Broadcast to the Network"}),g.jsx(QP,{})]})]})}function lZ(){const[e,t]=b.useState([]),n=b.useRef(!1),r=o=>o&&o.length>0?o[0]:"";return b.useEffect(()=>{(async()=>{if(n.current)return;n.current=!0;const i=await Q.getState().getAllUsersFollowing();i&&t(i)})()},[]),g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Following"}),e.length>0?g.jsx(g.Fragment,{children:e.map(o=>g.jsx(Se,{mb:"3",children:g.jsx(Kf,{user:o.user,relayId:r(o.relayIds)},o.user.pubkey)},o.user.pubkey))}):g.jsxs(g.Fragment,{children:[g.jsx(xe,{children:"Follow users to subscribe to their messages. The subscription is stored in your browser and not shared with relays."}),g.jsx(xe,{fontWeight:"bold",children:"You are not following anyone."})]})]})}const XP=Object.keys(Or).map(e=>({name:e,value:Or[e]})),cZ=e=>{const t=XP.find(n=>n.value===e);return t?t.name:"Unknown"},uZ=e=>e.map(cZ).join(", ");function dZ(){const[e,t]=b.useState([]),[n,r]=b.useState(null),{isOpen:o,onOpen:i,onClose:s}=ql(),a=async()=>{const u=await Q.getState().getSubscriptions();u&&t(u)};b.useEffect(()=>{(async()=>{await a()})();const d=setInterval(a,1e3);return()=>clearInterval(d)},[]);const l=g.jsxs(Us,{isOpen:o,onClose:s,size:"xl",children:[" ",g.jsx(Gs,{}),g.jsxs(Ws,{maxHeight:"80vh",maxWidth:"80vw",children:[" ",g.jsx(Hs,{children:"Filters"}),g.jsx(Yl,{}),g.jsxs(qs,{overflowY:"auto",children:[" ",g.jsx("pre",{children:n})]})]})]}),c=u=>{const d=u.options&&u.options.view?u.options.view:"";return g.jsxs(Os,{children:[g.jsx(_t,{children:g.jsx(Rl,{label:u.id,children:`${u.id.substring(0,3)}..`})}),g.jsx(_t,{children:u.filters.kinds&&uZ(u.filters.kinds)}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>{r(JSON.stringify(u.filters,null,2)),i()},children:"Show"})}),g.jsx(_t,{children:g.jsx(Rl,{label:d,children:`${d.substring(0,4)}..`})}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>Q.getState().unsubscribe(u.id),children:"Unsubscribe"})})]},u.id)};return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Subscriptions"}),g.jsxs(Df,{variant:"simple",marginBottom:4,children:[g.jsx(A0,{children:g.jsxs(Os,{children:[g.jsx(Rt,{children:"ID"}),g.jsx(Rt,{children:"Kind"}),g.jsx(Rt,{children:"Filter"}),g.jsx(Rt,{children:"View"}),g.jsx(Rt,{children:"Action"})]})}),g.jsx($0,{children:e.map(u=>c(u))})]}),g.jsx(Vt,{size:"md",marginBottom:2,children:"Legend"}),XP.map(u=>g.jsxs(xe,{children:[u.name," - ",u.value]},u.name)),l]})}function fZ(){const[e,t]=Q(c=>[c.connected,c.events.length>=c.maxEvents]),[n,r]=b.useState(null),o=QU(),i=o.pubkey||"",s=o.relayid||"",a=`profile-${i}`,l=new Td({limit:Ls,authors:[i],kinds:[Or.SHORT_TEXT_NOTE,Or.LONG_FORM_CONTENT]});return b.useEffect(()=>{(async()=>{if(e){if(await Q.getState().clearEvents(),await Q.getState().setViewSubscription(a,l),!n){const u=await Q.getState().getUser(i);r(u||new Tg({pubkey:i}))}await Q.getState().count({type:H0.COUNT,filters:new Td({kinds:[3],"#p":[i]}),options:{timeout:1e4,timeoutAt:Date.now()+1e4}})}})()},[]),b.useEffect(()=>{t&&(async()=>{e&&await Q.getState().removeViewSubscription(a)})()},[t]),g.jsxs(zf,{templateColumns:["1fr","2fr 1fr"],gap:20,children:[g.jsxs(Se,{maxHeight:"80vh",overflowY:"auto",children:[g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Profile"}),n&&g.jsx(Kf,{user:n,relayId:s})]}),g.jsx(Se,{children:e?g.jsx(YP,{view:a,filters:l,connected:e}):g.jsx(xe,{children:"Not connected."})})]}),g.jsxs(Se,{display:"flex",flexDirection:"column",children:[g.jsx(Vt,{as:"h2",size:"md",marginBottom:4,children:"Broadcast to the Network"}),g.jsx(QP,{})]})]})}function hZ(){const[e,t]=b.useState([]),[n,r]=b.useState(null),[o,i]=b.useState(!1),{isOpen:s,onOpen:a,onClose:l}=ql(),c=async()=>{const h=await Q.getState().getRelays();h&&t(h)};b.useEffect(()=>{(async()=>{await c()})();const x=setInterval(c,2e3);return()=>clearInterval(x)},[]);const u=async h=>{i(!0);const x=!h.read;await Q.getState().updateRelay(h.id,{read:x}),await c(),i(!1)},d=async h=>{i(!0);const x=!h.write;await Q.getState().updateRelay(h.id,{write:x}),await c(),i(!1)};function f({obj:h}){return h?g.jsx("div",{children:Object.entries(h).map(([x,y])=>typeof y=="object"&&y!==null&&!Array.isArray(y)?g.jsxs("div",{children:[g.jsxs("strong",{children:[x,":"]}),g.jsx(f,{obj:y})]},x):Array.isArray(y)?g.jsxs("div",{children:[g.jsxs("strong",{children:[x,":"]}),g.jsx("ul",{children:y.map((m,w)=>g.jsx("li",{children:typeof m=="object"&&m!==null?g.jsx(f,{obj:m}):m.toString()},w))})]},x):g.jsxs("div",{children:[g.jsxs("strong",{children:[x,":"]})," ",y==null?void 0:y.toString()]},x))}):null}const p=g.jsxs(Us,{isOpen:s,onClose:l,size:"xl",children:[g.jsx(Gs,{}),g.jsxs(Ws,{maxHeight:"80vh",maxWidth:"80vw",children:[g.jsx(Hs,{children:"Relay"}),g.jsx(Yl,{}),g.jsx(qs,{overflowY:"auto",children:n&&n.info&&g.jsx(f,{obj:n.info})})]})]}),v=h=>g.jsxs(Os,{children:[g.jsx(_t,{children:g.jsx(Rl,{label:h.id,children:`${h.id.substring(0,3)}..`})}),g.jsx(_t,{children:h.url}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>{r(h),a()},children:"Show"})}),g.jsx(_t,{children:g.jsx(dg,{isChecked:h.read,onChange:()=>u(h),isDisabled:o})}),g.jsx(_t,{children:g.jsx(dg,{isChecked:h.write,onChange:()=>d(h),isDisabled:o})})]},h.id);return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Relays"}),g.jsxs(Df,{variant:"simple",marginBottom:4,children:[g.jsx(A0,{children:g.jsxs(Os,{children:[g.jsx(Rt,{children:"ID"}),g.jsx(Rt,{children:"Url"}),g.jsx(Rt,{children:"Info"}),g.jsx(Rt,{children:"Read"}),g.jsx(Rt,{children:"Write"})]})}),g.jsx($0,{children:e.map(h=>v(h))})]}),p]})}function pZ(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var Gd=pZ(b),mZ=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Wx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=gZ(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return Gd.createElement("svg",mZ({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),Gd.createElement("path",{d:"M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"}))},vZ=Gd.memo?Gd.memo(Wx):Wx,yZ=vZ;const Rp=Ge(yZ);function bZ(e){return e&&typeof e=="object"&&"default"in e?e.default:e}var qd=bZ(b),wZ=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},Hx=function(t){var n=t.color,r=n===void 0?"currentColor":n,o=t.size,i=o===void 0?24:o;t.children;var s=xZ(t,["color","size","children"]),a="mdi-icon "+(s.className||"");return qd.createElement("svg",wZ({},s,{className:a,width:i,height:i,fill:r,viewBox:"0 0 24 24"}),qd.createElement("path",{d:"M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"}))},SZ=qd.memo?qd.memo(Hx):Hx,kZ=SZ;const Ap=Ge(kZ);function CZ(){const[e]=Q(d=>[d.eventsPublishingQueue]),[t,n]=b.useState(null),r=d=>!!d.error,o=d=>d.error?d.error:"",{isOpen:i,onOpen:s,onClose:a}=ql();function l({obj:d}){return g.jsx("div",{children:Object.entries(d).map(([f,p])=>typeof p=="object"&&!Array.isArray(p)?g.jsxs("div",{children:[g.jsxs("strong",{children:[f,":"]}),g.jsx(l,{obj:p})]},f):Array.isArray(p)?g.jsxs("div",{children:[g.jsxs("strong",{children:[f,":"]}),g.jsx("ul",{children:p.map((v,h)=>g.jsx("li",{children:typeof v=="object"?g.jsx(l,{obj:v}):v},h))})]},f):g.jsxs("div",{children:[g.jsxs("strong",{children:[f,":"]})," ",p?p.toString():"null"]},f))})}const c=g.jsxs(Us,{isOpen:i,onClose:a,size:"xl",children:[g.jsx(Gs,{}),g.jsxs(Ws,{maxHeight:"80vh",maxWidth:"80vw",children:[g.jsx(Hs,{children:"Queue Item Detail"}),g.jsx(Yl,{}),g.jsx(qs,{overflowY:"auto",children:t&&g.jsx(l,{obj:t})})]})]}),u=d=>{const f=d.event.id||"";return g.jsxs(Os,{children:[g.jsx(_t,{children:g.jsx(Rl,{label:f,children:`${f.substring(0,3)}..`})}),g.jsx(_t,{children:g.jsxs(Mn,{children:[d.pow?g.jsx(xe,{children:d.pow}):g.jsx(xe,{children:"0"}),g.jsx(xe,{children:"/"}),g.jsx($e,{as:d.powDone?Rp:Ap})]})}),g.jsx(_t,{children:g.jsx(Oe,{size:"sm",onClick:()=>{n(d),s()},children:"Show"})}),g.jsx(_t,{children:g.jsx($e,{as:d.send?Rp:Ap,marginRight:1})}),g.jsxs(_t,{children:[g.jsx($e,{as:d.accepted?Rp:Ap}),r(d)&&g.jsx(xe,{color:"red.500",children:o(d)})]})]},f)};return g.jsxs(Se,{children:[g.jsx(Vt,{size:"lg",children:"Queue"}),g.jsxs(Df,{variant:"simple",marginBottom:4,children:[g.jsx(A0,{children:g.jsxs(Os,{children:[g.jsx(Rt,{children:"Event ID"}),g.jsx(Rt,{children:"POW / Done"}),g.jsx(Rt,{children:"Info"}),g.jsx(Rt,{children:"Send"}),g.jsx(Rt,{children:"Accepted"})]})}),g.jsx($0,{children:e.map(d=>u(d))})]}),c]})}const EZ=async()=>{await Q.getState().init({maxEvents:Ls})};EZ();hg.createRoot(document.getElementById("root")).render(g.jsx(ei.StrictMode,{children:g.jsx(DN,{children:g.jsx(yW,{basename:"/nostr-ts/",children:g.jsx(fW,{children:g.jsxs(dr,{element:g.jsx(dK,{}),children:[g.jsx(dr,{path:"/",element:g.jsx(aZ,{})}),g.jsx(dr,{path:"/account",element:g.jsx(pq,{})}),g.jsx(dr,{path:"/following",element:g.jsx(lZ,{})}),g.jsx(dr,{path:"/subscriptions",element:g.jsx(dZ,{})}),g.jsx(dr,{path:"/relays",element:g.jsx(hZ,{})}),g.jsx(dr,{path:"/queue",element:g.jsx(CZ,{})}),g.jsx(dr,{path:"/p/:relayid/:pubkey",element:g.jsx(fZ,{})})]})})})})})); diff --git a/index.html b/index.html index c5dbaf6..f4ef557 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ Nostr React Client Playground - +