@liberfi.io/ui-predict 0.1.122 → 0.1.123
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {createContext,memo,useRef,forwardRef,useState,useImperativeHandle,useMemo,useEffect,useCallback,useContext,Fragment as Fragment$1,startTransition,Component}from'react';import {ChartRange,useInfiniteMatchMarkets,useBalance,useDFlowKYC,usePolymarketSetup,usePredictClient,PolymarketContext,useTickSize,usePositions,useDFlowQuote,useDFlowSubmit,useOrder,buildCtfExchangeDomain,buildOrderMessage,CTF_ORDER_TYPES,buildSignedOrder,buildClobPayload,buildPolymarketL2Headers,resolveEventsParams,useInfiniteEvents,useEventStats,useInfiniteOrders,useCancelOrder,useInfiniteTrades,useOrderbook,useMarketHistory,useEvent,useSimilarEvents,candlesticksQueryKey,useSearchEvents}from'@liberfi.io/react-predict';export{PredictClient,PredictContext,PredictProvider,PredictWsClient,createPredictClient,createPredictWsClient,eventStatsQueryKey,fetchMatchMarketsPage,fetchMatchesPage,matchMarketsQueryKey,matchQueryKey,matchesQueryKey,useBalance,useCancelOrder,useCandlesticks,useDFlowKYC,useDFlowQuote,useDFlowSubmit,useEvent,useEventStats,useEvents,useInfiniteEvents,useInfiniteMatchMarkets,useInfiniteMatches,useInfiniteOrders,useInfiniteTrades,useMarket,useMarketHistory,useMarketTrades,useMatch,useOrder,useOrderbook,useOrders,usePositions,usePredictClient,usePriceHistory,useSearchEvents,useSimilarEvents,useTrades}from'@liberfi.io/react-predict';import {PolymarketIcon,KalshiIcon,cn as cn$1,Skeleton,toast,StyledModal,ModalContent,useDisclosure,Tabs,Tab,StyledNumberInput,StyledInput,StyledSwitch,Select,SelectItem,ChevronDownIcon,Button,Spinner,useScreen,TimerIcon,DropletIcon,ChartLineIcon,CalendarIcon,Linkable,Avatar,ChevronUpIcon,OrderbookTableIcon,OrderbookDepthIcon,Dropdown,DropdownTrigger,DropdownMenu,DropdownItem,ChevronRightIcon,ChevronLeftIcon,TrashIcon,Chip,XCloseIcon,Kbd,SearchIcon,EmptyIcon,ModalHeader,ModalBody}from'@liberfi.io/ui';import {AsyncModal,useAsyncModal}from'@liberfi.io/ui-scaffold';import {useTranslation}from'@liberfi.io/i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useWallets,useAuth,useSwitchChain,useAuthCallback}from'@liberfi.io/wallet-connector';import {keepPreviousData,useQueryClient,useQueries}from'@tanstack/react-query';import rn from'canvas-confetti';import {ChainNamespace,Chain}from'@liberfi.io/types';import {SOLANA_TOKENS,debounce}from'@liberfi.io/utils';import {List}from'react-window';import {useInfiniteLoader}from'react-window-infinite-loader';import {useScrollCollapse,useResizeObserver,useCallbackRef}from'@liberfi.io/hooks';import {ResponsiveContainer,LineChart,CartesianGrid,XAxis,YAxis,Tooltip,Line,ReferenceDot}from'recharts';import {useAtom}from'jotai';import {atomWithStorage}from'jotai/utils';typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.122");var Na="0.1.122";var Ca={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:["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},lo=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],Zr=(()=>{let e=t=>{let r=lo.indexOf(t);return r===-1?lo.length:r};return Object.entries(Ca).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 uo({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:o,onTagSelect:i,trailing:s,pulsingTab:l="Trending",className:a}){let{t:d}=useTranslation(),p=useCallback(()=>{o(null);},[o]),u=d("predict.categories.trending");return jsxs("div",{className:cn$1("sticky top-0 z-30 flex w-full flex-col justify-between gap-2 px-4 py-2.5 lg:px-4 lg:py-2",a),children:[jsxs("div",{className:"flex w-full items-center gap-2",children:[jsx("div",{className:"hideScrollbar min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:jsxs("div",{className:"flex min-h-9 items-stretch gap-x-3 lg:min-h-10",children:[jsx(co,{label:u,isSelected:t===null,onPress:p,showPulse:u===l}),jsx(La,{}),e.map(m=>jsx(co,{label:m.category,isSelected:t===m.category,onPress:()=>o(m.category),badge:m.badge,showPulse:m.category===l},m.category))]})}),s&&jsx("div",{className:"flex-shrink-0",children:s})]}),t&&n.length>0&&jsx("div",{className:"hideScrollbar overflow-x-auto overflow-y-hidden flex items-center",children:jsxs("div",{className:"flex gap-x-1.5 pl-1 lg:w-full lg:gap-x-2",children:[jsx(po,{label:d("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null)}),n.map(m=>jsx(po,{label:m.label,icon:m.icon,isSelected:r===m.label,onPress:()=>i(m.label)},m.label))]})})]})}function co({label:e,isSelected:t,onPress:r,badge:n,showPulse:o}){return jsxs("button",{type:"button",onClick:r,className:cn$1("relative shrink-0 cursor-pointer whitespace-nowrap border-b px-2.5 py-1.5 text-sm font-medium capitalize transition-colors",t?"border-primary/50 text-primary":"border-transparent text-neutral-500 hover:text-neutral-300"),children:[o?jsxs("span",{className:"flex items-center gap-x-1.5",children:[jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-[rgb(240,68,56)]"}),jsx("span",{children:e})]}):e,n&&jsx("span",{className:"absolute -right-1 top-0 rounded bg-primary px-0.5 py-px text-[0.625rem] font-semibold leading-none text-neutral-950",children:n})]})}function La(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function po({label:e,icon:t,isSelected:r,onPress:n}){return jsxs("button",{type:"button",onClick:n,className:cn$1("flex shrink-0 items-center justify-center gap-x-1 min-w-14 rounded-2xl border px-3 py-1.5 text-sm font-medium uppercase transition-colors cursor-pointer",r?"border-primary/40 bg-primary/15 text-primary":"border-border/80 text-neutral-500 hover:bg-primary/10 hover:text-primary"),children:[t&&jsx("span",{className:cn$1("iconify size-4",t)}),e]})}function _f({count:e=6}){return jsx("div",{className:"flex w-full flex-col gap-2 px-4 py-2.5 lg:px-4 lg:py-2",children:jsx("div",{className:"flex min-h-9 items-center gap-x-3 lg:min-h-10",children:Array.from({length:e}).map((t,r)=>jsx(Skeleton,{className:"h-6 w-16 shrink-0 rounded"},r))})})}function _a(e){return e.map(t=>({category:t.label,tags:t.tags.map(r=>r.label)}))}function Ra(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function go({onSelect:e,trailing:t,className:r}){let[n,o]=useState(null),[i,s]=useState(null),l=useCallback(m=>{o(m),s(null),e?.({categorySlug:m,tagSlug:null});},[e]),a=useCallback(m=>{s(m),e?.({categorySlug:n,tagSlug:m});},[n,e]),d=_a(Zr),p=Zr.find(m=>m.slug===n),u=Ra(p);return jsx(uo,{categories:d,selectedCategory:n,selectedTag:i,activeTags:u,onCategorySelect:l,onTagSelect:a,trailing:t,className:r})}function ho(e){return {title:e.title,imageUrl:e.image_url}}function vo(e){let t=e.outcomes[0],r=e.outcomes[1];return {question:e.question,yesAsk:t?.best_ask??t?.price,noAsk:r?.best_ask??r?.price,yesBid:t?.best_bid,noBid:r?.best_bid,yesSubTitle:t?.label??"Yes",noSubTitle:r?.label??"No"}}var Ut=48,Jr=4,gr={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},Ee={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},hr=Ee.ALL,zf={[Ee.ONE_DAY]:gr.ONE_MINUTE,[Ee.ONE_WEEK]:gr.ONE_HOUR,[Ee.ONE_MONTH]:gr.ONE_HOUR,[Ee.ALL]:gr.ONE_DAY},$f={[Ee.ONE_DAY]:300,[Ee.ONE_WEEK]:3600,[Ee.ONE_MONTH]:10800,[Ee.ALL]:1440*60},Wf={[Ee.ONE_DAY]:1440*60,[Ee.ONE_WEEK]:10080*60,[Ee.ONE_MONTH]:720*60*60,[Ee.ALL]:null},vr=1,xr=1,Uf=1,Kf=1,Vf=99,Mt={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},jf=Mt.ONE_WEEK,Yf={[Mt.ONE_HOUR]:60,[Mt.SIX_HOURS]:60,[Mt.ONE_DAY]:300,[Mt.ONE_WEEK]:1800,[Mt.MAX]:1800};var yo=createContext(null);function tn(){let e=useContext(yo);if(!e)throw new Error("usePredictWallet must be used within a PredictWalletProvider");return e}var Ha=1e4;function za({pollingInterval:e=Ha,enabled:t=true,children:r}){let n=useWallets(),o=useMemo(()=>n.find(x=>x.chainNamespace===ChainNamespace.SOLANA&&x.isConnected)?.address,[n]),i=useMemo(()=>n.find(x=>x.chainNamespace===ChainNamespace.EVM&&x.isConnected)?.address,[n]),{data:s,isLoading:l,isFetching:a,error:d}=useBalance({source:"kalshi",user:o??""},{enabled:t&&!!o,refetchInterval:e}),{data:p,isLoading:u}=useDFlowKYC(o,{enabled:t&&!!o,refetchInterval:3e4}),{data:m,isLoading:c}=usePolymarketSetup(i,{enabled:t&&!!i,refetchInterval:3e4}),f=m?.safe_address,g=m?.verified??false,{data:h,isLoading:v,isFetching:S,error:C}=useBalance({source:"polymarket",user:i??""},{enabled:t&&g&&!!i,refetchInterval:e}),P=useMemo(()=>({solanaAddress:o,evmAddress:i,polymarketSafeAddress:f,kalshiUsdcBalance:s?Number(s.balance):null,polymarketUsdcBalance:g&&h?Number(h.balance):null,kalshiKycVerified:p?.verified??false,kalshiKycUrl:p?.kyc_url??null,kalshiKycLoading:u,polymarketSetupVerified:g,polymarketSafeDeployed:m?.safe_deployed??false,polymarketTokenApproved:m?.token_approved??false,polymarketSetupLoading:c,isLoading:l||v,isFetching:a||S,error:d??C??null}),[o,i,f,s,h,g,p,u,m,c,l,v,a,S,d,C]);return jsx(yo.Provider,{value:P,children:r})}var ll={minutes:60,hours:3600,days:86400};function cl(e,t,r){let n=Math.floor(Date.now()/1e3);switch(e){case "5m":return n+300;case "1h":return n+3600;case "12h":return n+720*60;case "24h":return n+1440*60;case "eod":{let o=new Date;return o.setUTCHours(23,59,59,0),Math.floor(o.getTime()/1e3)}case "custom":return n+t*ll[r]}}function nn(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};rn({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{rn({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{rn({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Po({market:e,initialOutcome:t="yes",initialSide:r="buy"}){let{t:n}=useTranslation(),{status:o}=useAuth(),i=useWallets(),s=useSwitchChain(),l=usePredictClient(),a=useContext(PolymarketContext),d=useQueryClient(),p=e.source,u=p==="polymarket",m=i.find(k=>k.chainNamespace===ChainNamespace.SOLANA&&k.isConnected),c=i.find(k=>k.chainNamespace===ChainNamespace.EVM&&k.isConnected&&"switchChain"in k),f=o==="authenticated",g=m?.address,h=c?.address,v=useMemo(()=>{if(p!=="polymarket")return;let k=e.provider_meta?.["polymarket.clobTokenIds"];return k?(typeof k=="string"?JSON.parse(k):k)[0]:void 0},[p,e.provider_meta]),{data:S}=useTickSize(v),C=S?.minimum_tick_size?String(S.minimum_tick_size):"0.01",[P,x]=useState(t),[b,T]=useState(r),[z,ae]=useState("market"),[D,ve]=useState(NaN),[I,H]=useState(NaN),[$,J]=useState(false),[ie,M]=useState(null),[_,G]=useState(null),[A,pe]=useState(false),[le,we]=useState(false),[Qe,ut]=useState("1h"),[Ke,Dt]=useState(30),[At,mt]=useState("minutes"),Be=null,lr=false,cr=null,Nt;try{let k=tn();Be={kalshiUsdcBalance:k.kalshiUsdcBalance,polymarketUsdcBalance:k.polymarketUsdcBalance,isLoading:k.isLoading},lr=k.kalshiKycVerified,cr=k.kalshiKycUrl,Nt=k.polymarketSafeAddress;}catch{}let Ne=useMemo(()=>{let k=P==="yes"?0:1,q=e.outcomes[k];return b==="buy"?q?.best_ask??q?.price??.5:q?.best_bid??q?.price??.5},[e.outcomes,P,b]),Kr=useCallback(k=>{ae(k);},[]),Ft=useCallback(k=>{x(k),H(NaN);},[]);useEffect(()=>{z==="limit"&&isNaN(I)&&H(Math.round(Ne*100)/100);},[z,I,Ne]);let Vr=useMemo(()=>isNaN(D)||D<=0?0:b==="buy"?Ne>0?D/Ne:0:D,[b,D,Ne]),E=useMemo(()=>isNaN(D)||D<=0?"0":String(Math.round(D*1e6)),[D]),Ce=e.provider_meta?.["dflow.yesMint"]??"",Xe=e.provider_meta?.["dflow.noMint"]??"",ft=SOLANA_TOKENS.stablecoins.USDC.address,oa=e.provider_meta?.["dflow.collateralMint"]||"",Qn=P==="yes"?Ce:Xe,Xn=p==="kalshi"?g??"":h??"",{data:Ae,isLoading:ia}=usePositions({source:p,user:Xn},{enabled:!!Xn}),Zn=useMemo(()=>!Ae||b!=="sell"?null:Ae.positions.find(k=>k.side?.toLowerCase()===P&&k.market?.slug===e.slug)??null,[Ae,e.slug,P,b])?.market?.provider_meta,sa=b==="sell"&&Zn?.["dflow.outcomeMint"]||Qn,Bt=b==="sell"&&Zn?.["dflow.collateralMint"]||oa,Ht=b==="buy"?ft:sa,zt=b==="buy"?Qn:Bt||ft,aa=p==="kalshi"&&!!Ht&&!!zt&&!!g&&E!=="0",{refetch:Jn}=useDFlowQuote({inputMint:Ht,outputMint:zt,amount:E,userPublicKey:g??"",slippageBps:100},{enabled:aa}),dr=useMemo(()=>Be?p==="kalshi"?Be.kalshiUsdcBalance:Be.polymarketUsdcBalance:Ae&&Ae.positions.reduce((q,Me)=>Me.side==="USDC"||Me.side==="collateral"?q+(Me.current_value??0):q,0)||null,[Be,Ae,p]),la=Be?Be.isLoading:ia,jr=useMemo(()=>Ae?Ae.positions.find(q=>q.side?.toLowerCase()==="yes"&&q.market?.slug===e.slug)?.size??0:null,[Ae,e.slug]),Yr=useMemo(()=>Ae?Ae.positions.find(q=>q.side?.toLowerCase()==="no"&&q.market?.slug===e.slug)?.size??0:null,[Ae,e.slug]),Gr=useMemo(()=>z==="limit"&&u&&!isNaN(I)?I:Ne,[z,u,I,Ne]),pr=useMemo(()=>{if(isNaN(D)||D<=0)return 0;if(b==="buy")return D;let k=P==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return D*k},[b,P,D,e.outcomes]),eo=useMemo(()=>isNaN(D)||D<=0?0:b==="buy"?Gr>0?D/Gr*1:0:pr,[b,D,Gr,pr]),ca=eo-pr,da=useCallback(k=>{T(k),ve(NaN);},[]),pa=useCallback(k=>{if(isNaN(k)){ve(NaN);return}let q=Math.max(0,k),Me=b==="buy"?Math.round(q*100)/100:Math.round(q);ve(Me);},[b]),ua=useCallback(k=>{if(isNaN(k)){H(NaN);return}let q=Math.max(.01,Math.min(.99,k));H(Math.round(q*100)/100);},[]),$t=useCallback(()=>{ve(NaN),H(NaN),ae("market"),we(false),ut("1h"),Dt(30),mt("minutes");},[]),qr=useMemo(()=>{let k=[];isNaN(D)||D<=0?b==="buy"?k.push(n("predict.trade.minAmountUsd",{amount:xr})):k.push(n("predict.trade.minQuantity",{amount:vr})):b==="buy"&&D<xr?k.push(n("predict.trade.minAmountUsd",{amount:xr})):b==="sell"&&D<vr&&k.push(n("predict.trade.minQuantity",{amount:vr})),e.status!=="open"&&k.push(n("predict.trade.marketNotActive")),b==="buy"&&dr!=null&&!isNaN(D)&&D>0&&D>dr&&k.push(n("predict.trade.insufficientBalance"));let q=P==="yes"?jr:Yr;return b==="sell"&&q!=null&&!isNaN(D)&&D>0&&D>q&&k.push(n("predict.trade.insufficientShares")),z==="limit"&&u&&(isNaN(I)||I<.01||I>.99)&&k.push(n("predict.trade.limitPriceRange")),z==="limit"&&u&&le&&Qe==="custom"&&(isNaN(Ke)||Ke<=0)&&k.push(n("predict.trade.expiration.invalidDate")),{isValid:k.length===0,errors:k}},[D,e.status,b,p,dr,jr,Yr,P,z,u,I,le,Qe,Ke,n]),{mutateAsync:ur}=useDFlowSubmit(),{data:Qr}=useOrder({id:ie??"",source:p},{enabled:!!ie}),to=useCallback(async()=>{if(!_||!g||!m)return;let{cashAmount:k,collateral:q}=_;G(null);try{let gt=(await l.createDFlowQuote({inputMint:q,outputMint:ft,amount:k,userPublicKey:g,slippageBps:100}))?.transaction;if(!gt)return;let it=Uint8Array.from(atob(gt),Wt=>Wt.charCodeAt(0)),Ze=await m.signTransaction(it);await ur({signedTransaction:btoa(String.fromCharCode(...Ze)),orderContext:{user_public_key:g,input_mint:q,output_mint:ft,amount:k,price:"1",side:"SELL",outcome:"",market_slug:"",slippage_bps:100}});}catch{}},[_,g,m,l,ur,ft]);useEffect(()=>{if(!Qr||!ie)return;let{status:k}=Qr;k==="closed"?(M(null),_?to().finally(()=>{J(false),toast.success(n("predict.trade.submitSuccess")),nn(),$t();}):(J(false),toast.success(n("predict.trade.submitSuccess")),nn(),$t())):(k==="failed"||k==="expired")&&(J(false),M(null),G(null),toast.error(n("predict.trade.submitError")));},[Qr,ie,_,to,$t,n]);let ro=useCallback(async()=>{if(!g||!m)return;if(!Ht||!zt){toast.error("Missing token mint addresses"),J(false);return}if(!lr){pe(true),J(false);return}let Me=(await Jn()).data,gt=Me?.transaction;if(!gt){toast.error(n("predict.trade.submitError")),J(false);return}if(b==="sell"&&Bt&&Bt!==ft){let st=String(Me?.outAmount??"");st&&st!=="0"&&G({cashAmount:st,collateral:Bt});}let it=Uint8Array.from(atob(gt),st=>st.charCodeAt(0)),Ze=await m.signTransaction(it),Wt=await ur({signedTransaction:btoa(String.fromCharCode(...Ze)),orderContext:{user_public_key:g,input_mint:Ht,output_mint:zt,amount:E,price:String(Ne),side:b==="buy"?"BUY":"SELL",outcome:P==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}});M(Wt.signature);},[g,m,l,Jn,ur,Ht,zt,E,Ne,b,P,e.slug,Bt,ft,n]),no=useCallback(async()=>{if(!c||!a)return;let k=c.chain,q=k!==Chain.POLYGON;q&&await s(Chain.POLYGON);try{let Me=await c.getEip1193Provider();if(!Me){toast.error(n("predict.trade.submitError")),J(!1);return}let gt=!!Nt,it={address:c.address,signatureType:gt?2:0,signTypedData:async(ht,ka,Sa,wa)=>{let Ct=[];"name"in ht&&Ct.push({name:"name",type:"string"}),"version"in ht&&Ct.push({name:"version",type:"string"}),"chainId"in ht&&Ct.push({name:"chainId",type:"uint256"}),"verifyingContract"in ht&&Ct.push({name:"verifyingContract",type:"address"}),"salt"in ht&&Ct.push({name:"salt",type:"bytes32"});let Pa={EIP712Domain:Ct,...ka};return await Me.request({method:"eth_signTypedData_v4",params:[c.address,JSON.stringify({domain:ht,types:Pa,primaryType:Sa,message:wa})]})}},Ze=a.credentials??await a.authenticate(it),Wt=P==="yes"?0:1,st="",mr=e.provider_meta?.["polymarket.clobTokenIds"];mr&&(st=(typeof mr=="string"?JSON.parse(mr):mr)[Wt]??"");let oo=e.provider_meta?.["polymarket.negRisk"]??!1,Xr=z==="limit"&&!isNaN(I)?I:Ne,fa=z==="limit"?le?"GTD":"GTC":"FOK",ga=b==="buy"&&Xr>0?D/Xr:D,io={tokenId:st,price:Xr,size:ga,side:b==="buy"?"BUY":"SELL",orderType:fa,tickSize:C,negRisk:oo,...Nt&&{funderAddress:Nt},...z==="limit"&&le&&{expiration:cl(Qe,Ke,At)}},ha=buildCtfExchangeDomain(oo),so=buildOrderMessage({...io,signerAddress:it.address,signatureType:it.signatureType}),va=await it.signTypedData(ha,CTF_ORDER_TYPES,"Order",so),xa=buildSignedOrder(so,va,io.orderType),ao=buildClobPayload(xa,Ze.apiKey),ba=JSON.stringify(ao),ya=await buildPolymarketL2Headers(Ze.address,{apiKey:Ze.apiKey,secret:Ze.secret,passphrase:Ze.passphrase,method:"POST",requestPath:"/order",body:ba});await l.createPolymarketOrder(ao,ya),d.invalidateQueries({queryKey:["predict","orders"]}),d.invalidateQueries({queryKey:["predict","positions"]}),toast.success(n("predict.trade.submitSuccess")),nn(),$t(),J(!1);}finally{q&&k&&s(k).catch(()=>{});}},[c,a,s,P,e.provider_meta,z,I,Ne,D,b,l,d,le,Qe,Ke,At,$t,n]),ma=useCallback(async()=>{if(!(!qr.isValid||!f)){J(true),M(null),pe(false);try{p==="kalshi"?await ro():await no();}catch(k){let q=k instanceof Error?k.message:void 0;toast.error(q||n("predict.trade.submitError")),J(false);}}},[qr.isValid,f,p,ro,no,n]);return {outcome:P,side:b,orderType:z,quantity:D,limitPrice:I,shares:Vr,estimatedCost:pr,potentialPayout:eo,potentialProfit:ca,usdcBalance:dr,yesTokenBalance:jr,noTokenBalance:Yr,isBalanceLoading:la,isSubmitting:$,validation:qr,supportsLimitOrder:u,kycRequired:A,kycUrl:cr,expirationEnabled:le,expirationPreset:Qe,customDuration:Ke,customDurationUnit:At,setOutcome:Ft,setSide:da,setOrderType:Kr,setQuantity:pa,setLimitPrice:ua,setExpirationEnabled:we,setExpirationPreset:ut,setCustomDuration:Dt,setCustomDurationUnit:mt,submit:ma}}function No({isOpen:e,onClose:t,kycUrl:r}){let{t:n}=useTranslation();return jsx(StyledModal,{isOpen:e,onOpenChange:o=>{o||t();},size:"md",classNames:{base:"!bg-[#18181b] !rounded-[14px] !border !border-[rgba(39,39,42,1)] !shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)]",body:"!p-0"},children:jsx(ModalContent,{children:jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-4",children:[jsx("h3",{className:"text-base font-semibold text-white",children:n("predict.trade.kycModalTitle")}),jsx("button",{type:"button",onClick:t,className:"p-1 rounded-[10px] hover:bg-[rgba(39,39,42,0.5)] text-zinc-400 hover:text-white transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:jsxs("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),jsxs("div",{className:"px-5 pb-5",children:[jsx("p",{className:"text-[13px] text-zinc-400 mb-4 text-left",children:n("predict.trade.kycModalDescription")}),jsx("div",{className:"flex flex-col gap-2 mb-4",children:["predict.trade.kycModalBullet1","predict.trade.kycModalBullet2","predict.trade.kycModalBullet3"].map(o=>jsxs("div",{className:"flex items-center gap-2.5 text-[13px] text-zinc-300",children:[jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#c7ff2e] shrink-0",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:n(o)})]},o))}),r&&jsxs("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[13px] text-[#c7ff2e]/70 hover:text-[#c7ff2e] transition-colors mb-3",children:[n("predict.trade.goToKYC")," \u2192"]}),jsx("p",{className:"text-[11px] text-zinc-500 mb-5",children:n("predict.trade.kycModalNote")}),jsx("button",{type:"button",onClick:t,className:"w-full py-2.5 rounded-[10px] bg-[#c7ff2e] text-zinc-900 text-sm font-semibold hover:bg-[#c7ff2e]/90 transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:n("common.ok")})]})]})})})}var Pl=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`,Nl=["5m","1h","12h","24h","eod","custom"],Cl={"5m":"predict.trade.expiration.5m","1h":"predict.trade.expiration.1h","12h":"predict.trade.expiration.12h","24h":"predict.trade.expiration.24h",eod:"predict.trade.expiration.eod",custom:"predict.trade.expiration.custom"},Ml=["minutes","hours","days"],El={minutes:"predict.trade.expiration.minutes",hours:"predict.trade.expiration.hours",days:"predict.trade.expiration.days"};function Ro({event:e,market:t,variant:r="bordered",outcome:n,side:o,orderType:i,quantity:s,limitPrice:l,shares:a,potentialProfit:d,potentialPayout:p,estimatedCost:u,usdcBalance:m,yesTokenBalance:c,noTokenBalance:f,isBalanceLoading:g,isSubmitting:h,isValid:v,validationErrors:S,supportsLimitOrder:C,kycRequired:P,kycUrl:x,expirationEnabled:b,expirationPreset:T,customDuration:z,customDurationUnit:ae,onOutcomeChange:D,onSideChange:ve,onOrderTypeChange:I,onQuantityChange:H,onLimitPriceChange:$,onExpirationEnabledChange:J,onExpirationPresetChange:ie,onCustomDurationChange:M,onCustomDurationUnitChange:_,onSubmit:G}){let{t:A}=useTranslation(),[pe,le]=useState(false),we=useDisclosure(),[Qe,ut]=useState(""),Ke=useRef(false),Dt=useRef(o);useEffect(()=>{Ke.current||ut(isNaN(s)?"":String(s));},[s]),useEffect(()=>{o!==Dt.current&&(Dt.current=o,ut(""));},[o]);let At=useCallback(E=>{if(E!==""&&!(o==="buy"?/^\d*\.?\d{0,2}$/:/^\d*$/).test(E))return;if(ut(E),Ft(false),E===""||E==="."){H(NaN);return}let Xe=parseFloat(E);isNaN(Xe)||H(Xe);},[o,H]);useEffect(()=>{P&&!we.isOpen&&we.onOpen();},[P]);let mt=useMemo(()=>{let E=o==="buy"?n==="yes"?t.yesAsk:t.noAsk:n==="yes"?t.yesBid:t.noBid;return E!=null?parseFloat((Number(E)*100).toFixed(2)):null},[o,n,t]),Be=!isNaN(s)&&s>0,lr=useMemo(()=>{if(g)return A("predict.trade.loadingBalance");if(h)return A("predict.trade.submitting");if(P)return A("predict.trade.kycRequired");if(!Be)return A("predict.trade.enterAmount");let E=A(o==="buy"?"predict.trade.buy":"predict.trade.sell"),Ce=A(n==="yes"?"predict.trade.yes":"predict.trade.no"),Xe=o==="buy"&&d>0?` \u2192 Win $${d.toFixed(2)}`:"";return `${E} ${Ce}${Xe}`},[g,h,P,Be,o,n,d,A]),cr=useMemo(()=>n==="yes"?"primary":"secondary",[n]),Nt=()=>{H(Math.floor((m??0)/2*100)/100);},Ne=()=>{H(m??0);},[Kr,Ft]=useState(false),Vr=()=>{if(P){we.onOpen();return}if(!v){Ft(true);return}Ft(false),G();};return jsxs(Fragment,{children:[jsxs("div",{className:"flex w-full flex-col gap-y-4 p-4",style:r==="bordered"?{borderRadius:14,border:"1px solid rgba(39,39,42,0.6)",background:"rgba(24,24,27,0.4)",transition:"border-color 0.2s"}:void 0,onMouseEnter:E=>{r==="bordered"&&(E.currentTarget.style.borderColor="rgba(63,63,70,0.8)");},onMouseLeave:E=>{r==="bordered"&&(E.currentTarget.style.borderColor="rgba(39,39,42,0.6)");},children:[e&&jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxs("span",{className:n==="yes"?"text-bullish":"text-bearish",children:[A(o==="buy"?"predict.trade.buy":"predict.trade.sell")," ",A(n==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxs("span",{className:"text-foreground",children:[" \xB7 ",t.yesSubTitle]})]})]})]}),jsxs("div",{className:"flex items-center justify-between",children:[C?jsxs(Tabs,{variant:"underlined",selectedKey:i,onSelectionChange:E=>I(E),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:A("predict.trade.market")},"market"),jsx(Tab,{title:A("predict.trade.limit")},"limit")]}):jsx("span",{className:"text-sm font-medium text-foreground",children:A("predict.trade.market")}),i==="limit"&&C?jsx(StyledNumberInput,{"aria-label":"Limit price",placeholder:"50",size:"sm",radius:"none",value:isNaN(l)?void 0:parseFloat((l*100).toFixed(2)),onValueChange:E=>$(E/100),minValue:1,maxValue:99,step:1,formatOptions:{maximumFractionDigits:2},endContent:jsx("span",{className:"text-xl font-bold tabular-nums text-foreground",children:"\xA2"}),classNames:{base:"w-28",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 rounded-lg px-2 h-9 min-h-9",input:"text-xl font-bold tabular-nums text-right"}}):mt!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[mt," \xA2"]})]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(E=>{let Ce=E==="yes"?c:f;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>D(E),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${n===E?E==="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:[jsx("span",{children:A(E==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let Xe=o==="buy"?E==="yes"?t.yesAsk:t.noAsk:E==="yes"?t.yesBid:t.noBid;return Xe!=null?jsxs("span",{className:"ml-1 opacity-70",children:[parseFloat((Number(Xe)*100).toFixed(2)),"\xA2"]}):null})()]}),o==="sell"&&n===E&&jsx("span",{className:"text-center text-xs text-foreground",children:g?"\u2013":`${Ce??0} shares`})]},E)})}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:A(o==="buy"?"predict.trade.youArePaying":"predict.trade.contracts")}),o==="buy"&&jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:Pl,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:m!=null?`${m.toFixed(2)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:Nt,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:A("predict.trade.half")}),jsx("button",{type:"button",onClick:Ne,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:A("predict.trade.max")})]})]}),jsx(StyledInput,{"aria-label":"Trade amount",fullWidth:true,placeholder:"0",radius:"lg",size:"lg",inputMode:o==="buy"?"decimal":"numeric",value:Qe,onChange:E=>At(E.target.value),onFocus:()=>{Ke.current=true;},onBlur:()=>{Ke.current=false,ut(isNaN(s)?"":String(s));},startContent:o==="buy"?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"}}),o==="sell"&&jsxs("div",{className:"flex gap-x-2 justify-end",children:[[25,50].map(E=>jsxs("button",{type:"button",onClick:()=>{H(Math.floor((n==="yes"?c??0:f??0)*E/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:[E,"%"]},E)),jsx("button",{type:"button",onClick:()=>{H(n==="yes"?c??0:f??0);},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:A("common.all")})]}),Kr&&S.length>0&&jsx("div",{className:"flex flex-col gap-y-0.5",children:S.map(E=>jsx("span",{className:"text-xs text-danger",children:E},E))})]}),i==="limit"&&C&&jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-sm font-medium text-primary",children:A("predict.trade.setExpiration")}),jsx(StyledSwitch,{size:"sm",color:"primary",isSelected:b,onValueChange:J,"aria-label":A("predict.trade.setExpiration")})]}),b&&jsxs(Fragment,{children:[jsx(Select,{"aria-label":A("predict.trade.setExpiration"),selectedKeys:[T],onSelectionChange:E=>{let Ce=Array.from(E)[0];Ce&&ie(Ce);},size:"sm",radius:"lg",classNames:{trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:Nl.map(E=>jsx(SelectItem,{children:A(Cl[E])},E))}),T==="custom"&&jsxs("div",{className:"flex gap-x-2",children:[jsx(StyledNumberInput,{"aria-label":"Duration amount",size:"sm",radius:"lg",value:isNaN(z)?void 0:z,onValueChange:M,minValue:1,step:1,formatOptions:{maximumFractionDigits:0},classNames:{base:"flex-1",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 min-h-10",input:"text-sm"}}),jsx(Select,{"aria-label":"Duration unit",selectedKeys:[ae],onSelectionChange:E=>{let Ce=Array.from(E)[0];Ce&&_(Ce);},size:"sm",radius:"lg",classNames:{base:"w-32",trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:Ml.map(E=>jsx(SelectItem,{children:A(El[E])},E))})]})]})]}),jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between text-sm",children:[jsxs("button",{type:"button",onClick:()=>le(E=>!E),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:A("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",pe&&"rotate-180")})]}),mt!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[mt,"% chance"]})]}),pe&&jsxs("div",{className:"flex flex-col gap-y-1.5 border-l-2 border-default-300 pl-3 text-sm text-neutral-500",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Total Size"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${u.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"No. of Contracts"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(a)&&a>0?parseFloat(a.toFixed(2)):"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Payout"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${p.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Est. Profit"}),jsx("span",{className:"tabular-nums text-bullish",children:!isNaN(s)&&s>0&&d>0?`+$${d.toFixed(2)}`:"\u2013"})]})]})]}),jsx(Button,{color:cr,fullWidth:true,radius:"lg",size:"lg",isDisabled:g||!Be||h,isLoading:h||g,spinner:jsx(Spinner,{size:"sm",color:"current"}),onPress:Vr,children:lr})]}),jsx(No,{isOpen:we.isOpen,onClose:we.onClose,kycUrl:x})]})}function br({event:e,market:t,variant:r,initialSide:n,initialOutcome:o,chain:i}){let{outcome:s,side:l,orderType:a,quantity:d,limitPrice:p,shares:u,estimatedCost:m,potentialPayout:c,potentialProfit:f,usdcBalance:g,yesTokenBalance:h,noTokenBalance:v,isBalanceLoading:S,isSubmitting:C,validation:P,supportsLimitOrder:x,kycRequired:b,kycUrl:T,expirationEnabled:z,expirationPreset:ae,customDuration:D,customDurationUnit:ve,setOutcome:I,setSide:H,setOrderType:$,setQuantity:J,setLimitPrice:ie,setExpirationEnabled:M,setExpirationPreset:_,setCustomDuration:G,setCustomDurationUnit:A,submit:pe}=Po({market:t,initialSide:n,initialOutcome:o}),le=useAuthCallback(pe),we=useMemo(()=>e?ho(e):void 0,[e]),Qe=useMemo(()=>vo(t),[t]);return jsx(Ro,{event:we,market:Qe,variant:r,outcome:s,side:l,orderType:a,quantity:d,limitPrice:p,shares:u,estimatedCost:m,potentialPayout:c,potentialProfit:f,usdcBalance:g,yesTokenBalance:h,noTokenBalance:v,isBalanceLoading:S,isSubmitting:C,isValid:P.isValid,validationErrors:P.errors,supportsLimitOrder:x,kycRequired:b,kycUrl:T,expirationEnabled:z,expirationPreset:ae,customDuration:D,customDurationUnit:ve,onOutcomeChange:I,onSideChange:H,onOrderTypeChange:$,onQuantityChange:J,onLimitPriceChange:ie,onExpirationEnabledChange:M,onExpirationPresetChange:_,onCustomDurationChange:G,onCustomDurationUnitChange:A,onSubmit:le})}var Kt="predict-trade";function yr({id:e=Kt}){return jsx(AsyncModal,{id:e,children:t=>jsx(Al,{...t})})}function Al({params:e,isOpen:t,onOpenChange:r}){let{t:n}=useTranslation(),{isMobile:o}=useScreen();return e?jsx(StyledModal,{isOpen:t,onOpenChange:r,size:o?"lg":"md",backdrop:"blur",hideCloseButton:true,classNames:{base:"!bg-[#18181b] !rounded-[14px] !border !border-[rgba(39,39,42,1)] !shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)]",body:"!p-0"},children:jsx(ModalContent,{children:jsxs("div",{className:o?"":"p-2",children:[jsx(br,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:e.initialSide??"buy",chain:e.chain,variant:"flat"}),jsx("div",{className:"px-4 pb-4",children:jsx("button",{type:"button",onClick:()=>r(false),className:"w-full h-12 rounded-xl text-sm font-medium text-zinc-400 hover:text-white hover:bg-[rgba(39,39,42,0.5)] transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:n("common.cancel")})})]})})}):null}var ln={sortPreset:"volume",sortAsc:false,source:void 0,timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function cn(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function Oo({isOpen:e,onClose:t,value:r,onChange:n}){let{t:o}=useTranslation(),[i,s]=useState(r),l=useCallback(h=>{h?s(r):t();},[r,t]),a=useCallback(()=>{s(ln);},[]),d=useCallback(()=>{n(i),t();},[i,n,t]),p=useCallback((h,v)=>{s(S=>({...S,[h]:v}));},[]),u=useMemo(()=>cn(i),[i]),m=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"polymarket",label:o("predict.platform.polymarket")},{value:"kalshi",label:o("predict.platform.kalshi")}],[o]),c=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"1d",label:o("predict.filter.lessThanDay")},{value:"7d",label:o("predict.filter.lessThanWeek")},{value:"30d",label:o("predict.filter.lessThanMonth")}],[o]),f=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[o]),g=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[o]);return jsx(StyledModal,{isOpen:e,onOpenChange:l,size:"md",backdrop:"blur",scrollBehavior:"inside",classNames:{base:"!bg-[#18181b] !rounded-[14px] !border !border-[rgba(39,39,42,1)] !shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)]",body:"!p-0"},children:jsx(ModalContent,{children:jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-4",children:[jsx("h3",{className:"text-base font-semibold text-white",children:o("predict.filter.title")}),jsx(Wl,{onClick:()=>l(false)})]}),jsxs("div",{style:{padding:"0 20px 16px",display:"flex",flexDirection:"column",gap:20},children:[jsx(Sr,{label:o("predict.filter.platform"),children:jsx(wr,{options:m,selected:i.source,onSelect:h=>p("source",h)})}),jsx(Sr,{label:o("predict.filter.timeRemaining"),children:jsx(wr,{options:c,selected:i.timeRemaining,onSelect:h=>p("timeRemaining",h)})}),jsx(Sr,{label:o("predict.filter.minVolume"),children:jsx(wr,{options:f,selected:i.minVolume,onSelect:h=>p("minVolume",h)})}),jsx(Sr,{label:o("predict.filter.minLiquidity"),children:jsx(wr,{options:g,selected:i.minLiquidity,onSelect:h=>p("minLiquidity",h)})})]}),jsxs("div",{className:"flex items-center gap-3 px-5 py-4",style:{borderTop:"1px solid rgba(39,39,42,0.5)"},children:[jsx("button",{type:"button",className:"inline-flex items-center justify-center py-2.5 px-5 rounded-[10px] text-zinc-400 text-sm font-medium hover:text-white transition-colors cursor-pointer",onClick:a,children:o("predict.filter.reset")}),jsxs("button",{type:"button",className:"flex-1 inline-flex items-center justify-center gap-2 py-2.5 rounded-[10px] bg-[#c7ff2e] text-zinc-900 text-sm font-semibold hover:bg-[#c7ff2e]/90 transition-colors cursor-pointer",onClick:d,children:[o("predict.filter.showResults"),u>0&&jsxs("span",{style:{opacity:.7},children:["(",u,")"]})]})]})]})})})}function Sr({label:e,children:t}){return jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[jsx("span",{style:{fontSize:11,fontWeight:500,color:"#71717a",textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t]})}function Wl({onClick:e}){return jsx("button",{type:"button",onClick:e,className:"p-1 rounded-[10px] hover:bg-[rgba(39,39,42,0.5)] text-zinc-400 hover:text-white transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:jsxs("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}function wr({options:e,selected:t,onSelect:r,allowDeselect:n=true}){return jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:e.map(o=>{let i=t===o.value;return jsx("button",{type:"button",onClick:()=>{r(i&&n?void 0:o.value);},style:{flexShrink:0,borderRadius:10,padding:"6px 14px",fontSize:13,fontWeight:500,cursor:"pointer",transition:"all 0.15s",border:i?"1px solid rgba(199,255,46,0.3)":"1px solid rgba(63,63,70,0.5)",background:i?"rgba(199,255,46,0.08)":"rgba(39,39,42,0.4)",color:i?"#c7ff2e":"#a1a1aa"},onMouseEnter:s=>{i||(s.currentTarget.style.background="rgba(39,39,42,0.8)",s.currentTarget.style.color="#fff");},onMouseLeave:s=>{i||(s.currentTarget.style.background="rgba(39,39,42,0.4)",s.currentTarget.style.color="#a1a1aa");},children:o.label},o.value??"__all")})})}function Do(e){return e>=1e9?`$${(e/1e9).toFixed(1)}B`:e>=1e6?`$${(e/1e6).toFixed(1)}M`:e>=1e3?`$${(e/1e3).toFixed(1)}K`:`$${e.toFixed(0)}`}var Kl=[{key:"total_events",labelKey:"predict.events.stats.totalEvents",format:e=>e.toLocaleString(),valueColor:"#c7ff2e",gradientFrom:"rgba(199,255,46,0.18)",gradientTo:"rgba(199,255,46,0.04)"},{key:"total_volume_24h",labelKey:"predict.events.stats.volume24h",format:Do,valueColor:"#f76816",gradientFrom:"rgba(247,104,22,0.18)",gradientTo:"rgba(247,104,22,0.04)"},{key:"avg_liquidity",labelKey:"predict.events.stats.avgLiquidity",format:Do,valueColor:"#17c964",gradientFrom:"rgba(23,201,100,0.18)",gradientTo:"rgba(23,201,100,0.04)"},{key:"active_sources",labelKey:"predict.events.stats.activeSources",format:e=>e.toLocaleString(),valueColor:"#f5a524",gradientFrom:"rgba(245,165,36,0.18)",gradientTo:"rgba(245,165,36,0.04)"}];function Ao({stats:e}){let{t}=useTranslation();return jsxs(Fragment,{children:[jsx("style",{children:`
|
|
1
|
+
import {createContext,memo,useRef,forwardRef,useState,useImperativeHandle,useMemo,useEffect,useCallback,useContext,Fragment as Fragment$1,startTransition,Component}from'react';import {ChartRange,useInfiniteMatchMarkets,useBalance,useDFlowKYC,usePolymarketSetup,usePredictClient,PolymarketContext,useTickSize,usePositions,useDFlowQuote,useDFlowSubmit,useOrder,buildCtfExchangeDomain,buildOrderMessage,CTF_ORDER_TYPES,buildSignedOrder,buildClobPayload,buildPolymarketL2Headers,resolveEventsParams,useInfiniteEvents,useEventStats,useInfiniteOrders,useCancelOrder,useInfiniteTrades,useOrderbook,useMarketHistory,useEvent,useSimilarEvents,candlesticksQueryKey,useSearchEvents}from'@liberfi.io/react-predict';export{PredictClient,PredictContext,PredictProvider,PredictWsClient,createPredictClient,createPredictWsClient,eventStatsQueryKey,fetchMatchMarketsPage,fetchMatchesPage,matchMarketsQueryKey,matchQueryKey,matchesQueryKey,useBalance,useCancelOrder,useCandlesticks,useDFlowKYC,useDFlowQuote,useDFlowSubmit,useEvent,useEventStats,useEvents,useInfiniteEvents,useInfiniteMatchMarkets,useInfiniteMatches,useInfiniteOrders,useInfiniteTrades,useMarket,useMarketHistory,useMarketTrades,useMatch,useOrder,useOrderbook,useOrders,usePositions,usePredictClient,usePriceHistory,useSearchEvents,useSimilarEvents,useTrades}from'@liberfi.io/react-predict';import {PolymarketIcon,KalshiIcon,cn as cn$1,Skeleton,toast,StyledModal,ModalContent,useDisclosure,Tabs,Tab,StyledNumberInput,StyledInput,StyledSwitch,Select,SelectItem,ChevronDownIcon,Button,Spinner,useScreen,TimerIcon,DropletIcon,ChartLineIcon,CalendarIcon,Linkable,Avatar,ChevronUpIcon,OrderbookTableIcon,OrderbookDepthIcon,Dropdown,DropdownTrigger,DropdownMenu,DropdownItem,ChevronRightIcon,ChevronLeftIcon,TrashIcon,Chip,XCloseIcon,Kbd,SearchIcon,EmptyIcon,ModalHeader,ModalBody}from'@liberfi.io/ui';import {AsyncModal,useAsyncModal}from'@liberfi.io/ui-scaffold';import {useTranslation}from'@liberfi.io/i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useWallets,useAuth,useSwitchChain,useAuthCallback}from'@liberfi.io/wallet-connector';import {keepPreviousData,useQueryClient,useQueries}from'@tanstack/react-query';import rn from'canvas-confetti';import {ChainNamespace,Chain}from'@liberfi.io/types';import {SOLANA_TOKENS,debounce}from'@liberfi.io/utils';import {List}from'react-window';import {useInfiniteLoader}from'react-window-infinite-loader';import {useScrollCollapse,useResizeObserver,useCallbackRef}from'@liberfi.io/hooks';import {ResponsiveContainer,LineChart,CartesianGrid,XAxis,YAxis,Tooltip,Line,ReferenceDot}from'recharts';import {useAtom}from'jotai';import {atomWithStorage}from'jotai/utils';typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.123");var Na="0.1.123";var Ca={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:["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},lo=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],Zr=(()=>{let e=t=>{let r=lo.indexOf(t);return r===-1?lo.length:r};return Object.entries(Ca).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 uo({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:o,onTagSelect:i,trailing:s,pulsingTab:l="Trending",className:a}){let{t:d}=useTranslation(),p=useCallback(()=>{o(null);},[o]),u=d("predict.categories.trending");return jsxs("div",{className:cn$1("sticky top-0 z-30 flex w-full flex-col justify-between gap-2 px-4 py-2.5 lg:px-4 lg:py-2",a),children:[jsxs("div",{className:"flex w-full items-center gap-2",children:[jsx("div",{className:"hideScrollbar min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:jsxs("div",{className:"flex min-h-9 items-stretch gap-x-3 lg:min-h-10",children:[jsx(co,{label:u,isSelected:t===null,onPress:p,showPulse:u===l}),jsx(La,{}),e.map(m=>jsx(co,{label:m.category,isSelected:t===m.category,onPress:()=>o(m.category),badge:m.badge,showPulse:m.category===l},m.category))]})}),s&&jsx("div",{className:"flex-shrink-0",children:s})]}),t&&n.length>0&&jsx("div",{className:"hideScrollbar overflow-x-auto overflow-y-hidden flex items-center",children:jsxs("div",{className:"flex gap-x-1.5 pl-1 lg:w-full lg:gap-x-2",children:[jsx(po,{label:d("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null)}),n.map(m=>jsx(po,{label:m.label,icon:m.icon,isSelected:r===m.label,onPress:()=>i(m.label)},m.label))]})})]})}function co({label:e,isSelected:t,onPress:r,badge:n,showPulse:o}){return jsxs("button",{type:"button",onClick:r,className:cn$1("relative shrink-0 cursor-pointer whitespace-nowrap border-b px-2.5 py-1.5 text-sm font-medium capitalize transition-colors",t?"border-primary/50 text-primary":"border-transparent text-neutral-500 hover:text-neutral-300"),children:[o?jsxs("span",{className:"flex items-center gap-x-1.5",children:[jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-[rgb(240,68,56)]"}),jsx("span",{children:e})]}):e,n&&jsx("span",{className:"absolute -right-1 top-0 rounded bg-primary px-0.5 py-px text-[0.625rem] font-semibold leading-none text-neutral-950",children:n})]})}function La(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function po({label:e,icon:t,isSelected:r,onPress:n}){return jsxs("button",{type:"button",onClick:n,className:cn$1("flex shrink-0 items-center justify-center gap-x-1 min-w-14 rounded-2xl border px-3 py-1.5 text-sm font-medium uppercase transition-colors cursor-pointer",r?"border-primary/40 bg-primary/15 text-primary":"border-border/80 text-neutral-500 hover:bg-primary/10 hover:text-primary"),children:[t&&jsx("span",{className:cn$1("iconify size-4",t)}),e]})}function _f({count:e=6}){return jsx("div",{className:"flex w-full flex-col gap-2 px-4 py-2.5 lg:px-4 lg:py-2",children:jsx("div",{className:"flex min-h-9 items-center gap-x-3 lg:min-h-10",children:Array.from({length:e}).map((t,r)=>jsx(Skeleton,{className:"h-6 w-16 shrink-0 rounded"},r))})})}function _a(e){return e.map(t=>({category:t.label,tags:t.tags.map(r=>r.label)}))}function Ra(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function go({onSelect:e,trailing:t,className:r}){let[n,o]=useState(null),[i,s]=useState(null),l=useCallback(m=>{o(m),s(null),e?.({categorySlug:m,tagSlug:null});},[e]),a=useCallback(m=>{s(m),e?.({categorySlug:n,tagSlug:m});},[n,e]),d=_a(Zr),p=Zr.find(m=>m.slug===n),u=Ra(p);return jsx(uo,{categories:d,selectedCategory:n,selectedTag:i,activeTags:u,onCategorySelect:l,onTagSelect:a,trailing:t,className:r})}function ho(e){return {title:e.title,imageUrl:e.image_url}}function vo(e){let t=e.outcomes[0],r=e.outcomes[1];return {question:e.question,yesAsk:t?.best_ask??t?.price,noAsk:r?.best_ask??r?.price,yesBid:t?.best_bid,noBid:r?.best_bid,yesSubTitle:t?.label??"Yes",noSubTitle:r?.label??"No"}}var Ut=24,Jr=4,gr={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},Ee={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},hr=Ee.ALL,zf={[Ee.ONE_DAY]:gr.ONE_MINUTE,[Ee.ONE_WEEK]:gr.ONE_HOUR,[Ee.ONE_MONTH]:gr.ONE_HOUR,[Ee.ALL]:gr.ONE_DAY},$f={[Ee.ONE_DAY]:300,[Ee.ONE_WEEK]:3600,[Ee.ONE_MONTH]:10800,[Ee.ALL]:1440*60},Wf={[Ee.ONE_DAY]:1440*60,[Ee.ONE_WEEK]:10080*60,[Ee.ONE_MONTH]:720*60*60,[Ee.ALL]:null},vr=1,xr=1,Uf=1,Kf=1,Vf=99,Mt={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},jf=Mt.ONE_WEEK,Yf={[Mt.ONE_HOUR]:60,[Mt.SIX_HOURS]:60,[Mt.ONE_DAY]:300,[Mt.ONE_WEEK]:1800,[Mt.MAX]:1800};var yo=createContext(null);function tn(){let e=useContext(yo);if(!e)throw new Error("usePredictWallet must be used within a PredictWalletProvider");return e}var Ha=1e4;function za({pollingInterval:e=Ha,enabled:t=true,children:r}){let n=useWallets(),o=useMemo(()=>n.find(x=>x.chainNamespace===ChainNamespace.SOLANA&&x.isConnected)?.address,[n]),i=useMemo(()=>n.find(x=>x.chainNamespace===ChainNamespace.EVM&&x.isConnected)?.address,[n]),{data:s,isLoading:l,isFetching:a,error:d}=useBalance({source:"kalshi",user:o??""},{enabled:t&&!!o,refetchInterval:e}),{data:p,isLoading:u}=useDFlowKYC(o,{enabled:t&&!!o,refetchInterval:3e4}),{data:m,isLoading:c}=usePolymarketSetup(i,{enabled:t&&!!i,refetchInterval:3e4}),f=m?.safe_address,g=m?.verified??false,{data:h,isLoading:v,isFetching:S,error:C}=useBalance({source:"polymarket",user:i??""},{enabled:t&&g&&!!i,refetchInterval:e}),P=useMemo(()=>({solanaAddress:o,evmAddress:i,polymarketSafeAddress:f,kalshiUsdcBalance:s?Number(s.balance):null,polymarketUsdcBalance:g&&h?Number(h.balance):null,kalshiKycVerified:p?.verified??false,kalshiKycUrl:p?.kyc_url??null,kalshiKycLoading:u,polymarketSetupVerified:g,polymarketSafeDeployed:m?.safe_deployed??false,polymarketTokenApproved:m?.token_approved??false,polymarketSetupLoading:c,isLoading:l||v,isFetching:a||S,error:d??C??null}),[o,i,f,s,h,g,p,u,m,c,l,v,a,S,d,C]);return jsx(yo.Provider,{value:P,children:r})}var ll={minutes:60,hours:3600,days:86400};function cl(e,t,r){let n=Math.floor(Date.now()/1e3);switch(e){case "5m":return n+300;case "1h":return n+3600;case "12h":return n+720*60;case "24h":return n+1440*60;case "eod":{let o=new Date;return o.setUTCHours(23,59,59,0),Math.floor(o.getTime()/1e3)}case "custom":return n+t*ll[r]}}function nn(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};rn({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{rn({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{rn({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Po({market:e,initialOutcome:t="yes",initialSide:r="buy"}){let{t:n}=useTranslation(),{status:o}=useAuth(),i=useWallets(),s=useSwitchChain(),l=usePredictClient(),a=useContext(PolymarketContext),d=useQueryClient(),p=e.source,u=p==="polymarket",m=i.find(k=>k.chainNamespace===ChainNamespace.SOLANA&&k.isConnected),c=i.find(k=>k.chainNamespace===ChainNamespace.EVM&&k.isConnected&&"switchChain"in k),f=o==="authenticated",g=m?.address,h=c?.address,v=useMemo(()=>{if(p!=="polymarket")return;let k=e.provider_meta?.["polymarket.clobTokenIds"];return k?(typeof k=="string"?JSON.parse(k):k)[0]:void 0},[p,e.provider_meta]),{data:S}=useTickSize(v),C=S?.minimum_tick_size?String(S.minimum_tick_size):"0.01",[P,x]=useState(t),[b,T]=useState(r),[z,ae]=useState("market"),[D,ve]=useState(NaN),[I,H]=useState(NaN),[$,J]=useState(false),[ie,M]=useState(null),[_,G]=useState(null),[A,pe]=useState(false),[le,we]=useState(false),[Qe,ut]=useState("1h"),[Ke,Dt]=useState(30),[At,mt]=useState("minutes"),Be=null,lr=false,cr=null,Nt;try{let k=tn();Be={kalshiUsdcBalance:k.kalshiUsdcBalance,polymarketUsdcBalance:k.polymarketUsdcBalance,isLoading:k.isLoading},lr=k.kalshiKycVerified,cr=k.kalshiKycUrl,Nt=k.polymarketSafeAddress;}catch{}let Ne=useMemo(()=>{let k=P==="yes"?0:1,q=e.outcomes[k];return b==="buy"?q?.best_ask??q?.price??.5:q?.best_bid??q?.price??.5},[e.outcomes,P,b]),Kr=useCallback(k=>{ae(k);},[]),Ft=useCallback(k=>{x(k),H(NaN);},[]);useEffect(()=>{z==="limit"&&isNaN(I)&&H(Math.round(Ne*100)/100);},[z,I,Ne]);let Vr=useMemo(()=>isNaN(D)||D<=0?0:b==="buy"?Ne>0?D/Ne:0:D,[b,D,Ne]),E=useMemo(()=>isNaN(D)||D<=0?"0":String(Math.round(D*1e6)),[D]),Ce=e.provider_meta?.["dflow.yesMint"]??"",Xe=e.provider_meta?.["dflow.noMint"]??"",ft=SOLANA_TOKENS.stablecoins.USDC.address,oa=e.provider_meta?.["dflow.collateralMint"]||"",Qn=P==="yes"?Ce:Xe,Xn=p==="kalshi"?g??"":h??"",{data:Ae,isLoading:ia}=usePositions({source:p,user:Xn},{enabled:!!Xn}),Zn=useMemo(()=>!Ae||b!=="sell"?null:Ae.positions.find(k=>k.side?.toLowerCase()===P&&k.market?.slug===e.slug)??null,[Ae,e.slug,P,b])?.market?.provider_meta,sa=b==="sell"&&Zn?.["dflow.outcomeMint"]||Qn,Bt=b==="sell"&&Zn?.["dflow.collateralMint"]||oa,Ht=b==="buy"?ft:sa,zt=b==="buy"?Qn:Bt||ft,aa=p==="kalshi"&&!!Ht&&!!zt&&!!g&&E!=="0",{refetch:Jn}=useDFlowQuote({inputMint:Ht,outputMint:zt,amount:E,userPublicKey:g??"",slippageBps:100},{enabled:aa}),dr=useMemo(()=>Be?p==="kalshi"?Be.kalshiUsdcBalance:Be.polymarketUsdcBalance:Ae&&Ae.positions.reduce((q,Me)=>Me.side==="USDC"||Me.side==="collateral"?q+(Me.current_value??0):q,0)||null,[Be,Ae,p]),la=Be?Be.isLoading:ia,jr=useMemo(()=>Ae?Ae.positions.find(q=>q.side?.toLowerCase()==="yes"&&q.market?.slug===e.slug)?.size??0:null,[Ae,e.slug]),Yr=useMemo(()=>Ae?Ae.positions.find(q=>q.side?.toLowerCase()==="no"&&q.market?.slug===e.slug)?.size??0:null,[Ae,e.slug]),Gr=useMemo(()=>z==="limit"&&u&&!isNaN(I)?I:Ne,[z,u,I,Ne]),pr=useMemo(()=>{if(isNaN(D)||D<=0)return 0;if(b==="buy")return D;let k=P==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return D*k},[b,P,D,e.outcomes]),eo=useMemo(()=>isNaN(D)||D<=0?0:b==="buy"?Gr>0?D/Gr*1:0:pr,[b,D,Gr,pr]),ca=eo-pr,da=useCallback(k=>{T(k),ve(NaN);},[]),pa=useCallback(k=>{if(isNaN(k)){ve(NaN);return}let q=Math.max(0,k),Me=b==="buy"?Math.round(q*100)/100:Math.round(q);ve(Me);},[b]),ua=useCallback(k=>{if(isNaN(k)){H(NaN);return}let q=Math.max(.01,Math.min(.99,k));H(Math.round(q*100)/100);},[]),$t=useCallback(()=>{ve(NaN),H(NaN),ae("market"),we(false),ut("1h"),Dt(30),mt("minutes");},[]),qr=useMemo(()=>{let k=[];isNaN(D)||D<=0?b==="buy"?k.push(n("predict.trade.minAmountUsd",{amount:xr})):k.push(n("predict.trade.minQuantity",{amount:vr})):b==="buy"&&D<xr?k.push(n("predict.trade.minAmountUsd",{amount:xr})):b==="sell"&&D<vr&&k.push(n("predict.trade.minQuantity",{amount:vr})),e.status!=="open"&&k.push(n("predict.trade.marketNotActive")),b==="buy"&&dr!=null&&!isNaN(D)&&D>0&&D>dr&&k.push(n("predict.trade.insufficientBalance"));let q=P==="yes"?jr:Yr;return b==="sell"&&q!=null&&!isNaN(D)&&D>0&&D>q&&k.push(n("predict.trade.insufficientShares")),z==="limit"&&u&&(isNaN(I)||I<.01||I>.99)&&k.push(n("predict.trade.limitPriceRange")),z==="limit"&&u&&le&&Qe==="custom"&&(isNaN(Ke)||Ke<=0)&&k.push(n("predict.trade.expiration.invalidDate")),{isValid:k.length===0,errors:k}},[D,e.status,b,p,dr,jr,Yr,P,z,u,I,le,Qe,Ke,n]),{mutateAsync:ur}=useDFlowSubmit(),{data:Qr}=useOrder({id:ie??"",source:p},{enabled:!!ie}),to=useCallback(async()=>{if(!_||!g||!m)return;let{cashAmount:k,collateral:q}=_;G(null);try{let gt=(await l.createDFlowQuote({inputMint:q,outputMint:ft,amount:k,userPublicKey:g,slippageBps:100}))?.transaction;if(!gt)return;let it=Uint8Array.from(atob(gt),Wt=>Wt.charCodeAt(0)),Ze=await m.signTransaction(it);await ur({signedTransaction:btoa(String.fromCharCode(...Ze)),orderContext:{user_public_key:g,input_mint:q,output_mint:ft,amount:k,price:"1",side:"SELL",outcome:"",market_slug:"",slippage_bps:100}});}catch{}},[_,g,m,l,ur,ft]);useEffect(()=>{if(!Qr||!ie)return;let{status:k}=Qr;k==="closed"?(M(null),_?to().finally(()=>{J(false),toast.success(n("predict.trade.submitSuccess")),nn(),$t();}):(J(false),toast.success(n("predict.trade.submitSuccess")),nn(),$t())):(k==="failed"||k==="expired")&&(J(false),M(null),G(null),toast.error(n("predict.trade.submitError")));},[Qr,ie,_,to,$t,n]);let ro=useCallback(async()=>{if(!g||!m)return;if(!Ht||!zt){toast.error("Missing token mint addresses"),J(false);return}if(!lr){pe(true),J(false);return}let Me=(await Jn()).data,gt=Me?.transaction;if(!gt){toast.error(n("predict.trade.submitError")),J(false);return}if(b==="sell"&&Bt&&Bt!==ft){let st=String(Me?.outAmount??"");st&&st!=="0"&&G({cashAmount:st,collateral:Bt});}let it=Uint8Array.from(atob(gt),st=>st.charCodeAt(0)),Ze=await m.signTransaction(it),Wt=await ur({signedTransaction:btoa(String.fromCharCode(...Ze)),orderContext:{user_public_key:g,input_mint:Ht,output_mint:zt,amount:E,price:String(Ne),side:b==="buy"?"BUY":"SELL",outcome:P==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}});M(Wt.signature);},[g,m,l,Jn,ur,Ht,zt,E,Ne,b,P,e.slug,Bt,ft,n]),no=useCallback(async()=>{if(!c||!a)return;let k=c.chain,q=k!==Chain.POLYGON;q&&await s(Chain.POLYGON);try{let Me=await c.getEip1193Provider();if(!Me){toast.error(n("predict.trade.submitError")),J(!1);return}let gt=!!Nt,it={address:c.address,signatureType:gt?2:0,signTypedData:async(ht,ka,Sa,wa)=>{let Ct=[];"name"in ht&&Ct.push({name:"name",type:"string"}),"version"in ht&&Ct.push({name:"version",type:"string"}),"chainId"in ht&&Ct.push({name:"chainId",type:"uint256"}),"verifyingContract"in ht&&Ct.push({name:"verifyingContract",type:"address"}),"salt"in ht&&Ct.push({name:"salt",type:"bytes32"});let Pa={EIP712Domain:Ct,...ka};return await Me.request({method:"eth_signTypedData_v4",params:[c.address,JSON.stringify({domain:ht,types:Pa,primaryType:Sa,message:wa})]})}},Ze=a.credentials??await a.authenticate(it),Wt=P==="yes"?0:1,st="",mr=e.provider_meta?.["polymarket.clobTokenIds"];mr&&(st=(typeof mr=="string"?JSON.parse(mr):mr)[Wt]??"");let oo=e.provider_meta?.["polymarket.negRisk"]??!1,Xr=z==="limit"&&!isNaN(I)?I:Ne,fa=z==="limit"?le?"GTD":"GTC":"FOK",ga=b==="buy"&&Xr>0?D/Xr:D,io={tokenId:st,price:Xr,size:ga,side:b==="buy"?"BUY":"SELL",orderType:fa,tickSize:C,negRisk:oo,...Nt&&{funderAddress:Nt},...z==="limit"&&le&&{expiration:cl(Qe,Ke,At)}},ha=buildCtfExchangeDomain(oo),so=buildOrderMessage({...io,signerAddress:it.address,signatureType:it.signatureType}),va=await it.signTypedData(ha,CTF_ORDER_TYPES,"Order",so),xa=buildSignedOrder(so,va,io.orderType),ao=buildClobPayload(xa,Ze.apiKey),ba=JSON.stringify(ao),ya=await buildPolymarketL2Headers(Ze.address,{apiKey:Ze.apiKey,secret:Ze.secret,passphrase:Ze.passphrase,method:"POST",requestPath:"/order",body:ba});await l.createPolymarketOrder(ao,ya),d.invalidateQueries({queryKey:["predict","orders"]}),d.invalidateQueries({queryKey:["predict","positions"]}),toast.success(n("predict.trade.submitSuccess")),nn(),$t(),J(!1);}finally{q&&k&&s(k).catch(()=>{});}},[c,a,s,P,e.provider_meta,z,I,Ne,D,b,l,d,le,Qe,Ke,At,$t,n]),ma=useCallback(async()=>{if(!(!qr.isValid||!f)){J(true),M(null),pe(false);try{p==="kalshi"?await ro():await no();}catch(k){let q=k instanceof Error?k.message:void 0;toast.error(q||n("predict.trade.submitError")),J(false);}}},[qr.isValid,f,p,ro,no,n]);return {outcome:P,side:b,orderType:z,quantity:D,limitPrice:I,shares:Vr,estimatedCost:pr,potentialPayout:eo,potentialProfit:ca,usdcBalance:dr,yesTokenBalance:jr,noTokenBalance:Yr,isBalanceLoading:la,isSubmitting:$,validation:qr,supportsLimitOrder:u,kycRequired:A,kycUrl:cr,expirationEnabled:le,expirationPreset:Qe,customDuration:Ke,customDurationUnit:At,setOutcome:Ft,setSide:da,setOrderType:Kr,setQuantity:pa,setLimitPrice:ua,setExpirationEnabled:we,setExpirationPreset:ut,setCustomDuration:Dt,setCustomDurationUnit:mt,submit:ma}}function No({isOpen:e,onClose:t,kycUrl:r}){let{t:n}=useTranslation();return jsx(StyledModal,{isOpen:e,onOpenChange:o=>{o||t();},size:"md",classNames:{base:"!bg-[#18181b] !rounded-[14px] !border !border-[rgba(39,39,42,1)] !shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)]",body:"!p-0"},children:jsx(ModalContent,{children:jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-4",children:[jsx("h3",{className:"text-base font-semibold text-white",children:n("predict.trade.kycModalTitle")}),jsx("button",{type:"button",onClick:t,className:"p-1 rounded-[10px] hover:bg-[rgba(39,39,42,0.5)] text-zinc-400 hover:text-white transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:jsxs("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),jsxs("div",{className:"px-5 pb-5",children:[jsx("p",{className:"text-[13px] text-zinc-400 mb-4 text-left",children:n("predict.trade.kycModalDescription")}),jsx("div",{className:"flex flex-col gap-2 mb-4",children:["predict.trade.kycModalBullet1","predict.trade.kycModalBullet2","predict.trade.kycModalBullet3"].map(o=>jsxs("div",{className:"flex items-center gap-2.5 text-[13px] text-zinc-300",children:[jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#c7ff2e] shrink-0",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),jsx("span",{children:n(o)})]},o))}),r&&jsxs("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[13px] text-[#c7ff2e]/70 hover:text-[#c7ff2e] transition-colors mb-3",children:[n("predict.trade.goToKYC")," \u2192"]}),jsx("p",{className:"text-[11px] text-zinc-500 mb-5",children:n("predict.trade.kycModalNote")}),jsx("button",{type:"button",onClick:t,className:"w-full py-2.5 rounded-[10px] bg-[#c7ff2e] text-zinc-900 text-sm font-semibold hover:bg-[#c7ff2e]/90 transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:n("common.ok")})]})]})})})}var Pl=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`,Nl=["5m","1h","12h","24h","eod","custom"],Cl={"5m":"predict.trade.expiration.5m","1h":"predict.trade.expiration.1h","12h":"predict.trade.expiration.12h","24h":"predict.trade.expiration.24h",eod:"predict.trade.expiration.eod",custom:"predict.trade.expiration.custom"},Ml=["minutes","hours","days"],El={minutes:"predict.trade.expiration.minutes",hours:"predict.trade.expiration.hours",days:"predict.trade.expiration.days"};function Ro({event:e,market:t,variant:r="bordered",outcome:n,side:o,orderType:i,quantity:s,limitPrice:l,shares:a,potentialProfit:d,potentialPayout:p,estimatedCost:u,usdcBalance:m,yesTokenBalance:c,noTokenBalance:f,isBalanceLoading:g,isSubmitting:h,isValid:v,validationErrors:S,supportsLimitOrder:C,kycRequired:P,kycUrl:x,expirationEnabled:b,expirationPreset:T,customDuration:z,customDurationUnit:ae,onOutcomeChange:D,onSideChange:ve,onOrderTypeChange:I,onQuantityChange:H,onLimitPriceChange:$,onExpirationEnabledChange:J,onExpirationPresetChange:ie,onCustomDurationChange:M,onCustomDurationUnitChange:_,onSubmit:G}){let{t:A}=useTranslation(),[pe,le]=useState(false),we=useDisclosure(),[Qe,ut]=useState(""),Ke=useRef(false),Dt=useRef(o);useEffect(()=>{Ke.current||ut(isNaN(s)?"":String(s));},[s]),useEffect(()=>{o!==Dt.current&&(Dt.current=o,ut(""));},[o]);let At=useCallback(E=>{if(E!==""&&!(o==="buy"?/^\d*\.?\d{0,2}$/:/^\d*$/).test(E))return;if(ut(E),Ft(false),E===""||E==="."){H(NaN);return}let Xe=parseFloat(E);isNaN(Xe)||H(Xe);},[o,H]);useEffect(()=>{P&&!we.isOpen&&we.onOpen();},[P]);let mt=useMemo(()=>{let E=o==="buy"?n==="yes"?t.yesAsk:t.noAsk:n==="yes"?t.yesBid:t.noBid;return E!=null?parseFloat((Number(E)*100).toFixed(2)):null},[o,n,t]),Be=!isNaN(s)&&s>0,lr=useMemo(()=>{if(g)return A("predict.trade.loadingBalance");if(h)return A("predict.trade.submitting");if(P)return A("predict.trade.kycRequired");if(!Be)return A("predict.trade.enterAmount");let E=A(o==="buy"?"predict.trade.buy":"predict.trade.sell"),Ce=A(n==="yes"?"predict.trade.yes":"predict.trade.no"),Xe=o==="buy"&&d>0?` \u2192 Win $${d.toFixed(2)}`:"";return `${E} ${Ce}${Xe}`},[g,h,P,Be,o,n,d,A]),cr=useMemo(()=>n==="yes"?"primary":"secondary",[n]),Nt=()=>{H(Math.floor((m??0)/2*100)/100);},Ne=()=>{H(m??0);},[Kr,Ft]=useState(false),Vr=()=>{if(P){we.onOpen();return}if(!v){Ft(true);return}Ft(false),G();};return jsxs(Fragment,{children:[jsxs("div",{className:"flex w-full flex-col gap-y-4 p-4",style:r==="bordered"?{borderRadius:14,border:"1px solid rgba(39,39,42,0.6)",background:"rgba(24,24,27,0.4)",transition:"border-color 0.2s"}:void 0,onMouseEnter:E=>{r==="bordered"&&(E.currentTarget.style.borderColor="rgba(63,63,70,0.8)");},onMouseLeave:E=>{r==="bordered"&&(E.currentTarget.style.borderColor="rgba(39,39,42,0.6)");},children:[e&&jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxs("span",{className:n==="yes"?"text-bullish":"text-bearish",children:[A(o==="buy"?"predict.trade.buy":"predict.trade.sell")," ",A(n==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxs("span",{className:"text-foreground",children:[" \xB7 ",t.yesSubTitle]})]})]})]}),jsxs("div",{className:"flex items-center justify-between",children:[C?jsxs(Tabs,{variant:"underlined",selectedKey:i,onSelectionChange:E=>I(E),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:A("predict.trade.market")},"market"),jsx(Tab,{title:A("predict.trade.limit")},"limit")]}):jsx("span",{className:"text-sm font-medium text-foreground",children:A("predict.trade.market")}),i==="limit"&&C?jsx(StyledNumberInput,{"aria-label":"Limit price",placeholder:"50",size:"sm",radius:"none",value:isNaN(l)?void 0:parseFloat((l*100).toFixed(2)),onValueChange:E=>$(E/100),minValue:1,maxValue:99,step:1,formatOptions:{maximumFractionDigits:2},endContent:jsx("span",{className:"text-xl font-bold tabular-nums text-foreground",children:"\xA2"}),classNames:{base:"w-28",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 rounded-lg px-2 h-9 min-h-9",input:"text-xl font-bold tabular-nums text-right"}}):mt!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[mt," \xA2"]})]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(E=>{let Ce=E==="yes"?c:f;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>D(E),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${n===E?E==="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:[jsx("span",{children:A(E==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let Xe=o==="buy"?E==="yes"?t.yesAsk:t.noAsk:E==="yes"?t.yesBid:t.noBid;return Xe!=null?jsxs("span",{className:"ml-1 opacity-70",children:[parseFloat((Number(Xe)*100).toFixed(2)),"\xA2"]}):null})()]}),o==="sell"&&n===E&&jsx("span",{className:"text-center text-xs text-foreground",children:g?"\u2013":`${Ce??0} shares`})]},E)})}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:A(o==="buy"?"predict.trade.youArePaying":"predict.trade.contracts")}),o==="buy"&&jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:Pl,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:m!=null?`${m.toFixed(2)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:Nt,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:A("predict.trade.half")}),jsx("button",{type:"button",onClick:Ne,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:A("predict.trade.max")})]})]}),jsx(StyledInput,{"aria-label":"Trade amount",fullWidth:true,placeholder:"0",radius:"lg",size:"lg",inputMode:o==="buy"?"decimal":"numeric",value:Qe,onChange:E=>At(E.target.value),onFocus:()=>{Ke.current=true;},onBlur:()=>{Ke.current=false,ut(isNaN(s)?"":String(s));},startContent:o==="buy"?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"}}),o==="sell"&&jsxs("div",{className:"flex gap-x-2 justify-end",children:[[25,50].map(E=>jsxs("button",{type:"button",onClick:()=>{H(Math.floor((n==="yes"?c??0:f??0)*E/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:[E,"%"]},E)),jsx("button",{type:"button",onClick:()=>{H(n==="yes"?c??0:f??0);},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:A("common.all")})]}),Kr&&S.length>0&&jsx("div",{className:"flex flex-col gap-y-0.5",children:S.map(E=>jsx("span",{className:"text-xs text-danger",children:E},E))})]}),i==="limit"&&C&&jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-sm font-medium text-primary",children:A("predict.trade.setExpiration")}),jsx(StyledSwitch,{size:"sm",color:"primary",isSelected:b,onValueChange:J,"aria-label":A("predict.trade.setExpiration")})]}),b&&jsxs(Fragment,{children:[jsx(Select,{"aria-label":A("predict.trade.setExpiration"),selectedKeys:[T],onSelectionChange:E=>{let Ce=Array.from(E)[0];Ce&&ie(Ce);},size:"sm",radius:"lg",classNames:{trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:Nl.map(E=>jsx(SelectItem,{children:A(Cl[E])},E))}),T==="custom"&&jsxs("div",{className:"flex gap-x-2",children:[jsx(StyledNumberInput,{"aria-label":"Duration amount",size:"sm",radius:"lg",value:isNaN(z)?void 0:z,onValueChange:M,minValue:1,step:1,formatOptions:{maximumFractionDigits:0},classNames:{base:"flex-1",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 min-h-10",input:"text-sm"}}),jsx(Select,{"aria-label":"Duration unit",selectedKeys:[ae],onSelectionChange:E=>{let Ce=Array.from(E)[0];Ce&&_(Ce);},size:"sm",radius:"lg",classNames:{base:"w-32",trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:Ml.map(E=>jsx(SelectItem,{children:A(El[E])},E))})]})]})]}),jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between text-sm",children:[jsxs("button",{type:"button",onClick:()=>le(E=>!E),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:A("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",pe&&"rotate-180")})]}),mt!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[mt,"% chance"]})]}),pe&&jsxs("div",{className:"flex flex-col gap-y-1.5 border-l-2 border-default-300 pl-3 text-sm text-neutral-500",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Total Size"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${u.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"No. of Contracts"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(a)&&a>0?parseFloat(a.toFixed(2)):"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Payout"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${p.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Est. Profit"}),jsx("span",{className:"tabular-nums text-bullish",children:!isNaN(s)&&s>0&&d>0?`+$${d.toFixed(2)}`:"\u2013"})]})]})]}),jsx(Button,{color:cr,fullWidth:true,radius:"lg",size:"lg",isDisabled:g||!Be||h,isLoading:h||g,spinner:jsx(Spinner,{size:"sm",color:"current"}),onPress:Vr,children:lr})]}),jsx(No,{isOpen:we.isOpen,onClose:we.onClose,kycUrl:x})]})}function br({event:e,market:t,variant:r,initialSide:n,initialOutcome:o,chain:i}){let{outcome:s,side:l,orderType:a,quantity:d,limitPrice:p,shares:u,estimatedCost:m,potentialPayout:c,potentialProfit:f,usdcBalance:g,yesTokenBalance:h,noTokenBalance:v,isBalanceLoading:S,isSubmitting:C,validation:P,supportsLimitOrder:x,kycRequired:b,kycUrl:T,expirationEnabled:z,expirationPreset:ae,customDuration:D,customDurationUnit:ve,setOutcome:I,setSide:H,setOrderType:$,setQuantity:J,setLimitPrice:ie,setExpirationEnabled:M,setExpirationPreset:_,setCustomDuration:G,setCustomDurationUnit:A,submit:pe}=Po({market:t,initialSide:n,initialOutcome:o}),le=useAuthCallback(pe),we=useMemo(()=>e?ho(e):void 0,[e]),Qe=useMemo(()=>vo(t),[t]);return jsx(Ro,{event:we,market:Qe,variant:r,outcome:s,side:l,orderType:a,quantity:d,limitPrice:p,shares:u,estimatedCost:m,potentialPayout:c,potentialProfit:f,usdcBalance:g,yesTokenBalance:h,noTokenBalance:v,isBalanceLoading:S,isSubmitting:C,isValid:P.isValid,validationErrors:P.errors,supportsLimitOrder:x,kycRequired:b,kycUrl:T,expirationEnabled:z,expirationPreset:ae,customDuration:D,customDurationUnit:ve,onOutcomeChange:I,onSideChange:H,onOrderTypeChange:$,onQuantityChange:J,onLimitPriceChange:ie,onExpirationEnabledChange:M,onExpirationPresetChange:_,onCustomDurationChange:G,onCustomDurationUnitChange:A,onSubmit:le})}var Kt="predict-trade";function yr({id:e=Kt}){return jsx(AsyncModal,{id:e,children:t=>jsx(Al,{...t})})}function Al({params:e,isOpen:t,onOpenChange:r}){let{t:n}=useTranslation(),{isMobile:o}=useScreen();return e?jsx(StyledModal,{isOpen:t,onOpenChange:r,size:o?"lg":"md",backdrop:"blur",hideCloseButton:true,classNames:{base:"!bg-[#18181b] !rounded-[14px] !border !border-[rgba(39,39,42,1)] !shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)]",body:"!p-0"},children:jsx(ModalContent,{children:jsxs("div",{className:o?"":"p-2",children:[jsx(br,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:e.initialSide??"buy",chain:e.chain,variant:"flat"}),jsx("div",{className:"px-4 pb-4",children:jsx("button",{type:"button",onClick:()=>r(false),className:"w-full h-12 rounded-xl text-sm font-medium text-zinc-400 hover:text-white hover:bg-[rgba(39,39,42,0.5)] transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:n("common.cancel")})})]})})}):null}var ln={sortPreset:"volume",sortAsc:false,source:void 0,timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function cn(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function Oo({isOpen:e,onClose:t,value:r,onChange:n}){let{t:o}=useTranslation(),[i,s]=useState(r),l=useCallback(h=>{h?s(r):t();},[r,t]),a=useCallback(()=>{s(ln);},[]),d=useCallback(()=>{n(i),t();},[i,n,t]),p=useCallback((h,v)=>{s(S=>({...S,[h]:v}));},[]),u=useMemo(()=>cn(i),[i]),m=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"polymarket",label:o("predict.platform.polymarket")},{value:"kalshi",label:o("predict.platform.kalshi")}],[o]),c=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"1d",label:o("predict.filter.lessThanDay")},{value:"7d",label:o("predict.filter.lessThanWeek")},{value:"30d",label:o("predict.filter.lessThanMonth")}],[o]),f=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[o]),g=useMemo(()=>[{value:void 0,label:o("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[o]);return jsx(StyledModal,{isOpen:e,onOpenChange:l,size:"md",backdrop:"blur",scrollBehavior:"inside",classNames:{base:"!bg-[#18181b] !rounded-[14px] !border !border-[rgba(39,39,42,1)] !shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)]",body:"!p-0"},children:jsx(ModalContent,{children:jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-4",children:[jsx("h3",{className:"text-base font-semibold text-white",children:o("predict.filter.title")}),jsx(Wl,{onClick:()=>l(false)})]}),jsxs("div",{style:{padding:"0 20px 16px",display:"flex",flexDirection:"column",gap:20},children:[jsx(Sr,{label:o("predict.filter.platform"),children:jsx(wr,{options:m,selected:i.source,onSelect:h=>p("source",h)})}),jsx(Sr,{label:o("predict.filter.timeRemaining"),children:jsx(wr,{options:c,selected:i.timeRemaining,onSelect:h=>p("timeRemaining",h)})}),jsx(Sr,{label:o("predict.filter.minVolume"),children:jsx(wr,{options:f,selected:i.minVolume,onSelect:h=>p("minVolume",h)})}),jsx(Sr,{label:o("predict.filter.minLiquidity"),children:jsx(wr,{options:g,selected:i.minLiquidity,onSelect:h=>p("minLiquidity",h)})})]}),jsxs("div",{className:"flex items-center gap-3 px-5 py-4",style:{borderTop:"1px solid rgba(39,39,42,0.5)"},children:[jsx("button",{type:"button",className:"inline-flex items-center justify-center py-2.5 px-5 rounded-[10px] text-zinc-400 text-sm font-medium hover:text-white transition-colors cursor-pointer",onClick:a,children:o("predict.filter.reset")}),jsxs("button",{type:"button",className:"flex-1 inline-flex items-center justify-center gap-2 py-2.5 rounded-[10px] bg-[#c7ff2e] text-zinc-900 text-sm font-semibold hover:bg-[#c7ff2e]/90 transition-colors cursor-pointer",onClick:d,children:[o("predict.filter.showResults"),u>0&&jsxs("span",{style:{opacity:.7},children:["(",u,")"]})]})]})]})})})}function Sr({label:e,children:t}){return jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[jsx("span",{style:{fontSize:11,fontWeight:500,color:"#71717a",textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t]})}function Wl({onClick:e}){return jsx("button",{type:"button",onClick:e,className:"p-1 rounded-[10px] hover:bg-[rgba(39,39,42,0.5)] text-zinc-400 hover:text-white transition-colors cursor-pointer focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",children:jsxs("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}function wr({options:e,selected:t,onSelect:r,allowDeselect:n=true}){return jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:e.map(o=>{let i=t===o.value;return jsx("button",{type:"button",onClick:()=>{r(i&&n?void 0:o.value);},style:{flexShrink:0,borderRadius:10,padding:"6px 14px",fontSize:13,fontWeight:500,cursor:"pointer",transition:"all 0.15s",border:i?"1px solid rgba(199,255,46,0.3)":"1px solid rgba(63,63,70,0.5)",background:i?"rgba(199,255,46,0.08)":"rgba(39,39,42,0.4)",color:i?"#c7ff2e":"#a1a1aa"},onMouseEnter:s=>{i||(s.currentTarget.style.background="rgba(39,39,42,0.8)",s.currentTarget.style.color="#fff");},onMouseLeave:s=>{i||(s.currentTarget.style.background="rgba(39,39,42,0.4)",s.currentTarget.style.color="#a1a1aa");},children:o.label},o.value??"__all")})})}function Do(e){return e>=1e9?`$${(e/1e9).toFixed(1)}B`:e>=1e6?`$${(e/1e6).toFixed(1)}M`:e>=1e3?`$${(e/1e3).toFixed(1)}K`:`$${e.toFixed(0)}`}var Kl=[{key:"total_events",labelKey:"predict.events.stats.totalEvents",format:e=>e.toLocaleString(),valueColor:"#c7ff2e",gradientFrom:"rgba(199,255,46,0.18)",gradientTo:"rgba(199,255,46,0.04)"},{key:"total_volume_24h",labelKey:"predict.events.stats.volume24h",format:Do,valueColor:"#f76816",gradientFrom:"rgba(247,104,22,0.18)",gradientTo:"rgba(247,104,22,0.04)"},{key:"avg_liquidity",labelKey:"predict.events.stats.avgLiquidity",format:Do,valueColor:"#17c964",gradientFrom:"rgba(23,201,100,0.18)",gradientTo:"rgba(23,201,100,0.04)"},{key:"active_sources",labelKey:"predict.events.stats.activeSources",format:e=>e.toLocaleString(),valueColor:"#f5a524",gradientFrom:"rgba(245,165,36,0.18)",gradientTo:"rgba(245,165,36,0.04)"}];function Ao({stats:e}){let{t}=useTranslation();return jsxs(Fragment,{children:[jsx("style",{children:`
|
|
2
2
|
@keyframes evt-live-ping{75%,100%{transform:scale(2.2);opacity:0}}
|
|
3
3
|
@keyframes evt-live-breathe{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.55;transform:scale(.85)}}
|
|
4
4
|
@keyframes evtHeroTitleEnter{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}
|
|
@@ -52,7 +52,7 @@ import {createContext,memo,useRef,forwardRef,useState,useImperativeHandle,useMem
|
|
|
52
52
|
.evt-skel-hero-wrap{padding:40px 16px 32px}
|
|
53
53
|
@media(min-width:640px){.evt-skel-hero-wrap{padding:48px 24px 40px}}
|
|
54
54
|
@media(min-width:1024px){.evt-skel-hero-wrap{padding:52px 32px 44px}}
|
|
55
|
-
`,Yo={background:"linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%)",backgroundSize:"200% 100%",animation:"evtShimmer 1.8s ease-in-out infinite",borderRadius:6};function He(e){return {...Yo,animationDelay:`${e}ms`}}function dn({count:e=6}){return jsxs(Fragment,{children:[jsx("style",{children:jo}),jsx("div",{className:"evt-skel-grid",style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",width:"100%"},children:Array.from({length:e}).map((t,r)=>jsx(ac,{index:r},r))})]})}function ac({index:e}){let t=e*120,r={...Yo,animationDelay:`${t}ms`},n=e%3===0?"85%":e%3===1?"70%":"60%";return jsx("div",{style:{padding:8},children:jsxs("div",{className:"evt-skel-card",style:{display:"flex",flexDirection:"column",minHeight:248,borderRadius:14,border:"1px solid rgba(39,39,42,0.6)",background:"rgba(24,24,27,0.4)",overflow:"hidden"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 14px 8px"},children:[jsx("div",{style:{...r,width:36,height:36,borderRadius:10,flexShrink:0}}),jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[jsx("div",{style:{...r,height:12,width:n}}),jsx("div",{style:{...r,height:10,width:"40%"}})]})]}),jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"4px 14px 14px",flex:1},children:[0,1,2].map(o=>jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[jsx("div",{style:{...r,height:11,width:o===0?"55%":o===1?"45%":"35%"}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[jsx("div",{style:{...r,height:11,width:32}}),jsx("div",{style:{...r,height:28,width:80,borderRadius:8}})]})]},o))}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid rgba(39,39,42,0.5)",background:"rgba(39,39,42,0.15)",padding:"8px 14px"},children:[jsx("div",{style:{...r,height:10,width:56}}),jsx("div",{style:{...r,height:10,width:72}})]})]})})}function lc(){return jsxs("div",{style:{position:"relative",overflow:"hidden",borderBottom:"1px solid rgba(39,39,42,0.5)",width:"100vw",marginLeft:"calc(-50vw + 50%)"},children:[jsx("div",{style:{position:"absolute",inset:0,opacity:.025,backgroundImage:"radial-gradient(circle at 1px 1px, rgb(255 255 255) 1px, transparent 0)",backgroundSize:"20px 20px",pointerEvents:"none"}}),jsx("div",{className:"evt-skel-hero-wrap",style:{position:"relative",zIndex:1,maxWidth:1152,margin:"0 auto"},children:jsxs("div",{className:"evt-skel-hero-outer",children:[jsxs("div",{className:"evt-skel-hero-left",style:{minWidth:0,flex:1,gap:16},children:[jsx("div",{style:{...He(0),width:120,height:28,borderRadius:9999}}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[jsx("div",{style:{...He(50),width:280,height:28,borderRadius:8}}),jsx("div",{style:{...He(80),width:200,height:28,borderRadius:8}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("div",{style:{...He(120),height:14,width:360,maxWidth:"100%"}}),jsx("div",{style:{...He(150),height:14,width:300,maxWidth:"100%"}})]})]}),jsx("div",{className:"evt-skel-stat-grid",children:[0,1,2,3].map(e=>jsxs("div",{style:{padding:"14px 16px",background:"rgba(255,255,255,0.02)",borderRight:e%2===0?"1px solid rgba(39,39,42,0.4)":"none",borderBottom:e<2?"1px solid rgba(39,39,42,0.4)":"none"},children:[jsx("div",{style:{...He(200+e*60),height:22,width:56,borderRadius:4}}),jsx("div",{style:{...He(230+e*60),height:14,width:64,borderRadius:4,marginTop:4}})]},e))})]})})]})}function cc(){return jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",borderBottom:"1px solid rgba(39,39,42,0.3)",background:"rgba(10,10,11,0.8)"},children:[jsx("div",{style:{display:"flex",alignItems:"center",gap:10,minHeight:40,flex:1},children:[48,64,48,56,72,56].map((e,t)=>jsx("div",{style:{...He(t*50),height:28,width:e,borderRadius:6}},t))}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[jsx("div",{style:{...He(0),height:36,width:120,borderRadius:10}}),jsx("div",{style:{...He(50),height:36,width:36,borderRadius:10}}),jsx("div",{style:{...He(100),height:36,width:80,borderRadius:10}})]})]})}function r0({count:e=
|
|
55
|
+
`,Yo={background:"linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%)",backgroundSize:"200% 100%",animation:"evtShimmer 1.8s ease-in-out infinite",borderRadius:6};function He(e){return {...Yo,animationDelay:`${e}ms`}}function dn({count:e=6}){return jsxs(Fragment,{children:[jsx("style",{children:jo}),jsx("div",{className:"evt-skel-grid",style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",width:"100%"},children:Array.from({length:e}).map((t,r)=>jsx(ac,{index:r},r))})]})}function ac({index:e}){let t=e*120,r={...Yo,animationDelay:`${t}ms`},n=e%3===0?"85%":e%3===1?"70%":"60%";return jsx("div",{style:{padding:8},children:jsxs("div",{className:"evt-skel-card",style:{display:"flex",flexDirection:"column",minHeight:248,borderRadius:14,border:"1px solid rgba(39,39,42,0.6)",background:"rgba(24,24,27,0.4)",overflow:"hidden"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 14px 8px"},children:[jsx("div",{style:{...r,width:36,height:36,borderRadius:10,flexShrink:0}}),jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[jsx("div",{style:{...r,height:12,width:n}}),jsx("div",{style:{...r,height:10,width:"40%"}})]})]}),jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"4px 14px 14px",flex:1},children:[0,1,2].map(o=>jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[jsx("div",{style:{...r,height:11,width:o===0?"55%":o===1?"45%":"35%"}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[jsx("div",{style:{...r,height:11,width:32}}),jsx("div",{style:{...r,height:28,width:80,borderRadius:8}})]})]},o))}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid rgba(39,39,42,0.5)",background:"rgba(39,39,42,0.15)",padding:"8px 14px"},children:[jsx("div",{style:{...r,height:10,width:56}}),jsx("div",{style:{...r,height:10,width:72}})]})]})})}function lc(){return jsxs("div",{style:{position:"relative",overflow:"hidden",borderBottom:"1px solid rgba(39,39,42,0.5)",width:"100vw",marginLeft:"calc(-50vw + 50%)"},children:[jsx("div",{style:{position:"absolute",inset:0,opacity:.025,backgroundImage:"radial-gradient(circle at 1px 1px, rgb(255 255 255) 1px, transparent 0)",backgroundSize:"20px 20px",pointerEvents:"none"}}),jsx("div",{className:"evt-skel-hero-wrap",style:{position:"relative",zIndex:1,maxWidth:1152,margin:"0 auto"},children:jsxs("div",{className:"evt-skel-hero-outer",children:[jsxs("div",{className:"evt-skel-hero-left",style:{minWidth:0,flex:1,gap:16},children:[jsx("div",{style:{...He(0),width:120,height:28,borderRadius:9999}}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[jsx("div",{style:{...He(50),width:280,height:28,borderRadius:8}}),jsx("div",{style:{...He(80),width:200,height:28,borderRadius:8}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("div",{style:{...He(120),height:14,width:360,maxWidth:"100%"}}),jsx("div",{style:{...He(150),height:14,width:300,maxWidth:"100%"}})]})]}),jsx("div",{className:"evt-skel-stat-grid",children:[0,1,2,3].map(e=>jsxs("div",{style:{padding:"14px 16px",background:"rgba(255,255,255,0.02)",borderRight:e%2===0?"1px solid rgba(39,39,42,0.4)":"none",borderBottom:e<2?"1px solid rgba(39,39,42,0.4)":"none"},children:[jsx("div",{style:{...He(200+e*60),height:22,width:56,borderRadius:4}}),jsx("div",{style:{...He(230+e*60),height:14,width:64,borderRadius:4,marginTop:4}})]},e))})]})})]})}function cc(){return jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",borderBottom:"1px solid rgba(39,39,42,0.3)",background:"rgba(10,10,11,0.8)"},children:[jsx("div",{style:{display:"flex",alignItems:"center",gap:10,minHeight:40,flex:1},children:[48,64,48,56,72,56].map((e,t)=>jsx("div",{style:{...He(t*50),height:28,width:e,borderRadius:6}},t))}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[jsx("div",{style:{...He(0),height:36,width:120,borderRadius:10}}),jsx("div",{style:{...He(50),height:36,width:36,borderRadius:10}}),jsx("div",{style:{...He(100),height:36,width:80,borderRadius:10}})]})]})}function r0({count:e=24}){return jsxs("div",{style:{minHeight:"100vh",position:"relative",width:"100%",maxWidth:1680,margin:"0 auto"},children:[jsx("style",{children:jo}),jsx(lc,{}),jsx(cc,{}),jsx("div",{style:{padding:"12px 8px 80px"},children:jsx(dn,{count:e})})]})}var Go=3,xc={polymarket:{border:"rgba(80,162,255,0.4)",shadow:"0 2px 18px rgba(80,162,255,0.45)"},kalshi:{border:"rgba(0,212,146,0.4)",shadow:"0 2px 18px rgba(0,212,146,0.45)"}},bc={border:"hsl(var(--heroui-primary) / 0.4)",shadow:"0 2px 18px hsl(var(--heroui-primary) / 0.45)"},un={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},Jo={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},yc={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},jt=[{bg:"rgba(139,92,246,0.14)",text:"rgb(139,92,246)",shadow:"rgba(139,92,246,0.18)"},{bg:"rgba(34,197,94,0.14)",text:"rgb(34,197,94)",shadow:"rgba(34,197,94,0.18)"},{bg:"rgba(0,166,212,0.14)",text:"rgb(0,166,212)",shadow:"rgba(0,166,212,0.18)"},{bg:"rgba(194,120,32,0.14)",text:"rgb(194,120,32)",shadow:"rgba(194,120,32,0.18)"},{bg:"rgba(202,138,4,0.14)",text:"rgb(202,138,4)",shadow:"rgba(202,138,4,0.18)"},{bg:"rgba(236,72,153,0.14)",text:"rgb(236,72,153)",shadow:"rgba(236,72,153,0.18)"},{bg:"rgba(99,102,241,0.14)",text:"rgb(99,102,241)",shadow:"rgba(99,102,241,0.18)"},{bg:"rgba(244,114,82,0.14)",text:"rgb(244,114,82)",shadow:"rgba(244,114,82,0.18)"}];function qo(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t)}function kc(e){let t=e.outcomes?.map(s=>s.label?.toLowerCase().trim()??"")??[];if(t.some(s=>s==="up")&&t.some(s=>s==="down"))return [un,yc];if(t.some(s=>s==="yes")&&t.some(s=>s==="no"))return [un,Jo];let r=t[0]??"",n=t[1]??"",o=qo(r)%jt.length,i=qo(n)%jt.length;return i===o&&(i=(i+1)%jt.length),[jt[o],jt[i]]}function Sc(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function ei(e){let t=Sc(e);return t!=null?parseFloat((t*100).toFixed(2)):0}function ti(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function Qo(e){let t=e.outcomes?.[0],r=t?.best_ask??t?.price??0;return parseFloat((r*100).toFixed(2)).toString()}function Xo(e){let t=e.outcomes?.[1];if(t){let o=t.best_ask??t.price??0;return parseFloat((o*100).toFixed(2)).toString()}let r=e.outcomes?.[0],n=r?.best_ask??r?.price??0;return parseFloat(((1-n)*100).toFixed(2)).toString()}function wc(e){let t=new Date(e).getTime()-Date.now();if(t<=0)return null;let r=Math.floor(t/864e5),n=Math.floor(t%864e5/36e5),o=Math.floor(t%36e5/6e4),i=[];return r>0&&i.push(`${r}d`),n>0&&i.push(`${n}h`),i.push(`${o}m`),i.join(" ")}var Pc=`
|
|
56
56
|
.badge-shine { position: relative; overflow: hidden; }
|
|
57
57
|
.badge-shine::after {
|
|
58
58
|
content: "";
|
|
@@ -82,7 +82,7 @@ import {createContext,memo,useRef,forwardRef,useState,useImperativeHandle,useMem
|
|
|
82
82
|
@media(max-width:767px){.evt-card-grid{grid-template-columns:1fr!important}}
|
|
83
83
|
@media(min-width:768px) and (max-width:1023px){.evt-card-grid{grid-template-columns:repeat(2,1fr)!important}}
|
|
84
84
|
@media(min-width:1024px) and (max-width:1279px){.evt-card-grid{grid-template-columns:repeat(3,1fr)!important}}
|
|
85
|
-
`}),jsx("div",{className:"evt-card-grid",style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)"},children:e.map((c,f)=>c==null?null:jsx("div",{style:{padding:Uc,animation:`eventCardEnter 0.45s cubic-bezier(0.34,1.56,0.64,1) ${f%4*35}ms both`},children:jsx(ri,{event:c,href:s?.(c),LinkComponent:l,onSelect:o,onSelectOutcome:i,onHover:a})},`${c.source}-${c.slug}`))}),jsx("div",{ref:p,style:{display:"flex",flexDirection:"column",alignItems:"center",gap:8,padding:"16px 0",minHeight:1},children:r&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#71717a",fontSize:13},children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"evt-load-spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),d("predict.events.loadMore")]})}),m&&jsx(Kc,{onScrollToTop:u})]})}function Kc({onScrollToTop:e}){let{t}=useTranslation();return jsxs("div",{className:"flex w-full flex-col items-center justify-center gap-y-4 py-6",children:[jsxs("div",{className:"flex w-full items-center justify-center gap-x-4",children:[jsx("div",{className:"h-px w-16 bg-neutral-700"}),jsx("span",{className:"text-xs font-medium text-neutral-500",children:t("predict.event.endOfList")}),jsx("div",{className:"h-px w-16 bg-neutral-700"})]}),jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-x-1 text-xs font-medium text-neutral-400",onClick:e,children:[jsx("span",{className:"iconify size-4 ph--arrow-up-bold"}),jsx("span",{children:t("predict.event.backToTop")})]})]})}function ci({tagSlugSelection:e,limit:t=48,status:r,sort_by:n,sort_asc:o,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:d,onSelect:p,onSelectOutcome:u,getEventHref:m,LinkComponent:c,onHover:f}){let{data:g,hasMore:h,fetchMore:v,isFetching:S,isFetchingMore:C}=Vo({tagSlugSelection:e,limit:t,status:r,sort_by:n,sort_asc:o,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:d});return S?jsx(dn,{count:48}):jsx(ai,{events:g,hasMore:h,isFetchingMore:C,onFetchMore:v,onSelect:p,onSelectOutcome:u,getEventHref:m,LinkComponent:c,onHover:f})}function _0({onSelect:e,onSelectOutcome:t,getEventHref:r,LinkComponent:n,onHover:o,bgImageSrc:i}){let[s,l]=useState({categorySlug:null,tagSlug:null}),[a,d]=useState(ln),{data:p}=useEventStats(),{isOpen:u,onOpen:m,onClose:c}=useDisclosure(),{onOpen:f}=useAsyncModal(Kt),g=useCallback((T,z,ae)=>{t?.(T,z,ae),f({params:{event:T,market:z,initialOutcome:ae}});},[t,f]),h=useCallback(T=>{l(T);},[]),v=useCallback(T=>{d(z=>({...z,sortPreset:T}));},[]),S=useCallback(T=>{d(z=>({...z,sortAsc:T}));},[]),C=useCallback(T=>{d(T);},[]),P=useMemo(()=>$o[a.sortPreset].sort_by,[a.sortPreset]),x=useMemo(()=>cn(a),[a]),b=useMemo(()=>jsx(Wo,{sortPreset:a.sortPreset,onSortChange:v,sortAsc:a.sortAsc,onSortAscChange:S,onFilterPress:m,filterCount:x}),[a.sortPreset,a.sortAsc,x,v,S,m]);return jsxs("div",{style:{minHeight:"100vh",position:"relative",width:"100%",maxWidth:1680,margin:"0 auto"},children:[jsxs("div",{style:{position:"relative",overflow:"hidden",borderBottom:"1px solid rgba(39,39,42,0.5)",width:"100vw",marginLeft:"calc(-50vw + 50%)"},children:[jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,overflow:"hidden"},children:[i&&jsx("img",{src:i,alt:"","aria-hidden":"true",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"center center",opacity:.3,mixBlendMode:"lighten",maskImage:"linear-gradient(to bottom, black 50%, transparent 100%)",WebkitMaskImage:"linear-gradient(to bottom, black 50%, transparent 100%)"}}),jsx("div",{style:{position:"absolute",inset:0,opacity:.025,backgroundImage:"radial-gradient(circle at 1px 1px, rgb(255 255 255) 1px, transparent 0)",backgroundSize:"20px 20px"}})]}),jsx("style",{children:".evt-hero-wrap{padding:40px 16px 32px}@media(min-width:640px){.evt-hero-wrap{padding:48px 24px 40px}}@media(min-width:1024px){.evt-hero-wrap{padding:52px 32px 44px}}"}),jsx("div",{className:"evt-hero-wrap",style:{position:"relative",zIndex:2,maxWidth:1152,margin:"0 auto"},children:jsx(Ao,{stats:p})})]}),jsx("div",{style:{position:"sticky",top:0,zIndex:40,background:"rgba(10,10,11,0.8)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",borderBottom:"1px solid rgba(39,39,42,0.5)"},children:jsx(go,{onSelect:h,trailing:b})}),jsxs("div",{style:{padding:"12px 8px 80px"},children:[jsx(Oo,{isOpen:u,onClose:c,value:a,onChange:C}),jsx(ci,{tagSlugSelection:s,sort_by:P,sort_asc:a.sortAsc,source:a.source,timeRemaining:a.timeRemaining,minVolume:a.minVolume,minLiquidity:a.minLiquidity,onSelect:e,onSelectOutcome:g,getEventHref:r,LinkComponent:n,onHover:o})]}),jsx(yr,{})]})}var xn=40,Mr=36,Xt=480,bn=Xt-Mr;function mi({event:e,walletAddress:t,onCancelOrder:r}){let{t:n}=useTranslation(),[o,i]=useState("positions"),s=useMemo(()=>e.markets?.map(u=>u.slug)??[],[e.markets]),{data:l}=usePositions({source:e.source,user:t??""}),a=useMemo(()=>!l?.positions||!t?0:s.length===0?l.positions.length:l.positions.filter(u=>u.market&&s.includes(u.market.slug)).length,[l?.positions,s,t]),p=[{key:"positions",label:a>0?`${n("predict.positions.title")} (${a})`:n("predict.positions.title")},{key:"orders",label:n("predict.openOrders.title")},{key:"trades",label:n("predict.tradeHistory.title")}];return jsxs("div",{className:"flex flex-col gap-y-2 mt-6 px-1 lg:px-4",children:[jsx("div",{className:"flex items-center gap-x-1 border-b border-border",children:p.map(u=>jsx("button",{type:"button",onClick:()=>i(u.key),className:cn$1("px-3 py-2 text-sm font-medium transition-colors cursor-pointer",o===u.key?"text-foreground border-b-2 border-primary":"text-neutral hover:text-foreground"),children:u.label},u.key))}),t?jsxs("div",{style:{height:Xt},children:[o==="positions"&&jsx(Jc,{source:e.source,walletAddress:t,marketSlugs:s}),o==="orders"&&jsx(td,{source:e.source,walletAddress:t,marketSlugs:s,onCancelOrder:r}),o==="trades"&&jsx(od,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:Xt},children:n("predict.trade.connectWallet")})]})}function Jc({source:e,walletAddress:t,marketSlugs:r}){let{t:n}=useTranslation(),{data:o,isLoading:i}=usePositions({source:e,user:t}),s=useMemo(()=>o?.positions?r.length===0?o.positions:o.positions.filter(l=>l.market&&r.includes(l.market.slug)):[],[o?.positions,r]);return i?jsx(kn,{}):s.length===0?jsx(yn,{message:n("predict.positions.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Mr},children:[jsx("div",{className:"flex-[3] min-w-0 pr-2 whitespace-nowrap",children:n("predict.positions.event")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.totalSize")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.value")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.avgPrice")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.markPrice")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:n("predict.positions.pnl")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.payoutIfRight")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:n("predict.positions.estSettlement")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:bn},rowComponent:ed,rowCount:s.length,rowHeight:xn,rowProps:{positions:s,closeLabel:n("predict.positions.close")}})]})}function ed({index:e,style:t,positions:r,closeLabel:n}){let o=r[e];if(!o)return null;let i=o.pnl??0,s=o.pnl_percent??0,l=o.avg_price??0,a=o.current_price??0,d=i>0?"text-success":i<0?"text-danger":"text-foreground",p=i>0?"+":"",u=o.market?.outcomes?.[0]?.label??o.market?.question??"\u2014",m=o.side,c=o.size,f=o.size*a,g=o.market?.end_at?ad(o.market.end_at):"\u2014";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 hover:bg-content2/40 transition-colors text-xs lg:text-sm",children:[jsx("div",{className:"flex-[3] min-w-0 pr-2",children:jsxs("div",{className:"flex flex-col gap-y-0.5",children:[jsx("span",{className:"text-foreground truncate font-medium",children:u}),jsx("span",{className:cn$1("text-[10px] font-medium",m.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:m})]})}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:o.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",f.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Nr(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Nr(a)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",d),children:[p,"$",Math.abs(i).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",p,s.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",c.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:g}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",className:"text-xs text-neutral hover:text-foreground cursor-pointer transition-colors rounded px-2 py-0.5 border border-border hover:border-foreground/40",children:n})})]})}function td({source:e,walletAddress:t,marketSlugs:r,onCancelOrder:n}){let{t:o}=useTranslation(),{data:i,isLoading:s,fetchNextPage:l,hasNextPage:a}=useInfiniteOrders({source:e,wallet_address:t}),d=useCancelOrder(),p=useMemo(()=>{let v=i?.pages?.flatMap(P=>P.items)??[],S=new Set(["live","open","submitted","pending"]),C=v.filter(P=>S.has(P.status));return r.length>0&&(C=C.filter(P=>P.market_id&&r.includes(P.market_id))),C},[i?.pages,r]),u=useCallback(v=>{n?n(v.id):d.mutate({source:v.source,id:v.id});},[n,d]),m=p.length,c=m+(a?1:0),f=useCallback(v=>v<m,[m]),g=useCallback(async()=>{await l();},[l]),h=useInfiniteLoader({isRowLoaded:f,loadMoreRows:g,rowCount:c,threshold:5});return s?jsx(kn,{}):p.length===0&&!a?jsx(yn,{message:o("predict.openOrders.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Mr},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:o("predict.openOrders.side")}),jsx("div",{className:"flex-1 pr-2",children:o("predict.openOrders.outcome")}),jsx("div",{className:"flex-1 pr-2",children:o("predict.openOrders.type")}),jsx("div",{className:"flex-1 pr-2 text-right",children:o("predict.openOrders.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:o("predict.openOrders.filled")}),jsx("div",{className:"w-20 shrink-0 pr-2",children:o("predict.openOrders.status")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:bn},onRowsRendered:h,rowComponent:rd,rowCount:c,rowHeight:xn,rowProps:{orders:p,itemCount:m,onCancel:u,isCancelling:d.isPending,cancelLabel:o("predict.openOrders.cancel")}})]})}function rd({index:e,style:t,orders:r,itemCount:n,onCancel:o,isCancelling:i,cancelLabel:s}){if(e>=n)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let l=r[e];if(!l)return null;let a=l.side==="BUY";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",a?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:l.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:l.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:l.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:l.price?Nr(parseFloat(l.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[l.size_matched??"0","/",l.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(nd,{status:l.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>o(l),disabled:i,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:i?jsx(Spinner,{size:"sm"}):s})})]})}function nd({status:e}){return jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium capitalize",{live:"bg-success/10 text-success",open:"bg-success/10 text-success",submitted:"bg-warning/10 text-warning",pending:"bg-warning/10 text-warning",matched:"bg-primary/10 text-primary",cancelled:"bg-neutral/10 text-neutral",failed:"bg-danger/10 text-danger",expired:"bg-neutral/10 text-neutral"}[e]??"bg-neutral/10 text-neutral"),children:e})}function od({source:e,walletAddress:t}){let{t:r}=useTranslation(),{data:n,isLoading:o,fetchNextPage:i,hasNextPage:s}=useInfiniteTrades({source:e,wallet:t,limit:50}),l=useMemo(()=>n?.pages?.flatMap(c=>c.items)??[],[n?.pages]),a=l.length,d=a+(s?1:0),p=useCallback(c=>c<a,[a]),u=useCallback(async()=>{await i();},[i]),m=useInfiniteLoader({isRowLoaded:p,loadMoreRows:u,rowCount:d,threshold:5});return o?jsx(kn,{}):l.length===0&&!s?jsx(yn,{message:r("predict.tradeHistory.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Mr},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:r("predict.tradeHistory.side")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.tradeHistory.outcome")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.qty")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.total")}),jsx("div",{className:"flex-[1.5] pr-2 text-right",children:r("predict.tradeHistory.time")})]}),jsx(List,{style:{height:bn},onRowsRendered:m,rowComponent:id,rowCount:d,rowHeight:xn,rowProps:{trades:l,itemCount:a}})]})}function id({index:e,style:t,trades:r,itemCount:n}){if(e>=n)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let o=r[e];if(!o)return null;let i=o.side?.toUpperCase()==="BUY",s=sd(o.timestamp),l=o.price??0,a=o.usd_size??0;return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",i?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:o.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:o.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:Nr(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:o.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:["$",a.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:s})]})}function yn({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:Xt},children:e})}function kn(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:Xt},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function Nr(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function sd(e){let t=new Date(e*1e3),r=(t.getMonth()+1).toString().padStart(2,"0"),n=t.getDate().toString().padStart(2,"0"),o=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return `${r}/${n} ${o}:${i}`}function ad(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}var fi=`
|
|
85
|
+
`}),jsx("div",{className:"evt-card-grid",style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)"},children:e.map((c,f)=>c==null?null:jsx("div",{style:{padding:Uc,animation:`eventCardEnter 0.45s cubic-bezier(0.34,1.56,0.64,1) ${f%4*35}ms both`},children:jsx(ri,{event:c,href:s?.(c),LinkComponent:l,onSelect:o,onSelectOutcome:i,onHover:a})},`${c.source}-${c.slug}`))}),jsx("div",{ref:p,style:{display:"flex",flexDirection:"column",alignItems:"center",gap:8,padding:"16px 0",minHeight:1},children:r&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#71717a",fontSize:13},children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"evt-load-spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),d("predict.events.loadMore")]})}),m&&jsx(Kc,{onScrollToTop:u})]})}function Kc({onScrollToTop:e}){let{t}=useTranslation();return jsxs("div",{className:"flex w-full flex-col items-center justify-center gap-y-4 py-6",children:[jsxs("div",{className:"flex w-full items-center justify-center gap-x-4",children:[jsx("div",{className:"h-px w-16 bg-neutral-700"}),jsx("span",{className:"text-xs font-medium text-neutral-500",children:t("predict.event.endOfList")}),jsx("div",{className:"h-px w-16 bg-neutral-700"})]}),jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-x-1 text-xs font-medium text-neutral-400",onClick:e,children:[jsx("span",{className:"iconify size-4 ph--arrow-up-bold"}),jsx("span",{children:t("predict.event.backToTop")})]})]})}function ci({tagSlugSelection:e,limit:t=24,status:r,sort_by:n,sort_asc:o,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:d,onSelect:p,onSelectOutcome:u,getEventHref:m,LinkComponent:c,onHover:f}){let{data:g,hasMore:h,fetchMore:v,isFetching:S,isFetchingMore:C}=Vo({tagSlugSelection:e,limit:t,status:r,sort_by:n,sort_asc:o,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:d});return S?jsx(dn,{count:24}):jsx(ai,{events:g,hasMore:h,isFetchingMore:C,onFetchMore:v,onSelect:p,onSelectOutcome:u,getEventHref:m,LinkComponent:c,onHover:f})}function _0({onSelect:e,onSelectOutcome:t,getEventHref:r,LinkComponent:n,onHover:o,bgImageSrc:i}){let[s,l]=useState({categorySlug:null,tagSlug:null}),[a,d]=useState(ln),{data:p}=useEventStats(),{isOpen:u,onOpen:m,onClose:c}=useDisclosure(),{onOpen:f}=useAsyncModal(Kt),g=useCallback((T,z,ae)=>{t?.(T,z,ae),f({params:{event:T,market:z,initialOutcome:ae}});},[t,f]),h=useCallback(T=>{l(T);},[]),v=useCallback(T=>{d(z=>({...z,sortPreset:T}));},[]),S=useCallback(T=>{d(z=>({...z,sortAsc:T}));},[]),C=useCallback(T=>{d(T);},[]),P=useMemo(()=>$o[a.sortPreset].sort_by,[a.sortPreset]),x=useMemo(()=>cn(a),[a]),b=useMemo(()=>jsx(Wo,{sortPreset:a.sortPreset,onSortChange:v,sortAsc:a.sortAsc,onSortAscChange:S,onFilterPress:m,filterCount:x}),[a.sortPreset,a.sortAsc,x,v,S,m]);return jsxs("div",{style:{minHeight:"100vh",position:"relative",width:"100%",maxWidth:1680,margin:"0 auto"},children:[jsxs("div",{style:{position:"relative",overflow:"hidden",borderBottom:"1px solid rgba(39,39,42,0.5)",width:"100vw",marginLeft:"calc(-50vw + 50%)"},children:[jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:0,overflow:"hidden"},children:[i&&jsx("img",{src:i,alt:"","aria-hidden":"true",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"center center",opacity:.3,mixBlendMode:"lighten",maskImage:"linear-gradient(to bottom, black 50%, transparent 100%)",WebkitMaskImage:"linear-gradient(to bottom, black 50%, transparent 100%)"}}),jsx("div",{style:{position:"absolute",inset:0,opacity:.025,backgroundImage:"radial-gradient(circle at 1px 1px, rgb(255 255 255) 1px, transparent 0)",backgroundSize:"20px 20px"}})]}),jsx("style",{children:".evt-hero-wrap{padding:40px 16px 32px}@media(min-width:640px){.evt-hero-wrap{padding:48px 24px 40px}}@media(min-width:1024px){.evt-hero-wrap{padding:52px 32px 44px}}"}),jsx("div",{className:"evt-hero-wrap",style:{position:"relative",zIndex:2,maxWidth:1152,margin:"0 auto"},children:jsx(Ao,{stats:p})})]}),jsx("div",{style:{position:"sticky",top:0,zIndex:40,background:"rgba(10,10,11,0.8)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",borderBottom:"1px solid rgba(39,39,42,0.5)"},children:jsx(go,{onSelect:h,trailing:b})}),jsxs("div",{style:{padding:"12px 8px 80px"},children:[jsx(Oo,{isOpen:u,onClose:c,value:a,onChange:C}),jsx(ci,{tagSlugSelection:s,sort_by:P,sort_asc:a.sortAsc,source:a.source,timeRemaining:a.timeRemaining,minVolume:a.minVolume,minLiquidity:a.minLiquidity,onSelect:e,onSelectOutcome:g,getEventHref:r,LinkComponent:n,onHover:o})]}),jsx(yr,{})]})}var xn=40,Mr=36,Xt=480,bn=Xt-Mr;function mi({event:e,walletAddress:t,onCancelOrder:r}){let{t:n}=useTranslation(),[o,i]=useState("positions"),s=useMemo(()=>e.markets?.map(u=>u.slug)??[],[e.markets]),{data:l}=usePositions({source:e.source,user:t??""}),a=useMemo(()=>!l?.positions||!t?0:s.length===0?l.positions.length:l.positions.filter(u=>u.market&&s.includes(u.market.slug)).length,[l?.positions,s,t]),p=[{key:"positions",label:a>0?`${n("predict.positions.title")} (${a})`:n("predict.positions.title")},{key:"orders",label:n("predict.openOrders.title")},{key:"trades",label:n("predict.tradeHistory.title")}];return jsxs("div",{className:"flex flex-col gap-y-2 mt-6 px-1 lg:px-4",children:[jsx("div",{className:"flex items-center gap-x-1 border-b border-border",children:p.map(u=>jsx("button",{type:"button",onClick:()=>i(u.key),className:cn$1("px-3 py-2 text-sm font-medium transition-colors cursor-pointer",o===u.key?"text-foreground border-b-2 border-primary":"text-neutral hover:text-foreground"),children:u.label},u.key))}),t?jsxs("div",{style:{height:Xt},children:[o==="positions"&&jsx(Jc,{source:e.source,walletAddress:t,marketSlugs:s}),o==="orders"&&jsx(td,{source:e.source,walletAddress:t,marketSlugs:s,onCancelOrder:r}),o==="trades"&&jsx(od,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:Xt},children:n("predict.trade.connectWallet")})]})}function Jc({source:e,walletAddress:t,marketSlugs:r}){let{t:n}=useTranslation(),{data:o,isLoading:i}=usePositions({source:e,user:t}),s=useMemo(()=>o?.positions?r.length===0?o.positions:o.positions.filter(l=>l.market&&r.includes(l.market.slug)):[],[o?.positions,r]);return i?jsx(kn,{}):s.length===0?jsx(yn,{message:n("predict.positions.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Mr},children:[jsx("div",{className:"flex-[3] min-w-0 pr-2 whitespace-nowrap",children:n("predict.positions.event")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.totalSize")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.value")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.avgPrice")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.markPrice")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:n("predict.positions.pnl")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:n("predict.positions.payoutIfRight")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:n("predict.positions.estSettlement")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:bn},rowComponent:ed,rowCount:s.length,rowHeight:xn,rowProps:{positions:s,closeLabel:n("predict.positions.close")}})]})}function ed({index:e,style:t,positions:r,closeLabel:n}){let o=r[e];if(!o)return null;let i=o.pnl??0,s=o.pnl_percent??0,l=o.avg_price??0,a=o.current_price??0,d=i>0?"text-success":i<0?"text-danger":"text-foreground",p=i>0?"+":"",u=o.market?.outcomes?.[0]?.label??o.market?.question??"\u2014",m=o.side,c=o.size,f=o.size*a,g=o.market?.end_at?ad(o.market.end_at):"\u2014";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 hover:bg-content2/40 transition-colors text-xs lg:text-sm",children:[jsx("div",{className:"flex-[3] min-w-0 pr-2",children:jsxs("div",{className:"flex flex-col gap-y-0.5",children:[jsx("span",{className:"text-foreground truncate font-medium",children:u}),jsx("span",{className:cn$1("text-[10px] font-medium",m.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:m})]})}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:o.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",f.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Nr(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Nr(a)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",d),children:[p,"$",Math.abs(i).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",p,s.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",c.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:g}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",className:"text-xs text-neutral hover:text-foreground cursor-pointer transition-colors rounded px-2 py-0.5 border border-border hover:border-foreground/40",children:n})})]})}function td({source:e,walletAddress:t,marketSlugs:r,onCancelOrder:n}){let{t:o}=useTranslation(),{data:i,isLoading:s,fetchNextPage:l,hasNextPage:a}=useInfiniteOrders({source:e,wallet_address:t}),d=useCancelOrder(),p=useMemo(()=>{let v=i?.pages?.flatMap(P=>P.items)??[],S=new Set(["live","open","submitted","pending"]),C=v.filter(P=>S.has(P.status));return r.length>0&&(C=C.filter(P=>P.market_id&&r.includes(P.market_id))),C},[i?.pages,r]),u=useCallback(v=>{n?n(v.id):d.mutate({source:v.source,id:v.id});},[n,d]),m=p.length,c=m+(a?1:0),f=useCallback(v=>v<m,[m]),g=useCallback(async()=>{await l();},[l]),h=useInfiniteLoader({isRowLoaded:f,loadMoreRows:g,rowCount:c,threshold:5});return s?jsx(kn,{}):p.length===0&&!a?jsx(yn,{message:o("predict.openOrders.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Mr},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:o("predict.openOrders.side")}),jsx("div",{className:"flex-1 pr-2",children:o("predict.openOrders.outcome")}),jsx("div",{className:"flex-1 pr-2",children:o("predict.openOrders.type")}),jsx("div",{className:"flex-1 pr-2 text-right",children:o("predict.openOrders.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:o("predict.openOrders.filled")}),jsx("div",{className:"w-20 shrink-0 pr-2",children:o("predict.openOrders.status")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:bn},onRowsRendered:h,rowComponent:rd,rowCount:c,rowHeight:xn,rowProps:{orders:p,itemCount:m,onCancel:u,isCancelling:d.isPending,cancelLabel:o("predict.openOrders.cancel")}})]})}function rd({index:e,style:t,orders:r,itemCount:n,onCancel:o,isCancelling:i,cancelLabel:s}){if(e>=n)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let l=r[e];if(!l)return null;let a=l.side==="BUY";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",a?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:l.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:l.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:l.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:l.price?Nr(parseFloat(l.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[l.size_matched??"0","/",l.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(nd,{status:l.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>o(l),disabled:i,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:i?jsx(Spinner,{size:"sm"}):s})})]})}function nd({status:e}){return jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium capitalize",{live:"bg-success/10 text-success",open:"bg-success/10 text-success",submitted:"bg-warning/10 text-warning",pending:"bg-warning/10 text-warning",matched:"bg-primary/10 text-primary",cancelled:"bg-neutral/10 text-neutral",failed:"bg-danger/10 text-danger",expired:"bg-neutral/10 text-neutral"}[e]??"bg-neutral/10 text-neutral"),children:e})}function od({source:e,walletAddress:t}){let{t:r}=useTranslation(),{data:n,isLoading:o,fetchNextPage:i,hasNextPage:s}=useInfiniteTrades({source:e,wallet:t,limit:50}),l=useMemo(()=>n?.pages?.flatMap(c=>c.items)??[],[n?.pages]),a=l.length,d=a+(s?1:0),p=useCallback(c=>c<a,[a]),u=useCallback(async()=>{await i();},[i]),m=useInfiniteLoader({isRowLoaded:p,loadMoreRows:u,rowCount:d,threshold:5});return o?jsx(kn,{}):l.length===0&&!s?jsx(yn,{message:r("predict.tradeHistory.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Mr},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:r("predict.tradeHistory.side")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.tradeHistory.outcome")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.qty")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.total")}),jsx("div",{className:"flex-[1.5] pr-2 text-right",children:r("predict.tradeHistory.time")})]}),jsx(List,{style:{height:bn},onRowsRendered:m,rowComponent:id,rowCount:d,rowHeight:xn,rowProps:{trades:l,itemCount:a}})]})}function id({index:e,style:t,trades:r,itemCount:n}){if(e>=n)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let o=r[e];if(!o)return null;let i=o.side?.toUpperCase()==="BUY",s=sd(o.timestamp),l=o.price??0,a=o.usd_size??0;return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",i?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:o.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:o.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:Nr(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:o.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:["$",a.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:s})]})}function yn({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:Xt},children:e})}function kn(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:Xt},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function Nr(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function sd(e){let t=new Date(e*1e3),r=(t.getMonth()+1).toString().padStart(2,"0"),n=t.getDate().toString().padStart(2,"0"),o=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return `${r}/${n} ${o}:${i}`}function ad(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}var fi=`
|
|
86
86
|
@keyframes detailShimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}
|
|
87
87
|
`,gi={background:"linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%)",backgroundSize:"200% 100%",animation:"detailShimmer 1.8s ease-in-out infinite",borderRadius:6};function te(e){return {...gi,animationDelay:`${e}ms`}}function Zt({marketCount:e=4,showBack:t}){return jsxs(Fragment,{children:[jsx("style",{children:fi}),jsxs("div",{style:{display:"flex",flexDirection:"column",width:"100%",gap:20},children:[t&&jsx("div",{style:{height:20}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[jsx("div",{style:{...gi,width:64,height:64,borderRadius:10,flexShrink:0}}),jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:8},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[jsx("div",{style:{...te(0),height:14,width:48}}),jsx("div",{style:{...te(30),height:14,width:40}}),jsx("div",{style:{...te(60),height:14,width:40}})]}),jsx("div",{style:{...te(80),height:20,width:"80%",maxWidth:384,borderRadius:4}})]})]}),jsx("div",{style:{...te(100),height:16,width:192}}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[jsx("div",{style:{...te(120),height:16,width:96}}),jsx("div",{style:{...te(140),height:16,width:80}})]}),jsx("div",{style:{...te(160),height:300,width:"100%",borderRadius:12}}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("div",{style:{...te(180),height:16,width:80}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[jsx("div",{style:{...te(200),height:28,width:200,borderRadius:8}}),jsx("div",{style:{...te(220),height:28,width:112,borderRadius:8}})]})]})]}),jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 0"},children:jsx("div",{style:{...te(240),height:14,width:56}})}),Array.from({length:e}).map((r,n)=>jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 0",borderBottom:"1px solid rgba(39,39,42,0.5)"},children:[jsx("div",{style:{...te(260+n*40),width:28,height:28,borderRadius:8,flexShrink:0}}),jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:4},children:[jsx("div",{style:{...te(280+n*40),height:14,width:n%2===0?192:160}}),jsx("div",{style:{...te(300+n*40),height:10,width:64}})]}),jsx("div",{style:{...te(320+n*40),height:16,width:40}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[jsx("div",{style:{...te(340+n*40),height:32,width:80,borderRadius:8}}),jsx("div",{style:{...te(360+n*40),height:32,width:80,borderRadius:8}})]})]},n))]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[jsx("div",{style:{...te(400),height:16,width:64}}),jsx("div",{style:{...te(420),height:14,width:"100%"}}),jsx("div",{style:{...te(440),height:14,width:"80%"}}),jsx("div",{style:{...te(460),height:14,width:"60%"}})]})]})]})}function hi(){return jsxs(Fragment,{children:[jsx("style",{children:fi}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,borderRadius:14,border:"1px solid rgba(39,39,42,0.6)",background:"rgba(24,24,27,0.4)",padding:16},children:[jsx("div",{style:{...te(0),height:40,width:"100%",borderRadius:8}}),jsx("div",{style:{...te(60),height:96,width:"100%",borderRadius:8}}),jsx("div",{style:{...te(120),height:40,width:"100%",borderRadius:8}})]})]})}var ki="var(--color-bullish)",Si="var(--color-bearish)";function Jt(e){let t=Math.abs(e);return t>=1e9?`${parseFloat((e/1e9).toFixed(2))}B`:t>=1e6?`${parseFloat((e/1e6).toFixed(2))}M`:t>=1e3?`${parseFloat((e/1e3).toFixed(2))}K`:e.toLocaleString()}function dd(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function pd(e,t){let r=new Float64Array(101),n=new Float64Array(101);for(let c of e){let f=Math.round(c.price*100);f>=0&&f<=100&&(r[f]+=c.quantity);}for(let c of t){let f=Math.round(c.price*100);f>=0&&f<=100&&(n[f]+=c.quantity);}let o=0,i=0,s=new Float64Array(101),l=new Float64Array(101);for(let c=100;c>=0;c--)o+=r[c],i+=r[c]*c/100,s[c]=o,l[c]=i;let a=0,d=0,p=new Float64Array(101),u=new Float64Array(101);for(let c=0;c<=100;c++)a+=n[c],d+=n[c]*c/100,p[c]=a,u[c]=d;let m=Math.max(s[0]??0,p[100]??0);return Array.from({length:101},(c,f)=>{let g=s[f]>0,h=p[f]>0,v=s[f]||p[f],S=r[f]>0||n[f]>0;return {priceCents:f,displayHeight:dd(v,m),opacity:v>0?S?1:.5:0,isBid:g,isAsk:h,bidCumTotal:s[f],askCumTotal:p[f],bidCumCost:l[f],askCumCost:u[f]}})}function ud({info:e}){let{t}=useTranslation(),r=e.isBid?ki:Si,n=e.leftPct>65?void 0:`${e.leftPct}%`,o=e.leftPct>65?`${100-e.leftPct}%`:void 0;return jsxs("div",{style:{position:"absolute",top:8,left:n,right:o,zIndex:10,background:"rgba(17,24,39,0.95)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:8,padding:"8px 12px",fontSize:12,color:"#f9fafb",minWidth:140,pointerEvents:"none"},children:[jsx("div",{style:{marginBottom:4,fontWeight:600},children:t("predict.orderBook.depthToPrice",{price:e.priceCents})}),jsx("div",{style:{color:r},children:t("predict.orderBook.depthContracts",{amount:Jt(Math.round(e.cumTotal))})}),jsxs("div",{style:{color:r},children:["$",Jt(Math.round(e.cumCost))]})]})}var md=memo(function({slot:t,onEnter:r,onLeave:n}){let o=useRef(null),i=t.isBid||t.isAsk,s=t.isBid?ki:t.isAsk?Si:void 0;return jsx("div",{style:{position:"absolute",left:`${t.priceCents}%`,width:"1%",height:"100%",boxSizing:"border-box",borderRight:t.priceCents<100?"1px solid transparent":"none",cursor:i?"crosshair":"default"},onMouseEnter:()=>r(t,o.current),onMouseLeave:n,children:i&&jsx("div",{ref:o,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:s,opacity:t.opacity}})})}),fd=[0,10,20,30,40,50,60,70,80,90,100];function gd(){return jsx("div",{className:"relative flex h-6 items-center border-b border-t border-border px-1",style:{background:"rgba(0,0,0,0.15)"},children:fd.map(e=>jsx("span",{className:"absolute text-neutral font-normal",style:{fontSize:10,left:`${e}%`,transform:e===0?"translateX(0px)":e===100?"translateX(-100%)":"translateX(-50%)"},children:e},e))})}function wi({bids:e,asks:t}){let{t:r}=useTranslation(),n=useMemo(()=>pd(e,t),[e,t]),o=useMemo(()=>{let u=e.length>0?Math.max(...e.map(c=>c.price)):0,m=t.length>0?Math.min(...t.map(c=>c.price)):1;return Math.round((u+m)/2*100)},[e,t]),i=useMemo(()=>n.some(u=>u.isBid||u.isAsk),[n]),[s,l]=useState(null),a=useRef(null),d=useCallback((u,m)=>{a.current&&(a.current.style.filter=""),m?(m.style.filter="brightness(1.5)",a.current=m):a.current=null,u.isBid||u.isAsk?l({priceCents:u.priceCents,isBid:u.isBid,cumTotal:u.isBid?u.bidCumTotal:u.askCumTotal,cumCost:u.isBid?u.bidCumCost:u.askCumCost,leftPct:u.priceCents}):l(null);},[]),p=useCallback(()=>{a.current&&(a.current.style.filter="",a.current=null),l(null);},[]);return i?jsxs("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%",userSelect:"none",overflow:"hidden"},children:[jsxs("div",{style:{flex:1,position:"relative",width:"100%",overflow:"hidden"},children:[o>0&&jsx("div",{style:{position:"absolute",left:`${o}%`,top:0,bottom:0,width:1,backgroundImage:"repeating-linear-gradient(to bottom, #6b7280 0, #6b7280 4px, transparent 4px, transparent 8px)",zIndex:1,pointerEvents:"none"}}),s&&jsx(ud,{info:s}),n.map(u=>jsx(md,{slot:u,onEnter:d,onLeave:p},u.priceCents))]}),jsx(gd,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:r("predict.orderBook.noData")})}function wn(e){let t=e*100,r=Math.round(t*10)/10;return Number.isInteger(r)?`${r}\xA2`:`${r.toFixed(1)}\xA2`}function Pi(){let{t:e}=useTranslation();return jsxs("div",{className:"flex items-center justify-center gap-x-2 h-full text-neutral text-xs",children:[jsx(Spinner,{size:"sm"}),jsx("span",{children:e("predict.orderBook.loading")})]})}function Ei({market:e,outcome:t="yes",onTradeAction:r}){let{t:n}=useTranslation(),[o,i]=useState("depth"),s=t==="no",l=e.source,{data:a,isLoading:d}=useOrderbook({slug:e.slug,source:l}),p=useMemo(()=>((s?a?.asks:a?.bids)??[]).map(h=>({price:s?1-h.price:h.price,quantity:h.size})),[a?.bids,a?.asks,s]),u=useMemo(()=>((s?a?.bids:a?.asks)??[]).map(h=>({price:s?1-h.price:h.price,quantity:h.size})),[a?.bids,a?.asks,s]),m=useMemo(()=>p.length>0?Math.max(...p.map(g=>g.price)):null,[p]),c=useMemo(()=>u.length>0?Math.min(...u.map(g=>g.price)):null,[u]),f=useMemo(()=>{if(m==null||c==null)return null;let g=(c-m)*100;return Math.round(g*10)/10},[m,c]);return jsxs("div",{className:"flex flex-col h-[262px]",children:[jsxs("div",{className:"flex h-9 items-center border-b border-border px-1 text-xs",children:[jsx("span",{className:"flex-1 text-left text-neutral",children:f!=null?`${n("predict.orderBook.spread")}: ${Number.isInteger(f)?`${f}\xA2`:`${f.toFixed(1)}\xA2`}`:null}),jsxs("span",{className:"flex flex-1 items-center justify-center gap-x-1 whitespace-nowrap",children:[m!=null&&jsxs("span",{style:{color:"var(--color-bullish)"},children:[n("predict.trade.bestBid"),": ",wn(m)]}),m!=null&&c!=null&&jsx("span",{className:"text-neutral",children:"|"}),c!=null&&jsxs("span",{style:{color:"var(--color-bearish)"},children:[n("predict.trade.bestAsk"),": ",wn(c)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:o==="depth"?"Orderbook":"Depth chart",onClick:()=>i(g=>g==="depth"?"table":"depth"),className:"flex items-center text-neutral transition-colors cursor-pointer hover:text-foreground",children:o==="depth"?jsx(OrderbookTableIcon,{className:"h-4 w-4"}):jsx(OrderbookDepthIcon,{className:"h-4 w-4"})})})]}),jsxs("div",{className:"flex-1 min-h-0 overflow-hidden",children:[o==="depth"&&jsx(Fragment,{children:d?jsx(Pi,{}):jsx(wi,{bids:p,asks:u})}),o==="table"&&jsx(Fragment,{children:d?jsx(Pi,{}):jsx(kd,{bids:p,asks:u,bestBid:m??void 0,bestAsk:c??void 0,spread:f??void 0})})]})]})}var Ni=8;function kd({bids:e,asks:t,spread:r}){let{t:n}=useTranslation(),o=useMemo(()=>[...t].sort((a,d)=>a.price-d.price).slice(0,Ni).reverse(),[t]),i=useMemo(()=>[...e].sort((a,d)=>d.price-a.price).slice(0,Ni),[e]),s=useMemo(()=>{let a=[...o,...i].map(d=>d.quantity);return Math.max(...a,1)},[o,i]);return o.length===0&&i.length===0?jsx("div",{className:"flex items-center justify-center h-full text-xs text-neutral",children:n("predict.orderBook.empty")}):jsxs("div",{className:"flex flex-col h-full overflow-y-auto text-xs font-mono select-none",children:[o.map(a=>jsx(Ci,{price:a.price,quantity:a.quantity,side:"ask",maxQty:s},`ask-${a.price}`)),jsx("div",{className:"flex items-center justify-center gap-x-2 py-1 border-y border-border text-neutral text-[10px]",children:r!=null&&jsxs("span",{children:[n("predict.orderBook.spread"),":"," ",Number.isInteger(r)?`${r}\xA2`:`${r.toFixed(1)}\xA2`]})}),i.map(a=>jsx(Ci,{price:a.price,quantity:a.quantity,side:"bid",maxQty:s},`bid-${a.price}`)),jsxs("div",{className:"grid grid-cols-3 px-2 pt-2 pb-0.5 text-[10px] text-neutral border-t border-border",children:[jsx("span",{children:n("predict.orderBook.price")}),jsx("span",{className:"text-center",children:n("predict.orderBook.contracts")}),jsx("span",{className:"text-right",children:n("predict.orderBook.total")})]})]})}function Ci({price:e,quantity:t,side:r,maxQty:n}){let o=r==="ask",i=Math.min(t/n*100,100),s=o?"bg-bearish/10":"bg-bullish/10",l=o?"text-bearish":"text-bullish",a=Jt(Math.round(t)),d=Math.round(t*e),p=`$${Jt(d)}`;return jsxs("div",{className:"relative grid grid-cols-3 px-2 py-1 hover:bg-content2 transition-colors cursor-default",children:[jsx("div",{className:`absolute inset-y-0 left-0 ${s} transition-[width] duration-200`,style:{width:`${i}%`}}),jsx("span",{className:`relative z-10 ${l}`,children:wn(e)}),jsx("span",{className:"relative z-10 text-foreground text-center",children:a}),jsx("span",{className:"relative z-10 text-foreground text-right",children:p})]})}var Cn=class extends Component{state={error:null};static getDerivedStateFromError(t){return {error:t}}componentDidCatch(t,r){}render(){return this.state.error?jsxs("div",{style:{height:this.props.fallbackHeight??320,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,color:"#6b7280",fontSize:13},children:[jsx("span",{children:"Chart unavailable"}),jsx("span",{style:{fontSize:11,opacity:.7},children:this.state.error.message})]}):this.props.children}},Lr=4,Ti=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function Id(e,t){let r=new Date(e);return t===ChartRange.ONE_DAY?r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Od(e,t){let r=new Date(e);return t===ChartRange.ONE_DAY?r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):t===ChartRange.ONE_WEEK?r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false}):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Li(e){return `${(e*100).toFixed(2)}%`}var Dd=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function Ad({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:Dd.map(({range:r,label:n})=>{let o=r===e;return jsx("button",{onClick:()=>t(r),style:{padding:"2px 8px",border:"none",background:"transparent",color:o?"#f9fafb":"#6b7280",fontWeight:o?700:400,fontSize:12,cursor:"pointer",borderRadius:4,letterSpacing:"0.02em",transition:"color 0.15s",userSelect:"none"},children:n},r)})})}function Fd(){let e=useRef(null),t=useRef(null),r=useCallback(o=>{let i=e.current,s=t.current;if(!i||!s)return;let l=i.getBoundingClientRect(),a=(o.clientX-l.left)/l.width*100;s.style.background=`linear-gradient(to right, transparent ${a}%, rgba(0,0,0,0.55) ${a}%)`,s.style.opacity="1";},[]),n=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:r,onMouseLeave:n}}function Bd({active:e,payload:t,label:r,labelMap:n,allSeries:o,range:i}){if(!e||!o?.length)return null;let s=new Map;t?.forEach(a=>s.set(a.dataKey,a));let l=o.map(a=>s.get(a.slug)??{dataKey:a.slug,value:void 0,stroke:a.color,color:a.color});return jsxs("div",{style:{background:"rgba(10,10,10,0.92)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:8,padding:"8px 12px",minWidth:180,backdropFilter:"blur(8px)",fontSize:12},children:[jsx("div",{style:{color:"#9ca3af",marginBottom:6,fontWeight:500},children:typeof r=="number"?Od(r,i):r}),l.map(a=>jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[jsx("span",{style:{display:"inline-block",width:3,height:14,borderRadius:2,background:a.stroke??a.color,flexShrink:0}}),jsx("span",{style:{color:"#9ca3af",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},children:n.get(a.dataKey)??a.dataKey}),jsx("span",{style:{color:"#f9fafb",fontWeight:700,fontVariantNumeric:"tabular-nums"},children:a.value!=null?Li(a.value):"--"})]},a.dataKey))]})}function Hd({markets:e,selectedSlugs:t,colorMap:r,onToggle:n}){let[o,i]=useState(false),s=useRef(null);useEffect(()=>{if(!o)return;function d(p){s.current&&!s.current.contains(p.target)&&i(false);}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[o]);let l=t.length>=Lr,a=jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0},children:[jsx("div",{style:{display:"flex",gap:3,flexShrink:0},children:t.map(d=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r.get(d)??"#6b7280",display:"inline-block"}},d))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let d=e.find(p=>p.slug===t[0]);return d?.outcomes?.[0]?.label??d?.question??"1 market"})():`${t.length} / ${e.length} markets`})]});return jsxs("div",{ref:s,style:{position:"relative",display:"inline-block",width:200},children:[jsxs("button",{onClick:()=>i(d=>!d),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",borderRadius:8,border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",cursor:"pointer",width:"100%",userSelect:"none"},children:[a,jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flexShrink:0,transform:o?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.15s",color:"#6b7280"},children:jsx("path",{d:"M2 4l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),o&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,zIndex:50,background:"#111827",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",minWidth:260,maxWidth:360,maxHeight:320,overflowY:"auto",padding:"6px 0"},children:[jsxs("div",{style:{padding:"4px 12px 8px",fontSize:11,color:"#6b7280",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:["Select up to ",Lr," markets"]}),e.map((d,p)=>{let u=t.includes(d.slug),m=!u&&l,c=u&&t.length===1,f=r.get(d.slug)??"#6b7280",g=d.outcomes.find(v=>v.label.toLowerCase()==="yes")??d.outcomes[0],h=g?.price!=null?`${Math.round(g.price*100)}%`:null;return jsxs("button",{onClick:()=>{c||m||n(d.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:u?"rgba(255,255,255,0.05)":"transparent",cursor:m||c?"not-allowed":"pointer",opacity:m?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:v=>{!m&&!c&&(v.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:v=>{v.currentTarget.style.background=u?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:u?`2px solid ${f}`:"2px solid rgba(255,255,255,0.2)",background:u?`${f}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:u&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke:f,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:f,flexShrink:0}}),jsx("span",{style:{color:u?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.outcomes?.[0]?.label??d.question}),h&&jsx("span",{style:{color:f,fontWeight:700,fontSize:12,flexShrink:0},children:h})]},d.id??`${p}-${d.slug}`)})]})]})}function zd({series:e,colorMap:t,displayValues:r}){return jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px 24px",padding:"0 2px"},children:e.map(n=>{let o=t.get(n.marketSlug)??"#6b7280",i=r.get(n.marketSlug);return jsxs("div",{style:{display:"inline-flex",alignItems:"flex-start",gap:6},children:[jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:o,flexShrink:0,marginTop:3}}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:1},children:[jsx("span",{style:{color:"#9ca3af",fontSize:12,lineHeight:"17px",whiteSpace:"nowrap"},children:n.label}),jsx("span",{style:{color:"#f9fafb",fontSize:14,fontWeight:700,lineHeight:"20px",fontVariantNumeric:"tabular-nums"},children:i!=null?Li(i):"--"})]})]},n.marketSlug)})})}function $d(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function Wd(e,t){if(e.length<=t)return e;let r=[],n=e.length/t;for(let o=0;o<t;o++){let i=Math.floor(o*n),s=Math.min(Math.floor((o+1)*n),e.length),l=e.slice(i,s),a=l.map(d=>d.price).sort((d,p)=>d-p);r.push({timestamp:l[l.length-1].timestamp,price:$d(a)});}return r}function Ud(e,t=200){if(e.length===0)return [];let r=e.map(l=>({...l,data:Wd(l.data,t)})),n=new Set;r.forEach(l=>l.data.forEach(a=>n.add(a.timestamp)));let o=Array.from(n).sort((l,a)=>l-a),i=r.map(l=>{let a=new Map;return l.data.forEach(d=>a.set(d.timestamp,d.price)),{slug:l.marketSlug,map:a}}),s=new Map;return o.map(l=>{let a={timestamp:l};return i.forEach(({slug:d,map:p})=>{let u=p.get(l);if(u!==void 0)s.set(d,u),a[d]=u;else {let m=s.get(d);m!==void 0&&(a[d]=m);}}),a})}function _i(e){return jsx(Cn,{children:jsx(Kd,{...e})})}function Kd({event:e,isLoading:t,className:r,volume:n}){let o=useMemo(()=>{let M=new Set;return (e.markets??[]).filter(_=>_.status!=="open"||M.has(_.slug)?false:(M.add(_.slug),true))},[e.markets]),i=useMemo(()=>[...o].sort((M,_)=>{let G=A=>(A.outcomes.find(pe=>pe.label.toLowerCase()==="yes")??A.outcomes[0])?.price??0;return G(_)-G(M)}),[o]),[s,l]=useState(()=>i.slice(0,Lr).map(M=>M.slug)),[a,d]=useState(hr),p=useMemo(()=>{let M=new Map;return s.forEach((_,G)=>{M.set(_,Ti[G%Ti.length]);}),M},[s]),u=useMemo(()=>o.filter(M=>s.includes(M.slug)),[o,s]),{series:m,isLoading:c}=useMarketHistory(u,a),f=t||c,g=useMemo(()=>{if(m.length>0&&m.some(G=>G.data.length>0))return m;let M=Date.now(),_=864e5;return u.map(G=>{let pe=(G.outcomes?.find(le=>le.label.toLowerCase()==="yes")??G.outcomes?.[0])?.price??.5;return {marketSlug:G.slug,label:G.outcomes?.[0]?.label??G.question,data:[{timestamp:M-7*_,price:pe},{timestamp:M,price:pe}]}})},[m,u]),h=useMemo(()=>a===ChartRange.ONE_DAY?96:a===ChartRange.ONE_WEEK?168:a===ChartRange.ONE_MONTH?180:300,[a]),v=useMemo(()=>Ud(g,h),[g,h]),S=useMemo(()=>{if(v.length===0)return [0,1];let M=1/0,_=-1/0;if(s.forEach(A=>{v.forEach(pe=>{let le=pe[A];le!=null&&(le<M&&(M=le),le>_&&(_=le));});}),!isFinite(M))return [0,1];let G=Math.max((_-M)*.15,.05);return [Math.max(0,M-G),Math.min(1,_+G)]},[v,s]),C=useMemo(()=>{let M=new Map;return g.forEach(_=>{_.data.length>0&&M.set(_.marketSlug,_.data[_.data.length-1].price);}),M},[g]),P=useMemo(()=>{let M=new Map;return g.forEach(_=>M.set(_.marketSlug,_.label)),M},[g]),x=useMemo(()=>g.map(M=>({slug:M.marketSlug,color:p.get(M.marketSlug)??"#6b7280"})),[g,p]),{wrapperRef:b,overlayRef:T,onMouseMove:z,onMouseLeave:ae}=Fd(),D=useCallback(M=>{l(_=>_.includes(M)?_.length<=1?_:_.filter(G=>G!==M):_.length>=Lr?_:[..._,M]);},[]),[ve,I]=useState(null),H=useRef(null),$=useRef(""),J=useRef(0),ie=!f&&v.length>0;return jsxs("div",{className:r,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx(zd,{series:g,colorMap:p,displayValues:ve??C}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:b,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:ie?M=>{z(M),cancelAnimationFrame(J.current),J.current=requestAnimationFrame(()=>{I(H.current);});}:void 0,onMouseLeave:ie?()=>{ae(),cancelAnimationFrame(J.current),$.current="",H.current=null,I(null);}:void 0,children:f?jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:jsx("div",{style:{width:28,height:28,borderRadius:"50%",border:"2.5px solid #22d3ee",borderTopColor:"transparent",animation:"spin 0.7s linear infinite"}})}):v.length===0?jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No price history data"}):jsxs(Fragment,{children:[jsx("div",{ref:T,style:{position:"absolute",inset:0,opacity:0,pointerEvents:"none",zIndex:1}}),jsx(ResponsiveContainer,{width:"100%",height:"100%",children:jsxs(LineChart,{data:v,margin:{top:8,right:16,left:0,bottom:0},children:[jsx(CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"#374151",opacity:.5}),jsx(XAxis,{dataKey:"timestamp",type:"number",scale:"time",domain:["dataMin","dataMax"],tickFormatter:M=>Id(M,a),axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},minTickGap:70}),jsx(YAxis,{domain:S,tickFormatter:M=>`${Math.round(M*100)}%`,axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},width:40,tickCount:6}),jsx(Tooltip,{content:M=>{let _=M;if(_.active&&_.payload?.length){let G=_.payload.map(A=>`${A.dataKey}:${A.value}`).join(",");if(G!==$.current){$.current=G;let A=new Map;_.payload.forEach(pe=>{pe.value!=null&&A.set(pe.dataKey,pe.value);}),H.current=A;}}return jsx(Bd,{..._,labelMap:P,allSeries:x,range:a})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(M=>{let _=p.get(M.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:M.marketSlug,stroke:_,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:_},connectNulls:true,isAnimationActive:false},M.marketSlug)}),ve==null&&v.length>0&&g.map(M=>{let _=v[v.length-1],G=_[M.marketSlug];if(G==null)return null;let A=p.get(M.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:_.timestamp,y:G,ifOverflow:"extendDomain",shape:pe=>{let{cx:le,cy:we}=pe;return le==null||we==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:le,cy:we,r:6,fill:A,opacity:.3,children:[jsx("animate",{attributeName:"r",values:"4;9;4",dur:"2s",repeatCount:"indefinite"}),jsx("animate",{attributeName:"opacity",values:"0.4;0.05;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsx("circle",{cx:le,cy:we,r:3.5,fill:A})]})}},`pulse-${M.marketSlug}`)})]})})]})}),jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"6px 8px",marginTop:6},children:[n!=null&&n>0&&jsxs("span",{style:{color:"#6b7280",fontSize:12},children:["$",Math.round(n).toLocaleString()," vol"]}),jsx("div",{style:{flex:1,minWidth:0}}),jsx(Ad,{value:a,onChange:d}),i.length>1&&jsx("div",{style:{width:"100%",display:"flex",alignItems:"center"},children:jsx(Hd,{markets:i,selectedSlugs:s,colorMap:p,onToggle:D})})]})]})]})}function tr(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function np(e){return `${parseFloat((e*100).toFixed(2))}%`}function Ri(e){let t=e*100;return t<1&&t>0?"< 1":parseFloat(t.toFixed(2)).toString()}function _r(e){return e.outcomes?.[0]?.label??e.question}function op(e){switch(e){case "polymarket":return "Polymarket";case "kalshi":return "Kalshi";default:return e}}function er(e){if(!e)return "\u2014";let t=new Date(e);if(isNaN(t.getTime()))return "\u2014";let r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),o=t.getFullYear(),i=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0");return `${r} ${n}, ${o} ${i}:${s}`}function Ii(e){let[t,r]=useState(0);if(useEffect(()=>{if(!e)return;r(Date.now());let p=setInterval(()=>r(Date.now()),1e3);return ()=>clearInterval(p)},[e]),!e||t===0)return null;let n=new Date(e).getTime();if(isNaN(n))return null;let o=n-t;if(o<=0)return null;let i=Math.floor(o/864e5),s=Math.floor(o%864e5/36e5),l=Math.floor(o%36e5/6e4),a=Math.floor(o%6e4/1e3),d=[];return i>0&&d.push(`${i}d`),d.push(`${String(s).padStart(2,"0")}h`),d.push(`${String(l).padStart(2,"0")}m`),d.push(`${String(a).padStart(2,"0")}s`),d.join(" ")}function Oi(e){if(!e)return null;let t=new Date(e);if(isNaN(t.getTime()))return null;let r=t.getHours().toString().padStart(2,"0"),n=t.getMinutes().toString().padStart(2,"0"),o=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),s=t.getFullYear(),l=-t.getTimezoneOffset(),a=l>=0?"+":"-",d=String(Math.abs(Math.floor(l/60))).padStart(2,"0");return `${r}:${n} ${o}/${i}/${s} (${a}${d})`}function Bi({event:e,onTradeAction:t}){let{t:r}=useTranslation(),{ref:n,isCollapsed:o}=useScrollCollapse(),i=useMemo(()=>{let u=[...e.markets||[]],m=u.filter(f=>f.status==="open").sort((f,g)=>tr(g)-tr(f)),c=u.filter(f=>f.status!=="open").sort((f,g)=>tr(g)-tr(f));return [...m,...c]},[e.markets]),s=e.status==="closed"||e.status==="voided",l=Ii(s?void 0:e.start_at),a=Ii(s?void 0:e.end_at),d=Oi(e.start_at),p=Oi(e.end_at);return jsxs("div",{className:"w-full flex flex-col gap-y-4 lg:gap-y-6",children:[jsxs("div",{ref:n,className:`sticky top-0 z-30 flex items-center backdrop-blur-md transition-all duration-300 ${o?"h-14 lg:h-16 gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"h-16 lg:h-20 gap-x-2 lg:gap-x-4"}`,children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"lg",classNames:{base:"bg-transparent"},className:`flex-shrink-0 transition-all duration-300 ${o?"!h-10 !w-10 lg:!h-12 lg:!w-12":"!h-16 !w-16 lg:!h-20 lg:!w-20"}`}),jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[!o&&jsxs("div",{className:"flex items-center gap-1.5",children:[e.tags?.slice(0,3).map((u,m)=>jsxs(Fragment$1,{children:[m>0&&jsx("span",{className:"text-sm text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-sm text-neutral truncate",children:u.label})]},u.slug)),jsx(lp,{source:e.source})]}),jsx("span",{className:`font-semibold truncate transition-all duration-300 ${o?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),(l||a||s)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:s?p&&jsx("span",{className:"text-neutral",children:r("predict.event.endedAt",{time:p})}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.beginsIn",{time:l})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):a?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.endsIn",{time:a})}),p&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:p})]})]}):null}),jsx(_i,{event:e,volume:e.volume??void 0}),jsx(ip,{markets:i,onTradeAction:t}),jsx(ap,{markets:i,event:e})]})}var Di=5;function ip({markets:e,onTradeAction:t}){let{t:r}=useTranslation(),{isMobile:n}=useScreen(),[o,i]=useState(false),[s,l]=useState(null),a=useMemo(()=>{let h=new Set;return e.filter(v=>h.has(v.slug)?false:(h.add(v.slug),true))},[e]),d=a.find(h=>h.status==="open")?.slug,[p,u]=useState(d?`${d}:yes`:null);if(a.length===0)return null;let m=a.length>Di,c=o?a:a.slice(0,Di),f=h=>{l(v=>v===h?null:h);},g=(h,v,S)=>{u(`${h.slug}:${v}`),n||l(h.slug),t?.(h,v,S);};return jsxs("div",{className:"flex flex-col",children:[jsxs("table",{className:"w-full border-collapse",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{}),jsx("th",{className:"py-2 text-left text-xs text-neutral font-normal lg:text-center lg:text-sm",children:r("predict.market.table.chance")}),jsx("th",{})]})}),jsx("tbody",{children:c.map((h,v)=>{let S=tr(h),C=h.outcomes[1]?.best_ask??h.outcomes[1]?.price,P=s===h.slug;return jsx(sp,{market:h,yesPrice:S,noPrice:C??void 0,activeYes:p===`${h.slug}:yes`,activeNo:p===`${h.slug}:no`,isExpanded:P,onToggleExpand:()=>f(h.slug),onTradeAction:g},h.id??`${v}-${h.slug}`)})})]}),m&&jsxs("button",{type:"button",onClick:()=>i(h=>!h),className:"flex w-full items-center justify-start gap-x-2 py-2 pl-1 text-xs text-neutral lg:pl-2 lg:text-sm cursor-pointer hover:text-foreground transition-colors",children:[jsx("span",{children:r(o?"predict.event.rules.collapse":"predict.event.moreMarketsLabel")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",o&&"rotate-180")})]})]})}function sp({market:e,yesPrice:t,noPrice:r,activeYes:n,activeNo:o,isExpanded:i,onToggleExpand:s,onTradeAction:l}){let{t:a}=useTranslation(),d=e.status==="open",p=e.volume?`$${Math.round(e.volume).toLocaleString("en-US")} vol`:void 0;return jsxs(Fragment,{children:[jsxs("tr",{className:"cursor-pointer border-b border-border text-xs hover:bg-content2 lg:text-base",onClick:s,role:"button",tabIndex:0,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),s());},children:[jsx("td",{className:"py-2 pl-1 lg:pl-2",children:jsxs("div",{className:"flex items-center gap-x-1 lg:gap-x-2",children:[e.image_url&&jsx(Avatar,{src:e.image_url,name:_r(e)?.[0]||"?",radius:"lg",className:"size-5 shrink-0 lg:size-8",imgProps:{className:"object-cover"}}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-foreground truncate max-w-[200px] lg:max-w-[300px]",children:_r(e)}),p&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:p})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:np(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:d?jsxs("div",{className:"flex items-center justify-end gap-x-2",children:[jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all focus-visible:outline-2 focus-visible:outline-primary/40 focus-visible:outline-offset-2",n?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"),onClick:u=>{u.stopPropagation(),l?.(e,"yes","buy");},children:a("predict.market.action.yes",{price:Ri(t)})}),jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all focus-visible:outline-2 focus-visible:outline-primary/40 focus-visible:outline-offset-2",o?"bg-secondary text-secondary-foreground":"bg-secondary/10 text-secondary"),onClick:u=>{u.stopPropagation(),l?.(e,"no","buy");},children:r!=null?a("predict.market.action.no",{price:Ri(r)}):a("predict.market.no")})]}):jsx("div",{className:"flex items-center justify-end",children:jsx("span",{className:cn$1("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",e.status==="closed"?"bg-neutral/10 text-neutral":e.status==="voided"?"bg-warning/10 text-warning":"bg-primary/10 text-primary"),children:e.status==="closed"?a("predict.event.status.closed"):e.status==="voided"?a("predict.event.status.voided"):a("predict.event.status.pending")})})})]}),i&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(Ei,{market:e,outcome:o?"no":"yes",onTradeAction:l})})})})]})}function ap({markets:e,event:t}){let{t:r}=useTranslation(),[n,o]=useState(false),[i,s]=useState(false),[l,a]=useState(0),d=e.filter(c=>c.rules&&c.rules.length>0||c.description);if(d.length===0)return null;let p=d[l]??d[0],u=p.rules&&p.rules.length>0?p.rules.join(`
|
|
88
88
|
|