PageSourceSearch

https://ultimateswarm.ai/assets/js/watchlistService-CYATTc8D.js

js ultimateswarm.ai collected 2026-10-05 13:12:17 UTC 13,525 bytes, 1 lines download raw bytes

1import{c as T,j as m,L as p}from"./index-gQh_1vMV.js";import"./vendor-shared-DDxGyXze.js";import"./vendor-react-WbYzT9B1.js";import"./vendor-supabase-bqjDK5Eu.js";import"./vendor-icons-DL8ftop_.js";import"./vendor-sentry-QE7Hifj1.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};n.SENTRY_RELEASE={id:"b19af26d6b3b2e41c3d08e2ef62b63e2331ea50d"};var t=new n.Error().stack;t&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[t]="c7fbe9b0-ca7c-4749-86c9-8587e338093d",n._sentryDebugIdIdentifier="sentry-dbid-c7fbe9b0-ca7c-4749-86c9-8587e338093d")}catch{}})();var w=(n=>(n.FAVORITES="FAVORITES",n.TRENDING="TRENDING",n.RESEARCH="RESEARCH",n.PORTFOLIO="PORTFOLIO",n.CUSTOM="CUSTOM",n))(w||{});const S=[{id:"favorites",name:"Favorites",description:"Your favorite tokens",category:"FAVORITES",defaultSettings:{defaultView:"GRID",defaultSort:"CUSTOM_ORDER",showSparklines:!0,enableDragDrop:!0},icon:"⭐",color:"#FFD700"},{id:"trending",name:"Trending",description:"Currently trending tokens",category:"TRENDING",defaultSettings:{defaultView:"LIST",defaultSort:"VOLUME",sortDirection:"desc",autoRefresh:!0,refreshInterval:3e4},icon:"🔥",color:"#FF6B6B"},{id:"research",name:"Research",description:"Tokens under research",category:"RESEARCH",defaultSettings:{defaultView:"LIST",defaultSort:"ADDED_DATE",showPriceAlerts:!0},icon:"🔍",color:"#4ECDC4"},{id:"portfolio",name:"Portfolio",description:"Tokens in your portfolio",category:"PORTFOLIO",defaultSettings:{defaultView:"LIST",defaultSort:"CHANGE_24H",showPerformanceMetrics:!0,autoRefresh:!0},icon:"💼",color:"#95E1D3"}],f={WATCHLISTS:"ultimate_swarm_watchlists",ACTIVE_WATCHLIST:"ultimate_swarm_active_watchlist",WATCHLIST_STATE:"ultimate_swarm_watchlist_state",PRICE_HISTORY:"ultimate_swarm_price_history",NOTIFICATIONS:"ultimate_swarm_watchlist_notifications"},d={MAX_WATCHLISTS:50,MAX_TOKENS_PER_WATCHLIST:1e3,MAX_NOTES_PER_TOKEN:10,MAX_ALERTS_PER_TOKEN:5,MAX_NOTE_LENGTH:1e3,MAX_WATCHLIST_NAME_LENGTH:50},c=m({level:p.INFO,context:{service:"watchlistService"}}),E=500,h=class h{constructor(){this.watchlists=new Map,this.priceHistory=new Map,this.shares=new Map,this.prices=new Map,this.config={maxWatchlists:d.MAX_WATCHLISTS,maxItemsPerWatchlist:d.MAX_TOKENS_PER_WATCHLIST,enableAutoSync:!0,syncIntervalMs:5e3},this.syncTimer=null,this.generateId=()=>`${Date.now()}-${T().toString(36).substring(2,11)}`,this.startAutoSync=()=>{this.syncTimer&&clearInterval(this.syncTimer),this.syncTimer=setInterval(()=>this.saveToStorage(),this.config.syncIntervalMs)},this.stopAutoSync=()=>{this.syncTimer&&(clearInterval(this.syncTimer),this.syncTimer=null)},this.getWatchlist=t=>this.watchlists.get(t),this.getAllWatchlists=()=>Array.from(this.watchlists.values()).sort((t,e)=>t.isPinned!==e.isPinned?t.isPinned?-1:1:(t.order||0)-(e.order||0)),this.getWatchlistsByCategory=t=>this.getAllWatchlists().filter(e=>e.category===t),this.getPriceHistory=t=>this.priceHistory.get(t),this.updatePrice=t=>{if(this.prices.set(t.symbol,t),this.prices.size>h.MAX_PRICE_ENTRIES){const e=Array.from(this.prices.keys()).slice(0,this.prices.size-h.MAX_PRICE_ENTRIES);for(const s of e)this.prices.delete(s)}},this.getTokenPrice=t=>this.prices.get(t)?.price,this.getConfig=()=>this.config,this.subscribeToPriceUpdates=t=>t(e=>this.updatePrice(e)),this.sync=()=>this.saveToStorage(),this.loadFromStorage(),this.config.enableAutoSync&&this.startAutoSync()}loadFromStorage(){try{const t=localStorage.getItem(f.WATCHLISTS);t?(JSON.parse(t).forEach(s=>this.watchlists.set(s.id,s)),c.info("Loaded watchlists from storage",{count:this.watchlists.size})):this.createDefaultWatchlists();const e=localStorage.getItem(f.PRICE_HISTORY);e&&JSON.parse(e).forEach(s=>this.priceHistory.set(s.address,s))}catch(t){c.error("Failed to load watchlists",{error:t}),this.createDefaultWatchlists()}}saveToStorage(){try{localStorage.setItem(f.WATCHLISTS,JSON.stringify(Array.from(this.watchlists.values()))),localStorage.setItem(f.PRICE_HISTORY,JSON.stringify(Array.from(this.priceHistory.values())))}catch(t){c.error("Failed to save watchlists",{error:t})}}createDefaultWatchlists(){const t=S[0],e=this.createWatchlist(t.name,t.category,{description:t.description,icon:t.icon,color:t.color,settings:t.defaultSettings,isPinned:!0});this.watchlists.set(e.id,e),this.saveToStorage()}createWatchlist(t,e=w.CUSTOM,s){if(this.watchlists.size>=this.config.maxWatchlists)throw new Error(`Maximum ${this.config.maxWatchlists} watchlists allowed`);const o={id:this.generateId(),name:t.slice(0,d.MAX_WATCHLIST_NAME_LENGTH),description:s?.description,category:e,tokens:[],color:s?.color,
1icon:s?.icon,createdAt:Date.now(),updatedAt:Date.now(),settings:s?.settings,isPinned:s?.isPinned||!1,order:this.watchlists.size};return this.watchlists.set(o.id,o),this.saveToStorage(),c.info("Watchlist created",{id:o.id,name:t}),o}updateWatchlist(t,e){const s=this.watchlists.get(t);if(!s)throw new Error(`Watchlist ${t} not found`);const o={...s,...e,id:s.id,createdAt:s.createdAt,updatedAt:Date.now()};return this.watchlists.set(t,o),this.saveToStorage(),c.info("Watchlist updated",{id:t}),o}deleteWatchlist(t){const e=this.watchlists.delete(t);return e&&(this.saveToStorage(),c.info("Watchlist deleted",{id:t})),e}addToken(t,e,s,o){const i=this.watchlists.get(t);if(!i)throw new Error(`Watchlist ${t} not found`);if(i.tokens.length>=this.config.maxItemsPerWatchlist)throw new Error(`Maximum ${this.config.maxItemsPerWatchlist} tokens per watchlist`);if(i.tokens.some(a=>a.address===e))throw new Error("Token already in watchlist");const r={address:e,addedAt:Date.now(),priceAtAdd:s,tags:o?.tags,isFavorite:o?.isFavorite,customOrder:i.tokens.length};return o?.note&&(r.notes=[{id:this.generateId(),content:o.note,createdAt:Date.now(),updatedAt:Date.now()}]),i.tokens.push(r),i.updatedAt=Date.now(),this.watchlists.set(t,i),this.saveToStorage(),this.recordPrice(e,s),c.info("Token added",{watchlistId:t,tokenAddress:e}),i}removeToken(t,e){const s=this.watchlists.get(t);if(!s)throw new Error(`Watchlist ${t} not found`);return s.tokens=s.tokens.filter(o=>o.address!==e),s.updatedAt=Date.now(),this.watchlists.set(t,s),this.saveToStorage(),c.info("Token removed",{watchlistId:t,tokenAddress:e}),s}batchAddTokens(t,e){const s={success:0,failed:0,errors:[]};for(const o of e)try{this.addToken(t,o.address,o.price),s.success++}catch(i){s.failed++,s.errors.push({address:o.address,error:i instanceof Error?i.message:"Unknown"})}return s}batchRemoveTokens(t,e){const s={success:0,failed:0,errors:[]};for(const o of e)try{this.removeToken(t,o),s.success++}catch(i){s.failed++,s.errors.push({address:o,error:i instanceof Error?i.message:"Unknown"})}return s}moveToken(t,e,s,o){const i=this.watchlists.get(t),r=this.watchlists.get(e);if(!i||!r)throw new Error("Source or target watchlist not found");const a=i.tokens.find(l=>l.address===s);if(!a)throw new Error("Token not found");this.removeToken(t,s),this.addToken(e,s,o,{tags:a.tags,isFavorite:a.isFavorite})}reorderTokens(t,e){const s=this.watchlists.get(t);if(!s)throw new Error(`Watchlist ${t} not found`);const o=new Map(s.tokens.map(i=>[i.address,i]));return s.tokens=e.map(i=>o.get(i)).filter(i=>!!i).map((i,r)=>({...i,customOrder:r})),s.updatedAt=Date.now(),this.watchlists.set(t,s),this.saveToStorage(),s}addTokenNote(t,e,s){const o=this.watchlists.get(t);if(!o)throw new Error(`Watchlist ${t} not found`);const i=o.tokens.find(r=>r.address===e);if(!i)throw new Error("Token not found");if(i.notes||(i.notes=[]),i.notes.length>=d.MAX_NOTES_PER_TOKEN)throw new Error(`Maximum ${d.MAX_NOTES_PER_TOKEN} notes`);i.notes.push({id:this.generateId(),content:s.slice(0,d.MAX_NOTE_LENGTH),createdAt:Date.now(),updatedAt:Date.now()}),o.updatedAt=Date.now(),this.saveToStorage()}addPriceAlert(t,e,s){const o=this.watchlists.get(t);if(!o)throw new Error(`Watchlist ${t} not found`);const i=o.tokens.find(r=>r.address===e);if(!i)throw new Error("Token not found");if(i.alerts||(i.alerts=[]),i.alerts.length>=d.MAX_ALERTS_PER_TOKEN)throw new Error(`Maximum ${d.MAX_ALERTS_PER_TOKEN} alerts`);i.alerts.push({...s,id:this.generateId(),tokenAddress:e,createdAt:Date.now()}),o.updatedAt=Date.now(),this.saveToStorage()}recordPrice(t,e,s){let o=this.priceHistory.get(t);if(o||(o={address:t,prices:[],firstRecorded:Date.now(),lastRecorded:Date.now()},this.priceHistory.set(t,o)),o.prices.push({timestamp:Date.now(),price:e,volume:s}),o.lastRecorded=Date.now(),o.prices.length>1e3&&(o.prices=o.prices.slice(-1e3)),this.priceHistory.size>h.MAX_PRICE_HISTORY_ENTRIES){const i=Array.from(this.priceHistory.keys()).slice(0,this.priceHistory.size-h.MAX_PRICE_HISTORY_ENTRIES);for(const r of i)this.priceHistory.delete(r)}this.saveToStorage()}searchTokens(t){const e=t.toLowerCase(),s=[];for(const o of this.watchlists.values())for(const i of o.tokens)(i.address.toLowerCase().includes(e)||i.tags?.some(r=>r.toLowerCase().includes(e))||i.notes?.some(r=>r.content.toLowerCase().includes(e)))&&s.push({watchlist:o,token:i});return s}filterTokens(t,e,s){const o=this.watchlists.get(t);if(!o)return[];let i=s;if(e.search){const r=e.search.toLowerCase();i=i.filter(a=>a.address.toLowerCase().includes(r)||a.symbol.toLowerCase().includes(r)||a.name?.toLowerCase().includes(r))}if(e.minPrice!==void 0&&(i=i.filter(r=>r.price>=e.minPrice)),e.maxPrice!==void 0&&(i=i.filter(r=>r.price<=e.maxPrice)),e.minChange24h!==void 0&&(i=i.filter(r=>(r.change24h||0)>=e.minChange24h)),e.maxChange24h!==void 0&&(i=i.filter(r=>(r.change24h||0)<=e.maxChange24h)),e.minVolume!==void 0&&(i=i.filter(r=>r.volume24h>=e.minVolume)),e.maxVolume!==void 0&&(i=i.filter(r=>r.volume24h<=e.maxVolume)),e.tags?.length){const r=new Map(o.tokens.map(a=>[a.address,a]));i=i.filter(a=>r.get(a.address)?.tags?.some(l=>e.tags.includes(l)))}if(e.hasFavorites){const r=new Map(o.tokens.map(a=>[a.address,a]));i=i.filter(a=>r.get(a.address)?.isFavorite)}return i}
1exportWatchlist(t,e){const s=this.watchlists.get(t);if(!s)throw new Error(`Watchlist ${t} not found`);return{version:"1.0.0",exportedAt:Date.now(),watchlist:{...s,tokens:s.tokens.map(o=>({...o,notes:e?.includeNotes?o.notes:void 0,alerts:e?.includeAlerts?o.alerts:void 0}))},tokens:s.tokens}}importWatchlist(t){const e={watchlistsImported:0,tokensImported:0,duplicatesSkipped:0,errors:[]};try{const s=Array.from(this.watchlists.values()).find(o=>o.name===t.watchlist.name);if(s){for(const o of t.watchlist.tokens)s.tokens.some(i=>i.address===o.address)?e.duplicatesSkipped++:(s.tokens.push(o),e.tokensImported++);this.watchlists.set(s.id,s)}else{const o={...t.watchlist,id:this.generateId(),createdAt:Date.now(),updatedAt:Date.now()};this.watchlists.set(o.id,o),e.watchlistsImported++,e.tokensImported+=o.tokens.length}this.saveToStorage()}catch(s){e.errors.push(s instanceof Error?s.message:"Unknown")}return e}createShareLink(t,e){if(!this.watchlists.get(t))throw new Error(`Watchlist ${t} not found`);const o={id:this.generateId(),watchlistId:t,shareLink:`${typeof window<"u"?window.location.origin:""}/watchlist/share/${this.generateId()}`,createdAt:Date.now(),expiresAt:e?.expiresIn?Date.now()+e.expiresIn:void 0,accessCount:0,maxAccessCount:e?.maxAccessCount,password:e?.password,allowCopy:e?.allowCopy??!0};if(this.shares.set(o.id,o),this.shares.size>E){const i=this.shares.keys().next().value;i!==void 0&&this.shares.delete(i)}return o}calculatePerformance(t,e){const s=this.watchlists.get(t);if(!s)throw new Error(`Watchlist ${t} not found`);const o=e.map(a=>a.change24h||0).filter(a=>!isNaN(a));let i,r;if(e.length>0){const a=[...e].sort((l,g)=>(g.change24h||0)-(l.change24h||0));i={address:a[0].address,change:a[0].change24h||0},r={address:a[a.length-1].address,change:a[a.length-1].change24h||0}}return{totalTokens:s.tokens.length,averageChange24h:o.length?o.reduce((a,l)=>a+l,0)/o.length:0,bestPerformer:i,worstPerformer:r,totalVolume24h:e.reduce((a,l)=>a+l.volume24h,0),updatedAt:Date.now()}}getGlobalStats(){const t=this.getAllWatchlists(),e=new Set;let s=0,o=0;for(const i of t)for(const r of i.tokens)e.add(r.address),r.isFavorite&&s++,r.alerts&&(o+=r.alerts.filter(a=>a.status==="ACTIVE").length);return{totalWatchlists:t.length,totalTokens:t.reduce((i,r)=>i+r.tokens.length,0),totalUniqueTokens:e.size,favoriteTokens:s,activeAlerts:o,performance:{totalTokens:e.size,averageChange24h:0,totalVolume24h:0,updatedAt:Date.now()},mostViewedTokens:[],recentlyAdded:[]}}initialize(t){t&&this.setConfig(t),c.info("Watchlist service initialized",{config:this.config})}setConfig(t){const e=this.config.enableAutoSync;this.config={...this.config,...t},e!==this.config.enableAutoSync&&(this.config.enableAutoSync?this.startAutoSync():this.stopAutoSync())}cleanup(){try{const t=Date.now()-36e5;for(const[e,s]of this.prices)s.timestamp<t&&this.prices.delete(e);if(this.priceHistory.size>h.MAX_PRICE_HISTORY_ENTRIES){const e=Array.from(this.priceHistory.keys()),s=e.slice(0,e.length-h.MAX_PRICE_HISTORY_ENTRIES);for(const o of s)this.priceHistory.delete(o)}c.info("Watchlist cache cleanup completed",{pricesSize:this.prices.size,priceHistorySize:this.priceHistory.size})}catch(t){c.error("Failed during watchlist cache cleanup",{error:t})}}shutdown(){this.stopAutoSync(),this.saveToStorage(),c.info("Watchlist service shut down")}};h.MAX_PRICE_ENTRIES=500,h.MAX_PRICE_HISTORY_ENTRIES=100;let u=h;const R=new u;export{S as DEFAULT_WATCHLIST_TEMPLATES,f as WATCHLIST_STORAGE_KEYS,d as WATCHLIST_VALIDATION,w as WatchlistCategory,u as WatchlistManagerService,u as WatchlistServiceClass,R as watchlistService};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.