Skip to content

Commit

Permalink
fix: Add cancellable to winnings popup to abort call when rerender (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil authored May 12, 2021
1 parent f9f1545 commit b373a52
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/views/Predictions/components/CollectWinningsPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,27 @@ const CollectWinningsPopup = () => {

// Check user's history for unclaimed winners
useEffect(() => {
let isCancelled = false
if (account) {
timer.current = setInterval(async () => {
const bets = await getBetHistory({ user: account.toLowerCase(), claimed: false })

// Filter out bets that were not winners
const winnerBets = bets.filter((bet) => {
return bet.position === bet.round.position
})
if (!isCancelled) {
// Filter out bets that were not winners
const winnerBets = bets.filter((bet) => {
return bet.position === bet.round.position
})

if (!isHistoryPaneOpen) {
setIsOpen(winnerBets.length > 0)
if (!isHistoryPaneOpen) {
setIsOpen(winnerBets.length > 0)
}
}
}, 30000)
}

return () => {
clearInterval(timer.current)
isCancelled = true
}
}, [account, timer, predictionStatus, setIsOpen, isHistoryPaneOpen])

Expand Down

0 comments on commit b373a52

Please sign in to comment.