Skip to content

Commit

Permalink
Trading Closed sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
casesandberg committed Sep 20, 2024
1 parent 9b615d7 commit dcd2e68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/markets/components/MarketPageSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import React from 'react'
import { isMarketResolved } from '../lib/helpers'
import { isMarketResolved, isMarketTradable } from '../lib/helpers'
import { ExtendedMarket } from '../types'
import { MarketTradePanel } from './MarketTradePanel'
import { RelatedMarkets } from './RelatedMarkets'
Expand All @@ -15,10 +15,12 @@ export function MarketPageSidebar({
activeOptionId: string
onTradeComplete: () => void
}) {
console.log(isMarketTradable(market))
return (
<div className="space-y-8">
<MarketTradePanel
market={market}
isTradable={isMarketTradable(market)}
isResolved={isMarketResolved(market)}
activeOptionId={activeOptionId}
onTradeComplete={onTradeComplete}
Expand Down
11 changes: 9 additions & 2 deletions packages/markets/components/MarketTradePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import { CircleOffIcon } from 'lucide-react'
import React from 'react'
import { mutate } from 'swr'
import {
Expand All @@ -8,7 +9,6 @@ import {
MY_BALANCE_PATH,
useMarketBalance,
} from '@play-money/api-helpers/client/hooks'
import { CurrencyDisplay } from '@play-money/finance/components/CurrencyDisplay'
import { useSearchParam } from '@play-money/ui'
import { Card, CardContent, CardHeader } from '@play-money/ui/card'
import { Combobox } from '@play-money/ui/combobox'
Expand All @@ -23,11 +23,13 @@ import { useSidebar } from './SidebarContext'

export function MarketTradePanel({
market,
isTradable = true,
isResolved = false,
activeOptionId,
onTradeComplete,
}: {
market: ExtendedMarket
isTradable: boolean
isResolved: boolean
activeOptionId: string
onTradeComplete?: () => void
Expand All @@ -53,7 +55,7 @@ export function MarketTradePanel({

return (
<div className="space-y-4">
{!isResolved ? (
{isTradable ? (
<Card className={cn(effect && 'animate-slide-in-right')} onAnimationEnd={resetEffect}>
<Tabs defaultValue="buy">
<CardHeader className="flex items-start bg-muted md:p-3">
Expand Down Expand Up @@ -88,6 +90,11 @@ export function MarketTradePanel({
</CardContent>
</Tabs>
</Card>
) : !isResolved ? (
<Card className="flex flex-col items-center justify-center gap-4 p-4 sm:h-64">
<CircleOffIcon className="size-8 stroke-[1.5px] text-muted-foreground" />
<div className="text-balance text-center text-sm uppercase text-muted-foreground">Trading closed</div>
</Card>
) : (
<MarketLeaderboardPanel market={market} />
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/markets/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function canResolveMarket({ market, userId }: { market: Market; userId?:

export function isMarketTradable(market: Market): boolean {
const now = new Date()
return !market.resolvedAt && (!market.closeDate || market.closeDate > now)
return !market.resolvedAt && (!market.closeDate || new Date(market.closeDate) > now)
}

export function isMarketResolved(market: ExtendedMarket): boolean {
Expand Down

0 comments on commit dcd2e68

Please sign in to comment.