PageSourceSearch

https://www.criptoxp.com.br/assets/Dashboard-CQpeIpuF.js

js criptoxp.com.br collected 2026-10-05 23:19:17 UTC 12,367 bytes, 5 lines download raw bytes

1import{j as e,R as X,l as ue,X as xe,Y as he,m as Z,n as ge,o as pe,i as fe,r as D,s as h,h as je,C as N,a as v,b as y,g as I,c as b,p as Ne,A as ve,q as ye,t as be,v as _e,w as Ae,e as q,T as Ce,x as Re,y as we}from"./index-cfPuqhaj.js";import{C as L}from"./card-kpi-no4bKsYd.js";import{L as Se,a as Be}from"./LineChart-DSZ4-tvl.js";import{P as De,a as Le}from"./PieChart-BA2QElJP.js";import{QuoteCard as J}from"./QuoteCard-BLWwO41r.js";import{f as O}from"./quotes-DDsfYPll.js";import{C as Q}from"./calendar-Dz-e4vms.js";import{D as Te}from"./dollar-sign-FuLC2YRa.js";import"./skeleton-CPU0MA4k.js";import"./refresh-cw-CG31ATXU.js";import"./trending-down-BlpjeSc0.js";function ke({data:u}){const t=n=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(n),f=n=>new Date(n).toLocaleDateString("pt-BR",{month:"short",year:"2-digit"});return e.jsx("div",{className:"h-[300px] w-full",children:e.jsx(X,{width:"100%",height:"100%",children:e.jsxs(Se,{data:u,children:[e.jsx(ue,{strokeDasharray:"3 3",className:"opacity-30"}),e.jsx(xe,{dataKey:"date",tickFormatter:f,className:"text-xs"}),e.jsx(he,{tickFormatter:t,className:"text-xs"}),e.jsx(Z,{formatter:n=>[t(n),"Saldo"],labelFormatter:n=>f(n),contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"0.5rem"}}),e.jsx(Be,{type:"monotone",dataKey:"value",stroke:"hsl(var(--primary))",strokeWidth:2,dot:{fill:"hsl(var(--primary))",strokeWidth:2,r:4},activeDot:{r:6,stroke:"hsl(var(--primary))",strokeWidth:2}})]})})})}const V=["hsl(142, 76%, 36%)","hsl(38, 92%, 50%)","hsl(217, 91%, 60%)","hsl(0, 84%, 60%)","hsl(262, 83%, 58%)","hsl(24, 100%, 50%)"];function Ie({data:u}){const t=n=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(n),f=({active:n,payload:c})=>{if(n&&c&&c.length){const l=c[0].payload;return e.jsxs("div",{className:"bg-card border border-border rounded-lg p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium",children:l.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t(l.value)," (",l.percentage.toFixed(1),"%)"]})]})}return null};return e.jsx("div",{className:"h-[300px] w-full",children:e.jsx(X,{width:"100%",height:"100%",children:e.jsxs(De,{children:[e.jsx(Le,{data:u,cx:"50%",cy:"50%",innerRadius:60,outerRadius:100,paddingAngle:2,dataKey:"value",children:u.map((n,c)=>e.jsx(ge,{fill:V[c%V.length]},`cell-${c}`))}),e.jsx(Z,{content:e.jsx(f,{})}),e.jsx(pe,{verticalAlign:"bottom",height:36,formatter:(n,c)=>e.jsx("span",{style:{color:c.color,fontSize:"12px"},children:n})})]})})})}function Ge(){var P,F,E,$,M,z,H,U,W,K,Y,G;const{user:u}=fe(),[t,f]=D.useState(null),[n,c]=D.useState(!0),[l,ee]=D.useState(null);D.useEffect(()=>{u&&(te(),se())},[u]);const te=async()=>{var o,R;try{c(!0);const{data:d}=await h.from("investor_accounts").select("id").eq("investor_id",u==null?void 0:u.id).single();if(!d){c(!1);return}const g=d.id,{data:qe}=await h.from("balances_history").select("date, end_balance").eq("account_id",g).order("date",{ascending:!0}),{data:i}=await h.from("monthly_results").select("year, month, return_percent, return_amount").eq("account_id",g).order("year",{ascending:!0}).order("month",{ascending:!0}),{data:x}=await h.from("positions").select(`
2          quantity,
3          avg_price,
4          assets!inner(symbol, name, class)
5        `).eq("account_id",g),{data:w}=await h.from("investment_amounts").select("total_invested").eq("account_id",g).maybeSingle(),T=(w==null?void 0:w.total_invested)||0,{data:j}=await h.from("withdrawals").select("amount, year, month").eq("account_id",g),ae=(j==null?void 0:j.reduce((s,a)=>s+Number(a.amount),0))||0,{data:k}=await h.from("monthly_results").select("return_amount").eq("account_id",g),re=(k==null?void 0:k.reduce((s,a)=>s+(Number(a.return_amount)||0),0))||0;let _=0;const S={};if(x&&x.length>0)for(const s of x){const a=(o=s.assets)==null?void 0:o.symbol;if(a){let m=0;if(a==="BTC"){const r=await O("btcbrl");r.success&&r.data&&(m=r.data.price,S.BTC=m)}else if(a==="USDT"||a==="USD"){const r=await O("usdbrl");r.success&&r.data&&(m=r.data.price,S[a]=m)}_+=s.quantity*m}}console.log("Dashboard calculation debug:",{totalInvested:T,totalReturnsAmount:re,totalWithdrawals:ae,currentBalance:_,assetPrices:S,accountId:g});const ne=((R=i==null?void 0:i[i.length-1])==null?void 0:R.return_percent)||0,le=(i==null?void 0:i.reduce((s,a)=>s+a.return_percent,0))||0,ce=(()=>
5{if(!w)return[];const s=[{month:6,year:2025,name:"Jun"},{month:7,year:2025,name:"Jul"},{month:8,year:2025,name:"Ago"}],a=[];let m=T;for(const r of s){const B=i==null?void 0:i.find(p=>p.year===r.year&&p.month===r.month);B&&(m+=Number(B.return_amount)||0);const de=(j==null?void 0:j.filter(p=>p.year===r.year&&p.month===r.month).reduce((p,me)=>p+Number(me.amount),0))||0;m-=de,a.push({date:`${r.year}-${String(r.month).padStart(2,"0")}-01`,value:Math.max(0,m)})}return a})(),oe=(i==null?void 0:i.map(s=>({month:`${s.year}-${String(s.month).padStart(2,"0")}`,return:s.return_percent})))||[],ie=(x==null?void 0:x.map(s=>{const a=s.assets.symbol,m=S[a]||s.avg_price,r=s.quantity*m,B=_>0?r/_*100:0;return{name:a,value:r,percentage:B}}))||[];f({totalInvested:T,currentBalance:_,monthlyReturn:ne,ytdReturn:le,numAssets:(x==null?void 0:x.length)||0,balanceHistory:ce,monthlyResults:oe,allocation:ie})}catch(d){console.error("Error loading dashboard data:",d)}finally{c(!1)}},se=async()=>{try{const{data:o,error:R}=await h.rpc("get_notices_with_search",{p_search:"",p_limit:1,p_offset:0});if(R||!o||o.length===0)return;const d=o[0];ee({id:d.id,content:d.content,created_at:d.created_at,author:{full_name:d.full_name,username:d.username,email:d.email,avatar_url:d.avatar_url}})}catch(o){console.error("Error loading latest notice:",o)}},A=o=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(o),C=o=>`${o>=0?"+":""}${o.toFixed(2)}%`;return n?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(je,{className:"h-8 w-8 animate-spin"})}):t?e.jsxs("div",{className:"space-y-4 lg:space-y-6 pb-20 lg:pb-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-xl lg:text-3xl font-bold",children:"Dashboard"}),e.jsx("p",{className:"text-sm lg:text-base text-muted-foreground",children:"Acompanhe a performance dos seus investimentos"})]}),e.jsxs(N,{className:"card-glass border-primary/20",children:[e.jsxs(v,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"h-5 w-5"}),"Últimas Atualizações"]}),e.jsx(I,{children:"Atividades recentes realizadas pelo administrador"})]}),e.jsx(b,{children:e.jsxs("div",{className:"space-y-3",children:[l&&e.jsx(Ne,{to:"/app/investidor/avisos",className:"block p-3 bg-accent/30 rounded-lg hover:bg-accent/50 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs(ve,{className:"h-8 w-8 flex-shrink-0",children:[e.jsx(ye,{src:(P=l.author)==null?void 0:P.avatar_url,alt:"Avatar"}),e.jsx(be,{className:"text-xs",children:((E=(F=l.author)==null?void 0:F.full_name)==null?void 0:E[0])||((M=($=l.author)==null?void 0:$.username)==null?void 0:M[0])||((U=(H=(z=l.author)==null?void 0:z.email)==null?void 0:H[0])==null?void 0:U.toUpperCase())||"A"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(_e,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"font-medium text-sm",children:"Novo aviso"})]}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2 mb-1",children:l.content}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:((W=l.author)==null?void 0:W.full_name)||((K=l.author)==null?void 0:K.username)||((Y=l.author)==null?void 0:Y.email)}),e.jsx("span",{children:"•"}),e.jsx("span",{children:Ae(new Date(l.created_at),{addSuffix:!0,locale:we})})]})]})]})}),t.monthlyResults.length>0&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-accent/30 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Novo resultado mensal"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Resultado do mês ",(G=t.monthlyResults[t.monthlyResults.length-1])==null?void 0:G.month]})]}),e.jsx(q,{variant:t.monthlyReturn>=0?"default":"destructive",children:C(t.monthlyReturn)})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-accent/30 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Saldo atualizado"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Última atualização de patr
5imônio"})]}),e.jsx("span",{className:"font-medium",children:A(t.currentBalance)})]}),t.numAssets>0&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-accent/30 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Carteira configurada"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ativos na sua carteira"})]}),e.jsxs("span",{className:"font-medium",children:[t.numAssets," ativos"]})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 lg:gap-4",children:[e.jsx(J,{title:"Dólar (USD/BRL)",endpoint:"usdbrl"}),e.jsx(J,{title:"Bitcoin (BTC/BRL)",endpoint:"btcbrl"})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 lg:gap-4",children:[e.jsx(L,{title:"Total Investido",value:A(t.totalInvested),icon:Te}),e.jsx(L,{title:"Saldo Atual",value:A(t.currentBalance),change:`Ganho: ${A(t.currentBalance-t.totalInvested)}`,changeType:t.currentBalance>=t.totalInvested?"positive":"negative",icon:Ce}),e.jsx(L,{title:"Retorno Mensal",value:C(t.monthlyReturn),changeType:t.monthlyReturn>=0?"positive":"negative",icon:Q}),e.jsx(L,{title:"Número de Ativos",value:t.numAssets.toString(),icon:Re})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 lg:gap-6",children:[e.jsxs(N,{className:"card-glass",children:[e.jsxs(v,{className:"pb-3 lg:pb-6",children:[e.jsx(y,{className:"text-lg lg:text-xl",children:"Evolução do Patrimônio"}),e.jsx(I,{className:"text-sm",children:"Crescimento do investimento ao longo do tempo"})]}),e.jsx(b,{className:"pt-0",children:e.jsx("div",{className:"h-64 lg:h-80",children:e.jsx(ke,{data:t.balanceHistory})})})]}),e.jsxs(N,{className:"card-glass",children:[e.jsxs(v,{className:"pb-3 lg:pb-6",children:[e.jsx(y,{className:"text-lg lg:text-xl",children:"Alocação por Ativo"}),e.jsx(I,{className:"text-sm",children:"Distribuição percentual dos investimentos"})]}),e.jsx(b,{className:"pt-0",children:e.jsx("div",{className:"h-64 lg:h-80",children:e.jsx(Ie,{data:t.allocation})})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 lg:gap-6",children:[e.jsxs(N,{className:"card-glass",children:[e.jsx(v,{className:"pb-3",children:e.jsx(y,{className:"text-base lg:text-lg",children:"Rentabilidade YTD"})}),e.jsxs(b,{className:"pt-0",children:[e.jsx("div",{className:"text-xl lg:text-2xl font-bold",children:e.jsx(q,{variant:t.ytdReturn>=0?"default":"destructive",className:"text-sm lg:text-lg px-2 lg:px-3 py-1",children:C(t.ytdReturn)})}),e.jsx("p",{className:"text-xs lg:text-sm text-muted-foreground mt-2",children:"Acumulado no ano"})]})]}),e.jsxs(N,{className:"card-glass",children:[e.jsx(v,{className:"pb-3",children:e.jsx(y,{className:"text-base lg:text-lg",children:"Último Mês"})}),e.jsxs(b,{className:"pt-0",children:[e.jsx("div",{className:"text-xl lg:text-2xl font-bold",children:e.jsx(q,{variant:t.monthlyReturn>=0?"default":"destructive",className:"text-sm lg:text-lg px-2 lg:px-3 py-1",children:C(t.monthlyReturn)})}),e.jsx("p",{className:"text-xs lg:text-sm text-muted-foreground mt-2",children:"Performance do mês anterior"})]})]}),e.jsxs(N,{className:"card-glass",children:[e.jsx(v,{className:"pb-3",children:e.jsx(y,{className:"text-base lg:text-lg",children:"Total de Ativos"})}),e.jsxs(b,{className:"pt-0",children:[e.jsx("div",{className:"text-xl lg:text-2xl font-bold text-primary",children:t.numAssets}),e.jsx("p",{className:"text-xs lg:text-sm text-muted-foreground mt-2",children:"Ativos na carteira"})]})]})]})]}):e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"Nenhum dado encontrado. Entre em contato com o administrador."})})}export{Ge 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.