Skip to content

Commit ec457a3

Browse files
authored
Merge pull request #3944 from IntersectMBO/develop
2.0.31
2 parents 48eb152 + 9e5ce6e commit ec457a3

File tree

12 files changed

+102
-102
lines changed

12 files changed

+102
-102
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ changes.
1414

1515
### Fixed
1616

17+
- Fix disappearing proposals in the governance actions list for the same tx hashes [Issue 3918](https://github.com/IntersectMBO/govtool/issues/3918)
18+
1719
### Changed
1820

1921
### Removed

govtool/backend/src/VVA/API.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do
407407

408408
CacheEnv {proposalListCache} <- asks vvaCache
409409

410-
proposals <- cacheRequest proposalListCache () (Proposal.listProposals mSearchQuery)
410+
let emptyMSearchQuery = Just "" :: Maybe Text -- issue 3918 temporary bypass
411+
proposals <- cacheRequest proposalListCache () (Proposal.listProposals emptyMSearchQuery)
411412

412413
mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
413414
let filteredProposals = filter

govtool/frontend/src/App.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,47 @@ export default () => {
6363
}, []);
6464

6565
const checkTheWalletIsActive = useCallback(() => {
66-
const hrefCondition =
67-
window.location.pathname === PATHS.home ||
68-
window.location.pathname === PATHS.governanceActions ||
69-
window.location.pathname === PATHS.governanceActionsAction;
66+
const isWalletAvailable = () =>
67+
window.cardano && walletName && Object.keys(window.cardano).includes(walletName);
7068

71-
const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
72-
if (window.cardano) {
73-
const walletExtensions = Object.keys(window.cardano);
74-
if (walletName && walletExtensions.includes(walletName)) {
75-
enable(walletName);
76-
return;
69+
const cleanUpWalletData = () => {
70+
removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
71+
removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`);
72+
};
73+
74+
const waitForWalletExtension = async () => {
75+
const timeout = 5000;
76+
const interval = 100;
77+
const startTime = Date.now();
78+
79+
while (Date.now() - startTime < timeout) {
80+
if (isWalletAvailable()) {
81+
enable(walletName);
82+
return;
83+
}
84+
// eslint-disable-next-line no-await-in-loop
85+
await new Promise((resolve) => {
86+
setTimeout(resolve, interval);
87+
});
7788
}
78-
}
79-
if (
80-
(!window.cardano && walletName) ||
81-
(walletName && !Object.keys(window.cardano).includes(walletName))
82-
) {
83-
if (!hrefCondition) {
89+
90+
if (!isOnAllowedPage) {
8491
navigate(PATHS.home);
8592
}
86-
removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
87-
removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`);
93+
cleanUpWalletData();
94+
};
95+
96+
const isOnAllowedPage = [PATHS.home, PATHS.governanceActions, PATHS.governanceActionsAction]
97+
.includes(window.location.pathname);
98+
99+
const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
100+
101+
if (!walletName) return;
102+
103+
if (isWalletAvailable()) {
104+
enable(walletName);
105+
} else {
106+
waitForWalletExtension();
88107
}
89108
}, []);
90109

govtool/frontend/src/components/atoms/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ChangeEvent } from "react";
2+
import { LinkProps } from "react-router-dom";
23
import {
34
ButtonProps as MUIButtonProps,
45
CheckboxProps as MUICheckboxProps,
@@ -13,6 +14,10 @@ export type ButtonProps = Omit<MUIButtonProps, "size"> & {
1314
isLoading?: boolean;
1415
size?: "small" | "medium" | "large" | "extraLarge";
1516
dataTestId?: string;
17+
to?: LinkProps["to"];
18+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19+
state?: any;
20+
component?: React.ElementType;
1621
};
1722

1823
export type LoadingButtonProps = ButtonProps & {

govtool/frontend/src/components/molecules/GovernanceActionCard.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FC } from "react";
22
import { Box, Skeleton } from "@mui/material";
3+
import { Link, useLocation } from "react-router-dom";
34

45
import { Button } from "@atoms";
56
import {
@@ -58,6 +59,9 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
5859
bech32Prefix: "gov_action",
5960
});
6061

