UNPKG

@accounter/client

Version:
1 lines 6.93 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{s as r,t as i}from"./routes-D0AKaVmS.js";import{J as a,Tt as o,wt as s,yt as c}from"./common-3blB_OGJ.js";import{o as l}from"./select-Bp1lD5cE.js";import{a as u,b as d,c as f,n as p,r as m}from"./separator-5ROkkkxt.js";import{a as h,c as g,d as _,i as v,n as y,o as b,r as x,s as S,t as C}from"./table-B6QCIQQv.js";import{fa as w,ls as T}from"./graphql-lcoKwSC9.js";import{B as E}from"./index-DMUEhX8V.js";import{n as D,r as O,t as k}from"./alert-55QsYEfR.js";import{t as A}from"./page-layout-Dg61gTWe.js";import{a as j,i as M,r as N,t as P}from"./empty-BJZb5Yi4.js";import{n as F,r as I}from"./security-executions-table-DoQmw4zs.js";import{t as L}from"./spinner-mf84JPDS.js";import{t as R}from"./security-descriptor-badges-CiNJ3N-U.js";var z=e(n(),1),B=t();function V(e){let{security:t}=e;return[t.engName,t.hebName,t.symbol,t.isin,t.exchange,t.currencyCode,...t.identifiers.map(e=>e.value)]}var H=e=>e.security.engName??e.security.isin,U=e=>(t,n)=>(t.original.position[e]?.raw??-1/0)-(n.original.position[e]?.raw??-1/0),W=e=>(t,n)=>(t.original.position[e]??``).localeCompare(n.original.position[e]??``),G=[{id:`security`,accessorFn:H,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`Security`}),cell:({row:e})=>{let{security:t}=e.original;return(0,B.jsxs)(r,{to:i.BUSINESSES.DETAIL(t.id),state:{from:i.SECURITIES},className:`font-medium text-blue-600 hover:underline`,children:[H(e.original),t.symbol&&(0,B.jsxs)(`span`,{className:`text-gray-500`,children:[` (`,t.symbol,`)`]}),t.hebName&&(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:t.hebName})]})}},{id:`isin`,accessorFn:e=>e.security.isin,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`ISIN`}),cell:({row:e})=>(0,B.jsx)(`span`,{className:`font-mono text-xs`,children:e.original.security.isin})},{id:`descriptors`,header:`Details`,enableSorting:!1,cell:({row:e})=>(0,B.jsx)(R,{security:e.original.security,withIsin:!1})},{id:`quantity`,accessorFn:e=>e.position.quantity,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`Current hold`}),cell:({row:e})=>(0,B.jsx)(`span`,{className:`tabular-nums`,children:I(e.original.position.quantity)})},{id:`averageCost`,accessorFn:e=>e.position.averageCost?.raw??null,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`Average cost`}),sortFn:U(`averageCost`),cell:({row:e})=>(0,B.jsx)(`span`,{className:`whitespace-nowrap tabular-nums`,children:e.original.position.averageCost?.formatted??`—`})},{id:`totalBought`,accessorFn:e=>e.position.totalBought?.raw??null,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`Total bought`}),sortFn:U(`totalBought`),cell:({row:e})=>(0,B.jsx)(`span`,{className:`whitespace-nowrap tabular-nums`,children:e.original.position.totalBought?.formatted??`—`})},{id:`totalSold`,accessorFn:e=>e.position.totalSold?.raw??null,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`Total sold`}),sortFn:U(`totalSold`),cell:({row:e})=>(0,B.jsx)(`span`,{className:`whitespace-nowrap tabular-nums`,children:e.original.position.totalSold?.formatted??`—`})},{id:`lastExecutionDate`,accessorFn:e=>e.position.lastExecutionDate,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`Last execution`}),sortFn:W(`lastExecutionDate`),cell:({row:e})=>(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:F(e.original.position.lastExecutionDate)||`—`})},{id:`historyStartDate`,accessorFn:e=>e.position.historyStartDate,header:({column:e})=>(0,B.jsx)(o,{column:e,title:`History since`}),sortFn:W(`historyStartDate`),cell:({row:e})=>(0,B.jsx)(`span`,{className:`whitespace-nowrap`,children:F(e.original.position.historyStartDate)||`—`})}],K=()=>{let[e,t]=(0,z.useState)(!1),[n,r]=(0,z.useState)(``),[{data:i,fetching:o,error:F}]=T({query:w,variables:{includeClosed:e}}),{setFiltersContext:I}=(0,z.useContext)(f),R=(0,z.useMemo)(()=>i?.securityHoldings??[],[i?.securityHoldings]),H=(0,z.useMemo)(()=>{let e=n.trim().toLowerCase();return e?R.filter(t=>V(t).some(t=>t?.toLowerCase().includes(e))):R},[R,n]),U=g({features:S,data:H,columns:G,getRowId:e=>e.id,initialState:{sorting:[{id:`quantity`,desc:!0}],pagination:{pageIndex:0,pageSize:100}}}),{pageIndex:W,pageSize:K}=U.state.pagination,q=U.getPageCount();return(0,z.useEffect)(()=>{I((0,B.jsx)(`div`,{className:`flex items-center justify-end gap-10 space-x-2 py-4`,children:(0,B.jsx)(s,{table:U})}))},[I,W,K,q]),(0,B.jsx)(A,{title:`Securities (${H.length})`,description:`What you hold, added up from the scraped executions`,headerActions:(0,B.jsxs)(`div`,{className:`flex flex-row flex-wrap items-center gap-4`,children:[o&&(0,B.jsx)(L,{}),(0,B.jsxs)(p,{className:`max-w-xs`,children:[(0,B.jsx)(u,{placeholder:`Search name, symbol, ISIN...`,value:n,onChange:e=>{r(e.target.value),U.setPageIndex(0)},className:`ps-10`}),(0,B.jsx)(m,{children:(0,B.jsx)(d,{})})]}),(0,B.jsxs)(`div`,{className:`flex flex-row items-center gap-2`,children:[(0,B.jsx)(c,{id:`include-closed`,checked:e,onCheckedChange:e=>{t(e),U.setPageIndex(0)}}),(0,B.jsx)(l,{htmlFor:`include-closed`,className:`whitespace-nowrap`,children:`Show closed positions`})]})]}),children:F?(0,B.jsxs)(k,{variant:`destructive`,children:[(0,B.jsx)(O,{children:`Could not load securities`}),(0,B.jsx)(D,{children:F.message})]}):o?(0,B.jsx)(`div`,{className:`rounded-md border p-4`,children:(0,B.jsx)(a,{columns:G.length,rows:10})}):R.length===0?(0,B.jsxs)(P,{className:`py-8 sm:py-12`,children:[(0,B.jsx)(M,{children:(0,B.jsx)(E,{className:`size-8 sm:size-10 text-muted-foreground`})}),(0,B.jsx)(j,{children:e?`No securities yet`:`No open positions`}),(0,B.jsx)(N,{children:e?`Securities appear here once trades naming them have been ingested.`:`Nothing is currently held. Turn on "Show closed positions" to see securities that were sold out.`})]}):(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsx)(`div`,{className:`rounded-md border`,children:(0,B.jsxs)(C,{children:[(0,B.jsx)(h,{children:U.getHeaderGroups().map(e=>(0,B.jsx)(b,{children:e.headers.map(e=>(0,B.jsx)(v,{children:e.isPlaceholder?null:_(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,B.jsx)(y,{children:U.getRowModel().rows.length===0?(0,B.jsx)(b,{children:(0,B.jsx)(x,{colSpan:G.length,className:`text-center py-8`,children:`No securities match this search`})}):U.getRowModel().rows.map(e=>(0,B.jsx)(b,{children:e.getVisibleCells().map(e=>(0,B.jsx)(x,{children:_(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})}),(0,B.jsx)(`p`,{className:`text-xs text-gray-400`,children:`Holdings are added up from the scraped executions, not read from a balance the bank reports. Anything held before a security's first scraped trade is therefore not counted, and a change in units with no execution behind it — a split, say — is invisible. Amounts are in each security's own trade currency and are never converted, so they do not compare across currencies.`})]})})};export{K as Securities};