Skip to content

Commit

Permalink
Merge pull request #226 from poap-xyz/release/v1.12.12
Browse files Browse the repository at this point in the history
Release v1.12.12
  • Loading branch information
jm42 authored May 10, 2024
2 parents 316ef6e + 85a8e33 commit dc56e48
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 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.12.11",
"version": "1.12.12",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
11 changes: 7 additions & 4 deletions src/loaders/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ async function getEventsOwners(eventIds, abortSignal, expiryDates) {
if (!FAMILY_API_KEY) {
return null
}
const queryString = expiryDates ? encodeExpiryDates(expiryDates) : ''
const encodedExpiryDates = expiryDates ? encodeExpiryDates(expiryDates) : ''
const response = await fetch(
`${FAMILY_API_URL}/events` +
`/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}` +
`/owners${queryString ? `?${queryString}` : ''}`,
`/owners${encodedExpiryDates ? `?${encodedExpiryDates}` : ''}`,
{
signal: abortSignal instanceof AbortSignal ? abortSignal : null,
headers: {
Expand Down Expand Up @@ -317,12 +317,15 @@ async function getEventMetrics(eventId, abortSignal, refresh = false) {
return EventMetrics(body)
}

async function getEventsMetrics(eventIds, abortSignal) {
async function getEventsMetrics(eventIds, abortSignal, expiryDates) {
if (!FAMILY_API_KEY) {
throw new Error(`Events (${eventIds.length}) metrics could not be fetched, configure Family API key`)
}
const encodedExpiryDates = expiryDates ? encodeExpiryDates(expiryDates) : ''
const response = await fetch(
`${FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}/metrics`,
`${FAMILY_API_URL}/events` +
`/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}` +
`/metrics${encodedExpiryDates ? `?${encodedExpiryDates}` : ''}`,
{
signal: abortSignal instanceof AbortSignal ? abortSignal : null,
headers: {
Expand Down
4 changes: 3 additions & 1 deletion src/models/event.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { parseEndOfDayDate } from '../utils/date'

function Event(event, includeDescription) {
return {
id: event.id,
Expand Down Expand Up @@ -88,7 +90,7 @@ function parseExpiryDates(events) {
([eventId, event]) => ([
eventId,
event?.expiry_date
? new Date(event.expiry_date.replace(/-/g, '/') + ' 23:59:00 UTC')
? parseEndOfDayDate(event.expiry_date)
: undefined,
])
)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function Events() {
const expiryDates = parseExpiryDates(events)
Promise.all([
getEventsOwners(eventIds, controller.signal, expiryDates),
getEventsMetrics(eventIds, controller.signal),
getEventsMetrics(eventIds, controller.signal, expiryDates),
]).then(
([eventsOwners, eventsMetrics]) => {
if (eventsMetrics) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ export function secondsInTheFuture(secs) {
export function formatMonthYear(d) {
return dayjs(d).format('MMM \'YY')
}

export function parseEndOfDayDate(date) {
return dayjs(date).endOf('day').toDate()
}

0 comments on commit dc56e48

Please sign in to comment.