Rm itemType field

This commit is contained in:
Pico2x 2022-10-14 11:56:33 +01:00
parent 46739d116c
commit 1bae261e68
8 changed files with 14 additions and 13 deletions

View File

@ -67,7 +67,6 @@ export type Contract<T extends AnyContractType = AnyContractType> = {
flaggedByUsernames?: string[]
openCommentBounties?: number
unlistedById?: string
itemType: 'contract'
} & T
export type BinaryContract = Contract & Binary

View File

@ -78,7 +78,6 @@ export function getNewContract(
liquidityFee: 0,
platformFee: 0,
},
itemType: 'contract',
})
return contract as Contract

View File

@ -16,8 +16,6 @@ export type Post = {
likedByUserIds?: string[]
likedByUserCount?: number
itemType: 'post'
}
export type DateDoc = Post & {

View File

@ -19,7 +19,7 @@ export function ExtraContractActionsRow(props: { contract: Contract }) {
<Row className="gap-1">
<FollowMarketButton contract={contract} user={user} />
<LikeItemButton item={contract} user={user} />
<LikeItemButton item={contract} user={user} itemType={'contract'} />
<Tooltip text="Share" placement="bottom" noTap noFade>
<IconButton

View File

@ -15,8 +15,9 @@ import { Post } from 'common/post'
export function LikeItemButton(props: {
item: Contract | Post
user: User | null | undefined
itemType: string
}) {
const { item, user } = props
const { item, user, itemType } = props
const tips = useItemTipTxns(item.id)
@ -36,7 +37,7 @@ export function LikeItemButton(props: {
if (!user) return firebaseLogin()
setIsLiking(true)
likeItem(user, item).catch(() => setIsLiking(false))
likeItem(user, item, itemType).catch(() => setIsLiking(false))
toast(`You tipped ${item.creatorName} ${formatMoney(LIKE_TIP_AMOUNT)}!`)
}

View File

@ -7,7 +7,7 @@ import { useUserLikedContracts } from 'web/hooks/use-likes'
import { SiteLink } from 'web/components/site-link'
import { Row } from 'web/components/layout/row'
import { XIcon } from '@heroicons/react/outline'
import { unLikeContract } from 'web/lib/firebase/likes'
import { unLikeItem } from 'web/lib/firebase/likes'
import { contractPath } from 'web/lib/firebase/contracts'
export function UserLikesButton(props: { user: User; className?: string }) {
@ -36,7 +36,7 @@ export function UserLikesButton(props: { user: User; className?: string }) {
</SiteLink>
<XIcon
className="ml-2 h-5 w-5 shrink-0 cursor-pointer"
onClick={() => unLikeContract(user.id, likedContract.id)}
onClick={() => unLikeItem(user.id, likedContract.id)}
/>
</Row>
))}

View File

@ -18,7 +18,11 @@ export const unLikeItem = async (userId: string, itemId: string) => {
return await deleteDoc(ref)
}
export const likeItem = async (user: User, item: Contract | Post) => {
export const likeItem = async (
user: User,
item: Contract | Post,
itemType: string
) => {
if (user.balance < LIKE_TIP_AMOUNT) {
toast('You do not have enough M$ to like this market!')
return
@ -34,7 +38,7 @@ export const likeItem = async (user: User, item: Contract | Post) => {
token: 'M$',
category: 'TIP',
data: { contractId: item.id },
description: `${user.name} liked ${item.itemType} ${item.id} for M$ ${LIKE_TIP_AMOUNT} to ${item.creatorId} `,
description: `${user.name} liked ${itemType}${item.id} for M$ ${LIKE_TIP_AMOUNT} to ${item.creatorId} `,
})
console.log('result', result)
}
@ -45,7 +49,7 @@ export const likeItem = async (user: User, item: Contract | Post) => {
id: ref.id,
userId: user.id,
createdTime: Date.now(),
type: item.itemType,
type: itemType,
tipTxnId: result.txn.id,
} as Like)
track('like', {

View File

@ -94,7 +94,7 @@ export default function PostPage(props: {
</div>
</Col>
<Row className="items-center">
<LikeItemButton item={post} user={user} />
<LikeItemButton item={post} user={user} itemType={'post'} />
<Col className="px-2">
<Button