Skip to content

Commit

Permalink
Add threshold for post memes
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmell committed Jun 18, 2024
1 parent cf5e1f9 commit 10f982e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/constants/chat-rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const POINTS_THRESHOLD = 900_000
47 changes: 35 additions & 12 deletions src/modules/chat/HomePage/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import Notice from '@/components/Notice'
import ChatRoom from '@/components/chats/ChatRoom'
import usePinnedMessage from '@/components/chats/hooks/usePinnedMessage'
import Modal, { ModalFunctionalityProps } from '@/components/modals/Modal'
import { POINTS_THRESHOLD } from '@/constants/chat-rules'
import PointsWidget from '@/modules/points/PointsWidget'
import { getPostQuery } from '@/services/api/query'
import { getBalanceQuery } from '@/services/datahub/leaderboard/points-balance/query'
import { useExtensionData } from '@/stores/extension'
import { useMyMainAddress } from '@/stores/my-account'
import { cx } from '@/utils/class-names'
import { formatNumber } from '@/utils/strings'
import { useState } from 'react'
import { LuPlusCircle } from 'react-icons/lu'

Expand All @@ -20,7 +24,6 @@ type Props = {

export default function ChatContent({ chatId, hubId, className }: Props) {
const [isOpenModal, setIsOpenModal] = useState(false)
const openExtensionModal = useExtensionData.use.openExtensionModal()
const pinnedMessageId = usePinnedMessage(chatId)
const { data: message } = getPostQuery.useQuery(pinnedMessageId ?? '', {
enabled: !!pinnedMessageId,
Expand Down Expand Up @@ -60,23 +63,43 @@ export default function ChatContent({ chatId, hubId, className }: Props) {
<Shield className='relative top-px text-text-muted' />
<span className='text-text'>Rules</span>
</Button>
<Button
type='button'
className='flex items-center justify-center gap-2'
size='lg'
onClick={() => {
openExtensionModal('subsocial-image', null)
}}
>
<LuPlusCircle className='relative top-px text-lg' />
<span>Post meme</span>
</Button>
<PostMemeButton />
</div>
}
/>
</>
)
}
function PostMemeButton() {
const openExtensionModal = useExtensionData.use.openExtensionModal()

const myAddress = useMyMainAddress()
const { data, isLoading } = getBalanceQuery.useQuery(myAddress || '')

const hasThreshold = !isLoading && data && data >= POINTS_THRESHOLD

let content = 'Loading...'
if (!isLoading) {
content = hasThreshold
? 'Post Meme'
: `Hold ${formatNumber(POINTS_THRESHOLD)} points to post`
}

return (
<Button
disabled={isLoading || !hasThreshold}
type='button'
className='flex items-center justify-center gap-2'
size='lg'
onClick={() => {
openExtensionModal('subsocial-image', null)
}}
>
<LuPlusCircle className='relative top-px text-lg' />
<span className='text-text'>{content}</span>
</Button>
)
}

function RulesModal(props: ModalFunctionalityProps) {
return (
Expand Down

0 comments on commit 10f982e

Please sign in to comment.