Skip to content

Commit 1d3ecb4

Browse files
authored
Merge pull request #3957 from IntersectMBO/test
v2.0.31.1
2 parents 0996a0e + 1485b42 commit 1d3ecb4

File tree

10 files changed

+113
-110
lines changed

10 files changed

+113
-110
lines changed

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: 25 additions & 6 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 {
@@ -19,13 +20,7 @@ import { ProposalData } from "@models";
1920

2021
type ActionTypeProps = Omit<
2122
ProposalData,
22-
| "yesVotes"
23-
| "noVotes"
24-
| "abstainVotes"
2523
| "id"
26-
| "details"
27-
| "rationale"
28-
| "motivation"
2924
> & {
3025
onClick?: () => void;
3126
inProgress?: boolean;
@@ -47,6 +42,7 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
4742
title,
4843
isValidating,
4944
metadataStatus,
45+
...otherProposalData
5046
}) => {
5147
const { isMobile, screenWidth } = useScreenDimension();
5248
const { t } = useTranslation();
@@ -58,6 +54,9 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
5854
bech32Prefix: "gov_action",
5955
});
6056

57+
const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions");
58+
const isCategoryView = useLocation().pathname.includes("category");
59+
6160
return (
6261
<Box
6362
sx={{
@@ -151,6 +150,26 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
151150
) : (
152151
<Button
153152
onClick={onClick}
153+
component={Link}
154+
to={`${pathname}/${govActionId}`}
155+
state={{
156+
proposal: {
157+
abstract,
158+
type,
159+
inProgress,
160+
expiryDate,
161+
expiryEpochNo,
162+
createdDate,
163+
createdEpochNo,
164+
txHash,
165+
index,
166+
title,
167+
isValidating,
168+
metadataStatus,
169+
...otherProposalData,
170+
},
171+
openedFromCategoryPage: isCategoryView
172+
}}
154173
variant={inProgress ? "outlined" : "contained"}
155174
size="large"
156175
sx={{

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,39 @@ export const DashboardGovernanceActionsVotedOn = ({
2626
const { t } = useTranslation();
2727

2828
// TODO: Filtering here is some kind of craziness. It should be done on the backend.
29+
2930
const filteredData = useMemo(() => {
30-
if (votes.length && searchPhrase) {
31-
return votes
32-
.map((entry) => ({
31+
if (!votes?.length) return [];
32+
if (!searchPhrase) return votes;
33+
const lowerSearch = searchPhrase.toLowerCase();
34+
return votes
35+
.map((entry) => {
36+
const filteredActions = entry.actions.filter((action) => {
37+
const hash = getFullGovActionId(
38+
action.proposal.txHash,
39+
action.proposal.index,
40+
).toLowerCase();
41+
42+
const title = action.proposal.title?.toLowerCase() || "";
43+
const motivation = action.proposal.motivation?.toLowerCase() || "";
44+
const rationale = action.proposal.rationale?.toLowerCase() || "";
45+
const abstract = action.proposal.abstract?.toLowerCase() || "";
46+
47+
return (
48+
hash.includes(lowerSearch) ||
49+
title.includes(lowerSearch) ||
50+
motivation.includes(lowerSearch) ||
51+
rationale.includes(lowerSearch) ||
52+
abstract.includes(lowerSearch)
53+
);
54+
});
55+
56+
return {
3357
...entry,
34-
actions: entry.actions.filter((action) =>
35-
getFullGovActionId(action.proposal.txHash, action.proposal.index)
36-
.toLowerCase()
37-
.includes(searchPhrase.toLowerCase()),
38-
),
39-
}))
40-
.filter((entry) => entry.actions?.length > 0);
41-
}
42-
return votes;
58+
actions: filteredActions,
59+
};
60+
})
61+
.filter((entry) => entry.actions.length > 0);
4362
}, [votes, searchPhrase, pendingTransaction.vote]);
4463

4564
return areDRepVotesLoading ? (

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
/>

govtool/frontend/src/pages/GovernanceActionsCategory.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
} from "@hooks";
2121
import {
2222
WALLET_LS_KEY,
23-
getFullGovActionId,
2423
getItemFromLocalStorage,
2524
getProposalTypeLabel,
2625
removeDuplicatedProposals,
@@ -142,19 +141,6 @@ export const GovernanceActionsCategory = () => {
142141
{...item}
143142
onClick={() => {
144143
saveScrollPosition();
145-
146-
navigate(
147-
PATHS.governanceActionsAction.replace(
148-
":proposalId",
149-
getFullGovActionId(item.txHash, item.index),
150-
),
151-
{
152-
state: {
153-
proposal: item,
154-
openedFromCategoryPage: true,
155-
},
156-
},
157-
);
158144
}}
159145
/>
160146
</Box>

govtool/frontend/src/stories/Slider.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ export const SliderComponentOverflow: Story = {
5858
await expect(canvas.getByText("Slider title")).toBeInTheDocument();
5959
await expect(canvas.getAllByTestId("slider")).toHaveLength(6);
6060

61-
await expect(canvas.getByRole("button")).toBeEnabled();
61+
await expect(canvas.getByRole("link")).toBeEnabled();
6262
},
6363
};

0 commit comments

Comments
 (0)