1import{r as v,j as t}from"./ui-vendor-efoDfjla.js";import{c as k,a as b}from"./router-vendor-CSWcbrtA.js";import{c as F}from"./index-Dy-yis_s.js";import{H as N,L as R}from"./utils-vendor-BXji2ymy.js";import"./query-vendor-BYBWvLyW.js";const f="vaulticks-tradovate-return-to";function w(){const[r]=k(),n=b(),[g,u]=v.useState("");return v.useEffect(()=>{const i=r.get("code"),l=r.get("state"),d=r.get("error"),T=r.get("error_description");let c="/settings?tradovate_connected=1";try{const o=localStorage.getItem(f);o&&(c=o,localStorage.removeItem(f))}catch{}if(console.log("[TradovateCallback] Params:",{code:i?"present":"missing",state:l?"present":"missing",error:d,returnTo:c}),d){const o=T||d||"Authorization denied";console.error("[TradovateCallback] OAuth error from Tradovate:",o),n(`/settings?tradovate_error=1&message=${encodeURIComponent(o)}`,{replace:!0});return}if(!i||!l){const o="Missing authorization code or state parameter";console.error("[TradovateCallback]",o),n(`/settings?tradovate_error=1&message=${encodeURIComponent(o)}`,{replace:!0});return}async function C(){var o,p,x,h;try{console.log("[TradovateCallback] Exchanging code for token via /api/v1/tradovate/auth/exchange");const e=await F.apiCall.invoke({url:"/api/v1/tradovate/auth/exchange",method:"POST",data:{code:i,state:l}});console.log("[TradovateCallback] Exchange response:",e==null?void 0:e.data);const s=e==null?void 0:e.data;if(s!=null&&s.success)console.log("[TradovateCallback] Success! Redirecting to:",c),n(c,{replace:!0});else{const a=(s==null?void 0:s.message)||"Token exchange failed";console.error("[TradovateCallback] Exchange failed:",a),n(`/settings?tradovate_error=1&message=${encodeURIComponent(a)}`,{replace:!0})}}catch(e){console.error("[TradovateCallback] Exchange error:",e);const s=(e==null?void 0:e.status)??(e==null?void 0:e.statusCode)??((o=e==null?void 0:e.response)==null?void 0:o.status),a=((x=(p=e==null?void 0:e.response)==null?void 0:p.data)==null?void 0:x.detail)??((h=e==null?void 0:e.data)==null?void 0:h.detail)??(e==null?void 0:e.detail),E=typeof a=="object"?a==null?void 0:a.reason:void 0;if(s===403&&E==="account_limit"){const j=`Manual Mode includes ${(a==null?void 0:a.limit)??3} connected accounts â upgrade to Auto Mode for unlimited.`;u(j),setTimeout(()=>{n("/pricing",{replace:!0})},4e3)}else{const m=(typeof a=="string"?a:null)||(e==null?void 0:e.message)||"Failed to complete Tradovate connection";u(m),setTimeout(()=>{n(`/settings?tradovate_error=1&message=${encodeURIComponent(m)}`,{replace:!0})},3e3)}}}C()},[r,n]),t.jsx("div",{className:"min-h-screen bg-[#0D1117] flex items-center justify-center",children:t.jsx("div",{className:"text-center space-y-4",children:g?t.jsxs(t.Fragment,{children:[t.jsx(N,{className:"w-10 h-10 text-[#EF4444] mx-auto"}),t.jsx("p",{className:"text-[#F0F6FC] text-lg font-semibold",children:"Connection Failed"}),t.jsx("p",{className:"text-[#8B949E] text-sm max-w-md",children:g}),t.jsx("p",{className:"text-[#8B949E] text-xs",children:"Redirecting to settings..."})]}):t.jsxs(t.Fragment,{children:[t.jsx(R,{className:"w-10 h-10 text-[#58A6FF] mx-auto animate-spin"}),t.jsx("p",{className:"text-[#F0F6FC] text-lg font-semibold",children:"Connecting Tradovate..."}),t.jsx("p",{className:"text-[#8B949E] text-sm",children:"Completing authorization, please wait."})]})})})}export{f as TRADOVATE_RETURN_TO_KEY,w as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.