Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#920 - bug 2] DRep details page Back button fix #952

Merged
merged 2 commits into from
May 8, 2024
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
1 change: 1 addition & 0 deletions govtool/frontend/src/components/organisms/DRepCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const DRepCard = ({
? PATHS.dashboardDRepDirectoryDRep
: PATHS.dRepDirectoryDRep
).replace(":dRepId", view),
{ state: { enteredFromWithinApp: true } },
)
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export const DRepDashboardCard = ({
};

const navigateToDrepDirectory = () =>
navigate(PATHS.dashboardDRepDirectoryDRep.replace(":dRepId", dRepIDBech32));
navigate(
PATHS.dashboardDRepDirectoryDRep.replace(":dRepId", dRepIDBech32),
{ state: { enteredFromWithinApp: true } },
);

const cardProps: Partial<DashboardActionCardProps> = (() => {
// transaction in progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const DelegateDashboardCard = ({
":dRepId",
displayedDelegationId || "",
),
{ state: { enteredFromWithinApp: true } },
),
[displayedDelegationId],
);
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export const en = {
editBtn: "Edit DRep data",
delegationOptions: "Delegation Options",
filterTitle: "DRep Status",
goToDRepDirectory: "Go to DRep Directory",
meAsDRep: "This DRep ID is connected to your wallet",
myDelegation: "You have delegated <strong>₳ {{ada}}</strong> to:",
myDRep: "This is your DRep",
Expand Down
40 changes: 28 additions & 12 deletions govtool/frontend/src/pages/DRepDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { PropsWithChildren } from "react";
import { Navigate, useNavigate, useParams } from "react-router-dom";
import {
Navigate,
useLocation,
useNavigate,
useParams,
} from "react-router-dom";
import { Box, ButtonBase, Chip, CircularProgress } from "@mui/material";

import { Button, StatusPill, Typography } from "@atoms";
Expand Down Expand Up @@ -35,12 +40,14 @@ export const DRepDetails = ({ isConnected }: DRepDetailsProps) => {
const { dRepID: myDRepId, pendingTransaction } = useCardano();
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const { openModal } = useModal();
const { screenWidth } = useScreenDimension();
const { dRepId: dRepParam } = useParams();

const { delegate, isDelegating } = useDelegateTodRep();

const displayBackButton = location.state?.enteredFromWithinApp || false;

const { dRepData, isDRepListLoading } = useGetDRepListInfiniteQuery({
searchPhrase: dRepParam,
});
Expand Down Expand Up @@ -74,16 +81,25 @@ export const DRepDetails = ({ isConnected }: DRepDetailsProps) => {

return (
<>
<LinkWithIcon
data-testid="back-to-list-button"
label={t("backToList")}
onClick={() =>
navigate(
isConnected ? PATHS.dashboardDRepDirectory : PATHS.dRepDirectory,
)
}
sx={{ mb: 2 }}
/>
{displayBackButton ? (
<LinkWithIcon
data-testid="back-button"
label={t("back")}
onClick={() => navigate(-1)}
sx={{ mb: 2 }}
/>
) : (
<LinkWithIcon
data-testid="go-to-drep-directory-button"
label={t("dRepDirectory.goToDRepDirectory")}
onClick={() =>
navigate(
isConnected ? PATHS.dashboardDRepDirectory : PATHS.dRepDirectory,
)
}
sx={{ mb: 2 }}
/>
)}
<Card
{...((isMe || isMyDrep) && {
border: true,
Expand Down
Loading