Skip to content

Commit

Permalink
Merge pull request #439 from poap-xyz/release/v1.21.0
Browse files Browse the repository at this point in the history
Release v1.21.0
  • Loading branch information
jm42 authored Dec 19, 2024
2 parents 010dd2e + 17a3dea commit b093327
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 448 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poap-family",
"version": "1.20.1",
"version": "1.21.0",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useEventsCollections.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { useCallback, useState } from 'react'
import { AbortedError } from 'models/error'
import { findEventsCollections } from 'loaders/collection'
import { fetchDropsCollections } from 'loaders/collection'

function useEventsCollections(eventIds: number[]): {
loadingCollections: boolean
collectionsError: Error | null
collections: Awaited<ReturnType<typeof findEventsCollections>>['collections'] | null
relatedCollections: Awaited<ReturnType<typeof findEventsCollections>>['related'] | null
collections: Awaited<ReturnType<typeof fetchDropsCollections>>['collections'] | null
relatedCollections: Awaited<ReturnType<typeof fetchDropsCollections>>['related'] | null
fetchEventsCollections: () => () => void
} {
const [loading, setLoading] = useState<boolean>(false)
const [error, setError] = useState<Error | null>(null)
const [result, setResult] = useState<Awaited<ReturnType<typeof findEventsCollections>> | null>(null)
const [result, setResult] = useState<Awaited<ReturnType<typeof fetchDropsCollections>> | null>(null)

const fetchEventsCollections = useCallback(
() => {
const controller = new AbortController()
setLoading(true)
findEventsCollections(
fetchDropsCollections(
eventIds,
controller.signal
).then((result) => {
Expand Down
54 changes: 24 additions & 30 deletions src/hooks/useEventsOwnersAndMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { useCallback, useState } from 'react'
import { filterInvalidOwners } from 'models/address'
import { DropMetrics } from 'models/drop'
import { AbortedError } from 'models/error'
import { EventAndOwners, InCommon } from 'models/api'
import { fetchDropCollectors } from 'loaders/collector'
import {
getEventAndOwners,
getEventMetrics,
getEventsMetrics,
getEventsOwners,
} from 'loaders/api'
import { EventAndOwners } from 'models/api'
import { fetchCollectorsByDrops, fetchDropsCollectors } from 'loaders/collector'
import { fetchDropMetrics, fetchDropsMetrics } from 'loaders/drop'
import { getEventAndOwners } from 'loaders/api'
import { fillNull } from 'utils/object'

function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<number, Date>, force: boolean = false): {
completedEventsOwnersAndMetrics: boolean
loadingEventsOwnersAndMetrics: boolean
loadingOwnersAndMetricsEvents: Record<number, boolean>
eventsOwnersAndMetricsErrors: Record<number, Error>
eventsOwners: InCommon
eventsMetrics: Record<number, { emailReservations: number; emailClaimsMinted: number; emailClaims: number; momentsUploaded: number; collectionsIncludes: number; ts: number }>
eventsOwners: Record<number, string[]>
eventsMetrics: Record<number, DropMetrics>
fetchEventsOwnersAndMetrics: () => () => void
retryEventOwnersAndMetrics: (eventId: number) => () => void
} {
const [completed, setCompleted] = useState<boolean>(false)
const [loadingCache, setLoadingCache] = useState<boolean>(false)
const [loading, setLoading] = useState<Record<number, boolean>>({})
const [errors, setErrors] = useState<Record<number, Error>>({})
const [owners, setOwners] = useState<InCommon>({})
const [metrics, setMetrics] = useState<Record<number, { emailReservations: number; emailClaimsMinted: number; emailClaims: number; momentsUploaded: number; collectionsIncludes: number; ts: number }>>({})
const [owners, setOwners] = useState<Record<number, string[]>>({})
const [metrics, setMetrics] = useState<Record<number, DropMetrics>>({})

function addLoading(eventId: number): void {
setLoading((alsoLoading) => ({
Expand Down Expand Up @@ -78,7 +76,7 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
}))
}

function updateEventsOwners(eventsOwners: InCommon): void {
function updateEventsOwners(eventsOwners: Record<number, string[]>): void {
setOwners((prevOwners) => ({
...prevOwners,
...Object.fromEntries(
Expand All @@ -94,7 +92,7 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
}))
}

function updateEventMetrics(eventId: number, metrics: { emailReservations: number; emailClaimsMinted: number; emailClaims: number; momentsUploaded: number; collectionsIncludes: number; ts: number }): void {
function updateEventMetrics(eventId: number, metrics: DropMetrics): void {
if (metrics == null) {
return
}
Expand All @@ -104,7 +102,7 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
}))
}

function updateEventsMetrics(eventsMetrics: Record<number, { emailReservations: number; emailClaimsMinted: number; emailClaims: number; momentsUploaded: number; collectionsIncludes: number; ts: number }>): void {
function updateEventsMetrics(eventsMetrics: Record<number, DropMetrics>): void {
setMetrics((prevMetrics) => ({
...prevMetrics,
...Object.fromEntries(
Expand Down Expand Up @@ -156,12 +154,12 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
async (eventId: number, abortSignal: AbortSignal) => {
removeError(eventId)
addLoading(eventId)
let eventCollectorsResult: PromiseSettledResult<Awaited<ReturnType<typeof fetchDropCollectors>>>
let eventMetricsResult: PromiseSettledResult<Awaited<ReturnType<typeof getEventMetrics>>>
let eventCollectorsResult: PromiseSettledResult<Awaited<ReturnType<typeof fetchDropsCollectors>>>
let eventMetricsResult: PromiseSettledResult<Awaited<ReturnType<typeof fetchDropMetrics>>>
try {
[eventCollectorsResult, eventMetricsResult] = await Promise.allSettled([
fetchDropCollectors([eventId], abortSignal),
getEventMetrics(eventId, abortSignal, force),
fetchDropsCollectors([eventId], abortSignal),
fetchDropMetrics(eventId, abortSignal),
])
} catch (err: unknown) {
removeLoading(eventId)
Expand Down Expand Up @@ -202,7 +200,7 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
}
}
},
[force]
[]
)

const fetchEventsOwnersAndMetrics = useCallback(
Expand Down Expand Up @@ -235,17 +233,14 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
setLoadingCache(true)
controller = new AbortController()
Promise.all([
getEventsOwners(eventIds, controller.signal, expiryDates),
getEventsMetrics(eventIds, controller.signal, expiryDates),
fetchCollectorsByDrops(eventIds, controller.signal),
fetchDropsMetrics(eventIds, controller.signal),
]).then(([eventsOwners, eventsMetrics]) => {
updateEventsOwners(
Object.fromEntries(
Object.entries(eventsOwners).map(
([rawEventId, eventOwners]) => [
rawEventId,
eventOwners.owners,
]
)
fillNull(
eventsOwners,
eventIds.map((eventId) => String(eventId)),
[]
)
)
updateEventsMetrics(eventsMetrics)
Expand Down Expand Up @@ -285,7 +280,6 @@ function useEventsOwnersAndMetrics(eventIds: number[], expiryDates: Record<numbe
},
[
eventIds,
expiryDates,
force,
loadCachedOwnersAndMetrics,
loadOwnersAndMetrics,
Expand Down
Loading

0 comments on commit b093327

Please sign in to comment.