2022-08-31 03:28:30 +00:00
|
|
|
import clsx from 'clsx'
|
2022-06-27 00:00:02 +00:00
|
|
|
import dayjs from 'dayjs'
|
2022-09-15 15:12:56 +00:00
|
|
|
import { BETTOR, User } from 'common/user'
|
2022-06-27 00:00:02 +00:00
|
|
|
import { useUser, useUserById } from 'web/hooks/use-user'
|
|
|
|
import { Row } from 'web/components/layout/row'
|
|
|
|
import { Avatar, EmptyAvatar } from 'web/components/avatar'
|
|
|
|
import { formatMoney } from 'common/util/format'
|
|
|
|
import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
|
|
|
import React from 'react'
|
|
|
|
import { LiquidityProvision } from 'common/liquidity-provision'
|
2022-08-30 15:38:59 +00:00
|
|
|
import { UserLink } from 'web/components/user-link'
|
2022-06-27 00:00:02 +00:00
|
|
|
|
|
|
|
export function FeedLiquidity(props: {
|
2022-08-30 09:41:47 +00:00
|
|
|
className?: string
|
2022-06-27 00:00:02 +00:00
|
|
|
liquidity: LiquidityProvision
|
|
|
|
}) {
|
2022-08-30 09:41:47 +00:00
|
|
|
const { liquidity } = props
|
2022-09-15 20:47:07 +00:00
|
|
|
const { userId, createdTime } = liquidity
|
2022-06-27 00:00:02 +00:00
|
|
|
|
|
|
|
const isBeforeJune2022 = dayjs(createdTime).isBefore('2022-06-01')
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
const bettor = isBeforeJune2022 ? undefined : useUserById(userId)
|
|
|
|
|
|
|
|
const user = useUser()
|
|
|
|
const isSelf = user?.id === userId
|
|
|
|
|
|
|
|
return (
|
2022-09-14 08:13:53 +00:00
|
|
|
<Row className="items-center gap-2 pt-3">
|
2022-08-31 03:28:30 +00:00
|
|
|
{isSelf ? (
|
|
|
|
<Avatar avatarUrl={user.avatarUrl} username={user.username} />
|
|
|
|
) : bettor ? (
|
|
|
|
<Avatar avatarUrl={bettor.avatarUrl} username={bettor.username} />
|
|
|
|
) : (
|
|
|
|
<div className="relative px-1">
|
|
|
|
<EmptyAvatar />
|
2022-06-27 00:00:02 +00:00
|
|
|
</div>
|
2022-08-31 03:28:30 +00:00
|
|
|
)}
|
|
|
|
<LiquidityStatusText
|
|
|
|
liquidity={liquidity}
|
|
|
|
isSelf={isSelf}
|
|
|
|
bettor={bettor}
|
|
|
|
className={'flex-1'}
|
|
|
|
/>
|
|
|
|
</Row>
|
2022-06-27 00:00:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function LiquidityStatusText(props: {
|
|
|
|
liquidity: LiquidityProvision
|
|
|
|
isSelf: boolean
|
|
|
|
bettor?: User
|
2022-08-31 03:28:30 +00:00
|
|
|
className?: string
|
2022-06-27 00:00:02 +00:00
|
|
|
}) {
|
2022-08-31 03:28:30 +00:00
|
|
|
const { liquidity, bettor, isSelf, className } = props
|
2022-06-27 00:00:02 +00:00
|
|
|
const { amount, createdTime } = liquidity
|
|
|
|
|
|
|
|
// TODO: Withdrawn liquidity will never be shown, since liquidity amounts currently are zeroed out upon withdrawal.
|
|
|
|
const bought = amount >= 0 ? 'added' : 'withdrew'
|
|
|
|
const money = formatMoney(Math.abs(amount))
|
|
|
|
|
|
|
|
return (
|
2022-08-31 03:28:30 +00:00
|
|
|
<div className={clsx(className, 'text-sm text-gray-500')}>
|
2022-06-27 00:00:02 +00:00
|
|
|
{bettor ? (
|
|
|
|
<UserLink name={bettor.name} username={bettor.username} />
|
|
|
|
) : (
|
2022-09-15 15:12:56 +00:00
|
|
|
<span>{isSelf ? 'You' : `A ${BETTOR}`}</span>
|
2022-06-27 00:00:02 +00:00
|
|
|
)}{' '}
|
2022-07-25 19:22:38 +00:00
|
|
|
{bought} a subsidy of {money}
|
2022-06-27 00:00:02 +00:00
|
|
|
<RelativeTimestamp time={createdTime} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|