diff --git a/apps/api/app/api/users/[id]/positions/route.ts b/apps/api/app/api/users/[id]/positions/route.ts index 88eabefd..936ca4a7 100644 --- a/apps/api/app/api/users/[id]/positions/route.ts +++ b/apps/api/app/api/users/[id]/positions/route.ts @@ -15,13 +15,14 @@ export async function GET( const searchParams = new URLSearchParams(url.search) const urlParams = Object.fromEntries(searchParams) - const { id, pageSize } = schema.GET.parameters.parse({ ...(params || {}), ...urlParams }) + const { id, pageSize, status } = schema.GET.parameters.parse({ ...(params || {}), ...urlParams }) const user = await getUserById({ id }) const { positions } = await getPositions( { accountId: user.primaryAccountId, + status, }, { field: 'updatedAt', direction: 'desc' }, { take: pageSize ?? 25, skip: 0 } diff --git a/apps/api/app/api/users/[id]/positions/schema.ts b/apps/api/app/api/users/[id]/positions/schema.ts index 988f49b1..ca126ecd 100644 --- a/apps/api/app/api/users/[id]/positions/schema.ts +++ b/apps/api/app/api/users/[id]/positions/schema.ts @@ -4,7 +4,10 @@ import { MarketOptionPositionSchema, UserSchema } from '@play-money/database' export default createSchema({ GET: { - parameters: UserSchema.pick({ id: true }).extend({ pageSize: z.coerce.number().optional() }), + parameters: UserSchema.pick({ id: true }).extend({ + pageSize: z.coerce.number().optional(), + status: z.enum(['active', 'closed', 'all']).optional(), + }), responses: { 200: z.object({ positions: z.array(MarketOptionPositionSchema), diff --git a/packages/comments/lib/createComment.ts b/packages/comments/lib/createComment.ts index 518f3da8..c86080ad 100644 --- a/packages/comments/lib/createComment.ts +++ b/packages/comments/lib/createComment.ts @@ -121,7 +121,7 @@ export async function createComment({ } else if (entityType === 'LIST') { const list = await getList({ id: entityId }) - if (authorId !== list.ownerId) { + if (![authorId, comment.parent?.authorId, ...userIdsMentioned].includes(list.ownerId)) { createNotification({ type: 'LIST_COMMENT', actorId: authorId, diff --git a/packages/finance/lib/getPositions.ts b/packages/finance/lib/getPositions.ts index 19eee383..7f028f3a 100644 --- a/packages/finance/lib/getPositions.ts +++ b/packages/finance/lib/getPositions.ts @@ -3,6 +3,7 @@ import { ExtendedMarketOptionPosition } from '../types' interface PositionsFilterOptions { accountId?: string + status?: 'active' | 'closed' | 'all' } interface SortOptions { @@ -20,11 +21,24 @@ export async function getPositions( sort: SortOptions = { field: 'createdAt', direction: 'desc' }, pagination: PaginationOptions = { skip: 0, take: 10 } ): Promise<{ positions: Array; total: number }> { + const statusFilters = + filters.status === 'active' + ? { + quantity: { gt: 0.0001 }, + } + : filters.status === 'closed' + ? { + quantity: { lte: 0.0001 }, + } + : filters.status === 'all' + ? {} + : {} + const [positions, total] = await Promise.all([ db.marketOptionPosition.findMany({ where: { accountId: filters.accountId, - value: { gt: 0 }, + ...statusFilters, }, include: { market: true, @@ -39,7 +53,7 @@ export async function getPositions( db.marketOptionPosition.count({ where: { accountId: filters.accountId, - value: { gt: 0 }, + ...statusFilters, }, }), ]) diff --git a/packages/markets/lib/getMarkets.ts b/packages/markets/lib/getMarkets.ts index 43cfdc88..5488fe27 100644 --- a/packages/markets/lib/getMarkets.ts +++ b/packages/markets/lib/getMarkets.ts @@ -38,6 +38,7 @@ export async function getMarkets( lt: new Date(), }, resolvedAt: null, + canceledAt: null, } : filters.status === 'resolved' ? { diff --git a/packages/ui/src/hooks/usePersistForm.ts b/packages/ui/src/hooks/usePersistForm.ts index cf22ff43..c7376833 100644 --- a/packages/ui/src/hooks/usePersistForm.ts +++ b/packages/ui/src/hooks/usePersistForm.ts @@ -20,6 +20,10 @@ export const getPersistedData = ({ defaultValue: T localStorageKey: string }): T => { + if (typeof window === 'undefined') { + return defaultValue + } + const data = localStorage.getItem(localStorageKey) if (data) { @@ -37,5 +41,9 @@ export const getPersistedData = ({ } export function clearPresistedData({ localStorageKey }: { localStorageKey: string }) { + if (typeof window === 'undefined') { + return + } + localStorage.removeItem(localStorageKey) } diff --git a/packages/users/components/UserPositionsTable.tsx b/packages/users/components/UserPositionsTable.tsx index 71f3d264..3c77dcd4 100644 --- a/packages/users/components/UserPositionsTable.tsx +++ b/packages/users/components/UserPositionsTable.tsx @@ -30,10 +30,17 @@ export const columns: Array> = [ }, cell: ({ row }) => { const option = row.original.option + const quantity = new Decimal(row.original.quantity).toDecimalPlaces(4) return ( - {_.truncate(option.name, { length: 40 })} + {quantity.gt(0) ? ( + <> + {_.truncate(option.name, { length: 40 })} + + ) : ( + <>Closed + )} ) }, @@ -49,8 +56,11 @@ export const columns: Array> = [ const cost = new Decimal(row.original.cost).toDecimalPlaces(4) const change = value.sub(cost).div(cost).times(100).round().toNumber() const changeLabel = `(${change > 0 ? '+' : ''}${change}%)` + const quantity = new Decimal(row.original.quantity).toDecimalPlaces(4) - return change ? 0 ? 'text-lime-500' : 'text-red-400'}>{changeLabel} : null + return change && quantity.gt(0) ? ( + 0 ? 'text-lime-500' : 'text-red-400'}>{changeLabel} + ) : null }, }, { diff --git a/packages/users/components/UserProfilePage.tsx b/packages/users/components/UserProfilePage.tsx index 80dfcc72..4a518411 100644 --- a/packages/users/components/UserProfilePage.tsx +++ b/packages/users/components/UserProfilePage.tsx @@ -199,7 +199,11 @@ async function UserPositionsTab({ sortDirection?: string } }) { - const { marketPositions, totalPages } = await getMarketPositions({ ownerId: userId, ...filters }) + const { marketPositions, totalPages } = await getMarketPositions({ + ownerId: userId, + ...filters, + status: filters?.status ?? 'active', + }) return (