Skip to content

Commit

Permalink
feat: integrate total super likes data
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jan 18, 2024
1 parent 6351f11 commit 228aaee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/components/statistics/Statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,22 @@ export function Statistics(props: FormProps) {

function combineOldLikesAndSuperLikes(
stats: StatType[],
superLikesStats: SuperLikesStat[],
superLikesStats: SuperLikesStat,
): StatType[] {
const likesStat = stats.find(
stat => stat.activityType === 'PostReactionCreated,CommentReactionCreated',
)
if (!likesStat) return stats

const totalSuperLikes = superLikesStats.reduce((acc, stat) => acc + stat.count, 0)
likesStat.totalCount += totalSuperLikes
const totalSuperLikes = superLikesStats.data.reduce((acc, stat) => acc + stat.count, 0)
likesStat.totalCount += superLikesStats.total
likesStat.countByPeriod += totalSuperLikes
likesStat.todayCount = superLikesStats[superLikesStats.length - 1].count
likesStat.todayCount = superLikesStats.data[superLikesStats.data.length - 1].count

const allLikesMap = new Map<string, StatsType>()
likesStat.statisticsData.forEach(stat => allLikesMap.set(stat.format_date, stat))

superLikesStats.forEach(stat => {
superLikesStats.data.forEach(stat => {
const dateFormat = dayjs(stat.dayUnixTimestamp * 1000).format('YYYY-MM-DD')
const existingStat = allLikesMap.get(dateFormat)
if (existingStat) {
Expand Down
25 changes: 17 additions & 8 deletions src/components/utils/datahub/active-staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,39 @@ export async function getRewardHistory(address: string): Promise<RewardHistory>
const GET_SUPER_LIKES_STATS = gql`
query GetSuperLikesStats($from: String!, $to: String!) {
activeStakingSuperLikeCountsByDate(args: { fromDate: $from, toDate: $to }) {
count
dayUnixTimestamp
byDate {
count
dayUnixTimestamp
}
total
}
}
`
export type SuperLikesStat = { count: number; dayUnixTimestamp: number }
export async function getSuperLikesStats(period: number): Promise<SuperLikesStat[]> {
export type SuperLikesStat = { total: number; data: { count: number; dayUnixTimestamp: number }[] }
export async function getSuperLikesStats(period: number): Promise<SuperLikesStat> {
const { day: currentTimestamp } = getDayAndWeekTimestamp()
const currentMinusPeriod = dayjs().subtract(period, 'day').toDate()
const { day: startTimestamp } = getDayAndWeekTimestamp(currentMinusPeriod)
const res = await datahubQueryRequest<
{
activeStakingSuperLikeCountsByDate: {
count: number
dayUnixTimestamp: number
}[]
byDate: {
count: number
dayUnixTimestamp: number
}[]
total: number
}
},
{ from: string; to: string }
>({
document: GET_SUPER_LIKES_STATS,
variables: { from: startTimestamp.toString(), to: currentTimestamp.toString() },
})

return res.activeStakingSuperLikeCountsByDate
return {
data: res.activeStakingSuperLikeCountsByDate.byDate,
total: res.activeStakingSuperLikeCountsByDate.total,
}
}

// MUTATIONS
Expand Down

0 comments on commit 228aaee

Please sign in to comment.