@liberfi.io/ui-predict 0.1.49 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +1 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/{index-B-NMsVEe.d.mts → index-D3Ek8yK4.d.mts} +187 -1
- package/dist/{index-B-NMsVEe.d.ts → index-D3Ek8yK4.d.ts} +187 -1
- package/dist/index.d.mts +278 -5
- package/dist/index.d.ts +278 -5
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var react=require('react'),reactQuery=require('@tanstack/react-query'),i18n=require('@liberfi.io/i18n'),ui=require('@liberfi.io/ui'),jsxRuntime=require('react/jsx-runtime'),reactWindow=require('react-window'),reactWindowInfiniteLoader=require('react-window-infinite-loader'),hooks=require('@liberfi.io/hooks'),utils=require('@liberfi.io/utils'),walletConnector=require('@liberfi.io/wallet-connector'),Mt=require('canvas-confetti'),types=require('@liberfi.io/types'),react$1=require('@liberfi.io/react'),recharts=require('recharts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Mt__default=/*#__PURE__*/_interopDefault(Mt);typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.49");var os="0.1.49";var we=react.createContext({});var me=react.createContext(null);function Yt(){let e=react.useContext(we);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function b(){let{client:e}=Yt();return e}function us(e){return ["predict","events",e??{}]}async function lt(e,t){return await e.getEvents(t)}function Ic(e,t={}){let r=b();return reactQuery.useQuery({queryKey:us(e),queryFn:async()=>lt(r,e),...t})}function ps(e){return ["predict","events","infinite",e??{}]}function Gt(e={},t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:ps(e),queryFn:async({pageParam:n})=>lt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function ys(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function fs(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function qe(e,t={}){let r=b();return reactQuery.useQuery({queryKey:ys(e),queryFn:async()=>fs(r,e),...t})}function gs(e){return ["predict","markets",e??{}]}async function hs(e,t){return await e.getMarkets(t)}function Kc(e,t={}){let r=b();return reactQuery.useQuery({queryKey:gs(e),queryFn:async()=>hs(r,e),...t})}function vs(e){return ["predict","market","byId",e.id]}async function ks(e,t){return await e.getMarketById(t.id)}function zc(e,t={}){let r=b();return reactQuery.useQuery({queryKey:vs(e),queryFn:async()=>ks(r,e),...t})}function Cs(e){return ["predict","market","byMint",e]}async function Ss(e,t){return await e.getMarketByMint(t)}function Xc(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Cs(e),queryFn:async()=>Ss(r,e),...t})}function Ms(e){return ["predict","markets","batch",e]}async function ws(e,t){return await e.getMarketsBatch(t)}function tu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ms(e),queryFn:async()=>ws(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function Os(e){return ["predict","orderBook",e]}async function Rs(e,t){return await e.getOrderbook(t)}function Oe(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Os(e),queryFn:async()=>Rs(r,e),...t})}function Ns(e){return ["predict","orderBook","byMint",e]}async function Es(e,t){return await e.getOrderbookByMint(t)}function ou(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ns(e),queryFn:async()=>Es(r,e),...t})}function Is(e){return ["predict","trades",e??{}]}async function Qs(e,t){return await e.getTrades(t)}function Zt(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Is(e),queryFn:async()=>Qs(r,e),...t})}function Bs(e){return ["predict","trades","byMint",e]}async function Ls(e,t){return await e.getTradesByMint(t)}function cu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Bs(e),queryFn:async()=>Ls(r,e),...t})}function Us(e){return ["predict","onchainTrades","byWallet",e]}async function ut(e,t){return await e.getOnchainTradesByWallet(t)}function Jt(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Us(e),queryFn:async()=>ut(r,e),...t})}function As(e){return ["predict","onchainTrades","byEvent",e]}async function dt(e,t){return await e.getOnchainTradesByEvent(t)}function mu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:As(e),queryFn:async()=>dt(r,e),...t})}function Ds(e){return ["predict","onchainTrades","byMarket",e]}async function pt(e,t){return await e.getOnchainTradesByMarket(t)}function yu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ds(e),queryFn:async()=>pt(r,e),...t})}function yt(e){return e.cursor??void 0}function Ws(e){return ["predict","onchainTrades","byWallet","infinite",e]}function bu(e,t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:Ws(e),queryFn:async({pageParam:n})=>ut(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:yt,...t})}function _s(e){return ["predict","onchainTrades","byEvent","infinite",e]}function vu(e,t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:_s(e),queryFn:async({pageParam:n})=>dt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:yt,...t})}function Fs(e){return ["predict","onchainTrades","byMarket","infinite",e]}function ku(e,t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:Fs(e),queryFn:async({pageParam:n})=>pt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:yt,...t})}function qs(e){return ["predict","candlesticks","event",e]}async function Ks(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function Tu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:qs(e),queryFn:async()=>Ks(r,e),...t})}function xt(e){return ["predict","candlesticks","market",e]}async function gt(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function ht(e,t={}){let r=b();return reactQuery.useQuery({queryKey:xt(e),queryFn:async()=>gt(r,e),...t})}function Hs(e){return ["predict","candlesticks","market","byMint",e]}async function $s(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function Mu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Hs(e),queryFn:async()=>$s(r,e),...t})}var wu=ht;function Vs(e){return ["predict","forecast","percentileHistory",e]}async function zs(e,t){return await e.getEventForecastPercentileHistory(t)}function Eu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Vs(e),queryFn:async()=>zs(r,e),...t})}function Ys(e){return ["predict","forecast","percentileHistory","byMint",e]}async function Gs(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function Iu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ys(e),queryFn:async()=>Gs(r,e),...t})}function js(e){return ["predict","liveData",e]}async function Xs(e,t){return await e.getLiveData(t)}function Uu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:js(e),queryFn:async()=>Xs(r,e),enabled:e.milestoneIds.length>0,...t})}function Zs(e){return ["predict","liveData","byEvent",e]}async function Js(e,t){return await e.getLiveDataByEvent(t)}function Au(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Zs(e),queryFn:async()=>Js(r,e),enabled:!!e.eventTicker,...t})}function eo(e){return ["predict","liveData","byMint",e]}async function to(e,t){return await e.getLiveDataByMint(t)}function Du(e,t={}){let r=b();return reactQuery.useQuery({queryKey:eo(e),queryFn:async()=>to(r,e),enabled:!!e.mintAddress,...t})}function ro(e){return ["predict","series",e??{}]}async function no(e,t){return await e.getSeries(t)}function rr(e,t={}){let r=b();return reactQuery.useQuery({queryKey:ro(e),queryFn:async()=>no(r,e),...t})}function so(e){return ["predict","series","byTicker",e]}async function oo(e,t){return await e.getSeriesByTicker(t)}function nr(e,t={}){let r=b();return reactQuery.useQuery({queryKey:so(e),queryFn:async()=>oo(r,e),...t})}function ao(){return ["predict","tags","byCategories"]}async function io(e){return await e.getTagsByCategories()}function vt(e={}){let t=b();return reactQuery.useQuery({queryKey:ao(),queryFn:async()=>io(t),...e})}function lo(){return ["predict","filters","bySports"]}async function co(e){return await e.getFiltersBySports()}function $u(e={}){let t=b();return reactQuery.useQuery({queryKey:lo(),queryFn:async()=>co(t),...e})}var Vu=vt;function po(e){return ["predict","search",e]}async function mo(e,t){return await e.search(t)}function ju(e,t={}){let r=b();return reactQuery.useQuery({queryKey:po(e),queryFn:async()=>mo(r,e),...t})}function fo(e){return ["predict","positions","byWallet",e]}async function xo(e,t){return await e.getPositionsByWallet(t)}function or(e,t={}){let r=b();return reactQuery.useQuery({queryKey:fo(e),queryFn:async()=>xo(r,e),...t})}function nd(){let e=react.useContext(me);if(!e)throw new Error("useUserPredictContext must be used within a UserPredictProvider");return e}function ar(e){let t=react.useContext(me);return react.useMemo(()=>t?{positions:t.positions.filter(n=>n.market?.ticker===e.ticker),isLoading:t.isLoading,isAvailable:true}:{positions:[],isLoading:false,isAvailable:false},[t,e.ticker])}function Po(e){return ["predict","outcomeMints",e??{}]}async function Co(e,t){return await e.getOutcomeMints(t)}function ud(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Po(e),queryFn:async()=>Co(r,e),...t})}async function So(e,t){return await e.filterOutcomeMints(t)}function dd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>So(t,r),...e})}function Mo(e){return ["predict","quote",e]}async function wo(e,t){return await e.getQuote(t)}function fd(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Mo(e),queryFn:async()=>wo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Oo(e,t){return await e.createSwap(t)}function bd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>Oo(t,r),...e})}async function Ro(e,t){return await e.createSwapInstructions(t)}function vd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>Ro(t,r),...e})}function No(e){return ["predict","order",e]}async function Eo(e,t){return await e.getOrder(t)}function cr(e,t={}){let r=b();return reactQuery.useQuery({queryKey:No(e),queryFn:async()=>Eo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function Io(e){return ["predict","order","status",e.signature]}async function Qo(e,t){return await e.getOrderStatus(t)}function Sd(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Io(e),queryFn:async()=>Qo(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,...t})}function Uo(e){return ["predict","intent","quote",e]}async function Ao(e,t){return await e.getIntentQuote(t)}function Od(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Uo(e),queryFn:async()=>Ao(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Do(e,t){return await e.submitIntentSwap(t)}function Rd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>Do(t,r),...e})}async function _o(e,t){return await e.initPredictionMarket(t)}function Qd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>_o(t,r),...e})}function Fo(){return ["predict","tokens"]}async function qo(e){return await e.getTokens()}function Ad(e={}){let t=b();return reactQuery.useQuery({queryKey:Fo(),queryFn:async()=>qo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function Ko(){return ["predict","tokens","decimals"]}async function Ho(e){return await e.getTokensWithDecimals()}function Dd(e={}){let t=b();return reactQuery.useQuery({queryKey:Ko(),queryFn:async()=>Ho(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function Vo(){return ["predict","venues"]}async function zo(e){return await e.getVenues()}function qd(e={}){let t=b();return reactQuery.useQuery({queryKey:Vo(),queryFn:async()=>zo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}var Ie=class{ws=null;wsUrl;autoReconnect;reconnectIntervalBase;reconnectMaxInterval;pingInterval;status="disconnected";reconnectAttempts=0;reconnectTimeout=null;pingIntervalId=null;shouldReconnect=true;listeners={connect:[],disconnect:[],reconnecting:[],error:[],price:[],trade:[],orderbook:[],status:[],subscribed:[],unsubscribed:[]};subscriptions={prices:{all:false,tickers:new Set},trades:{all:false,tickers:new Set},orderbook:{all:false,tickers:new Set}};constructor(t){this.wsUrl=t.wsUrl,this.autoReconnect=t.autoReconnect??true,this.reconnectIntervalBase=t.reconnectIntervalBase??1e3,this.reconnectMaxInterval=t.reconnectMaxInterval??3e4,this.pingInterval=t.pingInterval??3e4,t.autoConnect!==false&&this.connect();}connect(){if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))){this.shouldReconnect=true,this.setStatus("connecting");try{this.ws=new WebSocket(this.wsUrl),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus("connected"),this.emit("connect",void 0),this.restoreSubscriptions(),this.startPingInterval();},this.ws.onmessage=t=>{this.handleMessage(t.data);},this.ws.onerror=t=>{let r=new Error("WebSocket error");this.emit("error",r);},this.ws.onclose=t=>{this.stopPingInterval(),this.setStatus("disconnected"),this.emit("disconnect",{code:t.code,reason:t.reason}),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();};}catch(t){this.emit("error",t instanceof Error?t:new Error(String(t))),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();}}}disconnect(){this.shouldReconnect=false,this.stopPingInterval(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus("disconnected");}isConnected(){return this.ws!==null&&this.ws.readyState===WebSocket.OPEN}getStatus(){return this.status}subscribePrices(t,r){this.subscribeChannel("prices",t);let n=this.on("price",r);return ()=>{n(),this.unsubscribeChannel("prices",t);}}subscribeTrades(t,r){this.subscribeChannel("trades",t);let n=this.on("trade",r);return ()=>{n(),this.unsubscribeChannel("trades",t);}}subscribeOrderbook(t,r){this.subscribeChannel("orderbook",t);let n=this.on("orderbook",r);return ()=>{n(),this.unsubscribeChannel("orderbook",t);}}onStatusChange(t){return this.on("status",t)}on(t,r){return this.listeners[t].push(r),()=>{this.off(t,r);}}off(t,r){let n=this.listeners[t],s=n.indexOf(r);s!==-1&&n.splice(s,1);}removeAllListeners(t){if(t)this.listeners[t].length=0;else for(let r of Object.keys(this.listeners))this.listeners[r].length=0;}subscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=true,n.tickers.clear();else if(r.tickers&&r.tickers.length>0){n.all=false;for(let s of r.tickers)n.tickers.add(s);}this.sendSubscription("subscribe",t,r);}unsubscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=false,n.tickers.clear();else if(r.tickers&&r.tickers.length>0)for(let s of r.tickers)n.tickers.delete(s);this.sendSubscription("unsubscribe",t,r);}setStatus(t){this.status!==t&&(this.status=t,this.emit("status",t));}emit(t,r){let n=this.listeners[t];for(let s of n)try{s(r);}catch{}}send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)return false;try{return this.ws.send(JSON.stringify(t)),!0}catch{return false}}sendSubscription(t,r,n){this.send({type:t,channel:r,all:n.all,tickers:n.tickers});}handleMessage(t){try{let r=JSON.parse(t);switch(r.type){case "ticker":this.emit("price",r);break;case "trade":this.emit("trade",r);break;case "orderbook":this.emit("orderbook",r);break;case "status":break;case "subscribed":this.emit("subscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "unsubscribed":this.emit("unsubscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "pong":break;case "error":this.emit("error",new Error(r.message));break;default:if("channel"in r){let n=r;switch(n.channel){case "prices":this.emit("price",n);break;case "trades":this.emit("trade",n);break;case "orderbook":this.emit("orderbook",n);break}}}}catch{}}scheduleReconnect(){if(this.reconnectTimeout)return;let t=Math.min(this.reconnectIntervalBase*Math.pow(2,this.reconnectAttempts),this.reconnectMaxInterval);this.setStatus("reconnecting"),this.emit("reconnecting",{attempt:this.reconnectAttempts+1,delay:t}),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts++,this.connect();},t);}restoreSubscriptions(){for(let t of ["prices","trades","orderbook"]){let r=this.subscriptions[t];r.all?this.sendSubscription("subscribe",t,{all:true}):r.tickers.size>0&&this.sendSubscription("subscribe",t,{tickers:Array.from(r.tickers)});}}startPingInterval(){this.stopPingInterval(),this.pingIntervalId=setInterval(()=>{this.send({type:"ping"});},this.pingInterval);}stopPingInterval(){this.pingIntervalId&&(clearInterval(this.pingIntervalId),this.pingIntervalId=null);}};function Ke(e){return new Ie(e)}function Yd({wsEndpoint:e,autoConnect:t=true,autoReconnect:r=true,enabled:n=true}){let[s,a]=react.useState("disconnected"),[o,l]=react.useState(null),i=react.useRef(null);react.useEffect(()=>{if(!n){i.current&&(i.current.disconnect(),i.current=null),a("disconnected");return}let p=Ke({wsUrl:e,autoConnect:t,autoReconnect:r});i.current=p;let f=p.on("status",h=>{a(h);}),m=p.on("error",h=>{l(h);}),y=p.on("connect",()=>{l(null);});return ()=>{f(),m(),y(),p.disconnect(),i.current=null;}},[e,t,r,n]);let c=react.useCallback(()=>{i.current?.connect();},[]),d=react.useCallback(()=>{i.current?.disconnect();},[]);return {client:i.current,status:s,isConnected:s==="connected",connect:c,disconnect:d,error:o}}function Zd(){let e=react.useContext(we);if(!e)throw new Error("useWsClient must be used within a PredictProvider");let{wsClient:t}=e,[r,n]=react.useState(t?.getStatus()??"disconnected");return react.useEffect(()=>{if(!t){n("disconnected");return}return n(t.getStatus()),t.onStatusChange(n)},[t]),{wsClient:t,wsStatus:r,isWsConnected:r==="connected"}}function tp({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[a,o]=react.useState(new Map),[l,i]=react.useState(false),c=react.useRef(s);return react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){i(false);return}if(!t&&r.length===0)return;let d=t?{all:true}:{tickers:r},u=e.subscribePrices(d,p=>{o(f=>{let m=new Map(f);return m.set(p.market_ticker,{yesBid:p.yes_bid,yesAsk:p.yes_ask,noBid:p.no_bid,noAsk:p.no_ask,updatedAt:Date.now()}),m}),c.current?.(p);});return i(true),()=>{u(),i(false);}},[e,t,r.join(","),n]),{prices:a,isSubscribed:l}}function sp({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:a}){let[o,l]=react.useState([]),[i,c]=react.useState(false),d=react.useRef(a);react.useEffect(()=>{d.current=a;},[a]),react.useEffect(()=>{if(!e||!n){c(false);return}if(!t&&r.length===0)return;let p=t?{all:true}:{tickers:r},f=e.subscribeTrades(p,m=>{let y={tradeId:m.trade_id,marketTicker:m.market_ticker,price:m.price,count:m.count,yesPrice:m.yes_price,noPrice:m.no_price,takerSide:m.taker_side,createdTime:m.created_time};l(h=>{let g=[y,...h];return g.length>s?g.slice(0,s):g}),d.current?.(m);});return c(true),()=>{f(),c(false);}},[e,t,r.join(","),n,s]);let u=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:i,clearHistory:u}}function ip({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[a,o]=react.useState(new Map),[l,i]=react.useState(false),c=react.useRef(s);react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){i(false);return}if(!t&&r.length===0)return;let u=t?{all:true}:{tickers:r},p=e.subscribeOrderbook(u,f=>{o(m=>{let y=new Map(m);return y.set(f.market_ticker,{yesBids:f.yes_bids,yesAsks:f.yes_asks,noBids:f.no_bids,noAsks:f.no_asks,updatedAt:Date.now()}),y}),c.current?.(f);});return i(true),()=>{p(),i(false);}},[e,t,r.join(","),n]);let d=react.useCallback(u=>a.get(u),[a]);return {orderbooks:a,isSubscribed:l,getOrderbook:d}}var br=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function vr(){let{data:e,isLoading:t,isError:r,error:n}=vt();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let a=o=>{let l=br.indexOf(o);return l===-1?br.length:l};return Object.entries(e.tagsByCategories).map(([o,l])=>({category:o,tags:l})).sort((o,l)=>a(o.category)-a(l.category))},[e]),isLoading:t,isError:r,error:n??null}}function Cr({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:s,onTagSelect:a,className:o}){let{t:l}=i18n.useTranslation(),i=react.useCallback(()=>{s(null);},[s]);return jsxRuntime.jsxs("div",{className:ui.cn("flex w-full flex-col gap-2",o),children:[jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(He,{label:l("predict.categories.trending"),isSelected:t===null,onPress:i}),e.map(c=>jsxRuntime.jsx(He,{label:c.category,isSelected:t===c.category,onPress:()=>s(c.category)},c.category))]})}),t&&n.length>0&&jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(He,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>a(null),variant:"secondary"}),n.map(c=>jsxRuntime.jsx(He,{label:c,isSelected:r===c,onPress:()=>a(c),variant:"secondary"},c))]})})]})}function He({label:e,isSelected:t,onPress:r,variant:n="primary"}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:ui.cn("shrink-0 rounded-full px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer","border whitespace-nowrap",n==="primary"?t?"bg-foreground text-background border-foreground":"bg-content1 text-foreground/70 border-default-200 hover:bg-default-100 hover:text-foreground":t?"bg-primary/15 text-primary border-primary/40":"bg-content1 text-foreground/50 border-default-100 hover:bg-default-50 hover:text-foreground/70"),children:e})}function Sr({count:e=6}){return jsxRuntime.jsx("div",{className:"flex items-center gap-2 px-0.5 py-1",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-8 shrink-0 rounded-full",style:{width:`${60+Math.random()*40}px`}},r))})}function Or({onSelect:e,className:t}){let{data:r,isLoading:n}=vr(),[s,a]=react.useState(null),[o,l]=react.useState(null),i=react.useCallback(u=>{if(a(u),l(null),!u)e?.({category:null,tags:null});else {let p=r.find(f=>f.category===u);e?.({category:u,tags:p?.tags??null});}},[r,e]),c=react.useCallback(u=>{if(l(u),u)e?.({category:s,tags:[u]});else {let p=r.find(f=>f.category===s);e?.({category:s,tags:p?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(Sr,{});let d=r.find(u=>u.category===s)?.tags??[];return jsxRuntime.jsx(Cr,{categories:r,selectedCategory:s,selectedTag:o,activeTags:d,onCategorySelect:i,onTagSelect:c,className:t})}var Pe=48,ye=4,$e={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},S={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},fe=S.ALL,Ve={[S.ONE_DAY]:$e.ONE_MINUTE,[S.ONE_WEEK]:$e.ONE_HOUR,[S.ONE_MONTH]:$e.ONE_HOUR,[S.ALL]:$e.ONE_DAY},ze={[S.ONE_DAY]:300,[S.ONE_WEEK]:3600,[S.ONE_MONTH]:10800,[S.ALL]:1440*60},Ye={[S.ONE_DAY]:1440*60,[S.ONE_WEEK]:10080*60,[S.ONE_MONTH]:720*60*60,[S.ALL]:null},Pt=1,sm=1,om=1,am=99,Re={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},im=Re.ONE_WEEK,lm={[Re.ONE_HOUR]:60,[Re.SIX_HOURS]:60,[Re.ONE_DAY]:300,[Re.ONE_WEEK]:1800,[Re.MAX]:1800};function Rr(e={}){let{category:t,tags:r,...n}=e,s=!!t||!!r&&r.length>0,{data:a,isFetching:o,isError:l,error:i}=rr({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),c=react.useMemo(()=>{if(!s||!a?.series)return;let N=a.series.map(P=>P.ticker).slice(0,25);return N.length>0?N.join(","):void 0},[s,a]),d=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...c!==void 0?{seriesTickers:c}:{}}),[n,c]),{data:u,isLoading:p,isFetching:f,isFetchingNextPage:m,isError:y,error:h,hasNextPage:g,fetchNextPage:v,refetch:k}=Gt(d),x=react.useMemo(()=>u?.pages.flatMap(N=>N.events)??[],[u]),C=s&&!a&&!l;return {data:x,isLoading:C||p,isFetching:o||C||f&&!m,isFetchingMore:m,isError:l||y,error:i??h,hasMore:g,fetchMore:v,refetch:k}}function la({className:e}){return jsxRuntime.jsxs("div",{className:`flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 @5xl:gap-y-3 @5xl:p-4 ${e??""}`,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-8 flex-shrink-0 rounded-lg @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-md @5xl:h-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-12 flex-shrink-0 rounded-lg @5xl:h-10 @5xl:w-14"})]}),jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 @5xl:gap-y-1",children:[jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-2/3 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]}),jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-1/2 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-16 rounded-md @5xl:h-4"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded-md @5xl:h-4"})]})]})}function Nr({count:e=8}){return jsxRuntime.jsx("div",{className:"@container w-full h-full",children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 gap-4 @[640px]:grid-cols-2 @[1024px]:grid-cols-3 @[1280px]:grid-cols-4",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(la,{className:"min-h-44 @5xl:min-h-56"},r))})})}function Er({value:e,showLabel:t=true}){let r=e/100;return jsxRuntime.jsx("div",{className:"flex-shrink-0 flex flex-col items-center",children:jsxRuntime.jsxs("div",{className:"relative w-16 h-12 lg:w-20 lg:h-14",children:[jsxRuntime.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 100 70",children:[jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-default-200",strokeWidth:"6",strokeLinecap:"round"}),jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-primary",strokeWidth:"6",strokeLinecap:"round",strokeDasharray:`${r*125.6} 125.6`,style:{transition:"stroke-dasharray 0.5s ease-in-out"}})]}),t&&jsxRuntime.jsx("div",{className:"absolute inset-0 flex items-center justify-center pt-3 lg:pt-4",children:jsxRuntime.jsxs("span",{className:"text-sm font-bold text-foreground lg:text-base leading-none",children:[e.toFixed(0),"%"]})})]})})}function Br({event:e,onSelect:t,onSelectOutcome:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((P,Q)=>Number(Q.yesAsk??0)-Number(P.yesAsk??0)):o,i=l.filter(P=>P.status==="active"),c=l.length===1,d=c?l[0]:s,u=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),p=P=>P.yesAsk?parseFloat(P.yesAsk)*100:null,f=P=>P.noAsk?parseFloat(P.noAsk)*100:null,m=P=>{let Q=p(P),U=f(P);return Q!=null?U==null&&Q<=1?"< 1%":h(Q):U!=null?U<=1?"> 99%":h(100-U):"0%"},y=P=>{let Q=p(P),U=f(P);return U!=null?Q==null&&U<=1?"< 1%":h(U):Q!=null?Q<=1?"> 99%":h(100-Q):"0%"},h=P=>P!=null?`${P.toFixed(0)}%`:"--",g=react.useMemo(()=>{let P=l.some(U=>U.status==="active");return l.every(U=>U.status==="closed"||U.status==="determined")?{label:n("predict.event.status.closed"),color:"bg-danger-100/50 text-danger"}:P?{label:n("predict.event.status.live"),color:"bg-primary-100/50 text-primary"}:{label:n("predict.event.status.pending"),color:"bg-warning-100/50 text-warning"}},[l,n]),v=P=>{a(P);},k=()=>{a(null);},x=()=>{d&&r&&r(e,d,"yes");},C=()=>{d&&r&&r(e,d,"no");},M=()=>{t&&t(e);},R=i.slice(0,2),N=i.length>2;return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 transition-all duration-300 cursor-pointer hover:border-primary hover:ring-2 hover:ring-primary/20 focus-within:border-primary focus-within:bg-content2 focus-within:ring-2 focus-within:ring-primary/20 @5xl:gap-y-3 @5xl:p-4",onClick:M,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"md",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover:scale-110 @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.StyledTooltip,{content:e.title,placement:"bottom",children:jsxRuntime.jsx("p",{className:"flex-1 min-w-0 h-10 @5xl:h-12 text-sm font-semibold @5xl:text-base line-clamp-2",children:e.title})}),c?jsxRuntime.jsx(Er,{value:p(l[0])??50}):g.label!==n("predict.event.status.live")&&jsxRuntime.jsx("div",{className:`flex-shrink-0 flex items-center gap-x-2 rounded-lg px-2 py-1 text-sm @5xl:px-4 @5xl:py-2 ${g.color}`,children:jsxRuntime.jsx("span",{children:g.label})})]}),d&&!c&&jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:P=>{P.stopPropagation(),k();},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:d.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground @5xl:text-lg",children:m(d)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!d&&!c&&R.length>0&&jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 text-xs @5xl:gap-y-1 @5xl:text-sm",children:[R.map(P=>jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-8 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:Q=>{Q.stopPropagation(),v(P);},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:P.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-foreground @5xl:text-base",children:m(P)}),jsxRuntime.jsxs("div",{className:"flex h-full items-center gap-x-3 rounded-lg p-1 @5xl:p-1.5 bg-gradient-to-r from-primary-50/20 via-primary-50/20 to-secondary-50/20",children:[jsxRuntime.jsx("span",{className:"text-primary",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"text-default-400",children:"/"}),jsxRuntime.jsx("span",{className:"text-secondary",children:n("predict.market.no")})]})]})]},P.ticker)),N&&jsxRuntime.jsx("span",{className:"text-xxs text-default-500 @5xl:text-xs",children:n("predict.event.moreMarkets",{count:i.length-2})})]}),d&&jsxRuntime.jsxs("div",{className:`flex items-center gap-x-2 text-sm @5xl:text-base ${c?"mt-3":""}`,children:[jsxRuntime.jsxs(ui.Button,{color:"primary",fullWidth:true,className:"group/yes bg-primary-100 text-primary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:x,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:m(d)})]}),jsxRuntime.jsxs(ui.Button,{color:"secondary",fullWidth:true,className:"group/no bg-secondary-100 text-secondary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:C,children:[jsxRuntime.jsx("span",{className:"group-hover/no:hidden",children:n("predict.market.no")}),jsxRuntime.jsx("span",{className:"hidden group-hover/no:inline",children:y(d)})]})]})]}),!d||c?jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"flex items-center gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:P=>{P.stopPropagation(),M();},children:[jsxRuntime.jsx("span",{children:n("predict.event.showMore")}),jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"})]}),jsxRuntime.jsxs("span",{className:"text-xxs text-default-600 @5xl:text-xs",children:[u," ",n("predict.event.volume")]})]}):jsxRuntime.jsxs("button",{type:"button",className:"flex items-center cursor-pointer gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:P=>{P.stopPropagation(),k();},children:[jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"}),jsxRuntime.jsx("span",{children:n("predict.event.back")})]})]})}var Pa=640,Ca=768,Ur=1024,Sa=1280,Ta=16,Ma=192,wa=228,Oa=244;function Ra(e){return e>=Sa?4:e>=Ur?3:e>=Pa?2:1}function Na(e){return e>=Ur?Oa:e>=Ca?wa:Ma}function Ar({events:e,hasMore:t=false,onFetchMore:r,onSelect:n,onSelectOutcome:s}){let a=react.useRef(null),{width:o=0,height:l=0}=hooks.useResizeObserver({ref:a}),i=Ra(o),c=Na(o),d=Math.ceil(e.length/i)||0,u=t?d+1:d,p=react.useCallback(y=>y<d,[d]),f=react.useCallback(async()=>{r?.();},[r]),m=reactWindowInfiniteLoader.useInfiniteLoader({isRowLoaded:p,loadMoreRows:f,rowCount:u,threshold:3});return jsxRuntime.jsx("div",{ref:a,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(reactWindow.List,{style:{height:l},onRowsRendered:m,rowComponent:Ea,rowCount:u,rowHeight:c,rowProps:{events:e,columnCount:i,dataRowCount:d,gap:Ta,onSelect:n,onSelectOutcome:s}})})}function Ea({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:a,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let i=e*n,c=r.slice(i,i+n),d=n-c.length,u={display:"flex",gap:a,height:`calc(100% - ${a}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:u,children:[c.map(p=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(Br,{event:p,onSelect:o,onSelectOutcome:l})},p.ticker)),d>0&&Array.from({length:d}).map((p,f)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${f}`))]})})}function Wr({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:a,isFetching:o}=Rr({limit:48,...r});return o?jsxRuntime.jsx(Nr,{count:48}):jsxRuntime.jsx(Ar,{events:n,hasMore:s,onFetchMore:a,onSelect:e,onSelectOutcome:t})}function Km({onSelect:e,onSelectOutcome:t}){let[r,n]=react.useState({category:null,tags:null}),s=react.useCallback(a=>{n(a);},[]);return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col gap-y-3",children:[jsxRuntime.jsx(Or,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(Wr,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}function wt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Be=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Ka(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Mt__default.default({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Mt__default.default({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Mt__default.default({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Fr({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:n="buy"}){let{t:s}=i18n.useTranslation(),a=react.useContext(me),{status:o}=walletConnector.useAuth(),i=walletConnector.useWallets().find(T=>T.chainNamespace===types.ChainNamespace.SOLANA&&T.isConnected),c=o==="authenticated",d=i?.address,[u,p]=react.useState(r),[f,m]=react.useState(n),[y,h]=react.useState(NaN),g=react.useMemo(()=>wt(e.accounts,Be,u),[e.accounts,u]),{inputMint:v,outputMint:k}=react.useMemo(()=>f==="buy"?{inputMint:Be,outputMint:g}:{inputMint:g,outputMint:Be},[f,g]),x=!!v&&!!k&&y>0,C=react.useMemo(()=>Number(u==="yes"?e.yesAsk??.5:e.noAsk??.5),[u,e.yesAsk,e.noAsk]),M=react.useMemo(()=>isNaN(y)||y<=0?0:f==="buy"?C>0?y/C:0:y,[f,y,C]),R=react.useMemo(()=>isNaN(y)||y<=0?0:Math.round(y*1e6),[y]),{data:N,isLoading:P,error:Q,refetch:U}=cr({userPublicKey:d??void 0,inputMint:v??"",outputMint:k??"",amount:R,slippageBps:100},{enabled:x}),ke=a?.usdcBalance??null,pe=a?.isLoading??false,Ht=a?.refetch,oe=a?.positions,_e=react.useMemo(()=>{if(!oe||!g)return null;let T=oe.find(te=>te.mint===g);return T?T.balance:0},[oe,g]),nt=react.useMemo(()=>wt(e.accounts,Be,"yes"),[e.accounts]),st=react.useMemo(()=>wt(e.accounts,Be,"no"),[e.accounts]),zn=react.useMemo(()=>{if(!oe||!nt)return null;let T=oe.find(te=>te.mint===nt);return T?T.balance:0},[oe,nt]),Yn=react.useMemo(()=>{if(!oe||!st)return null;let T=oe.find(te=>te.mint===st);return T?T.balance:0},[oe,st]),{data:Me}=Oe(e.ticker,{refetchInterval:5e3}),Gn=react.useMemo(()=>(u==="yes"?Me?.yesBids:Me?.noBids)?.[0]?.price??null,[Me,u]),jn=react.useMemo(()=>(u==="yes"?Me?.yesAsks:Me?.noAsks)?.[0]?.price??null,[Me,u]),Xn=react.useMemo(()=>N?.priceImpactPct?parseFloat(N.priceImpactPct):null,[N]),Fe=react.useMemo(()=>{if(isNaN(y)||y<=0)return 0;if(N)return parseInt(N.inAmount)/1e6;if(f==="buy")return y;let T=Number(u==="yes"?e.yesBid??0:e.noBid??0);return y*T},[N,f,u,y,e.yesBid,e.noBid]),$t=react.useMemo(()=>isNaN(y)||y<=0?0:f==="buy"?M*1:Fe,[f,M,Fe,y]),Zn=$t-Fe,Jn=react.useCallback(T=>{m(T),h(NaN);},[]),es=react.useCallback(T=>{if(isNaN(T)){h(NaN);return}let te=Math.max(0,T),it=f==="buy"?Math.round(te*100)/100:Math.round(te);h(it);},[f]);react.useEffect(()=>{x&&U();},[y,u,f,x,U]);let ot=react.useMemo(()=>{let T=[];return (isNaN(y)||y<Pt)&&T.push(`Minimum quantity is ${Pt}`),e.status!=="active"&&T.push("Market is not active"),f==="buy"&&ke!=null&&!isNaN(y)&&y>0&&y>ke&&T.push("Insufficient USDC balance"),f==="sell"&&_e!=null&&!isNaN(y)&&y>0&&y>_e&&T.push("Insufficient shares"),{isValid:T.length===0,errors:T}},[y,e.status,f,ke,_e]),[ts,at]=react.useState(null),[rs,Vt]=react.useState(false),ns=react.useCallback(async()=>{if(!(!ot.isValid||!c||!d||!i||pe)){at(null),Vt(true);try{let T=N;if(T?.transaction||(T=(await U()).data),!T?.transaction)return;let te=Uint8Array.from(atob(T.transaction),zt=>zt.charCodeAt(0)),it=await i.sendTransaction(te);at(it),ui.toast.success(s("predict.trade.submitSuccess")),Ka(),h(NaN),Ht?.();}catch{ui.toast.error(s("predict.trade.submitError"));}finally{Vt(false);}}},[ot.isValid,c,d,i,N,pe,U,Ht,s]),ss=react.useCallback(()=>{p(r),m(n),h(NaN),at(null);},[r,n]);return {outcome:u,side:f,quantity:y,shares:M,estimatedCost:Fe,potentialPayout:$t,potentialProfit:Zn,isAuthenticated:c,bestBid:Gn,bestAsk:jn,order:N??null,priceImpact:Xn,usdcBalance:ke,outcomeTokenBalance:_e,yesTokenBalance:zn,noTokenBalance:Yn,isBalanceLoading:pe,isQuoteLoading:P,isSubmitting:rs,quoteError:Q??null,txHash:ts,validation:ot,setOutcome:p,setSide:Jn,setQuantity:es,submit:ns,reset:ss}}var Ga=`https://s1.chainstream.io/chains/sol/tokens/${utils.SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function $r({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:a,estimatedCost:o,usdcBalance:l,yesTokenBalance:i,noTokenBalance:c,isBalanceLoading:d,isSubmitting:u,isValid:p,onOutcomeChange:f,onSideChange:m,onQuantityChange:y,onSubmit:h}){let{t:g}=i18n.useTranslation(),v=react.useMemo(()=>{if(u)return g("predict.trade.submitting");let x=g(n==="buy"?"predict.trade.buy":"predict.trade.sell"),C=g(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${x} ${C}`},[u,n,r,g]),k=react.useMemo(()=>r==="yes"?"primary":"secondary",[r]);return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4",children:[e&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsxRuntime.jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxRuntime.jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxRuntime.jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxRuntime.jsxs("span",{className:r==="yes"?"text-bullish":"text-bearish",children:[g(n==="buy"?"predict.trade.buy":"predict.trade.sell")," ",g(r==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[" \xB7 ",r==="yes"?t.yesSubTitle:t.noSubTitle]})]})]})]}),jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:x=>m(x),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:g("predict.trade.buy")},"buy"),jsxRuntime.jsx(ui.Tab,{title:g("predict.trade.sell")},"sell")]}),jsxRuntime.jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(x=>{let C=x==="yes"?i:c;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>f(x),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===x?x==="yes"?"border-primary bg-primary-50 text-primary":"border-secondary bg-secondary-50 text-secondary":"border-default-400 text-foreground hover:border-default-500"}`,children:[jsxRuntime.jsx("span",{children:g(x==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let M=n==="buy"?x==="yes"?t.yesAsk:t.noAsk:x==="yes"?t.yesBid:t.noBid;return M!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(M)*100),"\xA2"]}):null})()]}),n==="sell"&&r===x&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${C??0} shares`})]},x)})}),n==="buy"&&jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-x-1 text-xs text-default-500",children:[jsxRuntime.jsx("img",{src:Ga,alt:"USDC",className:"h-4 w-4 rounded-full object-cover"}),jsxRuntime.jsxs("span",{children:[g("predict.trade.balance"),":"]}),jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:l!=null?`$${l.toFixed(2)}`:"\u2013"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-foreground",children:g(n==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsxRuntime.jsx(ui.StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:x=>{y(x);},minValue:0,step:n==="buy"?.01:1,formatOptions:n==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:n==="buy"?jsxRuntime.jsx("span",{className:"text-default-600 text-xl",children:"$"}):void 0,classNames:{inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 h-14 min-h-14",input:"text-lg"}},n),jsxRuntime.jsx("div",{className:"flex gap-x-2 justify-end",children:n==="buy"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[1,5,10,100].map(x=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>y(Math.round(((isNaN(s)?0:s)+x)*100)/100),className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:["+",x,"$"]},x)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:g("common.all")})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[25,50].map(x=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:[x,"%"]},x)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:g("common.all")})]})})]}),!isNaN(s)&&s>0&&jsxRuntime.jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-foreground",children:g(n==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxRuntime.jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(n==="buy"?a:o).toFixed(2)]})]}),jsxRuntime.jsx(ui.Button,{color:k,fullWidth:true,radius:"lg",size:"lg",isDisabled:!p||u,isLoading:u,onPress:h,children:v})]})}function Ot({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:a,side:o,quantity:l,estimatedCost:i,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:m,isSubmitting:y,validation:h,setOutcome:g,setSide:v,setQuantity:k,submit:x}=Fr({market:t,initialSide:r,initialOutcome:n,chain:s}),C=walletConnector.useAuthCallback(x);return jsxRuntime.jsx($r,{event:e,market:t,outcome:a,side:o,quantity:l,estimatedCost:i,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:m,isSubmitting:y,isValid:h.isValid,validationErrors:h.errors,onOutcomeChange:g,onSideChange:v,onQuantityChange:k,onSubmit:C})}function Za(){return jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 flex-1 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-10 shrink-0 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"})]})]})}function Le({marketCount:e=4}){return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 lg:px-4 lg:max-w-3xl animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-14 shrink-0 rounded-lg lg:h-18 lg:w-18"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5 min-w-0 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-24 rounded-md lg:w-32"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-48 rounded-md lg:h-6 lg:w-72"})]})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-[200px] w-full rounded-xl lg:h-[280px]"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-32 rounded-md"}),jsxRuntime.jsx("div",{className:"flex gap-x-1",children:Array.from({length:4}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-7 w-10 rounded-md"},r))})]}),jsxRuntime.jsx("div",{className:"flex flex-col divide-y divide-default-200",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(Za,{},r))})]})}function Vr(){return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4 animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 w-10 shrink-0 rounded-lg"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-28 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-40 rounded-md"})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-full rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-12 w-full rounded-lg"})]})}var zr=e=>{let{candlestickMarketTickers:t,chartRange:r=fe}=e,n=Ve[r],s=Ye[r],a=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=b(),{data:l,isLoading:i,error:c}=qe({id:e.eventId,withNestedMarkets:true}),d=react.useMemo(()=>{if(s!=null)return a-s;let k=l?.markets;return k?.length?Math.min(...k.map(x=>x.openTime)):a},[a,s,l?.markets]),{data:u,isLoading:p,error:f}=nr(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),m=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(x=>l.markets.find(C=>C.ticker===x)).filter(x=>x!==void 0):[...l.markets].sort((x,C)=>Number(C.yesAsk??0)-Number(x.yesAsk??0)).slice(0,4)).map(x=>x.ticker):[],[t,l?.markets]),y=reactQuery.useQueries({queries:m.map(k=>({queryKey:xt({ticker:k,startTs:d,endTs:a,periodInterval:n}),queryFn:()=>gt(o,{ticker:k,startTs:d,endTs:a,periodInterval:n}),enabled:m.length>0}))}),h=y.some(k=>k.isLoading),g=react.useMemo(()=>{let k=new Map;return m.forEach((x,C)=>{let M=y[C]?.error;M&&k.set(x,M);}),k},[m,y]),v=react.useMemo(()=>{let k=new Map;return m.forEach((x,C)=>{let M=y[C]?.data;M&&k.set(x,M);}),k},[m,y]);return {event:l,isEventLoading:i,eventError:c,series:u,isSeriesLoading:p,seriesError:f,periodInterval:n,candlesticks:v,isCandlesticksLoading:h,candlestickErrors:g}};var ii=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Yr(e){let{status:t}=walletConnector.useAuth(),n=walletConnector.useWallets().find(c=>c.chainNamespace===types.ChainNamespace.SOLANA&&c.isConnected),s=t==="authenticated",a=n?.address,{data:o,isLoading:l}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:a??""},{enabled:s&&!!a,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let c=new Map;if(!o?.portfolios||e.length===0)return c;let d=new Map;for(let u of o.portfolios)d.set(u.address,parseFloat(u.amount));for(let u of e){let p=u.accounts[ii];if(!p)continue;let f=d.get(p.yesMint)??0,m=d.get(p.noMint)??0;(f>0||m>0)&&c.set(u.ticker,{yesShares:f,noShares:m});}return c},[o,e]),isLoading:l}}function gi(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:a}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:a,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:a})]})}var Xe=[{stroke:"hsl(var(--heroui-primary))",id:"colorMarket0"},{stroke:"hsl(var(--heroui-secondary))",id:"colorMarket1"},{stroke:"hsl(var(--heroui-success))",id:"colorMarket2"},{stroke:"hsl(var(--heroui-warning))",id:"colorMarket3"}];function Gr(e,t){let r=new Date(e*1e3);switch(t){case S.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case S.ONE_WEEK:case S.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case S.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function hi(e,t,r){let n=ze[r],s=new Map;e.forEach((i,c)=>{let d=new Map;(i.candlesticks??[]).forEach(p=>{let f=p.end_period_ts-p.end_period_ts%n;d.set(f,p.yes_ask.close);}),s.set(c,d);});let a=new Set;for(let i of s.values())for(let c of i.keys())a.add(c);let o=Array.from(a).sort((i,c)=>i-c),l=new Map;return o.map(i=>{let d={date:new Date(i*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:i};return t.forEach(u=>{let p=s.get(u)?.get(i);if(p!==void 0)d[u]=Math.round(p*100)/100,l.set(u,d[u]);else {let f=l.get(u);f!==void 0&&(d[u]=f);}}),d})}function jr({candlesticks:e,markets:t=[],isLoading:r,chartRange:n=S.ALL,onDataChange:s}){let[a,o]=react.useState(null),l=react.useRef(s);react.useEffect(()=>{l.current=s;});let i=react.useMemo(()=>e?Array.from(e.keys()).slice(0,4):[],[e]),c=react.useMemo(()=>!e||e.size===0?[]:hi(e,i,n),[e,i,n]),d=react.useMemo(()=>{if(c.length===0||i.length===0)return [0,100];let m=1/0,y=-1/0;if(c.forEach(x=>{i.forEach(C=>{let M=x[C];M!==void 0&&(m=Math.min(m,M),y=Math.max(y,M));});}),m===1/0||y===-1/0)return [0,100];let h=y-m,g=Math.max(h*.2,5),v=Math.max(0,Math.floor(m-g)),k=Math.min(100,Math.ceil(y+g));return [v,k]},[c,i]),u=react.useCallback(m=>{if(c.length===0)return null;let y=m!==null?c[m]:c[c.length-1];return y?{timestamp:y.timestamp,date:y.date,markets:i.map((h,g)=>{let v=t.find(k=>k.ticker===h);return {id:h,label:v?.yesSubTitle||`Market ${g+1}`,value:y[h]??0,color:Xe[g%Xe.length].stroke}})}:null},[c,i,t]);react.useEffect(()=>{l.current&&c.length>0&&l.current(u(null));},[c,u]),react.useEffect(()=>{l.current&&l.current(u(a));},[a,u]);let p=react.useCallback(m=>{typeof m?.activeTooltipIndex=="number"&&o(m.activeTooltipIndex);},[]),f=react.useCallback(()=>{o(null);},[]);return r?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"Loading chart..."})}):c.length===0?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"No price history data"})}):jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px]",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:c,margin:{top:10,right:16,left:16,bottom:0},onMouseMove:p,onMouseLeave:f,children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:m=>{let{x:y,y:h,payload:g,index:v}=m,k=c.length,C=Math.max(1,Math.ceil(k/6)),M=v===0,R=v===k-1,N=v%C===0;return !M&&!R&&!N?null:jsxRuntime.jsx("text",{x:y,y:h+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Gr(g.value,n)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:d,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:m=>`${m}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{contentStyle:{backgroundColor:"hsl(var(--heroui-content1))",border:"1px solid hsl(var(--heroui-default-200))",borderRadius:"8px",fontSize:"12px"},labelFormatter:m=>Gr(m,n),formatter:(m,y)=>{let g=t.find(v=>v.ticker===y)?.yesSubTitle||y;return [`${m.toFixed(2)}%`,g]}}),i.map((m,y)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:m,stroke:Xe[y%Xe.length].stroke,strokeWidth:2,isAnimationActive:false,dot:h=>jsxRuntime.jsx(gi,{...h,dataLength:c.length},`dot-${m}-${h.index}`),activeDot:false},m))]})})})}function Xr(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function Jr({marketTicker:e,openTime:t,chartRange:r=fe}){let n=Ve[r],s=Ye[r],a=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=react.useMemo(()=>s!=null?a-s:t??a,[a,s,t]),{data:l,isLoading:i,isFetching:c,error:d}=ht({ticker:e,startTs:o,endTs:a,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:i,isFetching:c,error:d,periodInterval:n}}var Mi="hsl(var(--heroui-primary))",wi=[{value:S.ONE_DAY,label:"1D"},{value:S.ONE_WEEK,label:"1W"},{value:S.ONE_MONTH,label:"1M"},{value:S.ALL,label:"ALL"}];function Oi(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:a}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:a,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:a})]})}function tn(e,t){let r=new Date(e*1e3);switch(t){case S.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case S.ONE_WEEK:case S.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case S.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function Ri(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toFixed(0)}function Ni(e,t){let r=ze[t],n=e.candlesticks??[],s=new Map;for(let o of n){let l=o.end_period_ts-o.end_period_ts%r,i=s.get(l);s.set(l,{close:o.yes_ask.close,volume:(i?.volume??0)+(o.volume??0)});}return Array.from(s.entries()).sort((o,l)=>o[0]-l[0]).map(([o,{close:l,volume:i}])=>({timestamp:o,date:new Date(o*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),value:Math.round(l*100)/100,volume:i}))}function rn({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?Ni(e,r):[],[e,r]),a=react.useMemo(()=>{if(s.length===0)return [0,100];let o=1/0,l=-1/0;for(let p of s)p.value<o&&(o=p.value),p.value>l&&(l=p.value);if(o===1/0||l===-1/0)return [0,100];let i=l-o,c=Math.max(i*.2,5),d=Math.max(0,Math.floor(o-c)),u=Math.min(100,Math.ceil(l+c));return [d,u]},[s]);return t?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"Loading chart..."})}),jsxRuntime.jsx(Qt,{chartRange:r,onRangeChange:n})]}):s.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"No price history data"})}),jsxRuntime.jsx(Qt,{chartRange:r,onRangeChange:n})]}):jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:s,margin:{top:10,right:16,left:16,bottom:0},children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:o=>{let{x:l,y:i,payload:c,index:d}=o,u=s.length,f=Math.max(1,Math.ceil(u/6)),m=d===0,y=d===u-1,h=d%f===0;return !m&&!y&&!h?null:jsxRuntime.jsx("text",{x:l,y:i+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:tn(c.value,r)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:a,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:o=>`${o}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:"hsl(var(--heroui-default-300))"},content:({active:o,payload:l})=>{if(!o||!l?.length)return null;let i=l[0].payload,c=Math.round(i.value);return jsxRuntime.jsxs("div",{className:"rounded-lg border border-default-200 bg-content1 px-3 py-2 shadow-md",children:[jsxRuntime.jsxs("div",{className:"text-lg font-semibold text-primary",children:["Yes ",c,"\xA2"]}),jsxRuntime.jsxs("div",{className:"text-sm text-neutral",children:["Vol ",Ri(i.volume)," \xB7"," ",tn(i.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:Mi,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Oi,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(Qt,{chartRange:r,onRangeChange:n})]})}function Qt({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:wi.map(r=>{let n=e===r.value;return jsxRuntime.jsx("button",{type:"button",className:`px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,onClick:()=>t?.(r.value),children:r.label},r.value)})})}function nn({marketTicker:e}){let{data:t,isLoading:r,error:n}=Oe(e,{enabled:!!e});return {orderbook:react.useMemo(()=>{if(!t)return null;let{yesBids:a,yesAsks:o,noBids:l,noAsks:i}=t;return {yesBids:a,yesAsks:o,noBids:l,noAsks:i,bestYesBid:a.length>0?a[0].price:null,bestYesAsk:o.length>0?o[0].price:null,bestNoBid:l.length>0?l[0].price:null,bestNoAsk:i.length>0?i[0].price:null,sequence:t.sequence??null}},[t]),isOrderbookLoading:r,orderbookError:n}}function sn(e,t){let r=e.slice(0,t),n=0;return r.map(s=>(n+=s.quantity,{...s,cumulative:n,depth:0,total:s.price*s.quantity}))}function on(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function un(e){return `${Math.round(e*100)}\xA2`}function Qi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Bi(e){return e>=1e6?`$${(e/1e6).toFixed(2)}M`:e>=1e3?`$${(e/1e3).toFixed(2)}K`:e>=1?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function an({row:e,side:t,showType:r=false,onClick:n}){let{t:s}=i18n.useTranslation(),a=t==="ask",o=a?"bg-bullish/10":"bg-bearish/10",l=a?"text-bullish":"text-bearish";return jsxRuntime.jsxs("button",{type:"button",className:"relative grid w-full grid-cols-4 px-2 py-2.5 text-xs cursor-pointer hover:bg-default-100 transition-colors",onClick:()=>n?.(e.price,t),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 left-0 ${o} transition-[width] duration-200`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsx("span",{className:`relative z-10 font-mono font-medium ${l} text-left`,children:r?s(a?"predict.trade.bestAsk":"predict.trade.bestBid"):""}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:un(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Qi(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Bi(e.total)})]})}function ln({index:e}){let t=["60%","45%","75%","55%","65%","50%","70%","40%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function Li(){return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"})]}),Array.from({length:Bt}).map((e,t)=>jsxRuntime.jsx(ln,{index:t},`ask-${t}`)),jsxRuntime.jsx("div",{className:"flex justify-center border-y border-default-200 px-2 py-2.5",children:jsxRuntime.jsx("div",{className:"h-4 w-24 animate-pulse rounded bg-default-100"})}),Array.from({length:Bt}).map((e,t)=>jsxRuntime.jsx(ln,{index:t+3},`bid-${t}`))]})}var Bt=8;function Lt({bids:e,asks:t,isLoading:r=false,maxLevels:n=Bt,onPriceClick:s}){let{t:a}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:i,spreadPercent:c}=react.useMemo(()=>{let u=sn(e,n),p=sn(t,n),f=Math.max(u[u.length-1]?.cumulative??0,p[p.length-1]?.cumulative??0);on(u,f),on(p,f);let m=u[0]?.price??null,y=p[0]?.price??null,h=null,g=null;if(m!=null&&y!=null){h=y-m;let v=(m+y)/2;v>0&&(g=Math.round(h/v*1e4)/100);}return {bidRows:u,askRows:p,spread:h,spreadPercent:g}},[e,t,n]);return r?jsxRuntime.jsx(Li,{}):o.length===0&&l.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:a("predict.orderBook.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.price")}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.contracts")}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:l.map((u,p)=>jsxRuntime.jsx(an,{row:u,side:"ask",showType:p===0,onClick:s},u.price))}),i!=null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 px-2 py-2.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[a("predict.orderBook.spread"),": ",un(i)]}),c!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",c,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((u,p)=>jsxRuntime.jsx(an,{row:u,side:"bid",showType:p===0,onClick:s},u.price))})]})}function Di(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(2)}K`:e.toLocaleString(void 0,{maximumFractionDigits:2})}function Wi(e){let t=Math.abs(e),r=e>=0?"+":"-";return t>=1e3?`${r}$${(t/1e3).toFixed(1)}K`:t>=1?`${r}$${t.toFixed(2)}`:`${r}$${t.toFixed(4)}`}function dn({positions:e,isLoading:t=false}){let{t:r}=i18n.useTranslation();return t?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})}):e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:r("predict.positions.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-5 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{children:r("predict.positions.outcome")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.qty")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.avgCost")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.currentPrice")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.pnl")})]}),e.map(n=>{let s=n.position==="YES",a=s?"text-bullish":"text-bearish",o=r(s?"predict.market.yes":"predict.market.no"),l=n.avgCost!=null?`${Math.round(n.avgCost*100)}\xA2`:"\u2014",i=n.currentPrice!=null?`${Math.round(n.currentPrice*100)}\xA2`:"\u2014",c=n.pnl!=null&&n.pnlPercent!=null,d=c&&n.pnl>0?"text-bullish":c&&n.pnl<0?"text-bearish":"text-foreground";return jsxRuntime.jsxs("div",{className:"grid grid-cols-5 px-2 py-2.5 text-xs hover:bg-default-100 transition-colors",children:[jsxRuntime.jsx("span",{className:`font-medium ${a}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:Di(n.balance)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:l}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:i}),jsxRuntime.jsx("span",{className:`text-right font-mono ${d}`,children:c?jsxRuntime.jsxs("span",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{children:Wi(n.pnl)}),jsxRuntime.jsxs("span",{className:"text-[10px] opacity-70",children:[n.pnlPercent>=0?"+":"",n.pnlPercent.toFixed(1),"%"]})]}):"\u2014"})]},n.mint)})]})}function Fi(e){let t=e/1e6;return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${(t/1e3).toFixed(2)}K`:t.toLocaleString(void 0,{maximumFractionDigits:2})}function qi(e){return e==null?"\u2014":`${Math.round(e*100)}\xA2`}function Ki(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0");return `${r} ${n} ${s}:${a}`}function Hi({index:e}){let t=["60%","45%","75%","55%","65%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function pn({trades:e,isLoading:t=false}){let{t:r}=i18n.useTranslation();return t?jsxRuntime.jsx("div",{className:"flex flex-col",children:Array.from({length:6}).map((n,s)=>jsxRuntime.jsx(Hi,{index:s},s))}):e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:r("predict.tradeHistory.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{children:r("predict.tradeHistory.side")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.price")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.qty")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.time")})]}),e.map(n=>{let s=n.side==="yes",a=s?"text-bullish":"text-bearish",o=n.side?r(s?"predict.trade.yes":"predict.trade.no"):"\u2014";return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs hover:bg-default-100 transition-colors",children:[jsxRuntime.jsx("span",{className:`font-medium ${a}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:qi(n.usdPricePerContract)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:Fi(n.outputAmount)}),jsxRuntime.jsx("span",{className:"text-right text-default-500",children:Ki(n.createdAt)})]},n.id)})]})}function xn({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[a,o]=react.useState(fe),{orderbook:l,isOrderbookLoading:i}=nn({marketTicker:e.ticker}),{candlesticks:c,isFetching:d}=Jr({marketTicker:e.ticker,openTime:e.openTime,chartRange:a}),{positions:u,isLoading:p}=ar(e),{status:f}=walletConnector.useAuth(),h=walletConnector.useWallets().find(R=>R.chainNamespace===types.ChainNamespace.SOLANA&&R.isConnected)?.address,{data:g,isLoading:v}=Jt({walletAddress:h??""},{enabled:(n==="trade-history"||n==="positions")&&f==="authenticated"&&!!h}),k=(g?.trades??[]).filter(R=>R.marketTicker===e.ticker),x=react.useMemo(()=>u.map(R=>{let N=k.filter(pe=>pe.outputMint===R.mint&&pe.usdPricePerContract!=null&&pe.contracts!=null&&pe.contracts>0),P=Xi(N),Q=R.position==="YES"?fn(R.market?.yesAsk):fn(R.market?.noAsk),U=null,ke=null;return P!=null&&Q!=null&&(U=(Q-P)*R.balance,ke=P>0?(Q-P)/P*100:null),{...R,avgCost:P,currentPrice:Q,pnl:U,pnlPercent:ke}}),[u,k]),C=react.useCallback((R,N)=>{t?.(e,"yes",N==="ask"?"buy":"sell");},[e,t]),M=react.useCallback((R,N)=>{t?.(e,"no",N==="ask"?"buy":"sell");},[e,t]);return jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-3",children:[jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:R=>s(R),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeYes")},"trade-yes"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeNo")},"trade-no"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.graph")},"graph"),jsxRuntime.jsx(ui.Tab,{title:r("predict.positions.title")},"positions"),jsxRuntime.jsx(ui.Tab,{title:r("predict.tradeHistory.title")},"trade-history")]}),jsxRuntime.jsxs("div",{className:"min-h-[120px]",children:[n==="trade-yes"&&jsxRuntime.jsx(Lt,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:i,onPriceClick:C}),n==="trade-no"&&jsxRuntime.jsx(Lt,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:i,onPriceClick:M}),n==="graph"&&jsxRuntime.jsx(rn,{candlesticks:c,isLoading:d,chartRange:a,onRangeChange:o}),n==="positions"&&jsxRuntime.jsx(dn,{positions:x,isLoading:p}),n==="trade-history"&&jsxRuntime.jsx(pn,{trades:k,isLoading:v})]})]})}function Xi(e){if(e.length===0)return null;let t=0,r=0;for(let n of e)t+=n.contracts,r+=n.usdPricePerContract*n.contracts;return t>0?r/t:null}function fn(e){if(e==null)return null;let t=Number(e);return Number.isFinite(t)?t:null}var At=4;function Ji(e){let t=e.yesAsk?Math.round(parseFloat(e.yesAsk)*100):null,r=e.noAsk?Math.round(parseFloat(e.noAsk)*100):null;return {yesCents:t,noCents:r}}function Cn({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[a,o]=react.useState(false),[l,i]=react.useState(null);if(e.length===0)return null;let c=e.length>At,d=a?e:e.slice(0,At),u=p=>{i(f=>f===p?null:p);};return jsxRuntime.jsxs("div",{className:"flex flex-col divide-y divide-default-200",children:[d.map(p=>{let{yesCents:f,noCents:m}=Ji(p),y=l===p.ticker;return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 transition-colors hover:bg-content2 lg:gap-x-4 cursor-pointer",onClick:()=>u(p.ticker),role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),u(p.ticker));},children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 min-w-0 flex-1",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium truncate lg:text-base",children:p.yesSubTitle}),(()=>{let h=n?.get(p.ticker);if(!h)return null;let{yesShares:g,noShares:v}=h;return g<=0&&v<=0?null:jsxRuntime.jsxs("div",{className:"flex items-center gap-x-1.5",children:[g>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"primary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesYes",{shares:g%1===0?g:g.toFixed(2)})}),v>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"secondary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesNo",{shares:v%1===0?v:v.toFixed(2)})})]})})()]}),(()=>{let h=f!=null,g=m!=null;return h&&!g&&f<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):g&&!h&&m<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!h&&!g?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"0%"}):jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center lg:text-xl",children:`${f}%`})})(),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 flex-1 justify-end",children:[jsxRuntime.jsx(ui.Button,{size:"sm",color:"primary",className:"w-20 bg-primary-100 text-primary",onPress:()=>r?.(p,"yes","buy"),children:f!=null?s("predict.market.action.yes",{price:f}):s("predict.market.yes")}),jsxRuntime.jsx(ui.Button,{size:"sm",color:"secondary",className:"w-20 bg-secondary-100 text-secondary",onPress:()=>r?.(p,"no","buy"),children:m!=null?s("predict.market.action.no",{price:m}):s("predict.market.no")})]}),y?jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4 shrink-0 text-default-400"}):jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-default-400"})]}),y&&t&&jsxRuntime.jsx("div",{className:"max-h-100 overflow-y-auto px-2 pb-3",children:t(p)})]},p.ticker)}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>o(p=>!p),className:"flex items-center justify-center gap-x-1.5 px-2 py-2.5 text-sm text-default-500 transition-colors cursor-pointer hover:text-primary",children:a?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.rules.collapse")}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.moreMarkets",{count:e.length-At})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var sl=new Set(["closed","determined","finalized"]);function Je(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getFullYear(),a=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0");return `${r} ${n}, ${s} ${a}:${o}`}function ol({market:e}){let t=sl.has(e.status),r=react.useMemo(()=>{let s={label:"Market Open",value:Je(e.openTime),isActive:true},a={label:"Market Closes",value:t?Je(e.closeTime):"After the outcome occurs",isActive:t},o={label:"Projected Payout",value:"30 minutes after closing",isActive:e.status==="finalized"};return [s,a,o]},[e.openTime,e.closeTime,e.status,t]),n=react.useMemo(()=>t?null:e.canCloseEarly&&e.earlyCloseCondition?`${e.earlyCloseCondition} Otherwise, it closes by ${Je(e.expirationTime)}.`:`This market closes by ${Je(e.expirationTime)}.`,[t,e.canCloseEarly,e.earlyCloseCondition,e.expirationTime]);return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[r.map((s,a)=>jsxRuntime.jsxs("div",{className:"flex items-stretch gap-x-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center w-3",children:[jsxRuntime.jsx("div",{className:`h-3 w-3 shrink-0 rounded-full border-2 mt-0.5 ${s.isActive?"border-primary bg-primary":"border-default-300 bg-transparent"}`}),a<r.length-1&&jsxRuntime.jsx("div",{className:"w-px flex-1 bg-default-200"})]}),jsxRuntime.jsxs("div",{className:`flex flex-col ${a<r.length-1?"pb-4":""}`,children:[jsxRuntime.jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:s.label}),jsxRuntime.jsx("span",{className:"text-xs text-default-500 lg:text-sm",children:s.value})]})]},s.label)),n&&jsxRuntime.jsx("p",{className:"text-xs text-default-500 mt-3 lg:text-sm",children:n})]})}function Tn({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.filter(i=>i.rulesPrimary);if(o.length===0)return null;let l=o.find(i=>i.ticker===s)??o[0];return l?.rulesPrimary?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium lg:text-base",children:n("predict.event.rules")}),o.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm","aria-label":"Select market rules",className:"max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:new Set([l.ticker]),onSelectionChange:i=>{if(i==="all")return;let c=Array.from(i);c.length>0&&a(c[0]);},children:o.map(i=>jsxRuntime.jsx(ui.SelectItem,{textValue:i.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:i.yesSubTitle})},i.ticker))}),jsxRuntime.jsx("div",{className:"text-xs text-foreground lg:text-sm",children:l.rulesPrimary}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-default-500 mt-2 lg:text-sm",children:"Timeline and payout"}),jsxRuntime.jsx(ol,{market:l}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 text-xxs text-default-400 mt-2 lg:text-xs",children:[r?.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Series:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:r.ticker})]}),t.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Event:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:t.ticker})]}),jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Market:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:l.ticker})]})]})]}):null}var yl=[{value:S.ONE_DAY,label:"1D"},{value:S.ONE_WEEK,label:"1W"},{value:S.ONE_MONTH,label:"1M"},{value:S.ALL,label:"ALL"}];function wn({event:e,series:t,candlesticks:r,chartRange:n=S.ONE_DAY,periodInterval:s,isCandlesticksLoading:a,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:i,onTradeAction:c}){let{t:d}=i18n.useTranslation(),[u,p]=react.useState(Xr()),[f,m]=react.useState(false),y=react.useRef(null);react.useEffect(()=>{let x=y.current;if(!x)return;let C=false,M=0,R=()=>{let{bottom:P}=x.getBoundingClientRect(),Q=C?P<0:P<-20;Q!==C&&(C=Q,m(Q));},N=()=>{cancelAnimationFrame(M),M=requestAnimationFrame(R);};return window.addEventListener("scroll",N,{passive:true,capture:true}),R(),()=>{cancelAnimationFrame(M),window.removeEventListener("scroll",N,{capture:true});}},[]);let h=react.useMemo(()=>[...e.markets||[]].sort((x,C)=>Number(C.yesAsk??0)-Number(x.yesAsk??0)),[e.markets]),{holdings:g}=Yr(h),v=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),k=react.useMemo(()=>{if(!e.strikeDate)return null;let x=new Date(e.strikeDate*1e3),C=x.toLocaleString("default",{month:"short"}),M=x.getDate(),R=x.getFullYear();return `${C} ${M}, ${R}`},[e.strikeDate]);return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 pb-8 lg:px-4 lg:pb-12 lg:max-w-3xl",children:[jsxRuntime.jsx("div",{ref:y,className:"h-0 w-0"}),jsxRuntime.jsxs("div",{className:`sticky top-0 z-30 flex items-center bg-background/80 backdrop-blur-md transition-all duration-300 ${f?"gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"gap-x-2 lg:gap-x-4"}`,children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"lg",className:`flex-shrink-0 transition-all duration-300 ${f?"!h-8 !w-8 lg:!h-10 lg:!w-10":"!h-14 !w-14 lg:!h-18 lg:!w-18"}`}),jsxRuntime.jsxs("div",{className:"flex flex-col min-w-0",children:[!f&&(t?.category||t?.tags&&t.tags.length>0)&&jsxRuntime.jsxs("span",{className:"text-xs text-default-500 lg:text-sm truncate",children:[t.category,t.category&&t.tags?.length>0&&" \xB7 ",t.tags?.join(", ")]}),jsxRuntime.jsx("span",{className:`font-semibold truncate transition-all duration-300 ${f?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-4",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[u&&u.markets.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-xs lg:text-sm",children:u.markets.map(x=>jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("div",{className:"h-3 w-3 shrink-0 rounded-full",style:{backgroundColor:x.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:x.label})]},x.id))}),jsxRuntime.jsx(jr,{candlesticks:r,chartRange:n,markets:h,isLoading:a,onDataChange:x=>p(x)}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-2 mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 text-xs text-default-500 lg:text-sm",children:[jsxRuntime.jsxs("span",{children:[v," ",d("predict.event.volume")]}),k&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"text-default-300",children:"\xB7"}),jsxRuntime.jsx("span",{children:d("predict.event.endDate",{date:k})})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-x-1",children:yl.map(x=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(x.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===x.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:x.label},x.value))}),h.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm",selectionMode:"multiple",placeholder:"Markets","aria-label":"Select markets",className:"min-w-28 max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:l?new Set(l):void 0,onSelectionChange:x=>{if(x==="all")return;let C=Array.from(x);C.length<=4&&i?.(C);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:h.map(x=>jsxRuntime.jsx(ui.SelectItem,{textValue:x.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:x.yesSubTitle})},x.ticker))})})]})]})}),jsxRuntime.jsx(Cn,{markets:h,onTradeAction:c,marketHoldings:g,renderMarketDetail:x=>jsxRuntime.jsx(xn,{market:x,onTradeAction:c})}),jsxRuntime.jsx(Tn,{markets:h,event:e,series:t})]})}function _t({eventId:e,initialMarketTickers:t,initialChartRange:r=fe,onTradeAction:n}){let[s,a]=react.useState(r),[o,l]=react.useState(t),{event:i,isEventLoading:c,eventError:d,series:u,isSeriesLoading:p,periodInterval:f,candlesticks:m,isCandlesticksLoading:y,candlestickErrors:h}=zr({eventId:e,candlestickMarketTickers:o,chartRange:s}),g=react.useRef(!!t);react.useEffect(()=>{if(i?.markets&&!g.current){g.current=true;let x=[...i.markets].sort((C,M)=>Number(M.yesAsk??0)-Number(C.yesAsk??0)).slice(0,4).map(C=>C.ticker);l(x);}},[i?.markets]);let v=react.useMemo(()=>x=>{a(x);},[]),k=react.useMemo(()=>x=>{l(x);},[]);return c||p?jsxRuntime.jsx(Le,{}):d||!i?jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:d?.message||"Event not found"}):jsxRuntime.jsx(wn,{event:i,series:u,candlesticks:m,chartRange:s,periodInterval:f,isCandlesticksLoading:y,candlestickErrors:h,onRangeChange:v,selectedMarketTickers:o,onMarketSelectionChange:k,onTradeAction:n})}function px({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:a,onOpen:o,onClose:l}=ui.useDisclosure(),{data:i,isLoading:c}=qe({id:e,withNestedMarkets:true}),d=react.useMemo(()=>[...i?.markets||[]].sort((h,g)=>Number(g.yesAsk??0)-Number(h.yesAsk??0)),[i?.markets]),[u,p]=react.useState(null),f=react.useCallback((h,g,v)=>{p(k=>({market:h,outcome:g,side:v,version:(k?.version??0)+1})),s&&o();},[s,o]),m=u?.market??d[0];if(c)return s?jsxRuntime.jsx(Le,{}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(Le,{})}),jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4",children:jsxRuntime.jsx(Vr,{})})})]});let y=u?`${u.market.ticker}-${u.version}`:m?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(_t,{eventId:e,onTradeAction:f,...r})}),m&&jsxRuntime.jsx("div",{className:"fixed inset-x-0 bottom-0 z-40 flex justify-center p-3 bg-gradient-to-t from-background via-background/90 to-transparent",children:jsxRuntime.jsx(ui.Button,{color:"primary",size:"lg",className:"w-full max-w-md font-semibold",onPress:o,children:n("predict.trade.action")})}),jsxRuntime.jsx(ui.Drawer,{isOpen:a,onClose:l,placement:"bottom",size:"lg",hideCloseButton:true,classNames:{base:"max-h-[85dvh] rounded-t-2xl",body:"p-0"},children:jsxRuntime.jsx(ui.DrawerContent,{children:jsxRuntime.jsx(ui.DrawerBody,{children:m&&jsxRuntime.jsx(Ot,{event:i,market:m,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},y)})})})]}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(_t,{eventId:e,onTradeAction:f,...r})}),m&&jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4 flex flex-col gap-y-4",children:jsxRuntime.jsx(Ot,{event:i,market:m,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},y)})})]})}function Nn(e,t){if(!e)return [];let r=e.slice(0,t),n=0,s=r.map(o=>(n+=o.quantity,{...o,cumulative:n,depth:0})),a=s[s.length-1]?.cumulative??1;for(let o of s)o.depth=o.cumulative/a;return s}function En({marketTicker:e,maxLevels:t=10,refetchInterval:r=5e3,outcome:n="yes"}){let{data:s,isLoading:a,isFetching:o}=Oe(e,{refetchInterval:r||void 0}),l=react.useMemo(()=>n==="yes"?s?.yesBids:s?.noBids,[s,n]),i=react.useMemo(()=>n==="yes"?s?.yesAsks:s?.noAsks,[s,n]),c=react.useMemo(()=>Nn(l,t),[l,t]),d=react.useMemo(()=>Nn(i,t),[i,t]),u=react.useMemo(()=>c.length===0||d.length===0?null:d[0].price-c[0].price,[c,d]),p=react.useMemo(()=>c.length===0||d.length===0?null:(c[0].price+d[0].price)/2,[c,d]),f=react.useMemo(()=>u===null||p===null||p===0?null:Math.round(u/p*1e4)/100,[u,p]);return {bids:c,asks:d,spread:u,spreadPercent:f,midpoint:p,isLoading:a,isFetching:o}}function In({row:e,side:t,onClick:r}){let n=t==="bid",s=n?"bg-primary/10":"bg-danger/10",a=n?"text-primary":"text-danger";return jsxRuntime.jsxs("button",{type:"button",className:"relative flex w-full items-center justify-between px-3 py-1 text-xs hover:bg-default-100 cursor-pointer",onClick:()=>r?.(e.price),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 ${n?"right-0":"left-0"} ${s}`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsxs("span",{className:`relative z-10 font-medium ${a}`,children:[e.price,"\xA2"]}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-600",children:e.quantity}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-400",children:e.cumulative})]})}function Qn(){return jsxRuntime.jsx("div",{className:"flex flex-col gap-y-1 py-2",children:Array.from({length:5}).map((e,t)=>jsxRuntime.jsx("div",{className:"mx-3 h-4 animate-pulse rounded bg-default-100"},t))})}function Bn({bids:e,asks:t,spread:r,spreadPercent:n,isLoading:s,onPriceClick:a}){let{t:o}=i18n.useTranslation();if(s)return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:o("predict.orderBook.title")}),jsxRuntime.jsx(Qn,{}),jsxRuntime.jsx(Qn,{})]});let l=e.length===0&&t.length===0;return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsx("span",{className:"text-sm font-medium",children:o("predict.orderBook.title")})}),l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:o("predict.orderBook.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-1 text-xxs text-default-400",children:[jsxRuntime.jsx("span",{children:o("predict.orderBook.price")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.qty")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:t.map(i=>jsxRuntime.jsx(In,{row:i,side:"ask",onClick:a},i.price))}),r!==null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 py-1.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[o("predict.orderBook.spread"),": ",r,"\xA2"]}),n!==null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",n,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:e.map(i=>jsxRuntime.jsx(In,{row:i,side:"bid",onClick:a},i.price))})]})]})}function Bx({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:a,asks:o,spread:l,spreadPercent:i,isLoading:c}=En({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(Bn,{bids:a,asks:o,spread:l,spreadPercent:i,isLoading:c,onPriceClick:n})}function Un(e={}){let[t,r]=react.useState(null),[n]=react.useState(null),s=react.useCallback(a=>{r(null);},[]);return {orders:[],isLoading:false,isFetching:false,cancellingOrderId:t,cancelOrder:s,cancelError:n}}function _l(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function An({orders:e,isLoading:t,cancellingOrderId:r,onCancel:n}){let{t:s}=i18n.useTranslation(),a=react.useMemo(()=>e.map(o=>({key:o.id,side:o.side,outcome:o.outcome,type:o.type,price:o.price,filled:`${o.filledQuantity}/${o.quantity}`,status:o.status,createdAt:_l(o.createdAt),isCancelling:o.id===r,id:o.id})),[e,r]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.openOrders.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsxs("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:[s("predict.openOrders.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.openOrders.empty")}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Open orders",className:"min-w-[600px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:s("predict.openOrders.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.openOrders.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Type",width:60,children:s("predict.openOrders.type")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.openOrders.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Filled",width:80,children:s("predict.openOrders.filled")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Status",width:70,children:s("predict.openOrders.status")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:s("predict.openOrders.time")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Action",width:80,align:"end",children:" "})]}),jsxRuntime.jsx(ui.TableBody,{children:a.map(o=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.side==="buy"?"text-primary":"text-danger"}`,children:o.side==="buy"?s("predict.trade.buy"):s("predict.trade.sell")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.type})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.filled})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.status})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:o.createdAt})}),jsxRuntime.jsx(ui.TableCell,{className:"text-right",children:jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",color:"danger",isLoading:o.isCancelling,onPress:()=>n(o.id),children:s("predict.openOrders.cancel")})})]},o.key))})]})})]})}function jx({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=Un({});return jsxRuntime.jsx(An,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function Wn({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,a]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:i,isLoading:c,isFetching:d}=Zt(l),u=i,p=u?.trades??[],f=!!u?.cursor,m=r>1,y=react.useCallback(v=>{v>=1&&v<=s.length&&n(v);},[s.length]),h=react.useCallback(()=>{f&&u?.cursor&&(a(v=>{let k=[...v];return k.length===r&&k.push(u.cursor),k}),n(v=>v+1));},[f,u?.cursor,r]),g=react.useCallback(()=>{m&&n(v=>v-1);},[m]);return {trades:p,isLoading:c,isFetching:d,page:r,pageSize:t,hasNextPage:f,hasPrevPage:m,goToPage:y,nextPage:h,prevPage:g}}function Xl(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Fn({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:a,onNextPage:o,onPrevPage:l}){let{t:i}=i18n.useTranslation(),c=react.useMemo(()=>e.map(d=>({key:d.tradeId,ticker:d.ticker,takerSide:d.takerSide,price:d.price,yesPrice:d.yesPrice,noPrice:d.noPrice,count:d.count,createdAt:Xl(d.createdTime)})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:i("predict.tradeHistory.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((d,u)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},u))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:i("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:i("predict.tradeHistory.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:`w-full overflow-x-auto ${r?"opacity-60":""}`,children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Trade history",className:"min-w-[480px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:i("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:i("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:i("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:i("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:i("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:i("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:c.map(d=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${d.takerSide==="yes"?"text-primary":"text-secondary"}`,children:d.takerSide==="yes"?i("predict.trade.yes"):i("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[d.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-primary",children:[d.yesPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-secondary",children:[d.noPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:d.count})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:d.createdAt})})]},d.key))})]})}),(a||s)&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2",children:[jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!a,onPress:l,startContent:jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3"}),children:i("predict.pagination.prev")}),jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:i("predict.pagination.page",{page:n})}),jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!s,onPress:o,endContent:jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3"}),children:i("predict.pagination.next")})]})]})]})}function yg({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:a,hasNextPage:o,hasPrevPage:l,nextPage:i,prevPage:c}=Wn({ticker:e,pageSize:t});return jsxRuntime.jsx(Fn,{trades:r,isLoading:n,isFetching:s,page:a,hasNextPage:o,hasPrevPage:l,onNextPage:i,onPrevPage:c})}function qn(e={}){let t=react.useMemo(()=>({totalValue:0,totalUnrealizedPnl:0,totalRealizedPnl:0,count:0}),[]);return {positions:[],isLoading:false,isFetching:false,summary:t}}var et=e=>utils.formatAmountUSDCompact(e/100);function Kt({value:e}){if(e===0)return jsxRuntime.jsx("span",{className:"text-default-500",children:et(0)});let t=e>0;return jsxRuntime.jsxs("span",{className:t?"text-success":"text-danger",children:[t?"+":"",et(e)]})}function Kn({positions:e,isLoading:t,summary:r,onSell:n}){let{t:s}=i18n.useTranslation(),a=react.useMemo(()=>e.map(o=>({key:`${o.marketId}-${o.outcome}`,marketTitle:o.marketTitle,outcome:o.outcome,quantity:o.quantity,avgCost:o.avgCostBasis,currentPrice:o.currentPrice,value:o.currentPrice*o.quantity,unrealizedPnl:o.unrealizedPnl,position:o})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.positions.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[s("predict.positions.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]})}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.positions.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Positions",className:"min-w-[640px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Market",width:200,children:s("predict.positions.market")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.positions.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:50,children:s("predict.positions.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Avg Cost",width:70,children:s("predict.positions.avgCost")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.positions.currentPrice")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Value",width:80,children:s("predict.positions.value")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"PnL",width:80,children:s("predict.positions.pnl")})]}),jsxRuntime.jsx(ui.TableBody,{children:a.map(o=>jsxRuntime.jsxs(ui.TableRow,{className:n?"cursor-pointer hover:bg-default-50":"",onClick:()=>n?.(o.position),children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs font-medium line-clamp-1",children:o.marketTitle})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.quantity})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.avgCost,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.currentPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:et(o.value)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:jsxRuntime.jsx(Kt,{value:o.unrealizedPnl})})})]},o.key))})]})}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2 text-xs",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-x-4",children:jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.totalValue"),":"," ",jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:et(r.totalValue)})]})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-4",children:[jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.unrealizedPnl"),":"," ",jsxRuntime.jsx(Kt,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(Kt,{value:r.totalRealizedPnl})]})]})]})]})]})}function Eg({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=qn({});return jsxRuntime.jsx(Kn,{positions:r,isLoading:n,summary:s,onSell:t})}function Jg({client:e,wsClient:t=null,children:r}){let n=react.useMemo(()=>({client:e,wsClient:t}),[e,t]);return jsxRuntime.jsx(we.Provider,{value:n,children:r})}var mc=3e4;function oh({walletAddress:e,pollingInterval:t=mc,enabled:r=true,children:n}){let{data:s,isLoading:a,error:o,refetch:l}=or({walletAddress:e},{enabled:r&&!!e,refetchInterval:t}),i=react.useMemo(()=>({positions:s?.positions??[],usdcBalance:s?.usdcBalance??0,isLoading:a,error:o??null,refetch:l}),[s?.positions,s?.usdcBalance,a,o,l]);return jsxRuntime.jsx(me.Provider,{value:i,children:n})}function Hn(e,t){let r=new URLSearchParams;t&&r.set("provider",t);for(let[s,a]of Object.entries(e))a!=null&&(typeof a=="object"?r.set(s,JSON.stringify(a)):r.set(s,String(a)));let n=r.toString();return n?`?${n}`:""}function $n(e){return e}var We=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Hn(r??{},this.provider);return `${this.endpoint}${t}${n}`}async fetch(t,r){let n=this.buildUrl(t,r);return await utils.httpGet(n)}async postRequest(t,r,n){let s=this.buildUrl(t,n);return await utils.httpPost(s,r)}};function tt(e,t){if(!e)return [];let r=Object.entries(e).map(([n,s])=>({price:parseFloat(n),quantity:s}));return r.sort((n,s)=>t==="desc"?s.price-n.price:n.price-s.price),r}function Vn(e){return {yesBids:tt(e.yes_bids,"desc"),yesAsks:tt(e.yes_asks,"asc"),noBids:tt(e.no_bids,"desc"),noAsks:tt(e.no_asks,"asc"),sequence:e.sequence}}var rt=class extends We{constructor(t){super(t,"dflow");}async getEvents(t){return await this.fetch("/v2/event",t??{})}async getEventById(t,r){return await this.fetch(`/v2/event/${t}`,{withNestedMarkets:r})}async getEventCandlesticks(t,r){return await this.fetch(`/v2/event/${t}/candlesticks`,r)}async getEventForecastPercentileHistory(t){let{seriesTicker:r,eventId:n,...s}=t;return await this.fetch(`/v2/event/${r}/${n}/forecast_percentile_history`,s)}async getEventForecastPercentileHistoryByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/event/by-mint/${r}/forecast_percentile_history`,n)}async getMarkets(t){return await this.fetch("/v2/market",t??{})}async getMarketById(t){return await this.fetch(`/v2/market/${t}`)}async getMarketByMint(t){return await this.fetch(`/v2/market/by-mint/${t}`)}async getMarketsBatch(t){return await this.postRequest("/v2/market/batch",t)}async getMarketCandlesticks(t,r){return await this.fetch(`/v2/market/${t}/candlesticks`,r)}async getMarketCandlesticksByMint(t,r){return await this.fetch(`/v2/market/by-mint/${t}/candlesticks`,r)}async getOrderbook(t){let r=await this.fetch(`/v2/orderbook/${t}`);return Vn(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return Vn(r)}async getTrades(t){return await this.fetch("/v2/trades",t??{})}async getTradesByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/trades/by-mint/${r}`,n)}async getOnchainTradesByWallet(t){let{walletAddress:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-wallet/${r}`,n)}async getOnchainTradesByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-event/${r}`,n)}async getOnchainTradesByMarket(t){let{marketTicker:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-market/${r}`,n)}async getLiveData(t){return await this.fetch("/v2/live",{milestoneIds:t.milestoneIds.join(",")})}async getLiveDataByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/live/event/${r}`,n)}async getLiveDataByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/live/by-mint/${r}`,n)}async getSeries(t){return await this.fetch("/v2/series",t??{})}async getSeriesByTicker(t){return await this.fetch(`/v2/series/${t}`)}async getTagsByCategories(){return await this.fetch("/v2/tags/by_categories")}async getFiltersBySports(){return await this.fetch("/v2/sports/filters")}async search(t){return await this.fetch("/v2/search",t)}async getPositionsByWallet(t){let{walletAddress:r}=t;return await this.fetch(`/v2/positions/by-wallet/${r}`)}async getOutcomeMints(t){return await this.fetch("/v2/outcome_mints",t??{})}async filterOutcomeMints(t){return await this.postRequest("/v2/filter_outcome_mints",t)}async getQuote(t){return await this.fetch("/v2/swap/quote",t)}async createSwap(t){return await this.postRequest("/v2/swap",t)}async createSwapInstructions(t){return await this.postRequest("/v2/swap/instructions",t)}async getOrder(t){return await this.fetch("/v2/order",t)}async getOrderStatus(t){return await this.fetch("/v2/order/status",t)}async getIntentQuote(t){return await this.fetch("/v2/intent/quote",t)}async submitIntentSwap(t){return await this.postRequest("/v2/intent/swap",t)}async initPredictionMarket(t){return await this.fetch("/v2/prediction-market/init",t)}async getTokens(){return await this.fetch("/v2/tokens")}async getTokensWithDecimals(){return await this.fetch("/v2/tokens/decimals")}async getVenues(){return await this.fetch("/v2/venues")}};
|
|
2
|
-
exports.BasePredictClient=
|
|
1
|
+
'use strict';var react=require('react'),reactQuery=require('@tanstack/react-query'),i18n=require('@liberfi.io/i18n'),ui=require('@liberfi.io/ui'),jsxRuntime=require('react/jsx-runtime'),reactWindow=require('react-window'),reactWindowInfiniteLoader=require('react-window-infinite-loader'),hooks=require('@liberfi.io/hooks'),utils=require('@liberfi.io/utils'),walletConnector=require('@liberfi.io/wallet-connector'),Kt=require('canvas-confetti'),types=require('@liberfi.io/types'),react$1=require('@liberfi.io/react'),recharts=require('recharts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Kt__default=/*#__PURE__*/_interopDefault(Kt);typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.51");var Fs="0.1.51";var et=react.createContext(null);function mr(){let e=react.useContext(et);if(!e)throw new Error("usePredictV2Context must be used within a PredictV2Provider");return e}function Ne(){let{client:e}=mr();return e}function Ks(e){return ["predict-v2","events",e??{}]}async function $s(e,t){return e.listEvents(t)}function td(e,t={}){let r=Ne();return reactQuery.useQuery({queryKey:Ks(e),queryFn:()=>$s(r,e),...t})}function Gs(e){return ["predict-v2","event",e]}async function Ys(e,t){return e.getEvent(t)}function od(e,t={}){let r=Ne();return reactQuery.useQuery({queryKey:Gs(e.slug),queryFn:()=>Ys(r,e.slug),enabled:!!e.slug,...t})}var Ie=react.createContext({});var ge=react.createContext(null);function yr(){let e=react.useContext(Ie);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function h(){let{client:e}=yr();return e}function eo(e){return ["predict","events",e??{}]}async function St(e,t){return await e.getEvents(t)}function Ed(e,t={}){let r=h();return reactQuery.useQuery({queryKey:eo(e),queryFn:async()=>St(r,e),...t})}function ro(e){return ["predict","events","infinite",e??{}]}function fr(e={},t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:ro(e),queryFn:async({pageParam:n})=>St(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function so(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function oo(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function tt(e,t={}){let r=h();return reactQuery.useQuery({queryKey:so(e),queryFn:async()=>oo(r,e),...t})}function io(e){return ["predict","markets",e??{}]}async function lo(e,t){return await e.getMarkets(t)}function Wd(e,t={}){let r=h();return reactQuery.useQuery({queryKey:io(e),queryFn:async()=>lo(r,e),...t})}function uo(e){return ["predict","market","byId",e.id]}async function po(e,t){return await e.getMarketById(t.id)}function Vd(e,t={}){let r=h();return reactQuery.useQuery({queryKey:uo(e),queryFn:async()=>po(r,e),...t})}function yo(e){return ["predict","market","byMint",e]}async function fo(e,t){return await e.getMarketByMint(t)}function $d(e,t={}){let r=h();return reactQuery.useQuery({queryKey:yo(e),queryFn:async()=>fo(r,e),...t})}function xo(e){return ["predict","markets","batch",e]}async function vo(e,t){return await e.getMarketsBatch(t)}function jd(e,t={}){let r=h();return reactQuery.useQuery({queryKey:xo(e),queryFn:async()=>vo(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function ho(e){return ["predict","orderBook",e]}async function bo(e,t){return await e.getOrderbook(t)}function Qe(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ho(e),queryFn:async()=>bo(r,e),...t})}function ko(e){return ["predict","orderBook","byMint",e]}async function Po(e,t){return await e.getOrderbookByMint(t)}function ep(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ko(e),queryFn:async()=>Po(r,e),...t})}function Co(e){return ["predict","trades",e??{}]}async function So(e,t){return await e.getTrades(t)}function vr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Co(e),queryFn:async()=>So(r,e),...t})}function To(e){return ["predict","trades","byMint",e]}async function Mo(e,t){return await e.getTradesByMint(t)}function sp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:To(e),queryFn:async()=>Mo(r,e),...t})}function Eo(e){return ["predict","onchainTrades","byWallet",e]}async function Mt(e,t){return await e.getOnchainTradesByWallet(t)}function hr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Eo(e),queryFn:async()=>Mt(r,e),...t})}function wo(e){return ["predict","onchainTrades","byEvent",e]}async function Et(e,t){return await e.getOnchainTradesByEvent(t)}function lp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:wo(e),queryFn:async()=>Et(r,e),...t})}function Ro(e){return ["predict","onchainTrades","byMarket",e]}async function wt(e,t){return await e.getOnchainTradesByMarket(t)}function cp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ro(e),queryFn:async()=>wt(r,e),...t})}function Ot(e){return e.cursor??void 0}function Oo(e){return ["predict","onchainTrades","byWallet","infinite",e]}function yp(e,t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:Oo(e),queryFn:async({pageParam:n})=>Mt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:Ot,...t})}function No(e){return ["predict","onchainTrades","byEvent","infinite",e]}function fp(e,t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:No(e),queryFn:async({pageParam:n})=>Et(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:Ot,...t})}function Io(e){return ["predict","onchainTrades","byMarket","infinite",e]}function gp(e,t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:Io(e),queryFn:async({pageParam:n})=>wt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:Ot,...t})}function Qo(e){return ["predict","candlesticks","event",e]}async function Bo(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function bp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Qo(e),queryFn:async()=>Bo(r,e),...t})}function It(e){return ["predict","candlesticks","market",e]}async function Qt(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function Bt(e,t={}){let r=h();return reactQuery.useQuery({queryKey:It(e),queryFn:async()=>Qt(r,e),...t})}function Lo(e){return ["predict","candlesticks","market","byMint",e]}async function Uo(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function kp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Lo(e),queryFn:async()=>Uo(r,e),...t})}var Pp=Bt;function Ao(e){return ["predict","forecast","percentileHistory",e]}async function Wo(e,t){return await e.getEventForecastPercentileHistory(t)}function Mp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ao(e),queryFn:async()=>Wo(r,e),...t})}function Do(e){return ["predict","forecast","percentileHistory","byMint",e]}async function _o(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function Ep(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Do(e),queryFn:async()=>_o(r,e),...t})}function Fo(e){return ["predict","liveData",e]}async function Vo(e,t){return await e.getLiveData(t)}function Np(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Fo(e),queryFn:async()=>Vo(r,e),enabled:e.milestoneIds.length>0,...t})}function qo(e){return ["predict","liveData","byEvent",e]}async function Ho(e,t){return await e.getLiveDataByEvent(t)}function Ip(e,t={}){let r=h();return reactQuery.useQuery({queryKey:qo(e),queryFn:async()=>Ho(r,e),enabled:!!e.eventTicker,...t})}function Ko(e){return ["predict","liveData","byMint",e]}async function $o(e,t){return await e.getLiveDataByMint(t)}function Qp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ko(e),queryFn:async()=>$o(r,e),enabled:!!e.mintAddress,...t})}function zo(e){return ["predict","series",e??{}]}async function Go(e,t){return await e.getSeries(t)}function Pr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:zo(e),queryFn:async()=>Go(r,e),...t})}function Yo(e){return ["predict","series","byTicker",e]}async function jo(e,t){return await e.getSeriesByTicker(t)}function Cr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Yo(e),queryFn:async()=>jo(r,e),...t})}function Xo(){return ["predict","tags","byCategories"]}async function Zo(e){return await e.getTagsByCategories()}function Ut(e={}){let t=h();return reactQuery.useQuery({queryKey:Xo(),queryFn:async()=>Zo(t),...e})}function Jo(){return ["predict","filters","bySports"]}async function ea(e){return await e.getFiltersBySports()}function _p(e={}){let t=h();return reactQuery.useQuery({queryKey:Jo(),queryFn:async()=>ea(t),...e})}var Fp=Ut;function ra(e){return ["predict","search",e]}async function na(e,t){return await e.search(t)}function Kp(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ra(e),queryFn:async()=>na(r,e),...t})}function oa(e){return ["predict","positions","byWallet",e]}async function aa(e,t){return await e.getPositionsByWallet(t)}function Tr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:oa(e),queryFn:async()=>aa(r,e),...t})}function Zp(){let e=react.useContext(ge);if(!e)throw new Error("useUserPredictContext must be used within a UserPredictProvider");return e}function Mr(e){let t=react.useContext(ge);return react.useMemo(()=>t?{positions:t.positions.filter(n=>n.market?.ticker===e.ticker),isLoading:t.isLoading,isAvailable:true}:{positions:[],isLoading:false,isAvailable:false},[t,e.ticker])}function pa(e){return ["predict","outcomeMints",e??{}]}async function ma(e,t){return await e.getOutcomeMints(t)}function om(e,t={}){let r=h();return reactQuery.useQuery({queryKey:pa(e),queryFn:async()=>ma(r,e),...t})}async function ya(e,t){return await e.filterOutcomeMints(t)}function am(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>ya(t,r),...e})}function ga(e){return ["predict","quote",e]}async function xa(e,t){return await e.getQuote(t)}function um(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ga(e),queryFn:async()=>xa(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function va(e,t){return await e.createSwap(t)}function ym(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>va(t,r),...e})}async function ha(e,t){return await e.createSwapInstructions(t)}function fm(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>ha(t,r),...e})}function ba(e){return ["predict","order",e]}async function ka(e,t){return await e.getOrder(t)}function Rr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ba(e),queryFn:async()=>ka(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function Pa(e){return ["predict","order","status",e.signature]}async function Ca(e,t){return await e.getOrderStatus(t)}function Or(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Pa(e),queryFn:async()=>Ca(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,retry:false,...t})}function Ma(e){return ["predict","intent","quote",e]}async function Ea(e,t){return await e.getIntentQuote(t)}function Pm(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ma(e),queryFn:async()=>Ea(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function wa(e,t){return await e.submitIntentSwap(t)}function Cm(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>wa(t,r),...e})}async function Oa(e,t){return await e.initPredictionMarket(t)}function Em(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>Oa(t,r),...e})}function Na(){return ["predict","tokens"]}async function Ia(e){return await e.getTokens()}function Nm(e={}){let t=h();return reactQuery.useQuery({queryKey:Na(),queryFn:async()=>Ia(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function Qa(){return ["predict","tokens","decimals"]}async function Ba(e){return await e.getTokensWithDecimals()}function Im(e={}){let t=h();return reactQuery.useQuery({queryKey:Qa(),queryFn:async()=>Ba(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function Ua(){return ["predict","venues"]}async function Aa(e){return await e.getVenues()}function Um(e={}){let t=h();return reactQuery.useQuery({queryKey:Ua(),queryFn:async()=>Aa(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}var De=class{ws=null;wsUrl;autoReconnect;reconnectIntervalBase;reconnectMaxInterval;pingInterval;status="disconnected";reconnectAttempts=0;reconnectTimeout=null;pingIntervalId=null;shouldReconnect=true;listeners={connect:[],disconnect:[],reconnecting:[],error:[],price:[],trade:[],orderbook:[],status:[],subscribed:[],unsubscribed:[]};subscriptions={prices:{all:false,tickers:new Set},trades:{all:false,tickers:new Set},orderbook:{all:false,tickers:new Set}};constructor(t){this.wsUrl=t.wsUrl,this.autoReconnect=t.autoReconnect??true,this.reconnectIntervalBase=t.reconnectIntervalBase??1e3,this.reconnectMaxInterval=t.reconnectMaxInterval??3e4,this.pingInterval=t.pingInterval??3e4,t.autoConnect!==false&&this.connect();}connect(){if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))){this.shouldReconnect=true,this.setStatus("connecting");try{this.ws=new WebSocket(this.wsUrl),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus("connected"),this.emit("connect",void 0),this.restoreSubscriptions(),this.startPingInterval();},this.ws.onmessage=t=>{this.handleMessage(t.data);},this.ws.onerror=t=>{let r=new Error("WebSocket error");this.emit("error",r);},this.ws.onclose=t=>{this.stopPingInterval(),this.setStatus("disconnected"),this.emit("disconnect",{code:t.code,reason:t.reason}),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();};}catch(t){this.emit("error",t instanceof Error?t:new Error(String(t))),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();}}}disconnect(){this.shouldReconnect=false,this.stopPingInterval(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus("disconnected");}isConnected(){return this.ws!==null&&this.ws.readyState===WebSocket.OPEN}getStatus(){return this.status}subscribePrices(t,r){this.subscribeChannel("prices",t);let n=this.on("price",r);return ()=>{n(),this.unsubscribeChannel("prices",t);}}subscribeTrades(t,r){this.subscribeChannel("trades",t);let n=this.on("trade",r);return ()=>{n(),this.unsubscribeChannel("trades",t);}}subscribeOrderbook(t,r){this.subscribeChannel("orderbook",t);let n=this.on("orderbook",r);return ()=>{n(),this.unsubscribeChannel("orderbook",t);}}onStatusChange(t){return this.on("status",t)}on(t,r){return this.listeners[t].push(r),()=>{this.off(t,r);}}off(t,r){let n=this.listeners[t],s=n.indexOf(r);s!==-1&&n.splice(s,1);}removeAllListeners(t){if(t)this.listeners[t].length=0;else for(let r of Object.keys(this.listeners))this.listeners[r].length=0;}subscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=true,n.tickers.clear();else if(r.tickers&&r.tickers.length>0){n.all=false;for(let s of r.tickers)n.tickers.add(s);}this.sendSubscription("subscribe",t,r);}unsubscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=false,n.tickers.clear();else if(r.tickers&&r.tickers.length>0)for(let s of r.tickers)n.tickers.delete(s);this.sendSubscription("unsubscribe",t,r);}setStatus(t){this.status!==t&&(this.status=t,this.emit("status",t));}emit(t,r){let n=this.listeners[t];for(let s of n)try{s(r);}catch{}}send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)return false;try{return this.ws.send(JSON.stringify(t)),!0}catch{return false}}sendSubscription(t,r,n){this.send({type:t,channel:r,all:n.all,tickers:n.tickers});}handleMessage(t){try{let r=JSON.parse(t);switch(r.type){case "ticker":this.emit("price",r);break;case "trade":this.emit("trade",r);break;case "orderbook":this.emit("orderbook",r);break;case "status":break;case "subscribed":this.emit("subscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "unsubscribed":this.emit("unsubscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "pong":break;case "error":this.emit("error",new Error(r.message));break;default:if("channel"in r){let n=r;switch(n.channel){case "prices":this.emit("price",n);break;case "trades":this.emit("trade",n);break;case "orderbook":this.emit("orderbook",n);break}}}}catch{}}scheduleReconnect(){if(this.reconnectTimeout)return;let t=Math.min(this.reconnectIntervalBase*Math.pow(2,this.reconnectAttempts),this.reconnectMaxInterval);this.setStatus("reconnecting"),this.emit("reconnecting",{attempt:this.reconnectAttempts+1,delay:t}),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts++,this.connect();},t);}restoreSubscriptions(){for(let t of ["prices","trades","orderbook"]){let r=this.subscriptions[t];r.all?this.sendSubscription("subscribe",t,{all:true}):r.tickers.size>0&&this.sendSubscription("subscribe",t,{tickers:Array.from(r.tickers)});}}startPingInterval(){this.stopPingInterval(),this.pingIntervalId=setInterval(()=>{this.send({type:"ping"});},this.pingInterval);}stopPingInterval(){this.pingIntervalId&&(clearInterval(this.pingIntervalId),this.pingIntervalId=null);}};function rt(e){return new De(e)}function Vm({wsEndpoint:e,autoConnect:t=true,autoReconnect:r=true,enabled:n=true}){let[s,a]=react.useState("disconnected"),[o,l]=react.useState(null),i=react.useRef(null);react.useEffect(()=>{if(!n){i.current&&(i.current.disconnect(),i.current=null),a("disconnected");return}let p=rt({wsUrl:e,autoConnect:t,autoReconnect:r});i.current=p;let g=p.on("status",v=>{a(v);}),y=p.on("error",v=>{l(v);}),f=p.on("connect",()=>{l(null);});return ()=>{g(),y(),f(),p.disconnect(),i.current=null;}},[e,t,r,n]);let u=react.useCallback(()=>{i.current?.connect();},[]),c=react.useCallback(()=>{i.current?.disconnect();},[]);return {client:i.current,status:s,isConnected:s==="connected",connect:u,disconnect:c,error:o}}function $m(){let e=react.useContext(Ie);if(!e)throw new Error("useWsClient must be used within a PredictProvider");let{wsClient:t}=e,[r,n]=react.useState(t?.getStatus()??"disconnected");return react.useEffect(()=>{if(!t){n("disconnected");return}return n(t.getStatus()),t.onStatusChange(n)},[t]),{wsClient:t,wsStatus:r,isWsConnected:r==="connected"}}function Ym({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[a,o]=react.useState(new Map),[l,i]=react.useState(false),u=react.useRef(s);return react.useEffect(()=>{u.current=s;},[s]),react.useEffect(()=>{if(!e||!n){i(false);return}if(!t&&r.length===0)return;let c=t?{all:true}:{tickers:r},d=e.subscribePrices(c,p=>{o(g=>{let y=new Map(g);return y.set(p.market_ticker,{yesBid:p.yes_bid,yesAsk:p.yes_ask,noBid:p.no_bid,noAsk:p.no_ask,updatedAt:Date.now()}),y}),u.current?.(p);});return i(true),()=>{d(),i(false);}},[e,t,r.join(","),n]),{prices:a,isSubscribed:l}}function Zm({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:a}){let[o,l]=react.useState([]),[i,u]=react.useState(false),c=react.useRef(a);react.useEffect(()=>{c.current=a;},[a]),react.useEffect(()=>{if(!e||!n){u(false);return}if(!t&&r.length===0)return;let p=t?{all:true}:{tickers:r},g=e.subscribeTrades(p,y=>{let f={tradeId:y.trade_id,marketTicker:y.market_ticker,price:y.price,count:y.count,yesPrice:y.yes_price,noPrice:y.no_price,takerSide:y.taker_side,createdTime:y.created_time};l(v=>{let x=[f,...v];return x.length>s?x.slice(0,s):x}),c.current?.(y);});return u(true),()=>{g(),u(false);}},[e,t,r.join(","),n,s]);let d=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:i,clearHistory:d}}function ty({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[a,o]=react.useState(new Map),[l,i]=react.useState(false),u=react.useRef(s);react.useEffect(()=>{u.current=s;},[s]),react.useEffect(()=>{if(!e||!n){i(false);return}if(!t&&r.length===0)return;let d=t?{all:true}:{tickers:r},p=e.subscribeOrderbook(d,g=>{o(y=>{let f=new Map(y);return f.set(g.market_ticker,{yesBids:g.yes_bids,yesAsks:g.yes_asks,noBids:g.no_bids,noAsks:g.no_asks,updatedAt:Date.now()}),f}),u.current?.(g);});return i(true),()=>{p(),i(false);}},[e,t,r.join(","),n]);let c=react.useCallback(d=>a.get(d),[a]);return {orderbooks:a,isSubscribed:l,getOrderbook:c}}var _r=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function Fr(){let{data:e,isLoading:t,isError:r,error:n}=Ut();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let a=o=>{let l=_r.indexOf(o);return l===-1?_r.length:l};return Object.entries(e.tagsByCategories).map(([o,l])=>({category:o,tags:l})).sort((o,l)=>a(o.category)-a(l.category))},[e]),isLoading:t,isError:r,error:n??null}}function st({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:s,onTagSelect:a,className:o}){let{t:l}=i18n.useTranslation(),i=react.useCallback(()=>{s(null);},[s]);return jsxRuntime.jsxs("div",{className:ui.cn("flex w-full flex-col gap-2",o),children:[jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(nt,{label:l("predict.categories.trending"),isSelected:t===null,onPress:i}),e.map(u=>jsxRuntime.jsx(nt,{label:u.category,isSelected:t===u.category,onPress:()=>s(u.category)},u.category))]})}),t&&n.length>0&&jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(nt,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>a(null),variant:"secondary"}),n.map(u=>jsxRuntime.jsx(nt,{label:u,isSelected:r===u,onPress:()=>a(u),variant:"secondary"},u))]})})]})}function nt({label:e,isSelected:t,onPress:r,variant:n="primary"}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:ui.cn("shrink-0 rounded-full px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer","border whitespace-nowrap",n==="primary"?t?"bg-foreground text-background border-foreground":"bg-content1 text-foreground/70 border-default-200 hover:bg-default-100 hover:text-foreground":t?"bg-primary/15 text-primary border-primary/40":"bg-content1 text-foreground/50 border-default-100 hover:bg-default-50 hover:text-foreground/70"),children:e})}function Hr({count:e=6}){return jsxRuntime.jsx("div",{className:"flex items-center gap-2 px-0.5 py-1",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-8 shrink-0 rounded-full",style:{width:`${60+Math.random()*40}px`}},r))})}function Gr({onSelect:e,className:t}){let{data:r,isLoading:n}=Fr(),[s,a]=react.useState(null),[o,l]=react.useState(null),i=react.useCallback(d=>{if(a(d),l(null),!d)e?.({category:null,tags:null});else {let p=r.find(g=>g.category===d);e?.({category:d,tags:p?.tags??null});}},[r,e]),u=react.useCallback(d=>{if(l(d),d)e?.({category:s,tags:[d]});else {let p=r.find(g=>g.category===s);e?.({category:s,tags:p?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(Hr,{});let c=r.find(d=>d.category===s)?.tags??[];return jsxRuntime.jsx(st,{categories:r,selectedCategory:s,selectedTag:o,activeTags:c,onCategorySelect:i,onTagSelect:u,className:t})}var te=48,xe=4,ot={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},M={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},ve=M.ALL,at={[M.ONE_DAY]:ot.ONE_MINUTE,[M.ONE_WEEK]:ot.ONE_HOUR,[M.ONE_MONTH]:ot.ONE_HOUR,[M.ALL]:ot.ONE_DAY},it={[M.ONE_DAY]:300,[M.ONE_WEEK]:3600,[M.ONE_MONTH]:10800,[M.ALL]:1440*60},lt={[M.ONE_DAY]:1440*60,[M.ONE_WEEK]:10080*60,[M.ONE_MONTH]:720*60*60,[M.ALL]:null},Wt=1,Jy=1,ef=1,tf=99,Be={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},rf=Be.ONE_WEEK,nf={[Be.ONE_HOUR]:60,[Be.SIX_HOURS]:60,[Be.ONE_DAY]:300,[Be.ONE_WEEK]:1800,[Be.MAX]:1800};function Yr(e={}){let{category:t,tags:r,...n}=e,s=!!t||!!r&&r.length>0,{data:a,isFetching:o,isError:l,error:i}=Pr({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),u=react.useMemo(()=>{if(!s||!a?.series)return;let O=a.series.map(C=>C.ticker).slice(0,25);return O.length>0?O.join(","):void 0},[s,a]),c=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...u!==void 0?{seriesTickers:u}:{}}),[n,u]),{data:d,isLoading:p,isFetching:g,isFetchingNextPage:y,isError:f,error:v,hasNextPage:x,fetchNextPage:k,refetch:P}=fr(c),m=react.useMemo(()=>d?.pages.flatMap(O=>O.events)??[],[d]),b=s&&!a&&!l;return {data:m,isLoading:b||p,isFetching:o||b||g&&!y,isFetchingMore:y,isError:l||f,error:i??v,hasMore:x,fetchMore:k,refetch:P}}function Za({className:e}){return jsxRuntime.jsxs("div",{className:`flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 @5xl:gap-y-3 @5xl:p-4 ${e??""}`,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-8 flex-shrink-0 rounded-lg @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-md @5xl:h-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-12 flex-shrink-0 rounded-lg @5xl:h-10 @5xl:w-14"})]}),jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 @5xl:gap-y-1",children:[jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-2/3 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]}),jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-1/2 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-16 rounded-md @5xl:h-4"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded-md @5xl:h-4"})]})]})}function ct({count:e=8}){return jsxRuntime.jsx("div",{className:"@container w-full h-full",children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 gap-4 @[640px]:grid-cols-2 @[1024px]:grid-cols-3 @[1280px]:grid-cols-4",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(Za,{className:"min-h-44 @5xl:min-h-56"},r))})})}function dt({value:e,showLabel:t=true}){let r=e/100;return jsxRuntime.jsx("div",{className:"flex-shrink-0 flex flex-col items-center",children:jsxRuntime.jsxs("div",{className:"relative w-16 h-12 lg:w-20 lg:h-14",children:[jsxRuntime.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 100 70",children:[jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-default-200",strokeWidth:"6",strokeLinecap:"round"}),jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-primary",strokeWidth:"6",strokeLinecap:"round",strokeDasharray:`${r*125.6} 125.6`,style:{transition:"stroke-dasharray 0.5s ease-in-out"}})]}),t&&jsxRuntime.jsx("div",{className:"absolute inset-0 flex items-center justify-center pt-3 lg:pt-4",children:jsxRuntime.jsxs("span",{className:"text-sm font-bold text-foreground lg:text-base leading-none",children:[e.toFixed(0),"%"]})})]})})}function Zr({event:e,onSelect:t,onSelectOutcome:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((C,Q)=>Number(Q.yesAsk??0)-Number(C.yesAsk??0)):o,i=l.filter(C=>C.status==="active"),u=l.length===1,c=u?l[0]:s,d=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),p=C=>C.yesAsk?parseFloat(C.yesAsk)*100:null,g=C=>C.noAsk?parseFloat(C.noAsk)*100:null,y=C=>{let Q=p(C),A=g(C);return Q!=null?A==null&&Q<=1?"< 1%":v(Q):A!=null?A<=1?"> 99%":v(100-A):"0%"},f=C=>{let Q=p(C),A=g(C);return A!=null?Q==null&&A<=1?"< 1%":v(A):Q!=null?Q<=1?"> 99%":v(100-Q):"0%"},v=C=>C!=null?`${C.toFixed(0)}%`:"--",x=react.useMemo(()=>{let C=l.some(A=>A.status==="active");return l.every(A=>A.status==="closed"||A.status==="determined")?{label:n("predict.event.status.closed"),color:"bg-danger-100/50 text-danger"}:C?{label:n("predict.event.status.live"),color:"bg-primary-100/50 text-primary"}:{label:n("predict.event.status.pending"),color:"bg-warning-100/50 text-warning"}},[l,n]),k=C=>{a(C);},P=()=>{a(null);},m=()=>{c&&r&&r(e,c,"yes");},b=()=>{c&&r&&r(e,c,"no");},S=()=>{t&&t(e);},R=i.slice(0,2),O=i.length>2;return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 transition-all duration-300 cursor-pointer hover:border-primary hover:ring-2 hover:ring-primary/20 focus-within:border-primary focus-within:bg-content2 focus-within:ring-2 focus-within:ring-primary/20 @5xl:gap-y-3 @5xl:p-4",onClick:S,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"md",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover:scale-110 @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.StyledTooltip,{content:e.title,placement:"bottom",children:jsxRuntime.jsx("p",{className:"flex-1 min-w-0 h-10 @5xl:h-12 text-sm font-semibold @5xl:text-base line-clamp-2",children:e.title})}),u?jsxRuntime.jsx(dt,{value:p(l[0])??50}):x.label!==n("predict.event.status.live")&&jsxRuntime.jsx("div",{className:`flex-shrink-0 flex items-center gap-x-2 rounded-lg px-2 py-1 text-sm @5xl:px-4 @5xl:py-2 ${x.color}`,children:jsxRuntime.jsx("span",{children:x.label})})]}),c&&!u&&jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:C=>{C.stopPropagation(),P();},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:c.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground @5xl:text-lg",children:y(c)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!c&&!u&&R.length>0&&jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 text-xs @5xl:gap-y-1 @5xl:text-sm",children:[R.map(C=>jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-8 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:Q=>{Q.stopPropagation(),k(C);},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:C.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-foreground @5xl:text-base",children:y(C)}),jsxRuntime.jsxs("div",{className:"flex h-full items-center gap-x-3 rounded-lg p-1 @5xl:p-1.5 bg-gradient-to-r from-primary-50/20 via-primary-50/20 to-secondary-50/20",children:[jsxRuntime.jsx("span",{className:"text-primary",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"text-default-400",children:"/"}),jsxRuntime.jsx("span",{className:"text-secondary",children:n("predict.market.no")})]})]})]},C.ticker)),O&&jsxRuntime.jsx("span",{className:"text-xxs text-default-500 @5xl:text-xs",children:n("predict.event.moreMarkets",{count:i.length-2})})]}),c&&jsxRuntime.jsxs("div",{className:`flex items-center gap-x-2 text-sm @5xl:text-base ${u?"mt-3":""}`,children:[jsxRuntime.jsxs(ui.Button,{color:"primary",fullWidth:true,className:"group/yes bg-primary-100 text-primary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:m,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:y(c)})]}),jsxRuntime.jsxs(ui.Button,{color:"secondary",fullWidth:true,className:"group/no bg-secondary-100 text-secondary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:b,children:[jsxRuntime.jsx("span",{className:"group-hover/no:hidden",children:n("predict.market.no")}),jsxRuntime.jsx("span",{className:"hidden group-hover/no:inline",children:f(c)})]})]})]}),!c||u?jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"flex items-center gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:C=>{C.stopPropagation(),S();},children:[jsxRuntime.jsx("span",{children:n("predict.event.showMore")}),jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"})]}),jsxRuntime.jsxs("span",{className:"text-xxs text-default-600 @5xl:text-xs",children:[d," ",n("predict.event.volume")]})]}):jsxRuntime.jsxs("button",{type:"button",className:"flex items-center cursor-pointer gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:C=>{C.stopPropagation(),P();},children:[jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"}),jsxRuntime.jsx("span",{children:n("predict.event.back")})]})]})}var pi=640,mi=768,en=1024,yi=1280,fi=16,gi=192,xi=228,vi=244;function hi(e){return e>=yi?4:e>=en?3:e>=pi?2:1}function bi(e){return e>=en?vi:e>=mi?xi:gi}function tn({events:e,hasMore:t=false,onFetchMore:r,onSelect:n,onSelectOutcome:s}){let a=react.useRef(null),{width:o=0,height:l=0}=hooks.useResizeObserver({ref:a}),i=hi(o),u=bi(o),c=Math.ceil(e.length/i)||0,d=t?c+1:c,p=react.useCallback(f=>f<c,[c]),g=react.useCallback(async()=>{r?.();},[r]),y=reactWindowInfiniteLoader.useInfiniteLoader({isRowLoaded:p,loadMoreRows:g,rowCount:d,threshold:3});return jsxRuntime.jsx("div",{ref:a,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(reactWindow.List,{style:{height:l},onRowsRendered:y,rowComponent:ki,rowCount:d,rowHeight:u,rowProps:{events:e,columnCount:i,dataRowCount:c,gap:fi,onSelect:n,onSelectOutcome:s}})})}function ki({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:a,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let i=e*n,u=r.slice(i,i+n),c=n-u.length,d={display:"flex",gap:a,height:`calc(100% - ${a}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:d,children:[u.map(p=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(Zr,{event:p,onSelect:o,onSelectOutcome:l})},p.ticker)),c>0&&Array.from({length:c}).map((p,g)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${g}`))]})})}function nn({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:a,isFetching:o}=Yr({limit:48,...r});return o?jsxRuntime.jsx(ct,{count:48}):jsxRuntime.jsx(tn,{events:n,hasMore:s,onFetchMore:a,onSelect:e,onSelectOutcome:t})}function Df({onSelect:e,onSelectOutcome:t}){let[r,n]=react.useState({category:null,tags:null}),s=react.useCallback(a=>{n(a);},[]);return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col gap-y-3",children:[jsxRuntime.jsx(Gr,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(nn,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}var Mi={"Climate and Weather":["Daily temperature","Snow and rain","Climate change","Natural disasters","Hurricanes"],Companies:["IPOs","Product launches","KPIs","Elon Musk","CEOs","Layoffs"],Crypto:["BTC","15 min","Hourly","ETH","SOL","DOGE","Pre-Market","XRP","BNB","HYPE"],Economics:["Growth","Fed","Inflation","Oil and energy","Employment","Housing","Jobs & Economy","Bankruptcy & Defaults","GDP","Global Central Banks"],Elections:["Primaries","International elections"],Entertainment:["Music","Movies","Music charts","Television","Awards","Video games","Oscars","Rotten Tomatoes"],Financials:["S&P","Nasdaq","Daily","Metals","Treasuries","Oil","EUR/USD","USD/JPY","WTI"],Mentions:["Politicians","Earnings","Entertainment"],Politics:["Trump","Congress","International","SCOTUS & courts","Local","Recurring","Iran","House"],"Science and Technology":["AI","Energy","Space"],Social:null,Sports:["Soccer","Basketball","Baseball","Football","Hockey","Golf","Tennis","Motorsport","Esports","Boxing","MMA","Rugby","Lacrosse","Mentions","Chess","Cricket","Aussie Rules","Darts"],World:null},sn=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],Vt=(()=>{let e=t=>{let r=sn.indexOf(t);return r===-1?sn.length:r};return Object.entries(Mi).map(([t,r])=>({slug:t,label:t,tags:(r??[]).map(n=>({slug:n,label:n}))})).sort((t,r)=>e(t.slug)-e(r.slug))})();function Ei(e){return e.map(t=>({category:t.label,tags:t.tags.map(r=>r.label)}))}function ln({onSelect:e,className:t}){let[r,n]=react.useState(null),[s,a]=react.useState(null),o=react.useCallback(c=>{n(c),a(null),e?.({categorySlug:c,tagSlug:null});},[e]),l=react.useCallback(c=>{a(c),e?.({categorySlug:r,tagSlug:c});},[r,e]),i=Ei(Vt),u=Vt.find(c=>c.slug===r)?.tags.map(c=>c.label)??[];return jsxRuntime.jsx(st,{categories:i,selectedCategory:r,selectedTag:s,activeTags:u,onCategorySelect:o,onTagSelect:l,className:t})}function Oi(e){if(e)return e.tagSlug??e.categorySlug??void 0}function Ni(e){return ["predict-v2","events-infinite",e]}function dn(e={}){let{tagSlugSelection:t,limit:r=48,status:n="open",sort_by:s,sort_asc:a,with_markets:o=true}=e,l=Ne(),i=react.useMemo(()=>{let b=Oi(t);return {limit:r,status:n,with_markets:o,...b?{tag_slug:b}:{},...s?{sort_by:s}:{},...a!==void 0?{sort_asc:a}:{}}},[t,r,n,s,a,o]),{data:u,isLoading:c,isFetching:d,isFetchingNextPage:p,isError:g,error:y,hasNextPage:f,fetchNextPage:v,refetch:x}=reactQuery.useInfiniteQuery({queryKey:Ni(i),queryFn:({pageParam:b})=>l.listEvents({...i,...b!==void 0?{cursor:b}:{}}),initialPageParam:void 0,getNextPageParam:b=>b.has_more&&b.next_cursor?b.next_cursor:void 0}),k=react.useMemo(()=>u?.pages.flatMap(b=>b.items).filter(b=>b!=null)??[],[u]),P=react.useCallback(()=>{v();},[v]),m=react.useCallback(()=>{x();},[x]);return {data:k,isLoading:c,isFetching:d&&!p,isFetchingMore:p,isError:g,error:y??null,hasMore:f??false,fetchMore:P,refetch:m}}function _e(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function yn(e){let t=e.outcomes?.[1];return t?t.best_ask??t.price??null:null}function Fe(e){return e!=null?e*100:null}function pt(e){return e!=null?`${e.toFixed(0)}%`:"--"}function qt(e){let t=Fe(_e(e)),r=Fe(yn(e));return t!=null?r==null&&t<=1?"< 1%":pt(t):r!=null?r<=1?"> 99%":pt(100-r):"0%"}function _i(e){let t=Fe(_e(e)),r=Fe(yn(e));return r!=null?t==null&&r<=1?"< 1%":pt(r):t!=null?t<=1?"> 99%":pt(100-t):"0%"}function fn({event:e,onSelect:t,onSelectOutcome:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.markets??[],l=o.length>2?[...o].sort((m,b)=>(_e(b)??0)-(_e(m)??0)):o,i=l.filter(m=>m.status==="open"),u=l.length===1,c=u?l[0]:s,d=react.useMemo(()=>utils.formatAmountUSDCompact(e.volume??0),[e.volume]),p=react.useMemo(()=>{let m=l.some(S=>S.status==="open");return l.every(S=>S.status==="closed"||S.status==="voided")?{label:n("predict.event.status.closed"),color:"bg-danger-100/50 text-danger"}:m?{label:n("predict.event.status.live"),color:"bg-primary-100/50 text-primary"}:{label:n("predict.event.status.pending"),color:"bg-warning-100/50 text-warning"}},[l,n]),g=m=>{a(m);},y=()=>{a(null);},f=()=>{c&&r&&r(e,c,"yes");},v=()=>{c&&r&&r(e,c,"no");},x=()=>{t?.(e);},k=i.slice(0,2),P=i.length>2;return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 transition-all duration-300 cursor-pointer hover:border-primary hover:ring-2 hover:ring-primary/20 focus-within:border-primary focus-within:bg-content2 focus-within:ring-2 focus-within:ring-primary/20 @5xl:gap-y-3 @5xl:p-4",onClick:x,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"md",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover:scale-110 @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.StyledTooltip,{content:e.title,placement:"bottom",children:jsxRuntime.jsx("p",{className:"flex-1 min-w-0 h-10 @5xl:h-12 text-sm font-semibold @5xl:text-base line-clamp-2",children:e.title})}),u?jsxRuntime.jsx(dt,{value:Fe(_e(l[0]))??50}):p.label!==n("predict.event.status.live")&&jsxRuntime.jsx("div",{className:`flex-shrink-0 flex items-center gap-x-2 rounded-lg px-2 py-1 text-sm @5xl:px-4 @5xl:py-2 ${p.color}`,children:jsxRuntime.jsx("span",{children:p.label})})]}),c&&!u&&jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:m=>{m.stopPropagation(),y();},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:c.question}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground @5xl:text-lg",children:qt(c)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!c&&!u&&k.length>0&&jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 text-xs @5xl:gap-y-1 @5xl:text-sm",children:[k.map(m=>jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-8 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:b=>{b.stopPropagation(),g(m);},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:m.question}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-foreground @5xl:text-base",children:qt(m)}),jsxRuntime.jsxs("div",{className:"flex h-full items-center gap-x-3 rounded-lg p-1 @5xl:p-1.5 bg-gradient-to-r from-primary-50/20 via-primary-50/20 to-secondary-50/20",children:[jsxRuntime.jsx("span",{className:"text-primary",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"text-default-400",children:"/"}),jsxRuntime.jsx("span",{className:"text-secondary",children:n("predict.market.no")})]})]})]},m.slug)),P&&jsxRuntime.jsx("span",{className:"text-xxs text-default-500 @5xl:text-xs",children:n("predict.event.moreMarkets",{count:i.length-2})})]}),c&&jsxRuntime.jsxs("div",{className:`flex items-center gap-x-2 text-sm @5xl:text-base ${u?"mt-3":""}`,children:[jsxRuntime.jsxs(ui.Button,{color:"primary",fullWidth:true,className:"group/yes bg-primary-100 text-primary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:f,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:qt(c)})]}),jsxRuntime.jsxs(ui.Button,{color:"secondary",fullWidth:true,className:"group/no bg-secondary-100 text-secondary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:v,children:[jsxRuntime.jsx("span",{className:"group-hover/no:hidden",children:n("predict.market.no")}),jsxRuntime.jsx("span",{className:"hidden group-hover/no:inline",children:_i(c)})]})]})]}),!c||u?jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"flex items-center gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:m=>{m.stopPropagation(),x();},children:[jsxRuntime.jsx("span",{children:n("predict.event.showMore")}),jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"})]}),jsxRuntime.jsxs("span",{className:"text-xxs text-default-600 @5xl:text-xs",children:[d," ",n("predict.event.volume")]})]}):jsxRuntime.jsxs("button",{type:"button",className:"flex items-center cursor-pointer gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:m=>{m.stopPropagation(),y();},children:[jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"}),jsxRuntime.jsx("span",{children:n("predict.event.back")})]})]})}var $i=640,zi=768,xn=1024,Gi=1280,Yi=16,ji=192,Xi=228,Zi=244;function Ji(e){return e>=Gi?4:e>=xn?3:e>=$i?2:1}function el(e){return e>=xn?Zi:e>=zi?Xi:ji}function vn({events:e,hasMore:t=false,onFetchMore:r,onSelect:n,onSelectOutcome:s}){let a=react.useRef(null),{width:o=0,height:l=0}=hooks.useResizeObserver({ref:a}),i=Ji(o),u=el(o),c=Math.ceil(e.length/i)||0,d=t?c+1:c,p=react.useCallback(f=>f<c,[c]),g=react.useCallback(async()=>{r?.();},[r]),y=reactWindowInfiniteLoader.useInfiniteLoader({isRowLoaded:p,loadMoreRows:g,rowCount:d,threshold:3});return jsxRuntime.jsx("div",{ref:a,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(reactWindow.List,{style:{height:l},onRowsRendered:y,rowComponent:tl,rowCount:d,rowHeight:u,rowProps:{events:e,columnCount:i,dataRowCount:c,gap:Yi,onSelect:n,onSelectOutcome:s}})})}function tl({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:a,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let i=e*n,u=r.slice(i,i+n),c=n-u.length,d={display:"flex",gap:a,height:`calc(100% - ${a}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:d,children:[u.map(p=>p==null?null:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(fn,{event:p,onSelect:o,onSelectOutcome:l})},p.slug)),c>0&&Array.from({length:c}).map((p,g)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${g}`))]})})}function bn({tagSlugSelection:e,limit:t=48,status:r,sort_by:n,sort_asc:s,with_markets:a,onSelect:o,onSelectOutcome:l}){let{data:i,hasMore:u,fetchMore:c,isFetching:d}=dn({tagSlugSelection:e,limit:t,status:r,sort_by:n,sort_asc:s,with_markets:a});return d?jsxRuntime.jsx(ct,{count:48}):jsxRuntime.jsx(vn,{events:i,hasMore:u,onFetchMore:c,onSelect:o,onSelectOutcome:l})}function Cg({onSelect:e,onSelectOutcome:t}){let[r,n]=react.useState({categorySlug:null,tagSlug:null}),s=react.useCallback(a=>{n(a);},[]);return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col gap-y-3",children:[jsxRuntime.jsx(ln,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(bn,{tagSlugSelection:r,onSelect:e,onSelectOutcome:t})})]})}function zt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Ve=utils.SOLANA_TOKENS.stablecoins.USDC.address;function pl(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Kt__default.default({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Kt__default.default({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Kt__default.default({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Pn({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:n="buy"}){let{t:s}=i18n.useTranslation(),a=react.useContext(ge),{status:o}=walletConnector.useAuth(),i=walletConnector.useWallets().find(T=>T.chainNamespace===types.ChainNamespace.SOLANA&&T.isConnected),u=o==="authenticated",c=i?.address,[d,p]=react.useState(r),[g,y]=react.useState(n),[f,v]=react.useState(NaN),x=react.useMemo(()=>zt(e.accounts,Ve,d),[e.accounts,d]),{inputMint:k,outputMint:P}=react.useMemo(()=>g==="buy"?{inputMint:Ve,outputMint:x}:{inputMint:x,outputMint:Ve},[g,x]),m=!!k&&!!P&&f>0,b=react.useMemo(()=>Number(d==="yes"?e.yesAsk??.5:e.noAsk??.5),[d,e.yesAsk,e.noAsk]),S=react.useMemo(()=>isNaN(f)||f<=0?0:g==="buy"?b>0?f/b:0:f,[g,f,b]),R=react.useMemo(()=>isNaN(f)||f<=0?0:Math.round(f*1e6),[f]),{data:O,isLoading:C,error:Q,refetch:A}=Rr({userPublicKey:c??void 0,inputMint:k??"",outputMint:P??"",amount:R,slippageBps:100},{enabled:m}),Te=a?.usdcBalance??null,fe=a?.isLoading??false,ur=a?.refetch,le=a?.positions,Ye=react.useMemo(()=>{if(!le||!x)return null;let T=le.find(se=>se.mint===x);return T?T.balance:0},[le,x]),bt=react.useMemo(()=>zt(e.accounts,Ve,"yes"),[e.accounts]),kt=react.useMemo(()=>zt(e.accounts,Ve,"no"),[e.accounts]),Rs=react.useMemo(()=>{if(!le||!bt)return null;let T=le.find(se=>se.mint===bt);return T?T.balance:0},[le,bt]),Os=react.useMemo(()=>{if(!le||!kt)return null;let T=le.find(se=>se.mint===kt);return T?T.balance:0},[le,kt]),{data:Re}=Qe(e.ticker,{refetchInterval:5e3}),Ns=react.useMemo(()=>(d==="yes"?Re?.yesBids:Re?.noBids)?.[0]?.price??null,[Re,d]),Is=react.useMemo(()=>(d==="yes"?Re?.yesAsks:Re?.noAsks)?.[0]?.price??null,[Re,d]),Qs=react.useMemo(()=>O?.priceImpactPct?parseFloat(O.priceImpactPct):null,[O]),je=react.useMemo(()=>{if(isNaN(f)||f<=0)return 0;if(O)return parseInt(O.inAmount)/1e6;if(g==="buy")return f;let T=Number(d==="yes"?e.yesBid??0:e.noBid??0);return f*T},[O,g,d,f,e.yesBid,e.noBid]),dr=react.useMemo(()=>isNaN(f)||f<=0?0:g==="buy"?S*1:je,[g,S,je,f]),Bs=dr-je,Ls=react.useCallback(T=>{y(T),v(NaN);},[]),Us=react.useCallback(T=>{if(isNaN(T)){v(NaN);return}let se=Math.max(0,T),Je=g==="buy"?Math.round(se*100)/100:Math.round(se);v(Je);},[g]);react.useEffect(()=>{m&&A();},[f,d,g,m,A]);let Pt=react.useMemo(()=>{let T=[];return (isNaN(f)||f<Wt)&&T.push(`Minimum quantity is ${Wt}`),e.status!=="active"&&T.push("Market is not active"),g==="buy"&&Te!=null&&!isNaN(f)&&f>0&&f>Te&&T.push("Insufficient USDC balance"),g==="sell"&&Ye!=null&&!isNaN(f)&&f>0&&f>Ye&&T.push("Insufficient shares"),{isValid:T.length===0,errors:T}},[f,e.status,g,Te,Ye]),[As,Ct]=react.useState(null),[Ws,Oe]=react.useState(false),[Xe,We]=react.useState(null),{data:Ze}=Or({signature:Xe??""},{enabled:!!Xe});react.useEffect(()=>{if(!Ze||!Xe)return;let{status:T}=Ze;T==="closed"?(Oe(false),We(null),ui.toast.success(s("predict.trade.submitSuccess")),pl(),v(NaN),ur?.()):(T==="failed"||T==="expired")&&(Oe(false),We(null),ui.toast.error(s("predict.trade.submitError")));},[Ze,Xe,ur,s]);let Ds=react.useCallback(async()=>{if(!(!Pt.isValid||!u||!c||!i||fe)){Ct(null),We(null),Oe(true);try{let T=O;if(T?.transaction||(T=(await A()).data),!T?.transaction){Oe(!1);return}let se=Uint8Array.from(atob(T.transaction),pr=>pr.charCodeAt(0)),Je=await i.sendTransaction(se);Ct(Je),We(Je);}catch{ui.toast.error(s("predict.trade.submitError")),Oe(false);}}},[Pt.isValid,u,c,i,O,fe,A,s]),_s=react.useCallback(()=>{p(r),y(n),v(NaN),Ct(null),We(null),Oe(false);},[r,n]);return {outcome:d,side:g,quantity:f,shares:S,estimatedCost:je,potentialPayout:dr,potentialProfit:Bs,isAuthenticated:u,bestBid:Ns,bestAsk:Is,order:O??null,priceImpact:Qs,usdcBalance:Te,outcomeTokenBalance:Ye,yesTokenBalance:Rs,noTokenBalance:Os,isBalanceLoading:fe,isQuoteLoading:C,isSubmitting:Ws,quoteError:Q??null,txHash:As,orderStatus:Ze??null,validation:Pt,setOutcome:p,setSide:Ls,setQuantity:Us,submit:Ds,reset:_s}}var vl=`https://s1.chainstream.io/chains/sol/tokens/${utils.SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function Mn({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:a,estimatedCost:o,usdcBalance:l,yesTokenBalance:i,noTokenBalance:u,isBalanceLoading:c,isSubmitting:d,isValid:p,onOutcomeChange:g,onSideChange:y,onQuantityChange:f,onSubmit:v}){let{t:x}=i18n.useTranslation(),k=react.useMemo(()=>{if(d)return x("predict.trade.submitting");let m=x(n==="buy"?"predict.trade.buy":"predict.trade.sell"),b=x(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${m} ${b}`},[d,n,r,x]),P=react.useMemo(()=>r==="yes"?"primary":"secondary",[r]);return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4",children:[e&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsxRuntime.jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxRuntime.jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxRuntime.jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxRuntime.jsxs("span",{className:r==="yes"?"text-bullish":"text-bearish",children:[x(n==="buy"?"predict.trade.buy":"predict.trade.sell")," ",x(r==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[" \xB7 ",r==="yes"?t.yesSubTitle:t.noSubTitle]})]})]})]}),jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:m=>y(m),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:x("predict.trade.buy")},"buy"),jsxRuntime.jsx(ui.Tab,{title:x("predict.trade.sell")},"sell")]}),jsxRuntime.jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(m=>{let b=m==="yes"?i:u;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>g(m),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===m?m==="yes"?"border-primary bg-primary-50 text-primary":"border-secondary bg-secondary-50 text-secondary":"border-default-400 text-foreground hover:border-default-500"}`,children:[jsxRuntime.jsx("span",{children:x(m==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let S=n==="buy"?m==="yes"?t.yesAsk:t.noAsk:m==="yes"?t.yesBid:t.noBid;return S!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(S)*100),"\xA2"]}):null})()]}),n==="sell"&&r===m&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:c?"\u2013":`${b??0} shares`})]},m)})}),n==="buy"&&jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-x-1 text-xs text-default-500",children:[jsxRuntime.jsx("img",{src:vl,alt:"USDC",className:"h-4 w-4 rounded-full object-cover"}),jsxRuntime.jsxs("span",{children:[x("predict.trade.balance"),":"]}),jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:l!=null?`$${l.toFixed(2)}`:"\u2013"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-foreground",children:x(n==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsxRuntime.jsx(ui.StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:m=>{f(m);},minValue:0,step:n==="buy"?.01:1,formatOptions:n==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:n==="buy"?jsxRuntime.jsx("span",{className:"text-default-600 text-xl",children:"$"}):void 0,classNames:{inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 h-14 min-h-14",input:"text-lg"}},n),jsxRuntime.jsx("div",{className:"flex gap-x-2 justify-end",children:n==="buy"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[1,5,10,100].map(m=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>f(Math.round(((isNaN(s)?0:s)+m)*100)/100),className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:["+",m,"$"]},m)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:x("common.all")})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[25,50].map(m=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:[m,"%"]},m)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:x("common.all")})]})})]}),!isNaN(s)&&s>0&&jsxRuntime.jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-foreground",children:x(n==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxRuntime.jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(n==="buy"?a:o).toFixed(2)]})]}),jsxRuntime.jsx(ui.Button,{color:P,fullWidth:true,radius:"lg",size:"lg",isDisabled:!p||d,isLoading:d,onPress:v,children:k})]})}function Gt({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:a,side:o,quantity:l,estimatedCost:i,potentialPayout:u,potentialProfit:c,usdcBalance:d,yesTokenBalance:p,noTokenBalance:g,isBalanceLoading:y,isSubmitting:f,validation:v,setOutcome:x,setSide:k,setQuantity:P,submit:m}=Pn({market:t,initialSide:r,initialOutcome:n,chain:s}),b=walletConnector.useAuthCallback(m);return jsxRuntime.jsx(Mn,{event:e,market:t,outcome:a,side:o,quantity:l,estimatedCost:i,potentialPayout:u,potentialProfit:c,usdcBalance:d,yesTokenBalance:p,noTokenBalance:g,isBalanceLoading:y,isSubmitting:f,isValid:v.isValid,validationErrors:v.errors,onOutcomeChange:x,onSideChange:k,onQuantityChange:P,onSubmit:b})}function kl(){return jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 flex-1 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-10 shrink-0 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"})]})]})}function qe({marketCount:e=4}){return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 lg:px-4 lg:max-w-3xl animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-14 shrink-0 rounded-lg lg:h-18 lg:w-18"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5 min-w-0 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-24 rounded-md lg:w-32"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-48 rounded-md lg:h-6 lg:w-72"})]})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-[200px] w-full rounded-xl lg:h-[280px]"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-32 rounded-md"}),jsxRuntime.jsx("div",{className:"flex gap-x-1",children:Array.from({length:4}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-7 w-10 rounded-md"},r))})]}),jsxRuntime.jsx("div",{className:"flex flex-col divide-y divide-default-200",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(kl,{},r))})]})}function En(){return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4 animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 w-10 shrink-0 rounded-lg"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-28 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-40 rounded-md"})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-full rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-12 w-full rounded-lg"})]})}var wn=e=>{let{candlestickMarketTickers:t,chartRange:r=ve}=e,n=at[r],s=lt[r],a=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=h(),{data:l,isLoading:i,error:u}=tt({id:e.eventId,withNestedMarkets:true}),c=react.useMemo(()=>{if(s!=null)return a-s;let P=l?.markets;return P?.length?Math.min(...P.map(m=>m.openTime)):a},[a,s,l?.markets]),{data:d,isLoading:p,error:g}=Cr(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),y=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(m=>l.markets.find(b=>b.ticker===m)).filter(m=>m!==void 0):[...l.markets].sort((m,b)=>Number(b.yesAsk??0)-Number(m.yesAsk??0)).slice(0,4)).map(m=>m.ticker):[],[t,l?.markets]),f=reactQuery.useQueries({queries:y.map(P=>({queryKey:It({ticker:P,startTs:c,endTs:a,periodInterval:n}),queryFn:()=>Qt(o,{ticker:P,startTs:c,endTs:a,periodInterval:n}),enabled:y.length>0}))}),v=f.some(P=>P.isLoading),x=react.useMemo(()=>{let P=new Map;return y.forEach((m,b)=>{let S=f[b]?.error;S&&P.set(m,S);}),P},[y,f]),k=react.useMemo(()=>{let P=new Map;return y.forEach((m,b)=>{let S=f[b]?.data;S&&P.set(m,S);}),P},[y,f]);return {event:l,isEventLoading:i,eventError:u,series:d,isSeriesLoading:p,seriesError:g,periodInterval:n,candlesticks:k,isCandlesticksLoading:v,candlestickErrors:x}};var Ol=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Rn(e){let{status:t}=walletConnector.useAuth(),n=walletConnector.useWallets().find(u=>u.chainNamespace===types.ChainNamespace.SOLANA&&u.isConnected),s=t==="authenticated",a=n?.address,{data:o,isLoading:l}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:a??""},{enabled:s&&!!a,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let u=new Map;if(!o?.portfolios||e.length===0)return u;let c=new Map;for(let d of o.portfolios)c.set(d.address,parseFloat(d.amount));for(let d of e){let p=d.accounts[Ol];if(!p)continue;let g=c.get(p.yesMint)??0,y=c.get(p.noMint)??0;(g>0||y>0)&&u.set(d.ticker,{yesShares:g,noShares:y});}return u},[o,e]),isLoading:l}}function _l(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:a}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:a,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:a})]})}var yt=[{stroke:"hsl(var(--heroui-primary))",id:"colorMarket0"},{stroke:"hsl(var(--heroui-secondary))",id:"colorMarket1"},{stroke:"hsl(var(--heroui-success))",id:"colorMarket2"},{stroke:"hsl(var(--heroui-warning))",id:"colorMarket3"}];function On(e,t){let r=new Date(e*1e3);switch(t){case M.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case M.ONE_WEEK:case M.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case M.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function Fl(e,t,r){let n=it[r],s=new Map;e.forEach((i,u)=>{let c=new Map;(i.candlesticks??[]).forEach(p=>{let g=p.end_period_ts-p.end_period_ts%n;c.set(g,p.yes_ask.close);}),s.set(u,c);});let a=new Set;for(let i of s.values())for(let u of i.keys())a.add(u);let o=Array.from(a).sort((i,u)=>i-u),l=new Map;return o.map(i=>{let c={date:new Date(i*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:i};return t.forEach(d=>{let p=s.get(d)?.get(i);if(p!==void 0)c[d]=Math.round(p*100)/100,l.set(d,c[d]);else {let g=l.get(d);g!==void 0&&(c[d]=g);}}),c})}function Nn({candlesticks:e,markets:t=[],isLoading:r,chartRange:n=M.ALL,onDataChange:s}){let[a,o]=react.useState(null),l=react.useRef(s);react.useEffect(()=>{l.current=s;});let i=react.useMemo(()=>e?Array.from(e.keys()).slice(0,4):[],[e]),u=react.useMemo(()=>!e||e.size===0?[]:Fl(e,i,n),[e,i,n]),c=react.useMemo(()=>{if(u.length===0||i.length===0)return [0,100];let y=1/0,f=-1/0;if(u.forEach(m=>{i.forEach(b=>{let S=m[b];S!==void 0&&(y=Math.min(y,S),f=Math.max(f,S));});}),y===1/0||f===-1/0)return [0,100];let v=f-y,x=Math.max(v*.2,5),k=Math.max(0,Math.floor(y-x)),P=Math.min(100,Math.ceil(f+x));return [k,P]},[u,i]),d=react.useCallback(y=>{if(u.length===0)return null;let f=y!==null?u[y]:u[u.length-1];return f?{timestamp:f.timestamp,date:f.date,markets:i.map((v,x)=>{let k=t.find(P=>P.ticker===v);return {id:v,label:k?.yesSubTitle||`Market ${x+1}`,value:f[v]??0,color:yt[x%yt.length].stroke}})}:null},[u,i,t]);react.useEffect(()=>{l.current&&u.length>0&&l.current(d(null));},[u,d]),react.useEffect(()=>{l.current&&l.current(d(a));},[a,d]);let p=react.useCallback(y=>{typeof y?.activeTooltipIndex=="number"&&o(y.activeTooltipIndex);},[]),g=react.useCallback(()=>{o(null);},[]);return r?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"Loading chart..."})}):u.length===0?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"No price history data"})}):jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px]",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:u,margin:{top:10,right:16,left:16,bottom:0},onMouseMove:p,onMouseLeave:g,children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:y=>{let{x:f,y:v,payload:x,index:k}=y,P=u.length,b=Math.max(1,Math.ceil(P/6)),S=k===0,R=k===P-1,O=k%b===0;return !S&&!R&&!O?null:jsxRuntime.jsx("text",{x:f,y:v+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:On(x.value,n)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:c,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:y=>`${y}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{contentStyle:{backgroundColor:"hsl(var(--heroui-content1))",border:"1px solid hsl(var(--heroui-default-200))",borderRadius:"8px",fontSize:"12px"},labelFormatter:y=>On(y,n),formatter:(y,f)=>{let x=t.find(k=>k.ticker===f)?.yesSubTitle||f;return [`${y.toFixed(2)}%`,x]}}),i.map((y,f)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:y,stroke:yt[f%yt.length].stroke,strokeWidth:2,isAnimationActive:false,dot:v=>jsxRuntime.jsx(_l,{...v,dataLength:u.length},`dot-${y}-${v.index}`),activeDot:false},y))]})})})}function In(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function Bn({marketTicker:e,openTime:t,chartRange:r=ve}){let n=at[r],s=lt[r],a=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=react.useMemo(()=>s!=null?a-s:t??a,[a,s,t]),{data:l,isLoading:i,isFetching:u,error:c}=Bt({ticker:e,startTs:o,endTs:a,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:i,isFetching:u,error:c,periodInterval:n}}var Yl="hsl(var(--heroui-primary))",jl=[{value:M.ONE_DAY,label:"1D"},{value:M.ONE_WEEK,label:"1W"},{value:M.ONE_MONTH,label:"1M"},{value:M.ALL,label:"ALL"}];function Xl(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:a}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:a,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:a})]})}function Un(e,t){let r=new Date(e*1e3);switch(t){case M.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case M.ONE_WEEK:case M.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case M.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function Zl(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toFixed(0)}function Jl(e,t){let r=it[t],n=e.candlesticks??[],s=new Map;for(let o of n){let l=o.end_period_ts-o.end_period_ts%r,i=s.get(l);s.set(l,{close:o.yes_ask.close,volume:(i?.volume??0)+(o.volume??0)});}return Array.from(s.entries()).sort((o,l)=>o[0]-l[0]).map(([o,{close:l,volume:i}])=>({timestamp:o,date:new Date(o*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),value:Math.round(l*100)/100,volume:i}))}function An({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?Jl(e,r):[],[e,r]),a=react.useMemo(()=>{if(s.length===0)return [0,100];let o=1/0,l=-1/0;for(let p of s)p.value<o&&(o=p.value),p.value>l&&(l=p.value);if(o===1/0||l===-1/0)return [0,100];let i=l-o,u=Math.max(i*.2,5),c=Math.max(0,Math.floor(o-u)),d=Math.min(100,Math.ceil(l+u));return [c,d]},[s]);return t?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"Loading chart..."})}),jsxRuntime.jsx(Jt,{chartRange:r,onRangeChange:n})]}):s.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"No price history data"})}),jsxRuntime.jsx(Jt,{chartRange:r,onRangeChange:n})]}):jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:s,margin:{top:10,right:16,left:16,bottom:0},children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:o=>{let{x:l,y:i,payload:u,index:c}=o,d=s.length,g=Math.max(1,Math.ceil(d/6)),y=c===0,f=c===d-1,v=c%g===0;return !y&&!f&&!v?null:jsxRuntime.jsx("text",{x:l,y:i+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Un(u.value,r)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:a,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:o=>`${o}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:"hsl(var(--heroui-default-300))"},content:({active:o,payload:l})=>{if(!o||!l?.length)return null;let i=l[0].payload,u=Math.round(i.value);return jsxRuntime.jsxs("div",{className:"rounded-lg border border-default-200 bg-content1 px-3 py-2 shadow-md",children:[jsxRuntime.jsxs("div",{className:"text-lg font-semibold text-primary",children:["Yes ",u,"\xA2"]}),jsxRuntime.jsxs("div",{className:"text-sm text-neutral",children:["Vol ",Zl(i.volume)," \xB7"," ",Un(i.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:Yl,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Xl,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(Jt,{chartRange:r,onRangeChange:n})]})}function Jt({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:jl.map(r=>{let n=e===r.value;return jsxRuntime.jsx("button",{type:"button",className:`px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,onClick:()=>t?.(r.value),children:r.label},r.value)})})}function Wn({marketTicker:e}){let{data:t,isLoading:r,error:n}=Qe(e,{enabled:!!e});return {orderbook:react.useMemo(()=>{if(!t)return null;let{yesBids:a,yesAsks:o,noBids:l,noAsks:i}=t;return {yesBids:a,yesAsks:o,noBids:l,noAsks:i,bestYesBid:a.length>0?a[0].price:null,bestYesAsk:o.length>0?o[0].price:null,bestNoBid:l.length>0?l[0].price:null,bestNoAsk:i.length>0?i[0].price:null,sequence:t.sequence??null}},[t]),isOrderbookLoading:r,orderbookError:n}}function Dn(e,t){let r=e.slice(0,t),n=0;return r.map(s=>(n+=s.quantity,{...s,cumulative:n,depth:0,total:s.price*s.quantity}))}function _n(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function Hn(e){return `${Math.round(e*100)}\xA2`}function rc(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function nc(e){return e>=1e6?`$${(e/1e6).toFixed(2)}M`:e>=1e3?`$${(e/1e3).toFixed(2)}K`:e>=1?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function Fn({row:e,side:t,showType:r=false,onClick:n}){let{t:s}=i18n.useTranslation(),a=t==="ask",o=a?"bg-bullish/10":"bg-bearish/10",l=a?"text-bullish":"text-bearish";return jsxRuntime.jsxs("button",{type:"button",className:"relative grid w-full grid-cols-4 px-2 py-2.5 text-xs cursor-pointer hover:bg-default-100 transition-colors",onClick:()=>n?.(e.price,t),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 left-0 ${o} transition-[width] duration-200`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsx("span",{className:`relative z-10 font-mono font-medium ${l} text-left`,children:r?s(a?"predict.trade.bestAsk":"predict.trade.bestBid"):""}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Hn(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:rc(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:nc(e.total)})]})}function Vn({index:e}){let t=["60%","45%","75%","55%","65%","50%","70%","40%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function sc(){return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"})]}),Array.from({length:er}).map((e,t)=>jsxRuntime.jsx(Vn,{index:t},`ask-${t}`)),jsxRuntime.jsx("div",{className:"flex justify-center border-y border-default-200 px-2 py-2.5",children:jsxRuntime.jsx("div",{className:"h-4 w-24 animate-pulse rounded bg-default-100"})}),Array.from({length:er}).map((e,t)=>jsxRuntime.jsx(Vn,{index:t+3},`bid-${t}`))]})}var er=8;function tr({bids:e,asks:t,isLoading:r=false,maxLevels:n=er,onPriceClick:s}){let{t:a}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:i,spreadPercent:u}=react.useMemo(()=>{let d=Dn(e,n),p=Dn(t,n),g=Math.max(d[d.length-1]?.cumulative??0,p[p.length-1]?.cumulative??0);_n(d,g),_n(p,g);let y=d[0]?.price??null,f=p[0]?.price??null,v=null,x=null;if(y!=null&&f!=null){v=f-y;let k=(y+f)/2;k>0&&(x=Math.round(v/k*1e4)/100);}return {bidRows:d,askRows:p,spread:v,spreadPercent:x}},[e,t,n]);return r?jsxRuntime.jsx(sc,{}):o.length===0&&l.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:a("predict.orderBook.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.price")}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.contracts")}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:l.map((d,p)=>jsxRuntime.jsx(Fn,{row:d,side:"ask",showType:p===0,onClick:s},d.price))}),i!=null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 px-2 py-2.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[a("predict.orderBook.spread"),": ",Hn(i)]}),u!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",u,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((d,p)=>jsxRuntime.jsx(Fn,{row:d,side:"bid",showType:p===0,onClick:s},d.price))})]})}function ic(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(2)}K`:e.toLocaleString(void 0,{maximumFractionDigits:2})}function lc(e){let t=Math.abs(e),r=e>=0?"+":"-";return t>=1e3?`${r}$${(t/1e3).toFixed(1)}K`:t>=1?`${r}$${t.toFixed(2)}`:`${r}$${t.toFixed(4)}`}function Kn({positions:e,isLoading:t=false}){let{t:r}=i18n.useTranslation();return t?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})}):e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:r("predict.positions.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-5 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{children:r("predict.positions.outcome")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.qty")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.avgCost")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.currentPrice")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.pnl")})]}),e.map(n=>{let s=n.position==="YES",a=s?"text-bullish":"text-bearish",o=r(s?"predict.market.yes":"predict.market.no"),l=n.avgCost!=null?`${Math.round(n.avgCost*100)}\xA2`:"\u2014",i=n.currentPrice!=null?`${Math.round(n.currentPrice*100)}\xA2`:"\u2014",u=n.pnl!=null&&n.pnlPercent!=null,c=u&&n.pnl>0?"text-bullish":u&&n.pnl<0?"text-bearish":"text-foreground";return jsxRuntime.jsxs("div",{className:"grid grid-cols-5 px-2 py-2.5 text-xs hover:bg-default-100 transition-colors",children:[jsxRuntime.jsx("span",{className:`font-medium ${a}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:ic(n.balance)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:l}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:i}),jsxRuntime.jsx("span",{className:`text-right font-mono ${c}`,children:u?jsxRuntime.jsxs("span",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{children:lc(n.pnl)}),jsxRuntime.jsxs("span",{className:"text-[10px] opacity-70",children:[n.pnlPercent>=0?"+":"",n.pnlPercent.toFixed(1),"%"]})]}):"\u2014"})]},n.mint)})]})}function uc(e){let t=e/1e6;return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${(t/1e3).toFixed(2)}K`:t.toLocaleString(void 0,{maximumFractionDigits:2})}function dc(e){return e==null?"\u2014":`${Math.round(e*100)}\xA2`}function pc(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0");return `${r} ${n} ${s}:${a}`}function mc({index:e}){let t=["60%","45%","75%","55%","65%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function $n({trades:e,isLoading:t=false}){let{t:r}=i18n.useTranslation();return t?jsxRuntime.jsx("div",{className:"flex flex-col",children:Array.from({length:6}).map((n,s)=>jsxRuntime.jsx(mc,{index:s},s))}):e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:r("predict.tradeHistory.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{children:r("predict.tradeHistory.side")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.price")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.qty")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.time")})]}),e.map(n=>{let s=n.side==="yes",a=s?"text-bullish":"text-bearish",o=n.side?r(s?"predict.trade.yes":"predict.trade.no"):"\u2014";return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs hover:bg-default-100 transition-colors",children:[jsxRuntime.jsx("span",{className:`font-medium ${a}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:dc(n.usdPricePerContract)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:uc(n.outputAmount)}),jsxRuntime.jsx("span",{className:"text-right text-default-500",children:pc(n.createdAt)})]},n.id)})]})}function jn({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[a,o]=react.useState(ve),{orderbook:l,isOrderbookLoading:i}=Wn({marketTicker:e.ticker}),{candlesticks:u,isFetching:c}=Bn({marketTicker:e.ticker,openTime:e.openTime,chartRange:a}),{positions:d,isLoading:p}=Mr(e),{status:g}=walletConnector.useAuth(),v=walletConnector.useWallets().find(R=>R.chainNamespace===types.ChainNamespace.SOLANA&&R.isConnected)?.address,{data:x,isLoading:k}=hr({walletAddress:v??""},{enabled:(n==="trade-history"||n==="positions")&&g==="authenticated"&&!!v}),P=(x?.trades??[]).filter(R=>R.marketTicker===e.ticker),m=react.useMemo(()=>d.map(R=>{let O=P.filter(fe=>fe.outputMint===R.mint&&fe.usdPricePerContract!=null&&fe.contracts!=null&&fe.contracts>0),C=bc(O),Q=R.position==="YES"?Yn(R.market?.yesAsk):Yn(R.market?.noAsk),A=null,Te=null;return C!=null&&Q!=null&&(A=(Q-C)*R.balance,Te=C>0?(Q-C)/C*100:null),{...R,avgCost:C,currentPrice:Q,pnl:A,pnlPercent:Te}}),[d,P]),b=react.useCallback((R,O)=>{t?.(e,"yes",O==="ask"?"buy":"sell");},[e,t]),S=react.useCallback((R,O)=>{t?.(e,"no",O==="ask"?"buy":"sell");},[e,t]);return jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-3",children:[jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:R=>s(R),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeYes")},"trade-yes"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeNo")},"trade-no"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.graph")},"graph"),jsxRuntime.jsx(ui.Tab,{title:r("predict.positions.title")},"positions"),jsxRuntime.jsx(ui.Tab,{title:r("predict.tradeHistory.title")},"trade-history")]}),jsxRuntime.jsxs("div",{className:"min-h-[120px]",children:[n==="trade-yes"&&jsxRuntime.jsx(tr,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:i,onPriceClick:b}),n==="trade-no"&&jsxRuntime.jsx(tr,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:i,onPriceClick:S}),n==="graph"&&jsxRuntime.jsx(An,{candlesticks:u,isLoading:c,chartRange:a,onRangeChange:o}),n==="positions"&&jsxRuntime.jsx(Kn,{positions:m,isLoading:p}),n==="trade-history"&&jsxRuntime.jsx($n,{trades:P,isLoading:k})]})]})}function bc(e){if(e.length===0)return null;let t=0,r=0;for(let n of e)t+=n.contracts,r+=n.usdPricePerContract*n.contracts;return t>0?r/t:null}function Yn(e){if(e==null)return null;let t=Number(e);return Number.isFinite(t)?t:null}var nr=4;function Pc(e){let t=e.yesAsk?Math.round(parseFloat(e.yesAsk)*100):null,r=e.noAsk?Math.round(parseFloat(e.noAsk)*100):null;return {yesCents:t,noCents:r}}function ns({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[a,o]=react.useState(false),[l,i]=react.useState(null);if(e.length===0)return null;let u=e.length>nr,c=a?e:e.slice(0,nr),d=p=>{i(g=>g===p?null:p);};return jsxRuntime.jsxs("div",{className:"flex flex-col divide-y divide-default-200",children:[c.map(p=>{let{yesCents:g,noCents:y}=Pc(p),f=l===p.ticker;return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 transition-colors hover:bg-content2 lg:gap-x-4 cursor-pointer",onClick:()=>d(p.ticker),role:"button",tabIndex:0,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),d(p.ticker));},children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 min-w-0 flex-1",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium truncate lg:text-base",children:p.yesSubTitle}),(()=>{let v=n?.get(p.ticker);if(!v)return null;let{yesShares:x,noShares:k}=v;return x<=0&&k<=0?null:jsxRuntime.jsxs("div",{className:"flex items-center gap-x-1.5",children:[x>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"primary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesYes",{shares:x%1===0?x:x.toFixed(2)})}),k>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"secondary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesNo",{shares:k%1===0?k:k.toFixed(2)})})]})})()]}),(()=>{let v=g!=null,x=y!=null;return v&&!x&&g<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):x&&!v&&y<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!v&&!x?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"0%"}):jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center lg:text-xl",children:`${g}%`})})(),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 flex-1 justify-end",children:[jsxRuntime.jsx(ui.Button,{size:"sm",color:"primary",className:"w-20 bg-primary-100 text-primary",onPress:()=>r?.(p,"yes","buy"),children:g!=null?s("predict.market.action.yes",{price:g}):s("predict.market.yes")}),jsxRuntime.jsx(ui.Button,{size:"sm",color:"secondary",className:"w-20 bg-secondary-100 text-secondary",onPress:()=>r?.(p,"no","buy"),children:y!=null?s("predict.market.action.no",{price:y}):s("predict.market.no")})]}),f?jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4 shrink-0 text-default-400"}):jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-default-400"})]}),f&&t&&jsxRuntime.jsx("div",{className:"max-h-100 overflow-y-auto px-2 pb-3",children:t(p)})]},p.ticker)}),u&&jsxRuntime.jsx("button",{type:"button",onClick:()=>o(p=>!p),className:"flex items-center justify-center gap-x-1.5 px-2 py-2.5 text-sm text-default-500 transition-colors cursor-pointer hover:text-primary",children:a?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.rules.collapse")}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.moreMarkets",{count:e.length-nr})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var Ec=new Set(["closed","determined","finalized"]);function gt(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getFullYear(),a=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0");return `${r} ${n}, ${s} ${a}:${o}`}function wc({market:e}){let t=Ec.has(e.status),r=react.useMemo(()=>{let s={label:"Market Open",value:gt(e.openTime),isActive:true},a={label:"Market Closes",value:t?gt(e.closeTime):"After the outcome occurs",isActive:t},o={label:"Projected Payout",value:"30 minutes after closing",isActive:e.status==="finalized"};return [s,a,o]},[e.openTime,e.closeTime,e.status,t]),n=react.useMemo(()=>t?null:e.canCloseEarly&&e.earlyCloseCondition?`${e.earlyCloseCondition} Otherwise, it closes by ${gt(e.expirationTime)}.`:`This market closes by ${gt(e.expirationTime)}.`,[t,e.canCloseEarly,e.earlyCloseCondition,e.expirationTime]);return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[r.map((s,a)=>jsxRuntime.jsxs("div",{className:"flex items-stretch gap-x-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center w-3",children:[jsxRuntime.jsx("div",{className:`h-3 w-3 shrink-0 rounded-full border-2 mt-0.5 ${s.isActive?"border-primary bg-primary":"border-default-300 bg-transparent"}`}),a<r.length-1&&jsxRuntime.jsx("div",{className:"w-px flex-1 bg-default-200"})]}),jsxRuntime.jsxs("div",{className:`flex flex-col ${a<r.length-1?"pb-4":""}`,children:[jsxRuntime.jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:s.label}),jsxRuntime.jsx("span",{className:"text-xs text-default-500 lg:text-sm",children:s.value})]})]},s.label)),n&&jsxRuntime.jsx("p",{className:"text-xs text-default-500 mt-3 lg:text-sm",children:n})]})}function os({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.filter(i=>i.rulesPrimary);if(o.length===0)return null;let l=o.find(i=>i.ticker===s)??o[0];return l?.rulesPrimary?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium lg:text-base",children:n("predict.event.rules")}),o.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm","aria-label":"Select market rules",className:"max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:new Set([l.ticker]),onSelectionChange:i=>{if(i==="all")return;let u=Array.from(i);u.length>0&&a(u[0]);},children:o.map(i=>jsxRuntime.jsx(ui.SelectItem,{textValue:i.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:i.yesSubTitle})},i.ticker))}),jsxRuntime.jsx("div",{className:"text-xs text-foreground lg:text-sm",children:l.rulesPrimary}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-default-500 mt-2 lg:text-sm",children:"Timeline and payout"}),jsxRuntime.jsx(wc,{market:l}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 text-xxs text-default-400 mt-2 lg:text-xs",children:[r?.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Series:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:r.ticker})]}),t.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Event:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:t.ticker})]}),jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Market:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:l.ticker})]})]})]}):null}var Ac=[{value:M.ONE_DAY,label:"1D"},{value:M.ONE_WEEK,label:"1W"},{value:M.ONE_MONTH,label:"1M"},{value:M.ALL,label:"ALL"}];function is({event:e,series:t,candlesticks:r,chartRange:n=M.ONE_DAY,periodInterval:s,isCandlesticksLoading:a,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:i,onTradeAction:u}){let{t:c}=i18n.useTranslation(),[d,p]=react.useState(In()),[g,y]=react.useState(false),f=react.useRef(null);react.useEffect(()=>{let m=f.current;if(!m)return;let b=false,S=0,R=()=>{let{bottom:C}=m.getBoundingClientRect(),Q=b?C<0:C<-20;Q!==b&&(b=Q,y(Q));},O=()=>{cancelAnimationFrame(S),S=requestAnimationFrame(R);};return window.addEventListener("scroll",O,{passive:true,capture:true}),R(),()=>{cancelAnimationFrame(S),window.removeEventListener("scroll",O,{capture:true});}},[]);let v=react.useMemo(()=>[...e.markets||[]].sort((m,b)=>Number(b.yesAsk??0)-Number(m.yesAsk??0)),[e.markets]),{holdings:x}=Rn(v),k=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),P=react.useMemo(()=>{if(!e.strikeDate)return null;let m=new Date(e.strikeDate*1e3),b=m.toLocaleString("default",{month:"short"}),S=m.getDate(),R=m.getFullYear();return `${b} ${S}, ${R}`},[e.strikeDate]);return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 pb-8 lg:px-4 lg:pb-12 lg:max-w-3xl",children:[jsxRuntime.jsx("div",{ref:f,className:"h-0 w-0"}),jsxRuntime.jsxs("div",{className:`sticky top-0 z-30 flex items-center bg-background/80 backdrop-blur-md transition-all duration-300 ${g?"gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"gap-x-2 lg:gap-x-4"}`,children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"lg",className:`flex-shrink-0 transition-all duration-300 ${g?"!h-8 !w-8 lg:!h-10 lg:!w-10":"!h-14 !w-14 lg:!h-18 lg:!w-18"}`}),jsxRuntime.jsxs("div",{className:"flex flex-col min-w-0",children:[!g&&(t?.category||t?.tags&&t.tags.length>0)&&jsxRuntime.jsxs("span",{className:"text-xs text-default-500 lg:text-sm truncate",children:[t.category,t.category&&t.tags?.length>0&&" \xB7 ",t.tags?.join(", ")]}),jsxRuntime.jsx("span",{className:`font-semibold truncate transition-all duration-300 ${g?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-4",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[d&&d.markets.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-xs lg:text-sm",children:d.markets.map(m=>jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("div",{className:"h-3 w-3 shrink-0 rounded-full",style:{backgroundColor:m.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:m.label})]},m.id))}),jsxRuntime.jsx(Nn,{candlesticks:r,chartRange:n,markets:v,isLoading:a,onDataChange:m=>p(m)}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-2 mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 text-xs text-default-500 lg:text-sm",children:[jsxRuntime.jsxs("span",{children:[k," ",c("predict.event.volume")]}),P&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"text-default-300",children:"\xB7"}),jsxRuntime.jsx("span",{children:c("predict.event.endDate",{date:P})})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-x-1",children:Ac.map(m=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(m.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===m.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:m.label},m.value))}),v.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm",selectionMode:"multiple",placeholder:"Markets","aria-label":"Select markets",className:"min-w-28 max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:l?new Set(l):void 0,onSelectionChange:m=>{if(m==="all")return;let b=Array.from(m);b.length<=4&&i?.(b);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:v.map(m=>jsxRuntime.jsx(ui.SelectItem,{textValue:m.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:m.yesSubTitle})},m.ticker))})})]})]})}),jsxRuntime.jsx(ns,{markets:v,onTradeAction:u,marketHoldings:x,renderMarketDetail:m=>jsxRuntime.jsx(jn,{market:m,onTradeAction:u})}),jsxRuntime.jsx(os,{markets:v,event:e,series:t})]})}function ar({eventId:e,initialMarketTickers:t,initialChartRange:r=ve,onTradeAction:n}){let[s,a]=react.useState(r),[o,l]=react.useState(t),{event:i,isEventLoading:u,eventError:c,series:d,isSeriesLoading:p,periodInterval:g,candlesticks:y,isCandlesticksLoading:f,candlestickErrors:v}=wn({eventId:e,candlestickMarketTickers:o,chartRange:s}),x=react.useRef(!!t);react.useEffect(()=>{if(i?.markets&&!x.current){x.current=true;let m=[...i.markets].sort((b,S)=>Number(S.yesAsk??0)-Number(b.yesAsk??0)).slice(0,4).map(b=>b.ticker);l(m);}},[i?.markets]);let k=react.useMemo(()=>m=>{a(m);},[]),P=react.useMemo(()=>m=>{l(m);},[]);return u||p?jsxRuntime.jsx(qe,{}):c||!i?jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:c?.message||"Event not found"}):jsxRuntime.jsx(is,{event:i,series:d,candlesticks:y,chartRange:s,periodInterval:g,isCandlesticksLoading:f,candlestickErrors:v,onRangeChange:k,selectedMarketTickers:o,onMarketSelectionChange:P,onTradeAction:n})}function jv({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:a,onOpen:o,onClose:l}=ui.useDisclosure(),{data:i,isLoading:u}=tt({id:e,withNestedMarkets:true}),c=react.useMemo(()=>[...i?.markets||[]].sort((v,x)=>Number(x.yesAsk??0)-Number(v.yesAsk??0)),[i?.markets]),[d,p]=react.useState(null),g=react.useCallback((v,x,k)=>{p(P=>({market:v,outcome:x,side:k,version:(P?.version??0)+1})),s&&o();},[s,o]),y=d?.market??c[0];if(u)return s?jsxRuntime.jsx(qe,{}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(qe,{})}),jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4",children:jsxRuntime.jsx(En,{})})})]});let f=d?`${d.market.ticker}-${d.version}`:y?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(ar,{eventId:e,onTradeAction:g,...r})}),y&&jsxRuntime.jsx("div",{className:"fixed inset-x-0 bottom-0 z-40 flex justify-center p-3 bg-gradient-to-t from-background via-background/90 to-transparent",children:jsxRuntime.jsx(ui.Button,{color:"primary",size:"lg",className:"w-full max-w-md font-semibold",onPress:o,children:n("predict.trade.action")})}),jsxRuntime.jsx(ui.Drawer,{isOpen:a,onClose:l,placement:"bottom",size:"lg",hideCloseButton:true,classNames:{base:"max-h-[85dvh] rounded-t-2xl",body:"p-0"},children:jsxRuntime.jsx(ui.DrawerContent,{children:jsxRuntime.jsx(ui.DrawerBody,{children:y&&jsxRuntime.jsx(Gt,{event:i,market:y,initialSide:d?.side,initialOutcome:d?.outcome,chain:t},f)})})})]}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(ar,{eventId:e,onTradeAction:g,...r})}),y&&jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4 flex flex-col gap-y-4",children:jsxRuntime.jsx(Gt,{event:i,market:y,initialSide:d?.side,initialOutcome:d?.outcome,chain:t},f)})})]})}function us(e,t){if(!e)return [];let r=e.slice(0,t),n=0,s=r.map(o=>(n+=o.quantity,{...o,cumulative:n,depth:0})),a=s[s.length-1]?.cumulative??1;for(let o of s)o.depth=o.cumulative/a;return s}function ds({marketTicker:e,maxLevels:t=10,refetchInterval:r=5e3,outcome:n="yes"}){let{data:s,isLoading:a,isFetching:o}=Qe(e,{refetchInterval:r||void 0}),l=react.useMemo(()=>n==="yes"?s?.yesBids:s?.noBids,[s,n]),i=react.useMemo(()=>n==="yes"?s?.yesAsks:s?.noAsks,[s,n]),u=react.useMemo(()=>us(l,t),[l,t]),c=react.useMemo(()=>us(i,t),[i,t]),d=react.useMemo(()=>u.length===0||c.length===0?null:c[0].price-u[0].price,[u,c]),p=react.useMemo(()=>u.length===0||c.length===0?null:(u[0].price+c[0].price)/2,[u,c]),g=react.useMemo(()=>d===null||p===null||p===0?null:Math.round(d/p*1e4)/100,[d,p]);return {bids:u,asks:c,spread:d,spreadPercent:g,midpoint:p,isLoading:a,isFetching:o}}function ps({row:e,side:t,onClick:r}){let n=t==="bid",s=n?"bg-primary/10":"bg-danger/10",a=n?"text-primary":"text-danger";return jsxRuntime.jsxs("button",{type:"button",className:"relative flex w-full items-center justify-between px-3 py-1 text-xs hover:bg-default-100 cursor-pointer",onClick:()=>r?.(e.price),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 ${n?"right-0":"left-0"} ${s}`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsxs("span",{className:`relative z-10 font-medium ${a}`,children:[e.price,"\xA2"]}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-600",children:e.quantity}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-400",children:e.cumulative})]})}function ms(){return jsxRuntime.jsx("div",{className:"flex flex-col gap-y-1 py-2",children:Array.from({length:5}).map((e,t)=>jsxRuntime.jsx("div",{className:"mx-3 h-4 animate-pulse rounded bg-default-100"},t))})}function ys({bids:e,asks:t,spread:r,spreadPercent:n,isLoading:s,onPriceClick:a}){let{t:o}=i18n.useTranslation();if(s)return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:o("predict.orderBook.title")}),jsxRuntime.jsx(ms,{}),jsxRuntime.jsx(ms,{})]});let l=e.length===0&&t.length===0;return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsx("span",{className:"text-sm font-medium",children:o("predict.orderBook.title")})}),l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:o("predict.orderBook.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-1 text-xxs text-default-400",children:[jsxRuntime.jsx("span",{children:o("predict.orderBook.price")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.qty")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:t.map(i=>jsxRuntime.jsx(ps,{row:i,side:"ask",onClick:a},i.price))}),r!==null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 py-1.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[o("predict.orderBook.spread"),": ",r,"\xA2"]}),n!==null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",n,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:e.map(i=>jsxRuntime.jsx(ps,{row:i,side:"bid",onClick:a},i.price))})]})]})}function vh({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:a,asks:o,spread:l,spreadPercent:i,isLoading:u}=ds({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(ys,{bids:a,asks:o,spread:l,spreadPercent:i,isLoading:u,onPriceClick:n})}function gs(e={}){let[t,r]=react.useState(null),[n]=react.useState(null),s=react.useCallback(a=>{r(null);},[]);return {orders:[],isLoading:false,isFetching:false,cancellingOrderId:t,cancelOrder:s,cancelError:n}}function cu(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function xs({orders:e,isLoading:t,cancellingOrderId:r,onCancel:n}){let{t:s}=i18n.useTranslation(),a=react.useMemo(()=>e.map(o=>({key:o.id,side:o.side,outcome:o.outcome,type:o.type,price:o.price,filled:`${o.filledQuantity}/${o.quantity}`,status:o.status,createdAt:cu(o.createdAt),isCancelling:o.id===r,id:o.id})),[e,r]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.openOrders.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsxs("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:[s("predict.openOrders.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.openOrders.empty")}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Open orders",className:"min-w-[600px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:s("predict.openOrders.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.openOrders.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Type",width:60,children:s("predict.openOrders.type")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.openOrders.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Filled",width:80,children:s("predict.openOrders.filled")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Status",width:70,children:s("predict.openOrders.status")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:s("predict.openOrders.time")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Action",width:80,align:"end",children:" "})]}),jsxRuntime.jsx(ui.TableBody,{children:a.map(o=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.side==="buy"?"text-primary":"text-danger"}`,children:o.side==="buy"?s("predict.trade.buy"):s("predict.trade.sell")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.type})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.filled})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.status})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:o.createdAt})}),jsxRuntime.jsx(ui.TableCell,{className:"text-right",children:jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",color:"danger",isLoading:o.isCancelling,onPress:()=>n(o.id),children:s("predict.openOrders.cancel")})})]},o.key))})]})})]})}function Bh({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=gs({});return jsxRuntime.jsx(xs,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function hs({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,a]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:i,isLoading:u,isFetching:c}=vr(l),d=i,p=d?.trades??[],g=!!d?.cursor,y=r>1,f=react.useCallback(k=>{k>=1&&k<=s.length&&n(k);},[s.length]),v=react.useCallback(()=>{g&&d?.cursor&&(a(k=>{let P=[...k];return P.length===r&&P.push(d.cursor),P}),n(k=>k+1));},[g,d?.cursor,r]),x=react.useCallback(()=>{y&&n(k=>k-1);},[y]);return {trades:p,isLoading:u,isFetching:c,page:r,pageSize:t,hasNextPage:g,hasPrevPage:y,goToPage:f,nextPage:v,prevPage:x}}function bu(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ks({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:a,onNextPage:o,onPrevPage:l}){let{t:i}=i18n.useTranslation(),u=react.useMemo(()=>e.map(c=>({key:c.tradeId,ticker:c.ticker,takerSide:c.takerSide,price:c.price,yesPrice:c.yesPrice,noPrice:c.noPrice,count:c.count,createdAt:bu(c.createdTime)})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:i("predict.tradeHistory.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((c,d)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},d))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:i("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:i("predict.tradeHistory.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:`w-full overflow-x-auto ${r?"opacity-60":""}`,children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Trade history",className:"min-w-[480px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:i("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:i("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:i("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:i("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:i("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:i("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:u.map(c=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${c.takerSide==="yes"?"text-primary":"text-secondary"}`,children:c.takerSide==="yes"?i("predict.trade.yes"):i("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[c.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-primary",children:[c.yesPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-secondary",children:[c.noPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:c.count})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:c.createdAt})})]},c.key))})]})}),(a||s)&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2",children:[jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!a,onPress:l,startContent:jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3"}),children:i("predict.pagination.prev")}),jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:i("predict.pagination.page",{page:n})}),jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!s,onPress:o,endContent:jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3"}),children:i("predict.pagination.next")})]})]})]})}function Zh({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:a,hasNextPage:o,hasPrevPage:l,nextPage:i,prevPage:u}=hs({ticker:e,pageSize:t});return jsxRuntime.jsx(ks,{trades:r,isLoading:n,isFetching:s,page:a,hasNextPage:o,hasPrevPage:l,onNextPage:i,onPrevPage:u})}function Ps(e={}){let t=react.useMemo(()=>({totalValue:0,totalUnrealizedPnl:0,totalRealizedPnl:0,count:0}),[]);return {positions:[],isLoading:false,isFetching:false,summary:t}}var xt=e=>utils.formatAmountUSDCompact(e/100);function cr({value:e}){if(e===0)return jsxRuntime.jsx("span",{className:"text-default-500",children:xt(0)});let t=e>0;return jsxRuntime.jsxs("span",{className:t?"text-success":"text-danger",children:[t?"+":"",xt(e)]})}function Cs({positions:e,isLoading:t,summary:r,onSell:n}){let{t:s}=i18n.useTranslation(),a=react.useMemo(()=>e.map(o=>({key:`${o.marketId}-${o.outcome}`,marketTitle:o.marketTitle,outcome:o.outcome,quantity:o.quantity,avgCost:o.avgCostBasis,currentPrice:o.currentPrice,value:o.currentPrice*o.quantity,unrealizedPnl:o.unrealizedPnl,position:o})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.positions.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[s("predict.positions.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]})}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.positions.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Positions",className:"min-w-[640px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Market",width:200,children:s("predict.positions.market")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.positions.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:50,children:s("predict.positions.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Avg Cost",width:70,children:s("predict.positions.avgCost")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.positions.currentPrice")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Value",width:80,children:s("predict.positions.value")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"PnL",width:80,children:s("predict.positions.pnl")})]}),jsxRuntime.jsx(ui.TableBody,{children:a.map(o=>jsxRuntime.jsxs(ui.TableRow,{className:n?"cursor-pointer hover:bg-default-50":"",onClick:()=>n?.(o.position),children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs font-medium line-clamp-1",children:o.marketTitle})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.quantity})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.avgCost,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.currentPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:xt(o.value)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:jsxRuntime.jsx(cr,{value:o.unrealizedPnl})})})]},o.key))})]})}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2 text-xs",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-x-4",children:jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.totalValue"),":"," ",jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:xt(r.totalValue)})]})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-4",children:[jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.unrealizedPnl"),":"," ",jsxRuntime.jsx(cr,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(cr,{value:r.totalRealizedPnl})]})]})]})]})]})}function fb({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=Ps({});return jsxRuntime.jsx(Cs,{positions:r,isLoading:n,summary:s,onSell:t})}function Db({client:e,wsClient:t=null,children:r}){let n=react.useMemo(()=>({client:e,wsClient:t}),[e,t]);return jsxRuntime.jsx(Ie.Provider,{value:n,children:r})}var Uu=3e4;function Kb({walletAddress:e,pollingInterval:t=Uu,enabled:r=true,children:n}){let{data:s,isLoading:a,error:o,refetch:l}=Tr({walletAddress:e},{enabled:r&&!!e,refetchInterval:t}),i=react.useMemo(()=>({positions:s?.positions??[],usdcBalance:s?.usdcBalance??0,isLoading:a,error:o??null,refetch:l}),[s?.positions,s?.usdcBalance,a,o,l]);return jsxRuntime.jsx(ge.Provider,{value:i,children:n})}function jb({client:e,children:t}){let r=react.useMemo(()=>({client:e}),[e]);return jsxRuntime.jsx(et.Provider,{value:r,children:t})}function Ss(e,t){let r=new URLSearchParams;t&&r.set("provider",t);for(let[s,a]of Object.entries(e))a!=null&&(typeof a=="object"?r.set(s,JSON.stringify(a)):r.set(s,String(a)));let n=r.toString();return n?`?${n}`:""}function Ts(e){return e}var ze=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Ss(r??{},this.provider);return `${this.endpoint}${t}${n}`}async fetch(t,r){let n=this.buildUrl(t,r);return await utils.httpGet(n)}async postRequest(t,r,n){let s=this.buildUrl(t,n);return await utils.httpPost(s,r)}};function vt(e,t){if(!e)return [];let r=Object.entries(e).map(([n,s])=>({price:parseFloat(n),quantity:s}));return r.sort((n,s)=>t==="desc"?s.price-n.price:n.price-s.price),r}function Ms(e){return {yesBids:vt(e.yes_bids,"desc"),yesAsks:vt(e.yes_asks,"asc"),noBids:vt(e.no_bids,"desc"),noAsks:vt(e.no_asks,"asc"),sequence:e.sequence}}var ht=class extends ze{constructor(t){super(t,"dflow");}async getEvents(t){return await this.fetch("/v2/event",t??{})}async getEventById(t,r){return await this.fetch(`/v2/event/${t}`,{withNestedMarkets:r})}async getEventCandlesticks(t,r){return await this.fetch(`/v2/event/${t}/candlesticks`,r)}async getEventForecastPercentileHistory(t){let{seriesTicker:r,eventId:n,...s}=t;return await this.fetch(`/v2/event/${r}/${n}/forecast_percentile_history`,s)}async getEventForecastPercentileHistoryByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/event/by-mint/${r}/forecast_percentile_history`,n)}async getMarkets(t){return await this.fetch("/v2/market",t??{})}async getMarketById(t){return await this.fetch(`/v2/market/${t}`)}async getMarketByMint(t){return await this.fetch(`/v2/market/by-mint/${t}`)}async getMarketsBatch(t){return await this.postRequest("/v2/market/batch",t)}async getMarketCandlesticks(t,r){return await this.fetch(`/v2/market/${t}/candlesticks`,r)}async getMarketCandlesticksByMint(t,r){return await this.fetch(`/v2/market/by-mint/${t}/candlesticks`,r)}async getOrderbook(t){let r=await this.fetch(`/v2/orderbook/${t}`);return Ms(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return Ms(r)}async getTrades(t){return await this.fetch("/v2/trades",t??{})}async getTradesByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/trades/by-mint/${r}`,n)}async getOnchainTradesByWallet(t){let{walletAddress:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-wallet/${r}`,n)}async getOnchainTradesByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-event/${r}`,n)}async getOnchainTradesByMarket(t){let{marketTicker:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-market/${r}`,n)}async getLiveData(t){return await this.fetch("/v2/live",{milestoneIds:t.milestoneIds.join(",")})}async getLiveDataByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/live/event/${r}`,n)}async getLiveDataByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/live/by-mint/${r}`,n)}async getSeries(t){return await this.fetch("/v2/series",t??{})}async getSeriesByTicker(t){return await this.fetch(`/v2/series/${t}`)}async getTagsByCategories(){return await this.fetch("/v2/tags/by_categories")}async getFiltersBySports(){return await this.fetch("/v2/sports/filters")}async search(t){return await this.fetch("/v2/search",t)}async getPositionsByWallet(t){let{walletAddress:r}=t;return await this.fetch(`/v2/positions/by-wallet/${r}`)}async getOutcomeMints(t){return await this.fetch("/v2/outcome_mints",t??{})}async filterOutcomeMints(t){return await this.postRequest("/v2/filter_outcome_mints",t)}async getQuote(t){return await this.fetch("/v2/swap/quote",t)}async createSwap(t){return await this.postRequest("/v2/swap",t)}async createSwapInstructions(t){return await this.postRequest("/v2/swap/instructions",t)}async getOrder(t){return await this.fetch("/v2/order",t)}async getOrderStatus(t){try{return await this.fetch("/v2/order/status",t)}catch(r){if(r instanceof Error&&/\b404\b/.test(r.message))return {status:"pending",inAmount:"0",outAmount:"0"};throw r}}async getIntentQuote(t){return await this.fetch("/v2/intent/quote",t)}async submitIntentSwap(t){return await this.postRequest("/v2/intent/swap",t)}async initPredictionMarket(t){return await this.fetch("/v2/prediction-market/init",t)}async getTokens(){return await this.fetch("/v2/tokens")}async getTokensWithDecimals(){return await this.fetch("/v2/tokens/decimals")}async getVenues(){return await this.fetch("/v2/venues")}};function Vu(e){let t=new URLSearchParams;for(let[n,s]of Object.entries(e))s!=null&&t.set(n,String(s));let r=t.toString();return r?`?${r}`:""}var Ge=class{constructor(t){this.endpoint=t;}async listEvents(t){let r=Vu(t??{}),n=`${this.endpoint}/api/v1/events${r}`;return await utils.httpGet(n)}async getEvent(t){let r=`${this.endpoint}/api/v1/events/${encodeURIComponent(t)}`;return await utils.httpGet(r)}};function ws(e){return new Ge(e)}
|
|
2
|
+
exports.BasePredictClient=ze;exports.CATEGORIES_V2=Vt;exports.CHART_RANGE_DURATION=lt;exports.CHART_RANGE_PERIOD=at;exports.CHART_RANGE_SAMPLE_INTERVAL=it;exports.CandlestickPeriod=ot;exports.CategoriesSkeleton=Hr;exports.CategoriesUI=st;exports.CategoriesWidget=Gr;exports.CategoriesWidgetV2=ln;exports.ChartRange=M;exports.DEFAULT_CHART_RANGE=ve;exports.DEFAULT_PAGE_SIZE=te;exports.DEFAULT_PRICE_HISTORY_INTERVAL=rf;exports.DflowPredictClient=ht;exports.DflowPredictWsClient=De;exports.EventDetailPage=jv;exports.EventDetailSkeleton=qe;exports.EventDetailUI=is;exports.EventDetailWidget=ar;exports.EventItemSkeleton=Za;exports.EventItemUI=Zr;exports.EventItemV2UI=fn;exports.EventMarketDetailWidget=jn;exports.EventsPage=Df;exports.EventsPageV2=Cg;exports.EventsSkeleton=ct;exports.EventsUI=tn;exports.EventsV2UI=vn;exports.EventsWidget=nn;exports.EventsWidgetV2=bn;exports.MAX_PRICE_HISTORY_MARKETS=xe;exports.ORDER_MAX_PRICE=tf;exports.ORDER_MIN_PRICE=ef;exports.ORDER_MIN_QUANTITY=Wt;exports.ORDER_PRICE_STEP=Jy;exports.OpenOrdersUI=xs;exports.OpenOrdersWidget=Bh;exports.OrderBookUI=ys;exports.OrderBookWidget=vh;exports.PRICE_HISTORY_SAMPLE_INTERVAL=nf;exports.PositionsUI=Cs;exports.PositionsWidget=fb;exports.PredictClient=ht;exports.PredictClientV2=Ge;exports.PredictContext=Ie;exports.PredictProvider=Db;exports.PredictV2Context=et;exports.PredictV2Provider=jb;exports.PredictWsClient=De;exports.PriceHistoryInterval=Be;exports.TradeFormSkeleton=En;exports.TradeFormUI=Mn;exports.TradeFormWidget=Gt;exports.TradeHistoryUI=ks;exports.TradeHistoryWidget=Zh;exports.UserPredictContext=ge;exports.UserPredictProvider=Kb;exports.buildQuery=Ss;exports.createDflowPredictWsClient=rt;exports.createPredictClientV2=ws;exports.createPredictWsClient=rt;exports.createSwap=va;exports.createSwapInstructions=ha;exports.eventByIdQueryKey=so;exports.eventCandlesticksQueryKey=Qo;exports.eventV2QueryKey=Gs;exports.eventsInfiniteQueryKey=ro;exports.eventsQueryKey=eo;exports.eventsV2QueryKey=Ks;exports.fetchEventById=oo;exports.fetchEventCandlesticks=Bo;exports.fetchEventV2=Ys;exports.fetchEvents=St;exports.fetchEventsV2=$s;exports.fetchFiltersBySports=ea;exports.fetchForecastPercentileHistory=Wo;exports.fetchForecastPercentileHistoryByMint=_o;exports.fetchIntentQuote=Ea;exports.fetchLiveData=Vo;exports.fetchLiveDataByEvent=Ho;exports.fetchLiveDataByMint=$o;exports.fetchMarketById=po;exports.fetchMarketByMint=fo;exports.fetchMarketCandlesticks=Qt;exports.fetchMarketCandlesticksByMint=Uo;exports.fetchMarkets=lo;exports.fetchMarketsBatch=vo;exports.fetchOnchainTradesByEvent=Et;exports.fetchOnchainTradesByMarket=wt;exports.fetchOnchainTradesByWallet=Mt;exports.fetchOrder=ka;exports.fetchOrderBook=bo;exports.fetchOrderBookByMint=Po;exports.fetchOrderStatus=Ca;exports.fetchOutcomeMints=ma;exports.fetchPositionsByWallet=aa;exports.fetchQuote=xa;exports.fetchSearch=na;exports.fetchSeries=Go;exports.fetchSeriesByTicker=jo;exports.fetchTagsByCategories=Zo;exports.fetchTokens=Ia;exports.fetchTokensWithDecimals=Ba;exports.fetchTrades=So;exports.fetchTradesByMint=Mo;exports.fetchVenues=Aa;exports.filterOutcomeMints=ya;exports.filtersBySportsQueryKey=Jo;exports.forecastPercentileHistoryByMintQueryKey=Do;exports.forecastPercentileHistoryQueryKey=Ao;exports.initPredictionMarket=Oa;exports.intentQuoteQueryKey=Ma;exports.liveDataByEventQueryKey=qo;exports.liveDataByMintQueryKey=Ko;exports.liveDataQueryKey=Fo;exports.marketByIdQueryKey=uo;exports.marketByMintQueryKey=yo;exports.marketCandlesticksByMintQueryKey=Lo;exports.marketCandlesticksQueryKey=It;exports.marketsBatchQueryKey=xo;exports.marketsQueryKey=io;exports.onchainTradesByEventInfiniteQueryKey=No;exports.onchainTradesByEventQueryKey=wo;exports.onchainTradesByMarketInfiniteQueryKey=Io;exports.onchainTradesByMarketQueryKey=Ro;exports.onchainTradesByWalletInfiniteQueryKey=Oo;exports.onchainTradesByWalletQueryKey=Eo;exports.orderBookByMintQueryKey=ko;exports.orderBookQueryKey=ho;exports.orderQueryKey=ba;exports.orderStatusQueryKey=Pa;exports.outcomeMintsQueryKey=pa;exports.positionsByWalletQueryKey=oa;exports.quoteQueryKey=ga;exports.searchQueryKey=ra;exports.seriesByTickerQueryKey=Yo;exports.seriesQueryKey=zo;exports.submitIntentSwap=wa;exports.tagsByCategoriesQueryKey=Xo;exports.toRecord=Ts;exports.tokensQueryKey=Na;exports.tokensWithDecimalsQueryKey=Qa;exports.tradesByMintQueryKey=To;exports.tradesQueryKey=Co;exports.useCategoriesQuery=Fp;exports.useCreateSwapInstructionsMutation=fm;exports.useCreateSwapMutation=ym;exports.useEventByIdQuery=tt;exports.useEventCandlesticksQuery=bp;exports.useEventDetail=wn;exports.useEventV2Query=od;exports.useEvents=Yr;exports.useEventsCategories=Fr;exports.useEventsInfiniteQuery=fr;exports.useEventsQuery=Ed;exports.useEventsV2=dn;exports.useEventsV2Query=td;exports.useFilterOutcomeMintsMutation=am;exports.useFiltersBySportsQuery=_p;exports.useForecastPercentileHistoryByMintQuery=Ep;exports.useForecastPercentileHistoryQuery=Mp;exports.useInitPredictionMarketMutation=Em;exports.useIntentQuoteQuery=Pm;exports.useLiveDataByEventQuery=Ip;exports.useLiveDataByMintQuery=Qp;exports.useLiveDataQuery=Np;exports.useMarketByIdQuery=Vd;exports.useMarketByMintQuery=$d;exports.useMarketCandlesticksByMintQuery=kp;exports.useMarketCandlesticksQuery=Bt;exports.useMarketPositions=Mr;exports.useMarketsBatchQuery=jd;exports.useMarketsQuery=Wd;exports.useOnchainTradesByEventInfiniteQuery=fp;exports.useOnchainTradesByEventQuery=lp;exports.useOnchainTradesByMarketInfiniteQuery=gp;exports.useOnchainTradesByMarketQuery=cp;exports.useOnchainTradesByWalletInfiniteQuery=yp;exports.useOnchainTradesByWalletQuery=hr;exports.useOpenOrders=gs;exports.useOrderBook=ds;exports.useOrderBookByMintQuery=ep;exports.useOrderBookQuery=Qe;exports.useOrderQuery=Rr;exports.useOrderStatusQuery=Or;exports.useOrderbookSubscription=ty;exports.useOutcomeMintsQuery=om;exports.usePositions=Ps;exports.usePositionsByWalletQuery=Tr;exports.usePredictClient=h;exports.usePredictContext=yr;exports.usePredictV2Client=Ne;exports.usePredictV2Context=mr;exports.usePriceHistoryQuery=Pp;exports.usePricesSubscription=Ym;exports.useQuoteQuery=um;exports.useSearchQuery=Kp;exports.useSeriesByTickerQuery=Cr;exports.useSeriesQuery=Pr;exports.useSubmitIntentSwapMutation=Cm;exports.useTagsByCategoriesQuery=Ut;exports.useTokensQuery=Nm;exports.useTokensWithDecimalsQuery=Im;exports.useTradeForm=Pn;exports.useTradeHistory=hs;exports.useTradesByMintQuery=sp;exports.useTradesQuery=vr;exports.useTradesSubscription=Zm;exports.useUserPredictContext=Zp;exports.useVenuesQuery=Um;exports.useWsClient=$m;exports.useWsConnection=Vm;exports.venuesQueryKey=Ua;exports.version=Fs;//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|