diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ea3e9be5..4181941a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ changes. - -## [v1.0.23](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.23) 2024-10-28 +## [v1.0.23](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.23) 2024-10-29 ### Added diff --git a/govtool/backend/src/VVA/DRep.hs b/govtool/backend/src/VVA/DRep.hs index 98c05ae5a..730814e4f 100644 --- a/govtool/backend/src/VVA/DRep.hs +++ b/govtool/backend/src/VVA/DRep.hs @@ -107,17 +107,23 @@ getVotes :: m ([Vote], [Proposal]) getVotes drepId selectedProposals = withPool $ \conn -> do results <- liftIO $ SQL.query conn getVotesSql (SQL.Only drepId) - let proposalsToSelect = if null selectedProposals - then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results] - else selectedProposals - proposals <- Proposal.getProposals (Just proposalsToSelect) - let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals - timeZone <- liftIO getCurrentTimeZone - return - ([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash' - | (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results - , govActionId' `elem` proposalsToSelect - ], proposals) + + if null results + then return ([], []) + else do + let proposalsToSelect = if null selectedProposals + then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results] + else selectedProposals + proposals <- if null proposalsToSelect + then return [] + else Proposal.getProposals (Just proposalsToSelect) + let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals + timeZone <- liftIO getCurrentTimeZone + let votes = [ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash' + | (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results + , govActionId' `elem` proposalsToSelect + ] + return (votes, proposals) getDRepInfoSql :: SQL.Query getDRepInfoSql = sqlFrom $(embedFile "sql/get-drep-info.sql")