Skip to content

Commit cb64984

Browse files
authored
Merge pull request #3248 from IntersectMBO/fix/3242-bug-incorrect-redirect-after-voting-on-governance-action
fix(#3242): bug incorrect redirect after voting on governance action
2 parents 30d2e5c + f510e4b commit cb64984

File tree

9 files changed

+74
-52
lines changed

9 files changed

+74
-52
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ changes.
1414

1515
### Fixed
1616

17+
- Fix post-vote navigation to governance action list [Issue 3242](https://github.com/IntersectMBO/govtool/issues/3242)
18+
1719
### Changed
1820

1921
### Removed
2022

2123
## [v2.0.17](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.17) 2025-03-18
2224

23-
2425
### Added
2526

2627
### Fixed

govtool/backend/src/VVA/API.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,20 @@ getVotes (unHexText -> dRepId) selectedTypes sortMode mSearch = do
283283
CacheEnv {dRepGetVotesCache} <- asks vvaCache
284284
(votes, proposals) <- cacheRequest dRepGetVotesCache dRepId $ DRep.getVotes dRepId []
285285

286-
let voteMap = Map.fromList $ map (\vote@Types.Vote {..} -> (voteProposalId, vote)) votes
287-
288-
processedProposals <- filter (isProposalSearchedFor mSearch) <$> mapSortAndFilterProposals selectedTypes sortMode proposals
289-
286+
let voteMapByTxHash = Map.fromList $
287+
map (\vote -> (pack $ Prelude.takeWhile (/= '#') (unpack $ Types.voteGovActionId vote), vote)) votes
288+
289+
processedProposals <- filter (isProposalSearchedFor mSearch) <$>
290+
mapSortAndFilterProposals selectedTypes sortMode proposals
291+
290292
return $
291293
[ VoteResponse
292294
{ voteResponseVote = voteToResponse vote
293295
, voteResponseProposal = proposalResponse
294296
}
295-
| proposalResponse@ProposalResponse{proposalResponseId} <- processedProposals
296-
, let proposalIdInt = read (unpack proposalResponseId) :: Int
297-
, Just vote <- [Map.lookup (toInteger proposalIdInt) voteMap]
297+
| proposalResponse <- processedProposals
298+
, let txHash = unHexText (proposalResponseTxHash proposalResponse)
299+
, Just vote <- [Map.lookup txHash voteMapByTxHash]
298300
]
299301

300302
drepInfo :: App m => HexText -> m DRepInfoResponse

govtool/backend/src/VVA/DRep.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,22 @@ getVotes ::
115115
m ([Vote], [Proposal])
116116
getVotes drepId selectedProposals = withPool $ \conn -> do
117117
results <- liftIO $ SQL.query conn getVotesSql (SQL.Only drepId)
118-
118+
119119
if null results
120120
then return ([], [])
121121
else do
122122
let proposalsToSelect = if null selectedProposals
123123
then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results]
124124
else selectedProposals
125-
126125
allProposals <- mapM (Proposal.getProposals . Just . (:[])) proposalsToSelect
127-
128126
let proposals = concat allProposals
129127

130128
let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals
131129

132130
timeZone <- liftIO getCurrentTimeZone
133131

134132
let votes =
135-
[ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
133+
[ Vote proposalId' govActionId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
136134
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
137135
, govActionId' `elem` proposalsToSelect
138136
]

govtool/backend/src/VVA/Types.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ instance Exception AppError
6161

6262
data Vote
6363
= Vote
64-
{ voteProposalId :: Integer
65-
, voteDrepId :: Text
66-
, voteVote :: Text
67-
, voteUrl :: Maybe Text
68-
, voteDocHash :: Maybe Text
69-
, voteEpochNo :: Integer
70-
, voteDate :: UTCTime
71-
, voteTxHash :: Text
64+
{ voteProposalId :: Integer
65+
, voteGovActionId :: Text
66+
, voteDrepId :: Text
67+
, voteVote :: Text
68+
, voteUrl :: Maybe Text
69+
, voteDocHash :: Maybe Text
70+
, voteEpochNo :: Integer
71+
, voteDate :: UTCTime
72+
, voteTxHash :: Text
7273
}
7374

7475
data DRepInfo

govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "@consts";
1111
import { useCardano, useDataActionsBar, useFeatureFlag } from "@context";
1212
import {
13+
useGetDRepVotesQuery,
1314
useGetProposalsQuery,
1415
useGetVoterInfo,
1516
useScreenDimension,
@@ -89,6 +90,31 @@ export const DashboardGovernanceActions = () => {
8990
searchPhrase: debouncedSearchText,
9091
enabled: !isAdjusting,
9192
});
93+
const { data: votes, areDRepVotesLoading } = useGetDRepVotesQuery(
94+
queryFilters,
95+
chosenSorting,
96+
debouncedSearchText,
97+
);
98+
99+
// TODO: Black magic - that filtering should be done on the backend
100+
const filteredProposals = proposals
101+
?.map((proposalCategory) => {
102+
const filteredActions = proposalCategory.actions.filter((action) => {
103+
const hasVote = votes?.some((voteCategory) =>
104+
voteCategory.actions.some(
105+
(voteAction) => voteAction.proposal.txHash === action.txHash,
106+
),
107+
);
108+
109+
return !hasVote;
110+
});
111+
112+
return {
113+
...proposalCategory,
114+
actions: filteredActions,
115+
};
116+
})
117+
.filter((category) => category.actions.length > 0);
92118

93119
const { state } = useLocation();
94120
const [content, setContent] = useState<number>(
@@ -189,14 +215,14 @@ export const DashboardGovernanceActions = () => {
189215
onDashboard
190216
searchPhrase={debouncedSearchText}
191217
sorting={chosenSorting}
192-
proposals={proposals}
218+
proposals={filteredProposals}
193219
/>
194220
</CustomTabPanel>
195221
<CustomTabPanel value={content} index={1}>
196222
<DashboardGovernanceActionsVotedOn
197-
filters={chosenFilters}
198223
searchPhrase={debouncedSearchText}
199-
sorting={chosenSorting}
224+
votes={votes}
225+
areDRepVotesLoading={areDRepVotesLoading}
200226
/>
201227
</CustomTabPanel>
202228
</>

govtool/frontend/src/components/organisms/DashboardGovernanceActionsVotedOn.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,34 @@ import { useMemo } from "react";
22
import { Box, Typography, CircularProgress } from "@mui/material";
33

44
import { useCardano } from "@context";
5-
import {
6-
useGetDRepVotesQuery,
7-
useScreenDimension,
8-
useTranslation,
9-
} from "@hooks";
5+
import { useScreenDimension, useTranslation } from "@hooks";
106
import { GovernanceVotedOnCard } from "@molecules";
117
import { Slider } from "@organisms";
128
import { getFullGovActionId, getProposalTypeLabel } from "@utils";
9+
import { VotedProposal } from "@/models";
1310

1411
type DashboardGovernanceActionsVotedOnProps = {
15-
filters: string[];
1612
searchPhrase?: string;
17-
sorting: string;
13+
votes: {
14+
title: string;
15+
actions: VotedProposal[];
16+
}[];
17+
areDRepVotesLoading: boolean;
1818
};
1919

2020
export const DashboardGovernanceActionsVotedOn = ({
21-
filters,
2221
searchPhrase,
23-
sorting,
22+
votes,
23+
areDRepVotesLoading,
2424
}: DashboardGovernanceActionsVotedOnProps) => {
25-
const { data, areDRepVotesLoading } = useGetDRepVotesQuery(
26-
filters,
27-
sorting,
28-
searchPhrase,
29-
);
3025
const { isMobile } = useScreenDimension();
3126
const { pendingTransaction } = useCardano();
3227
const { t } = useTranslation();
3328

29+
// TODO: Filtering here is some kind of craziness. It should be done on the backend.
3430
const filteredData = useMemo(() => {
35-
if (data.length && searchPhrase) {
36-
return data
31+
if (votes.length && searchPhrase) {
32+
return votes
3733
.map((entry) => ({
3834
...entry,
3935
actions: entry.actions.filter((action) =>
@@ -44,16 +40,16 @@ export const DashboardGovernanceActionsVotedOn = ({
4440
}))
4541
.filter((entry) => entry.actions?.length > 0);
4642
}
47-
return data;
48-
}, [data, searchPhrase, pendingTransaction.vote]);
43+
return votes;
44+
}, [votes, searchPhrase, pendingTransaction.vote]);
4945

5046
return areDRepVotesLoading ? (
5147
<Box py={4} display="flex" justifyContent="center">
5248
<CircularProgress />
5349
</Box>
5450
) : (
5551
<>
56-
{!data.length ? (
52+
{!votes.length ? (
5753
<Typography py={4} fontWeight="300">
5854
{t("govActions.youHaventVotedYet")}
5955
</Typography>

govtool/frontend/src/hooks/queries/useGetDRepVotesQuery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const useGetDRepVotesQuery = (
3030
},
3131
}),
3232
enabled: !!dRepID,
33+
refetchOnWindowFocus: true,
34+
keepPreviousData: true,
3335
});
3436

3537
const groupedByType = data?.reduce((groups, item) => {

govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const useGetProposalsQuery = ({
1212
sorting,
1313
enabled,
1414
}: GetProposalsArguments) => {
15-
const { dRepID, pendingTransaction } = useCardano();
15+
const { dRepID } = useCardano();
1616
const { voter } = useGetVoterInfo();
1717

1818
const fetchProposals = async (): Promise<ProposalData[]> => {
@@ -34,17 +34,12 @@ export const useGetProposalsQuery = ({
3434
};
3535

3636
const { data, isLoading } = useQuery(
37-
[
38-
QUERY_KEYS.useGetProposalsKey,
39-
filters,
40-
searchPhrase,
41-
sorting,
42-
dRepID,
43-
pendingTransaction.vote?.transactionHash,
44-
],
37+
[QUERY_KEYS.useGetProposalsKey, filters, searchPhrase, sorting, dRepID],
4538
fetchProposals,
4639
{
4740
enabled,
41+
refetchOnWindowFocus: true,
42+
keepPreviousData: true,
4843
},
4944
);
5045

govtool/frontend/src/types/global.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare global {
1414

1515
type ActionTypeFromAPI = {
1616
id: string;
17+
txHash: string;
1718
type: string;
1819
details: string;
1920
expiryDate: string;
@@ -36,7 +37,7 @@ declare global {
3637

3738
type ToVoteDataType = {
3839
title: string;
39-
actions: ActionTypeToDsiplay[];
40+
actions: ProposalData[];
4041
}[];
4142

4243
type NestedKeys<T> = T extends Record<string, unknown>

0 commit comments

Comments
 (0)