Skip to content

Commit

Permalink
Merge pull request #114 from casesandberg/fix/10-15-tweaks
Browse files Browse the repository at this point in the history
10/15 Tweaks
  • Loading branch information
casesandberg authored Oct 16, 2024
2 parents 4f44802 + 69e3cfc commit c639407
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
3 changes: 3 additions & 0 deletions apps/web/app/(app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RecentTrades } from '@play-money/finance/components/RecentTrades'
import { MarketProbabilityDetail } from '@play-money/markets/components/MarketProbabilityDetail'
import { UserQuestCard } from '@play-money/quests/components/UserQuestCard'
import { SidebarReferralAlert } from '@play-money/referrals/components/SidebarReferralAlert'
import { SignedInReferralAlert } from '@play-money/referrals/components/SignedInReferralAlert'
import { formatDistanceToNowShort } from '@play-money/ui'
import { UserAvatar } from '@play-money/ui/UserAvatar'
import { Button } from '@play-money/ui/button'
Expand Down Expand Up @@ -175,6 +176,8 @@ export default async function AppPage() {
<div className="pb-2 text-xs font-semibold uppercase text-muted-foreground">New liquidity</div>
<RecentLiquidity />
</div>

<SignedInReferralAlert />
</div>
</div>
)
Expand Down
13 changes: 10 additions & 3 deletions packages/markets/components/MarketOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MY_BALANCE_PATH,
useMarketBalance,
} from '@play-money/api-helpers/client/hooks'
import { CurrencyDisplay } from '@play-money/finance/components/CurrencyDisplay'
import { marketOptionBalancesToProbabilities } from '@play-money/finance/lib/helpers'
import { UserAvatar } from '@play-money/ui/UserAvatar'
import { Alert, AlertDescription, AlertTitle } from '@play-money/ui/alert'
Expand Down Expand Up @@ -108,6 +109,12 @@ export function MarketOverviewPage({
{Math.round(mostLikelyOption.probability || 0)}% {_.truncate(mostLikelyOption.name, { length: 30 })}
</div>
) : null}
{market.liquidityCount ? (
<div className="flex-shrink-0">
<CurrencyDisplay value={market.liquidityCount} isShort /> Vol.
</div>
) : null}

