From e083739cd5379c24f3840fdc314b2f4cccfc23b0 Mon Sep 17 00:00:00 2001 From: case Date: Mon, 21 Oct 2024 10:48:55 -0700 Subject: [PATCH 1/5] Fix local storage crashing the create market page --- packages/ui/src/hooks/usePersistForm.ts | 8 ++++++++ 1 file changed, 8 insertions(+) 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) } From b284140cb948653af0c97804dd1427edb1835a8f Mon Sep 17 00:00:00 2001 From: case Date: Mon, 21 Oct 2024 10:56:52 -0700 Subject: [PATCH 2/5] Prevent Double notifications on list comments --- packages/comments/lib/createComment.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/comments/lib/createComment.ts b/packages/comments/lib/createComment.ts index 518f3da8..20676c85 100644 --- a/packages/comments/lib/createComment.ts +++ b/packages/comments/lib/createComment.ts @@ -121,6 +121,8 @@ export async function createComment({ } else if (entityType === 'LIST') { const list = await getList({ id: entityId }) + if ([authorId, comment.parent?.authorId, ...userIdsMentioned].includes(list.ownerId)) return + if (authorId !== list.ownerId) { createNotification({ type: 'LIST_COMMENT', From 485845a8ea677e8045c848b7f796945faef630e3 Mon Sep 17 00:00:00 2001 From: case Date: Mon, 21 Oct 2024 11:08:01 -0700 Subject: [PATCH 3/5] Stop canceled markets from showing up in closed category --- packages/markets/lib/getMarkets.ts | 1 + 1 file changed, 1 insertion(+) 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' ? { From aebc718b67d77ac57e3714ef4483c1fc37b6bc0d Mon Sep 17 00:00:00 2001 From: case Date: Mon, 21 Oct 2024 11:25:51 -0700 Subject: [PATCH 4/5] Fix user positions table status --- apps/api/app/api/users/[id]/positions/route.ts | 3 ++- .../api/app/api/users/[id]/positions/schema.ts | 5 ++++- packages/finance/lib/getPositions.ts | 18 ++++++++++++++++-- .../users/components/UserPositionsTable.tsx | 14 ++++++++++++-- packages/users/components/UserProfilePage.tsx | 6 +++++- 5 files changed, 39 insertions(+), 7 deletions(-) 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/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/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 (
From dce815d83b8d8fa08df224c7963cdd474896bd37 Mon Sep 17 00:00:00 2001 From: case Date: Mon, 21 Oct 2024 11:31:40 -0700 Subject: [PATCH 5/5] Fix build --- packages/comments/lib/createComment.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/comments/lib/createComment.ts b/packages/comments/lib/createComment.ts index 20676c85..c86080ad 100644 --- a/packages/comments/lib/createComment.ts +++ b/packages/comments/lib/createComment.ts @@ -121,9 +121,7 @@ export async function createComment({ } else if (entityType === 'LIST') { const list = await getList({ id: entityId }) - if ([authorId, comment.parent?.authorId, ...userIdsMentioned].includes(list.ownerId)) return - - if (authorId !== list.ownerId) { + if (![authorId, comment.parent?.authorId, ...userIdsMentioned].includes(list.ownerId)) { createNotification({ type: 'LIST_COMMENT', actorId: authorId,