Skip to content

Commit

Permalink
🐐 Show all time most paid channels in the YPP carrousel (#5213)
Browse files Browse the repository at this point in the history
* Update the custom schema loader

* Update Orion schema

* Fetch most paid channels directly

* Fix types

* Revert "Update the custom schema loader"

This reverts commit 34f7ccd.
  • Loading branch information
thesan authored Nov 8, 2023
1 parent a92bf8c commit 33945ad
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 144 deletions.
47 changes: 16 additions & 31 deletions packages/atlas/src/api/hooks/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
UnfollowChannelMutation,
useFollowChannelMutation,
useGetChannelNftCollectorsQuery,
useGetChannelsPaymentEventsQuery,
useGetDiscoverChannelsQuery,
useGetExtendedBasicChannelsQuery,
useGetExtendedFullChannelsQuery,
useGetMostPaidChannelsQuery,
useGetTop10ChannelsQuery,
useUnfollowChannelMutation,
} from '@/api/queries/__generated__/channels.generated'
Expand Down Expand Up @@ -84,40 +84,25 @@ export const useBasicChannels = (
}
}

type PayeeChannel = {
export type PayeeChannel = {
id: string
title?: string | null
cumulativeRewardPaid: BN
avatarPhoto?: { resolvedUrls: string[] } | null
}
export type YPPPaidChannels = { channel: PayeeChannel; amount: BN }
export const useRecentlyPaidChannels = (): { channels: YPPPaidChannels[] | undefined; loading: boolean } => {
const { data, loading } = useGetChannelsPaymentEventsQuery({ variables: { limit: 2000 } })

const channels = useMemo<YPPPaidChannels[] | undefined>(() => {
type PaymentMap = Map<string, YPPPaidChannels>
const paymentMap = data?.events.reduce<PaymentMap>((channels, { data }) => {
if (data.__typename !== 'ChannelPaymentMadeEventData' || !data.payeeChannel) return channels

const exisitng = channels.get(data.payeeChannel.id)
const channel = exisitng?.channel ?? data.payeeChannel
const amount = new BN(data.amount).add(exisitng?.amount ?? BN_ZERO)

channels.set(data.payeeChannel.id, { channel, amount })

return channels
}, new Map())

return (
paymentMap &&
Array.from(paymentMap.values())
.sort((a, b) => {
if (a.amount.gt(b.amount)) return -1
if (a.amount.lt(b.amount)) return 1
return 0
})
.slice(0, 50)
)
}, [data])
export const useMostPaidChannels = (): { channels: PayeeChannel[] | undefined; loading: boolean } => {
const { data, loading } = useGetMostPaidChannelsQuery()

const channels = useMemo<PayeeChannel[] | undefined>(
() =>
data?.channels.map(({ id, title, cumulativeRewardPaid, avatarPhoto }) => ({
id,
title: title ?? undefined,
cumulativeRewardPaid: cumulativeRewardPaid ? new BN(cumulativeRewardPaid) : BN_ZERO,
avatarPhoto: avatarPhoto ?? undefined,
})),
[data]
)

return { channels, loading }
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 33945ad

Please sign in to comment.