Fix broken useBets filters (#731)

This commit is contained in:
Marshall Polaris 2022-08-09 08:50:11 -07:00 committed by GitHub
parent e7f1d3924b
commit 592125b5e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,21 +14,22 @@ export const useBets = (
options?: { filterChallenges: boolean; filterRedemptions: boolean }
) => {
const [bets, setBets] = useState<Bet[] | undefined>()
const filterChallenges = !!options?.filterChallenges
const filterRedemptions = !!options?.filterRedemptions
useEffect(() => {
if (contractId)
return listenForBets(contractId, (bets) => {
if (options)
if (filterChallenges || filterRedemptions)
setBets(
bets.filter(
(bet) =>
(options.filterChallenges ? !bet.challengeSlug : true) &&
(options.filterRedemptions ? !bet.isRedemption : true)
(filterChallenges ? !bet.challengeSlug : true) &&
(filterRedemptions ? !bet.isRedemption : true)
)
)
else setBets(bets)
})
}, [contractId, options])
}, [contractId, filterChallenges, filterRedemptions])
return bets
}