Skip to content

Commit

Permalink
Merge pull request #65 from poap-xyz/release/v1.4.3
Browse files Browse the repository at this point in the history
Release v1.4.3
  • Loading branch information
jm42 authored May 25, 2023
2 parents 5449566 + 81c806a commit 61403dd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 49 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.4.2",
"version": "1.4.3",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
118 changes: 70 additions & 48 deletions src/pages/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,36 @@ function Events() {
})
}

const removeErrors = (eventId) => {
setErrors((alsoErrors) => {
const newErrors = {}
for (const [errorEventId, error] of Object.entries(alsoErrors)) {
if (String(eventId) !== String(errorEventId)) {
newErrors[errorEventId] = error
}
}
return newErrors
})
}

const removeEventOwnerErrors = (eventId) => {
setEventOwnerErrors((alsoErrors) => {
const newErrors = {}
for (const [errorEventId, error] of Object.entries(alsoErrors)) {
if (String(eventId) !== String(errorEventId)) {
newErrors[errorEventId] = error
}
}
return newErrors
})
}

const loadOwners = useCallback(
(eventId, abortSignal) => {
if (eventId in owners) {
return Promise.resolve()
}
removeErrors(eventId)
setLoading((alsoLoading) => ({ ...alsoLoading, [eventId]: LOADING_OWNERS }))
return fetchPOAPs(eventId, abortSignal).then(
(eventOwnerTokens) => {
Expand Down Expand Up @@ -116,6 +141,7 @@ function Events() {
if (eventId in owners) {
return Promise.resolve()
}
removeErrors(eventId)
setLoading((alsoLoading) => ({ ...alsoLoading, [eventId]: LOADING_OWNERS }))
return Promise.allSettled([
fetchPOAPs(eventId, abortSignal),
Expand Down Expand Up @@ -160,19 +186,30 @@ function Events() {
)

const processEventAddress = useCallback(
(eventId, address, abortSignal) => scanAddress(address, abortSignal).then(
(ownerTokens) => {
for (const ownerToken of ownerTokens) {
const ownerTokenEventId = ownerToken.event.id
setEventData((prevEventData) => {
if (eventId in prevEventData) {
if (ownerTokenEventId in prevEventData[eventId].inCommon) {
if (prevEventData[eventId].inCommon[ownerTokenEventId].indexOf(address) === -1) {
(eventId, address, abortSignal) => {
removeEventOwnerErrors(eventId)
return scanAddress(address, abortSignal).then(
(ownerTokens) => {
for (const ownerToken of ownerTokens) {
const ownerTokenEventId = ownerToken.event.id
setEventData((prevEventData) => {
if (eventId in prevEventData) {
if (ownerTokenEventId in prevEventData[eventId].inCommon) {
if (prevEventData[eventId].inCommon[ownerTokenEventId].indexOf(address) === -1) {
return {
...prevEventData,
[eventId]: {
events: { ...prevEventData[eventId].events, [ownerTokenEventId]: ownerToken.event },
inCommon: { ...prevEventData[eventId].inCommon, [ownerTokenEventId]: [...prevEventData[eventId].inCommon[ownerTokenEventId], address] },
ts: null,
},
}
}
return {
...prevEventData,
[eventId]: {
events: { ...prevEventData[eventId].events, [ownerTokenEventId]: ownerToken.event },
inCommon: { ...prevEventData[eventId].inCommon, [ownerTokenEventId]: [...prevEventData[eventId].inCommon[ownerTokenEventId], address] },
inCommon: prevEventData[eventId].inCommon,
ts: null,
},
}
Expand All @@ -181,47 +218,39 @@ function Events() {
...prevEventData,
[eventId]: {
events: { ...prevEventData[eventId].events, [ownerTokenEventId]: ownerToken.event },
inCommon: prevEventData[eventId].inCommon,
inCommon: { ...prevEventData[eventId].inCommon, [ownerTokenEventId]: [address] },
ts: null,
},
}
}
return {
...prevEventData,
[eventId]: {
events: { ...prevEventData[eventId].events, [ownerTokenEventId]: ownerToken.event },
inCommon: { ...prevEventData[eventId].inCommon, [ownerTokenEventId]: [address] },
events: { [ownerTokenEventId]: ownerToken.event },
inCommon: { [ownerTokenEventId]: [address] },
ts: null,
},
}
}
return {
...prevEventData,
[eventId]: {
events: { [ownerTokenEventId]: ownerToken.event },
inCommon: { [ownerTokenEventId]: [address] },
ts: null,
},
}
})
}
setLoadedCount((prevLoadedCount) => ({ ...prevLoadedCount, [eventId]: (prevLoadedCount[eventId] ?? 0) + 1 }))
return Promise.resolve()
},
(err) => {
setEventOwnerErrors((oldEventOwnerErrors) => ({
...oldEventOwnerErrors,
[eventId]: {
...(oldEventOwnerErrors[eventId] ?? {}),
[address]: err,
},
}))
if (!err.aborted) {
return Promise.reject(err)
})
}
setLoadedCount((prevLoadedCount) => ({ ...prevLoadedCount, [eventId]: (prevLoadedCount[eventId] ?? 0) + 1 }))
return Promise.resolve()
},
(err) => {
setEventOwnerErrors((oldEventOwnerErrors) => ({
...oldEventOwnerErrors,
[eventId]: {
...(oldEventOwnerErrors[eventId] ?? {}),
[address]: err,
},
}))
if (!err.aborted) {
return Promise.reject(err)
}
return Promise.resolve()
}
return Promise.resolve()
}
),
)
},
[]
)

Expand Down Expand Up @@ -468,6 +497,7 @@ function Events() {
eventData[eventId].events,
inCommonProcessedEventIds
)
removeErrors(eventId)
setLoading((alsoLoading) => ({ ...alsoLoading, [eventId]: LOADING_CACHING }))
Promise
.all([
Expand Down Expand Up @@ -513,15 +543,7 @@ function Events() {
)

const retryLoadOwners = (eventId) => {
setErrors((prevErrors) => {
const newErrors = {}
for (const [errorEventId, error] of Object.entries(prevErrors)) {
if (String(errorEventId) !== String(eventId)) {
newErrors[errorEventId] = error
}
}
return newErrors
})
removeErrors(eventId)
loadOwners(eventId)
}

Expand Down

0 comments on commit 61403dd

Please sign in to comment.