Skip to content

Commit b6cde91

Browse files
authored
Merge pull request #3947 from IntersectMBO/develop
Backing out changes to View Details and Vote
2 parents ec457a3 + 2a5bd88 commit b6cde91

File tree

9 files changed

+92
-77
lines changed

9 files changed

+92
-77
lines changed

govtool/frontend/src/App.tsx

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

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

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-
});
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;
8877
}
89-
90-
if (!isOnAllowedPage) {
78+
}
79+
if (
80+
(!window.cardano && walletName) ||
81+
(walletName && !Object.keys(window.cardano).includes(walletName))
82+
) {
83+
if (!hrefCondition) {
9184
navigate(PATHS.home);
9285
}
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();
86+
removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
87+
removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`);
10788
}
10889
}, []);
10990

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

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

2318
export type LoadingButtonProps = ButtonProps & {

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

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

54
import { Button } from "@atoms";
65
import {
@@ -59,9 +58,6 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
5958
bech32Prefix: "gov_action",
6059
});
6160

62-
const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions");
63-
const isCategoryView = useLocation().pathname.includes("category");
64-
6561
return (
6662
<Box
6763
sx={{
@@ -155,22 +151,6 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
155151
) : (
156152
<Button
157153
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-
}}
174154
variant={inProgress ? "outlined" : "contained"}
175155
size="large"
176156
sx={{

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

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

34
import { Typography } from "@atoms";
5+
import { PATHS } from "@consts";
46
import { useCardano } from "@context";
57
import { useScreenDimension, useTranslation } from "@hooks";
68
import { ProposalData } from "@models";
7-
import { getProposalTypeTitle } from "@utils";
9+
import { getProposalTypeTitle, getFullGovActionId } from "@utils";
810
import { Slider, ValidatedGovernanceActionCard } from "@organisms";
911

1012
type GovernanceActionsToVoteProps = {
@@ -23,6 +25,7 @@ export const GovernanceActionsToVote = ({
2325
sorting,
2426
}: GovernanceActionsToVoteProps) => {
2527
const { pendingTransaction } = useCardano();
28+
const navigate = useNavigate();
2629
const { isMobile, pagePadding } = useScreenDimension();
2730
const { t } = useTranslation();
2831

@@ -61,6 +64,29 @@ export const GovernanceActionsToVote = ({
6164
pendingTransaction.vote?.resourceId ===
6265
`${action.txHash ?? ""}${action.index ?? ""}`
6366
}
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+
}}
6490
/>
6591
</div>
6692
))}

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useEffect, useMemo, useState } from "react";
2-
import { generatePath, Link } from "react-router-dom";
1+
import { useCallback, useEffect, useMemo, useState } from "react";
2+
import { generatePath, useNavigate } 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,6 +39,7 @@ export const Slider = ({
3939
const [isSliderInitialized, setIsSliderInitialized] = useState(false);
4040

4141
const { isMobile, screenWidth } = useScreenDimension();
42+
const navigate = useNavigate();
4243
const { pendingTransaction } = useCardano();
4344
const { t } = useTranslation();
4445

@@ -76,6 +77,19 @@ export const Slider = ({
7677
instanceRef.current?.moveToIdx(0);
7778
};
7879

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+
7993
useEffect(() => {
8094
if (instanceRef.current) {
8195
setIsSliderInitialized(true);
@@ -115,15 +129,6 @@ export const Slider = ({
115129
<Typography variant="title2">{title}</Typography>
116130
{(notSlicedDataLength > 6 || (isMobile && isShowAll)) && (
117131
<Button
118-
component={Link}
119-
to={`${generatePath(
120-
onDashboard
121-
? PATHS.dashboardGovernanceActionsCategory
122-
: PATHS.governanceActionsCategory,
123-
{
124-
category: navigateKey,
125-
},
126-
)}`}
127132
variant="contained"
128133
size="medium"
129134
sx={{
@@ -134,6 +139,7 @@ export const Slider = ({
134139
minWidth: 93,
135140
"&:hover": { backgroundColor: arcticWhite },
136141
}}
142+
onClick={onClickShowAll}
137143
>
138144
{t("slider.showAll")}
139145
</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";
43
import { useValidateMutation } from "@/hooks/mutations";
54
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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useRef } from "react";
2-
import { useNavigate, useParams } from "react-router-dom";
2+
import { generatePath, useNavigate, useParams } from "react-router-dom";
33
import { Box, CircularProgress, Link } from "@mui/material";
44

55
import { Background, Typography } from "@atoms";
@@ -18,6 +18,7 @@ import {
1818
useTranslation,
1919
} from "@hooks";
2020
import {
21+
getFullGovActionId,
2122
getProposalTypeLabel,
2223
removeDuplicatedProposals,
2324
} from "@utils";
@@ -140,6 +141,18 @@ export const DashboardGovernanceActionsCategory = () => {
140141
}
141142
onClick={() => {
142143
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+
);
143156
}}
144157
txHash={item.txHash}
145158
/>

govtool/frontend/src/pages/GovernanceActionsCategory.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "@hooks";
2121
import {
2222
WALLET_LS_KEY,
23+
getFullGovActionId,
2324
getItemFromLocalStorage,
2425
getProposalTypeLabel,
2526
removeDuplicatedProposals,
@@ -141,6 +142,19 @@ export const GovernanceActionsCategory = () => {
141142
{...item}
142143
onClick={() => {
143144
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+
);
144158
}}
145159
/>
146160
</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("link")).toBeEnabled();
61+
await expect(canvas.getByRole("button")).toBeEnabled();
6262
},
6363
};

0 commit comments

Comments
 (0)