Skip to content

Commit 2a5bd88

Browse files
committed
Revert "Allow Opening Governance Actions in New Tab from Live Voting Page"
This reverts commit 0a50bb5.
1 parent a768ca4 commit 2a5bd88

File tree

5 files changed

+66
-52
lines changed

5 files changed

+66
-52
lines changed

govtool/frontend/src/App.tsx

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +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-
await new Promise(resolve => setTimeout(resolve, interval));
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;
8577
}
86-
87-
if (!isOnAllowedPage) {
78+
}
79+
if (
80+
(!window.cardano && walletName) ||
81+
(walletName && !Object.keys(window.cardano).includes(walletName))
82+
) {
83+
if (!hrefCondition) {
8884
navigate(PATHS.home);
8985
}
90-
cleanUpWalletData();
91-
};
92-
93-
const isOnAllowedPage = [PATHS.home, PATHS.governanceActions, PATHS.governanceActionsAction]
94-
.includes(window.location.pathname);
95-
96-
const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
97-
98-
if (!walletName) return;
99-
100-
if (isWalletAvailable()) {
101-
enable(walletName);
102-
} else {
103-
waitForWalletExtension();
86+
removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
87+
removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`);
10488
}
10589
}, []);
10690

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

Lines changed: 2 additions & 5 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 {
@@ -40,6 +39,7 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
4039
inProgress = false,
4140
expiryDate,
4241
expiryEpochNo,
42+
onClick,
4343
createdDate,
4444
createdEpochNo,
4545
txHash,
@@ -58,8 +58,6 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
5858
bech32Prefix: "gov_action",
5959
});
6060

61-
const location = useLocation();
62-
6361
return (
6462
<Box
6563
sx={{
@@ -152,8 +150,7 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
152150
<Skeleton width="100%" height="40px" sx={{ borderRadius: "20px" }} />
153151
) : (
154152
<Button
155-
component={Link}
156-
to={`${location.pathname}/${govActionId}`}
153+
onClick={onClick}
157154
variant={inProgress ? "outlined" : "contained"}
158155
size="large"
159156
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
22

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

77
type ActionTypeProps = Omit<
88
ProposalData,
@@ -14,6 +14,7 @@ type ActionTypeProps = Omit<
1414
| "rationale"
1515
| "motivation"
1616
> & {
17+
onClick?: () => void;
1718
inProgress?: boolean;
1819
};
1920
export const ValidatedGovernanceActionCard = (props: ActionTypeProps) => {

0 commit comments

Comments
 (0)