62+
const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions");
63+
const isCategoryView = useLocation().pathname.includes("category");
64+
6165
return (
6266
<Box
6367
sx={{
@@ -151,6 +155,22 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
151155
) : (
152156
<Button
153157
onClick={onClick}
158+
component={Link}
159+
to={`${pathname}/${govActionId}`}
160+
state={{
161+
proposal: {
162+
abstract,
163+
type,
164+
expiryDate,
165+
expiryEpochNo,
166+
createdDate,
167+
createdEpochNo,
168+
txHash,
169+
index,
170+
title,
171+
},
172+
openedFromCategoryPage: isCategoryView
173+
}}
154174
variant={inProgress ? "outlined" : "contained"}
155175
size="large"
156176
sx={{

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useCallback } from "react";
1+
import { useState, useEffect, useCallback, useMemo } from "react";
22
import { Box, CircularProgress, Tab, Tabs, styled } from "@mui/material";
33
import { useLocation, useNavigate } from "react-router-dom";
44

@@ -88,8 +88,12 @@ export const DashboardGovernanceActions = () => {
8888
const prevFilters = usePrevious(queryFilters);
8989
const prevSorting = usePrevious(chosenSorting);
9090

91-
const stableFilters = isAdjusting ? prevFilters ?? queryFilters : queryFilters;
92-
const stableSorting = isAdjusting ? prevSorting ?? chosenSorting : chosenSorting;
91+
const stableFilters = isAdjusting
92+
? prevFilters ?? queryFilters
93+
: queryFilters;
94+
const stableSorting = isAdjusting
95+
? prevSorting ?? chosenSorting
96+
: chosenSorting;
9397

9498
const { proposals, isProposalsLoading } = useGetProposalsQuery({
9599
filters: stableFilters,
@@ -103,16 +107,23 @@ export const DashboardGovernanceActions = () => {
103107
debouncedSearchText,
104108
);
105109

106-
// TODO: Black magic - that filtering should be done on the backend
107-
const filteredProposals = proposals
108-
?.map((proposalCategory) => {
110+
// White Magic :)
111+
const shouldFilter =
112+
voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter;
113+
114+
const filteredProposals = useMemo(() => {
115+
if (!shouldFilter || !proposals || !votes) return proposals;
116+
117+
return proposals
118+
.map((proposalCategory) => {
109119
const filteredActions = proposalCategory.actions.filter((action) => {
110-
const hasVote = votes?.some((voteCategory) =>
120+
const hasVote = votes.some((voteCategory) =>
111121
voteCategory.actions.some(
112-
(voteAction) => voteAction.proposal.txHash === action.txHash,
122+
(voteAction) =>
123+
voteAction.proposal.txHash === action.txHash &&
124+
voteAction.proposal.index === action.index,
113125
),
114126
);
115-
116127
return !hasVote;
117128
});
118129

@@ -122,6 +133,7 @@ export const DashboardGovernanceActions = () => {
122133
};
123134
})
124135
.filter((category) => category.actions.length > 0);
136+
}, [proposals, votes, shouldFilter]);
125137

126138
const { state } = useLocation();
127139
const [content, setContent] = useState<number>(

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { useNavigate, generatePath } from "react-router-dom";
21
import { Box } from "@mui/material";
32

43
import { Typography } from "@atoms";
5-
import { PATHS } from "@consts";
64
import { useCardano } from "@context";
75
import { useScreenDimension, useTranslation } from "@hooks";
86
import { ProposalData } from "@models";
9-
import { getProposalTypeTitle, getFullGovActionId } from "@utils";
7+
import { getProposalTypeTitle } from "@utils";
108
import { Slider, ValidatedGovernanceActionCard } from "@organisms";
119

1210
type GovernanceActionsToVoteProps = {
@@ -25,7 +23,6 @@ export const GovernanceActionsToVote = ({
2523
sorting,
2624
}: GovernanceActionsToVoteProps) => {
2725
const { pendingTransaction } = useCardano();
28-
const navigate = useNavigate();
2926
const { isMobile, pagePadding } = useScreenDimension();
3027
const { t } = useTranslation();
3128

@@ -64,29 +61,6 @@ export const GovernanceActionsToVote = ({
6461
pendingTransaction.vote?.resourceId ===
6562
`${action.txHash ?? ""}${action.index ?? ""}`
6663
}
67-
onClick={() => {
68-
navigate(
69-
onDashboard
70-
? generatePath(
71-
PATHS.dashboardGovernanceActionsAction,
72-
{
73-
proposalId: getFullGovActionId(
74-
action.txHash,
75-
action.index,
76-
),
77-
},
78-
)
79-
: PATHS.governanceActionsAction.replace(
80-
":proposalId",
81-
getFullGovActionId(action.txHash, action.index),
82-
),
83-
{
84-
state: {
85-
proposal: action,
86-
},
87-
},
88-
);
89-
}}
9064
/>
9165
</div>
9266
))}

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useCallback, useEffect, useMemo, useState } from "react";
2-
import { generatePath, useNavigate } from "react-router-dom";
1+
import { useEffect, useMemo, useState } from "react";
2+
import { generatePath, Link } from "react-router-dom";
33
import { Box } from "@mui/material";
44
import { KeenSliderOptions } from "keen-slider";
55
import "keen-slider/keen-slider.min.css";
@@ -39,7 +39,6 @@ export const Slider = ({
3939
const [isSliderInitialized, setIsSliderInitialized] = useState(false);
4040

4141
const { isMobile, screenWidth } = useScreenDimension();
42-
const navigate = useNavigate();
4342
const { pendingTransaction } = useCardano();
4443
const { t } = useTranslation();
4544

@@ -77,19 +76,6 @@ export const Slider = ({
7776
instanceRef.current?.moveToIdx(0);
7877
};
7978

80-
const onClickShowAll = useCallback(() => {
81-
navigate(
82-
generatePath(
83-
onDashboard
84-
? PATHS.dashboardGovernanceActionsCategory
85-
: PATHS.governanceActionsCategory,
86-
{
87-
category: navigateKey,
88-
},
89-
),
90-
);
91-
}, [navigate, onDashboard]);
92-
9379
useEffect(() => {
9480
if (instanceRef.current) {
9581
setIsSliderInitialized(true);
@@ -129,6 +115,15 @@ export const Slider = ({
129115
<Typography variant="title2">{title}</Typography>
130116
{(notSlicedDataLength > 6 || (isMobile && isShowAll)) && (
131117
<Button
118+
component={Link}
119+
to={`${generatePath(
120+
onDashboard
121+
? PATHS.dashboardGovernanceActionsCategory
122+
: PATHS.governanceActionsCategory,
123+
{
124+
category: navigateKey,
125+
},
126+
)}`}
132127
variant="contained"
133128
size="medium"
134129
sx={{
@@ -139,7 +134,6 @@ export const Slider = ({
139134
minWidth: 93,
140135
"&:hover": { backgroundColor: arcticWhite },
141136
}}
142-
onClick={onClickShowAll}
143137
>
144138
{t("slider.showAll")}
145139
</Button>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useState, useEffect } from "react";
22

3+
import { GovernanceActionCard } from "@molecules";
34
import { useValidateMutation } from "@/hooks/mutations";
45
import { MetadataStandard, ProposalData } from "@/models";
5-
import { GovernanceActionCard } from "../molecules";
66

77
type ActionTypeProps = Omit<
88
ProposalData,

govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useRef } from "react";
2-
import { generatePath, useNavigate, useParams } from "react-router-dom";
2+
import { useNavigate, useParams } from "react-router-dom";
33
import { Box, CircularProgress, Link } from "@mui/material";
44

55
import { Background, Typography } from "@atoms";
@@ -18,7 +18,6 @@ import {
1818
useTranslation,
1919
} from "@hooks";
2020
import {
21-
getFullGovActionId,
2221
getProposalTypeLabel,
2322
removeDuplicatedProposals,
2423
} from "@utils";
@@ -141,18 +140,6 @@ export const DashboardGovernanceActionsCategory = () => {
141140
}
142141
onClick={() => {
143142
saveScrollPosition();
144-
145-
navigate(
146-
generatePath(PATHS.dashboardGovernanceActionsAction, {
147-
proposalId: getFullGovActionId(item.txHash, item.index),
148-
}),
149-
{
150-
state: {
151-
proposal: item,
152-
openedFromCategoryPage: true,
153-
},
154-
},
155-
);
156143
}}
157144
txHash={item.txHash}
158145
/>

0 commit comments

Comments
 (0)