Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 18 additions & 37 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,47 +63,28 @@ export default () => {
}, []);

const checkTheWalletIsActive = useCallback(() => {
const isWalletAvailable = () =>
window.cardano && walletName && Object.keys(window.cardano).includes(walletName);
const hrefCondition =
window.location.pathname === PATHS.home ||
window.location.pathname === PATHS.governanceActions ||
window.location.pathname === PATHS.governanceActionsAction;

const cleanUpWalletData = () => {
removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`);
};

const waitForWalletExtension = async () => {
const timeout = 5000;
const interval = 100;
const startTime = Date.now();

while (Date.now() - startTime < timeout) {
if (isWalletAvailable()) {
enable(walletName);
return;
}
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => {
setTimeout(resolve, interval);
});
const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
if (window.cardano) {
const walletExtensions = Object.keys(window.cardano);
if (walletName && walletExtensions.includes(walletName)) {
enable(walletName);
return;
}

if (!isOnAllowedPage) {
}
if (
(!window.cardano && walletName) ||
(walletName && !Object.keys(window.cardano).includes(walletName))
) {
if (!hrefCondition) {
navigate(PATHS.home);
}
cleanUpWalletData();
};

const isOnAllowedPage = [PATHS.home, PATHS.governanceActions, PATHS.governanceActionsAction]
.includes(window.location.pathname);

const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`);

if (!walletName) return;

if (isWalletAvailable()) {
enable(walletName);
} else {
waitForWalletExtension();
removeItemFromLocalStorage(`${WALLET_LS_KEY}_name`);
removeItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`);
}
}, []);

Expand Down
5 changes: 0 additions & 5 deletions govtool/frontend/src/components/atoms/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChangeEvent } from "react";
import { LinkProps } from "react-router-dom";
import {
ButtonProps as MUIButtonProps,
CheckboxProps as MUICheckboxProps,
Expand All @@ -14,10 +13,6 @@ export type ButtonProps = Omit<MUIButtonProps, "size"> & {
isLoading?: boolean;
size?: "small" | "medium" | "large" | "extraLarge";
dataTestId?: string;
to?: LinkProps["to"];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state?: any;
component?: React.ElementType;
};

export type LoadingButtonProps = ButtonProps & {
Expand Down
20 changes: 0 additions & 20 deletions govtool/frontend/src/components/molecules/GovernanceActionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FC } from "react";
import { Box, Skeleton } from "@mui/material";
import { Link, useLocation } from "react-router-dom";

import { Button } from "@atoms";
import {
Expand Down Expand Up @@ -59,9 +58,6 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
bech32Prefix: "gov_action",
});

const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions");
const isCategoryView = useLocation().pathname.includes("category");

return (
<Box
sx={{
Expand Down Expand Up @@ -155,22 +151,6 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
) : (
<Button
onClick={onClick}
component={Link}
to={`${pathname}/${govActionId}`}
state={{
proposal: {
abstract,
type,
expiryDate,
expiryEpochNo,
createdDate,
createdEpochNo,
txHash,
index,
title,
},
openedFromCategoryPage: isCategoryView
}}
variant={inProgress ? "outlined" : "contained"}
size="large"
sx={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useNavigate, generatePath } from "react-router-dom";
import { Box } from "@mui/material";

import { Typography } from "@atoms";
import { PATHS } from "@consts";
import { useCardano } from "@context";
import { useScreenDimension, useTranslation } from "@hooks";
import { ProposalData } from "@models";
import { getProposalTypeTitle } from "@utils";
import { getProposalTypeTitle, getFullGovActionId } from "@utils";
import { Slider, ValidatedGovernanceActionCard } from "@organisms";

type GovernanceActionsToVoteProps = {
Expand All @@ -23,6 +25,7 @@ export const GovernanceActionsToVote = ({
sorting,
}: GovernanceActionsToVoteProps) => {
const { pendingTransaction } = useCardano();
const navigate = useNavigate();
const { isMobile, pagePadding } = useScreenDimension();
const { t } = useTranslation();

Expand Down Expand Up @@ -61,6 +64,29 @@ export const GovernanceActionsToVote = ({
pendingTransaction.vote?.resourceId ===
`${action.txHash ?? ""}${action.index ?? ""}`
}
onClick={() => {
navigate(
onDashboard
? generatePath(
PATHS.dashboardGovernanceActionsAction,
{
proposalId: getFullGovActionId(
action.txHash,
action.index,
),
},
)
: PATHS.governanceActionsAction.replace(
":proposalId",
getFullGovActionId(action.txHash, action.index),
),
{
state: {
proposal: action,
},
},
);
}}
/>
</div>
))}
Expand Down
28 changes: 17 additions & 11 deletions govtool/frontend/src/components/organisms/Slider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useState } from "react";
import { generatePath, Link } from "react-router-dom";
import { useCallback, useEffect, useMemo, useState } from "react";
import { generatePath, useNavigate } from "react-router-dom";
import { Box } from "@mui/material";
import { KeenSliderOptions } from "keen-slider";
import "keen-slider/keen-slider.min.css";
Expand Down Expand Up @@ -39,6 +39,7 @@ export const Slider = ({
const [isSliderInitialized, setIsSliderInitialized] = useState(false);

const { isMobile, screenWidth } = useScreenDimension();
const navigate = useNavigate();
const { pendingTransaction } = useCardano();
const { t } = useTranslation();

Expand Down Expand Up @@ -76,6 +77,19 @@ export const Slider = ({
instanceRef.current?.moveToIdx(0);
};

const onClickShowAll = useCallback(() => {
navigate(
generatePath(
onDashboard
? PATHS.dashboardGovernanceActionsCategory
: PATHS.governanceActionsCategory,
{
category: navigateKey,
},
),
);
}, [navigate, onDashboard]);

useEffect(() => {
if (instanceRef.current) {
setIsSliderInitialized(true);
Expand Down Expand Up @@ -115,15 +129,6 @@ export const Slider = ({
<Typography variant="title2">{title}</Typography>
{(notSlicedDataLength > 6 || (isMobile && isShowAll)) && (
<Button
component={Link}
to={`${generatePath(
onDashboard
? PATHS.dashboardGovernanceActionsCategory
: PATHS.governanceActionsCategory,
{
category: navigateKey,
},
)}`}
variant="contained"
size="medium"
sx={{
Expand All @@ -134,6 +139,7 @@ export const Slider = ({
minWidth: 93,
"&:hover": { backgroundColor: arcticWhite },
}}
onClick={onClickShowAll}
>
{t("slider.showAll")}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState, useEffect } from "react";

import { GovernanceActionCard } from "@molecules";
import { useValidateMutation } from "@/hooks/mutations";
import { MetadataStandard, ProposalData } from "@/models";
import { GovernanceActionCard } from "../molecules";

type ActionTypeProps = Omit<
ProposalData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo, useRef } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { generatePath, useNavigate, useParams } from "react-router-dom";
import { Box, CircularProgress, Link } from "@mui/material";

import { Background, Typography } from "@atoms";
Expand All @@ -18,6 +18,7 @@ import {
useTranslation,
} from "@hooks";
import {
getFullGovActionId,
getProposalTypeLabel,
removeDuplicatedProposals,
} from "@utils";
Expand Down Expand Up @@ -140,6 +141,18 @@ export const DashboardGovernanceActionsCategory = () => {
}
onClick={() => {
saveScrollPosition();

navigate(
generatePath(PATHS.dashboardGovernanceActionsAction, {
proposalId: getFullGovActionId(item.txHash, item.index),
}),
{
state: {
proposal: item,
openedFromCategoryPage: true,
},
},
);
}}
txHash={item.txHash}
/>
Expand Down
14 changes: 14 additions & 0 deletions govtool/frontend/src/pages/GovernanceActionsCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@hooks";
import {
WALLET_LS_KEY,
getFullGovActionId,
getItemFromLocalStorage,
getProposalTypeLabel,
removeDuplicatedProposals,
Expand Down Expand Up @@ -141,6 +142,19 @@ export const GovernanceActionsCategory = () => {
{...item}
onClick={() => {
saveScrollPosition();

navigate(
PATHS.governanceActionsAction.replace(
":proposalId",
getFullGovActionId(item.txHash, item.index),
),
{
state: {
proposal: item,
openedFromCategoryPage: true,
},
},
);
}}
/>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/stories/Slider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export const SliderComponentOverflow: Story = {
await expect(canvas.getByText("Slider title")).toBeInTheDocument();
await expect(canvas.getAllByTestId("slider")).toHaveLength(6);

await expect(canvas.getByRole("link")).toBeEnabled();
await expect(canvas.getByRole("button")).toBeEnabled();
},
};
Loading