Skip to content

Commit

Permalink
wait
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfirefist committed Oct 4, 2023
1 parent 5bf811b commit 80ba992
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions frontend/sections/SignAndClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,24 @@ export const SignAndClaim = ({ onBack, onProceed }: SignAndClaimProps) => {
}
})
setEcosystemsClaimState(stateObj)

const broadcastPromises = await tokenDispenser?.submitClaims(claims)
broadcastPromises.forEach(async (broadcastPromise, index) => {
const transactionError = await broadcastPromise
// NOTE: there is an implicit order restriction
// Transaction Order should be same as Ecosystems array order
setEcosystemsClaimState((ecosystemState) => ({
...ecosystemState,
[ecosystems[index]]: {
error: transactionError,
},
}))
})
const allPromises = broadcastPromises.map(
async (broadcastPromise, index) => {
const transactionError = await broadcastPromise
// NOTE: there is an implicit order restriction
// Transaction Order should be same as Ecosystems array order
setEcosystemsClaimState((ecosystemState) => ({
...ecosystemState,
[ecosystems[index]]: {
error: transactionError,
},
}))
}
)

// wait for all the promises before removing event handler
await Promise.allSettled(allPromises)
window.onbeforeunload = null
}, [getClaim, tokenDispenser])

Expand Down

0 comments on commit 80ba992

Please sign in to comment.