Skip to content

Commit

Permalink
Add query for top memes
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Sep 4, 2024
1 parent 344e287 commit 5811f6d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/components/chats/ChatRoom/MemeChatRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function PostMemeButton({
const { threshold, isLoading: loadingThreshold } =
usePostMemeThreshold(chatId)

const { evmAddress, isLoading: loadingEvmAddress } = useLinkedEvmAddress()
const { identityAddress, isLoading: loadingEvmAddress } =
useLinkedEvmAddress()
const { isBlocked, isLoading: loadingIsBlocked } = useIsAddressBlockedInChat(
myAddress,
chatId
Expand Down Expand Up @@ -178,7 +179,7 @@ function PostMemeButton({
hasOpenedMeme2EarnIntroStorage.set('true')
return
}
if (!evmAddress && isContestTab) {
if (!identityAddress && isContestTab) {
setIsOpenLinkEvm(true)
return
}
Expand Down
20 changes: 15 additions & 5 deletions src/components/wallets/UnlinkWalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
reloadEveryIntervalUntilLinkedIdentityFound,
useUpdateExternalProvider,
} from '@/services/datahub/identity/mutation'
import { useMyMainAddress } from '@/stores/my-account'
import { IdentityProvider } from '@subsocial/data-hub-sdk'
import { useEffect } from 'react'
import Button from '../Button'
Expand All @@ -18,7 +19,16 @@ export default function UnlinkWalletModal({
chain,
...props
}: ModalFunctionalityProps & { chain: 'evm' | 'solana' }) {
const { evmAddress, evmAddressProviderId } = useLinkedEvmAddress()
const myAddress = useMyMainAddress()

const identityProvider =
chain === 'evm' ? IdentityProvider.EVM : IdentityProvider.SOLANA

const { identityAddress, identityAddressProviderId } = useLinkedEvmAddress(
myAddress || '',
{ enabled: true },
identityProvider
)
const { mutate, isLoading, isSuccess, reset } = useUpdateExternalProvider({
onSuccess: (_, { externalProvider }) => {
reloadEveryIntervalUntilLinkedIdentityFound((identity) => {
Expand Down Expand Up @@ -54,12 +64,12 @@ export default function UnlinkWalletModal({
<Button
size='lg'
onClick={() => {
if (!evmAddress) return
if (!identityAddress) return
mutate({
entityId: evmAddressProviderId,
entityId: identityAddressProviderId,
externalProvider: {
id: evmAddress,
provider: IdentityProvider.EVM,
id: identityAddress,
provider: identityProvider,
enabled: false,
},
})
Expand Down
5 changes: 5 additions & 0 deletions src/modules/telegram/channels/ChannelsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ContentContainer,
getContentContainersQuery,
} from '@/services/datahub/content-containers/query'
import { getTopnMemesQuery } from '@/services/datahub/posts/query'
import { cx } from '@/utils/class-names'
import Image, { ImageProps } from 'next/image'
import Link from 'next/link'
Expand Down Expand Up @@ -79,6 +80,10 @@ function Channel({ channel }: { channel: ContentContainer }) {
}

function TopMemesToday() {
const { data, isLoading } = getTopnMemesQuery.useQuery({})

console.log(data)

return (
<div className='flex flex-col gap-4'>
<div className='flex flex-col gap-0.5'>
Expand Down
51 changes: 51 additions & 0 deletions src/services/datahub/posts/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,54 @@ export const getPostsCountByTodayQuery = createQuery({
enabled: !!params?.chatId,
}),
})

const GET_TOP_MEMES = gql`
query GetTopMemes($timestamp: String!) {
activeStakingRankedPostIdsBySuperLikesNumber(
args: {
filter: { period: DAY, timestamp: $timestamp }
limit: 2
offset: 0
order: DESC
}
) {
data {
postId
score
rank
}
total
}
}
`
export const getTopnMemesQuery = createQuery({
key: 'getTopMemes',
fetcher: async () => {
const timestamp = dayjs.utc(new Date()).startOf('day').unix().toString()

const res = await datahubQueryRequest<
{
activeStakingRankedPostIdsBySuperLikesNumber: {
data: {
postId: string
score: number
rank: number
}[]
total: number
}
},
{
timestamp: string
}
>({
document: GET_TOP_MEMES,
variables: {
timestamp: timestamp,
},
})
return res.activeStakingRankedPostIdsBySuperLikesNumber.data
},
defaultConfigGenerator: () => ({
enabled: true,
}),
})

0 comments on commit 5811f6d

Please sign in to comment.