Skip to content

Commit

Permalink
Fix tooltip formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Feb 9, 2024
1 parent 9a8dab1 commit bad7489
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/components/common/balances/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const log = newLogger('useCreateBallance')
const M_LENGTH = 6 + 1
const K_LENGTH = 3 + 1

function format({
export function formatBalanceToJsx({
value,
currency,
decimals,
Expand Down Expand Up @@ -111,7 +111,7 @@ export const FormatBalance = ({

const { unit: defaultCurrency, decimals: defaultDecimal } = formatBalance.getDefaults()

const balance = format({
const balance = formatBalanceToJsx({
value,
currency: currency || defaultCurrency,
decimals: decimals || defaultDecimal,
Expand Down
33 changes: 19 additions & 14 deletions src/components/posts/view-post/PostRewardStat.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
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 { FormatBalance, formatBalanceToJsx } 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'
Expand All @@ -19,21 +18,27 @@ function generateTooltip(
}: PostRewards['rewardsBySource'],
entity: 'post' | 'comment',
) {
let tooltip = `${capitalize(entity)} author has earned ${simpleFormatBalance(
fromDirectSuperLikes,
10,
)} SUB from this ${entity}`
let tooltip = `${capitalize(entity)} author has earned ${formatBalanceToJsx({
value: fromDirectSuperLikes,
precision: 2,
currency: 'SUB',
decimals: 10,
})} SUB from this ${entity}`
if (BigInt(fromCommentSuperLikes) > 0 && entity === 'post') {
tooltip += `, and another ${simpleFormatBalance(
fromCommentSuperLikes,
10,
)} SUB from comment reward splitting`
tooltip += `, and another ${formatBalanceToJsx({
value: fromCommentSuperLikes,
precision: 2,
currency: 'SUB',
decimals: 10,
})} SUB from comment reward splitting`
}
if (BigInt(fromShareSuperLikes) > 0) {
tooltip += `, and ${simpleFormatBalance(
fromShareSuperLikes,
10,
)} SUB from shares of this ${entity}`
tooltip += `, and ${formatBalanceToJsx({
value: fromShareSuperLikes,
precision: 2,
currency: 'SUB',
decimals: 10,
})} SUB from shares of this ${entity}`
}
return tooltip
}
Expand Down

0 comments on commit bad7489

Please sign in to comment.