{market.closeDate ? (
<div className="flex-shrink-0">
{isPast(market.closeDate) ? 'Ended' : 'Ending'} {format(market.closeDate, 'MMM d, yyyy')}
Expand Down Expand Up @@ -210,11 +217,11 @@ export function MarketOverviewPage({
) : null}
</CardContent>

<CardContent>
<ReadMoreEditor value={market.description} maxLines={6} />
<CardContent className="space-y-2">
{market.description ? <ReadMoreEditor value={market.description} maxLines={6} /> : null}

{market.tags.length ? (
<div className="mt-2 flex flex-wrap gap-2">
<div className="flex flex-wrap gap-2">
{market.tags.map((tag) => (
<Link href={`/questions/tagged/${tag}`} key={tag}>
<Badge variant="secondary">{tag}</Badge>
Expand Down
6 changes: 5 additions & 1 deletion packages/markets/components/MarketPositionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export function MarketPositionsPage({
{Math.round(mostLikelyOption.probability || 0)}% {_.truncate(mostLikelyOption.name, { length: 30 })}
</div>
) : null}

{market.liquidityCount ? (
<div className="flex-shrink-0">
<CurrencyDisplay value={market.liquidityCount} isShort /> Vol.
</div>
) : null}
{market.closeDate ? (
<div className="flex-shrink-0">
{isPast(market.closeDate) ? 'Ended' : 'Ending'} {format(market.closeDate, 'MMM d, yyyy')}
Expand Down
52 changes: 52 additions & 0 deletions packages/referrals/components/SignedInReferralAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use client'

import { ArrowRight, UserPlusIcon } from 'lucide-react'
import { useRouter } from 'next/navigation'
import React from 'react'
import { CurrencyDisplay } from '@play-money/finance/components/CurrencyDisplay'
import {
DAILY_COMMENT_BONUS_PRIMARY,
DAILY_LIQUIDITY_BONUS_PRIMARY,
DAILY_MARKET_BONUS_PRIMARY,
DAILY_TRADE_BONUS_PRIMARY,
} from '@play-money/finance/economy'
import { Spotlight, useSpotlight } from '@play-money/ui/Spotlight'
import { UserAvatar } from '@play-money/ui/UserAvatar'
import { Alert, AlertDescription, AlertTitle } from '@play-money/ui/alert'
import { Button } from '@play-money/ui/button'
import { cn } from '@play-money/ui/utils'
import { UserLink } from '@play-money/users/components/UserLink'
import { useUser } from '@play-money/users/context/UserContext'
import { useReferral } from './ReferralContext'

const BONUS =
DAILY_TRADE_BONUS_PRIMARY * 7 +
DAILY_MARKET_BONUS_PRIMARY * 7 +
DAILY_COMMENT_BONUS_PRIMARY * 7 +
DAILY_LIQUIDITY_BONUS_PRIMARY * 7

export function SignedInReferralAlert() {
const router = useRouter()
const { user } = useUser()
const { mouseX, mouseY, handleMouseMove, classNames } = useSpotlight()

return user ? (
<Alert
className={cn(
'flex cursor-pointer items-center gap-4 border-blue-300 bg-blue-50 pb-3 dark:bg-blue-600/20',
classNames
)}
onMouseMove={handleMouseMove}
onClick={() => router.push('/settings/referrals')}
>
{/* <UserAvatar user={referringUser} /> */}
<UserPlusIcon className="h-4 w-4 stroke-blue-500" />
<AlertDescription className="text-blue-500">
Refer a new user, earn up to <CurrencyDisplay value={BONUS} isShort className="underline underline-offset-2" />{' '}
<ArrowRight className="inline-block h-4 w-4" />
</AlertDescription>

<Spotlight mouseX={mouseX} mouseY={mouseY} color="blue" />
</Alert>
) : null
}
29 changes: 16 additions & 13 deletions packages/users/lib/getUserTotalTimeSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export async function getUserTotalTimeSeries({
type: {
notIn: excludeTransactionTypes,
},
isReverse: null,
},
},
include: {
Expand Down Expand Up @@ -103,23 +102,27 @@ export async function getUserTotalTimeSeries({
bucket.transactionEntries.forEach((entry) => {
if (entry.fromAccountId === accountId) {
bucket.balance = bucket.balance.sub(entry.amount)

if (entry.transaction.type === 'LIQUIDITY_DEPOSIT' || entry.transaction.type === 'LIQUIDITY_INITIALIZE') {
bucket.liquidity = bucket.liquidity.add(entry.amount)
}

if (entry.transaction.type === 'TRADE_BUY') {
bucket.markets = bucket.markets.add(entry.amount)
}
} else if (entry.toAccountId === accountId) {
bucket.balance = bucket.balance.add(entry.amount)
}

if (entry.transaction.type === 'LIQUIDITY_WITHDRAWAL' || entry.transaction.type === 'LIQUIDITY_RETURNED') {
bucket.liquidity = Decimal.max(bucket.liquidity.sub(entry.amount), 0) // Stop negative numbers
if (['TRADE_SELL', 'TRADE_WIN', 'TRADE_LOSS', 'TRADE_BUY'].includes(entry.transaction.type)) {
if (entry.fromAccountId === accountId) {
bucket.markets = bucket.markets.add(entry.amount)
} else if (entry.toAccountId === accountId) {
bucket.markets = Decimal.max(bucket.markets.sub(entry.amount), 0) // Stop negative numbers
}
}

if (entry.transaction.type === 'TRADE_SELL' || entry.transaction.type === 'TRADE_WIN') {
bucket.markets = Decimal.max(bucket.markets.sub(entry.amount), 0) // Stop negative numbers
if (
['LIQUIDITY_WITHDRAWAL', 'LIQUIDITY_RETURNED', 'LIQUIDITY_DEPOSIT', 'LIQUIDITY_INITIALIZE'].includes(
entry.transaction.type
)
) {
if (entry.fromAccountId === accountId) {
bucket.liquidity = bucket.liquidity.add(entry.amount)
} else if (entry.toAccountId === accountId) {
bucket.liquidity = Decimal.max(bucket.liquidity.sub(entry.amount), 0) // Stop negative numbers
}
}
})
Expand Down

0 comments on commit c639407

Please sign in to comment.