Skip to content

Commit

Permalink
Improve tooltip to differentiate post and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Feb 8, 2024
1 parent 7e999c4 commit 0609384
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/components/posts/view-post/PostRewardStat.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
import { simpleFormatBalance } from '@subsocial/utils'
import { Tooltip } from 'antd'
import clsx from 'clsx'
import capitalize from 'lodash/capitalize'
import { ComponentProps } from 'react'
import { TbCoins } from 'react-icons/tb'
import { FormatBalance } from 'src/components/common/balances'
import { useSelectPost } from 'src/rtk/app/hooks'
import { useSelectPostReward } from 'src/rtk/features/activeStaking/hooks'
import { PostRewards } from 'src/rtk/features/activeStaking/postRewardSlice'

export type PostRewardStatProps = ComponentProps<'div'> & { postId: string }

function generateTooltip({
fromCommentSuperLikes,
fromDirectSuperLikes,
fromShareSuperLikes,
}: PostRewards['rewardsBySource']) {
let tooltip = `Post author has earned ${simpleFormatBalance(
function generateTooltip(
{
fromCommentSuperLikes,
fromDirectSuperLikes,
fromShareSuperLikes,
}: PostRewards['rewardsBySource'],
entity: 'post' | 'comment',
) {
let tooltip = `${capitalize(entity)} author has earned ${simpleFormatBalance(
fromDirectSuperLikes,
10,
)} SUB from this post`
if (BigInt(fromCommentSuperLikes) > 0) {
)} SUB from this ${entity}`
if (BigInt(fromCommentSuperLikes) > 0 && entity === 'post') {
tooltip += `, and another ${simpleFormatBalance(
fromCommentSuperLikes,
10,
)} SUB from comment reward splitting`
}
if (BigInt(fromShareSuperLikes) > 0) {
tooltip += `, and ${simpleFormatBalance(fromShareSuperLikes, 10)} SUB from shares of this post`
tooltip += `, and ${simpleFormatBalance(
fromShareSuperLikes,
10,
)} SUB from shares of this ${entity}`
}
return tooltip
}

export default function PostRewardStat({ postId, ...props }: PostRewardStatProps) {
const reward = useSelectPostReward(postId)
const post = useSelectPost(postId)
const isComment = post?.post.struct.isComment
if (!reward?.isNotZero) return null

return (
Expand All @@ -42,7 +52,7 @@ export default function PostRewardStat({ postId, ...props }: PostRewardStatProps
</div>
<Tooltip
className='d-flex align-items-center GapMini'
title={generateTooltip(reward.rewardsBySource)}
title={generateTooltip(reward.rewardsBySource, isComment ? 'comment' : 'post')}
>
<span className='FontWeightSemibold'>
<FormatBalance
Expand Down

0 comments on commit 0609384

Please sign in to comment.