Skip to content

Commit

Permalink
Merge pull request #1030 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
Sync test with develop: #957, #1028, #928, #1019
  • Loading branch information
MSzalowski authored May 16, 2024
2 parents 45a50e5 + 899edbe commit f307ebd
Show file tree
Hide file tree
Showing 50 changed files with 737 additions and 184 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ changes.

### Fixed

- drep/list sql fix (now the drep type is correct) [Issue 957](https://github.com/IntersectMBO/govtool/issues/957)
- drep/list sql fix (now the latest tx date is correct) [Issue 826](https://github.com/IntersectMBO/govtool/issues/826)
- drep/info no longer returns null values [Issue 720](https://github.com/IntersectMBO/govtool/issues/720)
- drep/getVotes no longer returns 500 [Issue 685](https://github.com/IntersectMBO/govtool/issues/685)
Expand All @@ -86,6 +87,7 @@ changes.
- Fix all the existing eslint errors [Issue 514](https://github.com/IntersectMBO/govtool/issues/514)
- Fix all the existing typescript errors [Issue 514](https://github.com/IntersectMBO/govtool/issues/514)
- Fix endless spinner on a dashboard [Issue 539](https://github.com/IntersectMBO/govtool/issues/539)
- Remove wrongly appended `Yourself` filter on DRep Directory [Issue 1028](https://github.com/IntersectMBO/govtool/issues/1028)

### Changed

Expand Down
32 changes: 29 additions & 3 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ SELECT
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no, block_first_register.epoch_no))) <= DRepActivity.drep_activity AS active,
second_to_newest_drep_registration.voting_anchor_id IS NOT NULL AS has_voting_anchor,
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
newestRegister.time AS last_register_time
newestRegister.time AS last_register_time,
COALESCE(latestDeposit.deposit, 0),
non_deregister_voting_anchor.url IS NOT NULL AS has_non_deregister_voting_anchor
FROM
drep_hash dh
JOIN (
Expand All @@ -42,6 +43,15 @@ FROM
WHERE
dr.deposit IS NOT NULL) AS dr_deposit ON dr_deposit.drep_hash_id = dh.id
AND dr_deposit.rn = 1
JOIN (
SELECT
dr.id,
dr.drep_hash_id,
dr.deposit,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
FROM
drep_registration dr) AS latestDeposit ON latestDeposit.drep_hash_id = dh.id
AND latestDeposit.rn = 1
LEFT JOIN (
SELECT
dr.id,
Expand All @@ -53,6 +63,19 @@ FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id) AS dr_voting_anchor ON dr_voting_anchor.drep_hash_id = dh.id
AND dr_voting_anchor.rn = 1
LEFT JOIN (
SELECT
dr.id,
dr.drep_hash_id,
dr.voting_anchor_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn,
tx.hash AS tx_hash
FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id
WHERE dr.deposit is not null
AND dr.deposit >= 0) AS dr_non_deregister_voting_anchor ON dr_non_deregister_voting_anchor.drep_hash_id = dh.id
AND dr_non_deregister_voting_anchor.rn = 1
LEFT JOIN (
SELECT
dr.id,
Expand All @@ -65,6 +88,7 @@ FROM
LEFT JOIN DRepDistr ON DRepDistr.hash_id = dh.id
AND DRepDistr.rn = 1
LEFT JOIN voting_anchor va ON va.id = dr_voting_anchor.voting_anchor_id
LEFT JOIN voting_anchor non_deregister_voting_anchor on non_deregister_voting_anchor.id = dr_non_deregister_voting_anchor.voting_anchor_id
CROSS JOIN DRepActivity
LEFT JOIN voting_procedure AS voting_procedure ON voting_procedure.drep_voter = dh.id
LEFT JOIN tx AS tx ON tx.id = voting_procedure.tx_id
Expand Down Expand Up @@ -102,4 +126,6 @@ GROUP BY
DRepActivity.epoch_no,
DRepActivity.drep_activity,
dr_voting_anchor.tx_hash,
newestRegister.time
newestRegister.time,
latestDeposit.deposit,
non_deregister_voting_anchor.url
9 changes: 6 additions & 3 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ listDReps = withPool $ \conn -> do
timeZone <- liftIO getCurrentTimeZone
return
[ DRepRegistration drepHash drepView url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date)
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, wasDRep, txHash, date) <- results
| (drepHash, drepView, url, dataHash, deposit, votingPower, isActive, txHash, date, latestDeposit, latestNonDeregisterVotingAnchorWasNotNull) <- results
, let status = case (isActive, deposit) of
(_, d) | d < 0 -> Retired
(isActive, d) | d >= 0 && isActive -> Active
| d >= 0 && not isActive -> Inactive
, let drepType | isNothing url && wasDRep = DRep
| isNothing url && not wasDRep = SoleVoter
, let latestDeposit' = floor @Scientific latestDeposit :: Integer
, let drepType | latestDeposit' >= 0 && isNothing url = SoleVoter
| latestDeposit' >= 0 && not (isNothing url) = DRep
| latestDeposit' < 0 && not latestNonDeregisterVotingAnchorWasNotNull = SoleVoter
| latestDeposit' < 0 && latestNonDeregisterVotingAnchorWasNotNull = DRep
| Data.Maybe.isJust url = DRep
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useTranslation } from "@hooks";

import { Card } from "./Card";
import { Typography } from "../atoms";

export const EmptyStateDrepDirectory = () => {
const { t } = useTranslation();

return (
<Card
border
elevation={0}
sx={{
alignItems: "center",
display: "flex",
flexDirection: "column",
gap: 1,
py: 5,
width: "-webkit-fill-available",
}}
>
<Typography fontSize={22}>
{t("dRepDirectory.noResultsForTheSearchTitle")}
</Typography>
<Typography fontWeight={400}>
{t("dRepDirectory.noResultsForTheSearchDescription")}
</Typography>
</Card>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LinkWithIcon } from "@molecules";
export const GovernanceActionDetailsCardLinks = ({
links,
}: {
links?: string[];
links?: GovernanceActionLink[];
}) => {
const { isMobile } = useScreenDimension();
const { t } = useTranslation();
Expand Down Expand Up @@ -43,13 +43,13 @@ export const GovernanceActionDetailsCardLinks = ({
>
{links.map((link) => (
<LinkWithIcon
key={link}
label={link}
key={link.uri}
label={link.uri}
onClick={() => {
openModal({
type: "externalLink",
state: {
externalLink: link,
externalLink: link.uri,
},
});
}}
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/components/molecules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./DataActionsSorting";
export * from "./DataMissingInfoBox";
export * from "./DelegationAction";
export * from "./DRepInfoCard";
export * from "./EmptyStateDrepDirectory";
export * from "./EmptyStateGovernanceActionsCategory";
export * from "./Field";
export * from "./GovActionDetails";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type GovernanceActionDetailsCardProps = {
motivation?: string;
rationale?: string;
yesVotes: number;
links?: string[];
links?: GovernanceActionLink[];
govActionId: string;
isDataMissing: boolean | MetadataValidationStatus;
isDashboard?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type GovernanceActionDetailsCardDataProps = {
isInProgress?: boolean;
isOneColumn: boolean;
isSubmitted?: boolean;
links?: string[];
links?: GovernanceActionLink[];
motivation?: string;
rationale?: string;
title?: string;
Expand Down
27 changes: 27 additions & 0 deletions govtool/frontend/src/consts/dRepDirectory/filters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DREP_DIRECTORY_FILTERS } from "./filters";

describe("DREP_DIRECTORY_FILTERS", () => {
it("should exclude 'Yourself' from filters", () => {
// Arrange
const expectedFilters = [
{
key: "Active",
label: "Active",
},
{
key: "Inactive",
label: "Inactive",
},
{
key: "Retired",
label: "Retired",
},
];

// Act
const actualFilters = DREP_DIRECTORY_FILTERS;

// Assert
expect(actualFilters).toEqual(expectedFilters);
});
});
11 changes: 7 additions & 4 deletions govtool/frontend/src/consts/dRepDirectory/filters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { DRepStatus } from "@/models";

export const DREP_DIRECTORY_FILTERS = Object.values(DRepStatus).map((status) => ({
key: status,
label: status,
}));
export const DREP_DIRECTORY_FILTERS = Object.values(DRepStatus)
// `Yourself` should be excluded from filters
.filter((status) => status !== DRepStatus.Yourself)
.map((status) => ({
key: status,
label: status,
}));
25 changes: 16 additions & 9 deletions govtool/frontend/src/pages/DRepDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { PropsWithChildren } from "react";
import {
Navigate,
useLocation,
useNavigate,
useParams,
} from "react-router-dom";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { Box, ButtonBase, Chip, CircularProgress } from "@mui/material";

import { Button, StatusPill, Typography } from "@atoms";
Expand All @@ -17,7 +12,7 @@ import {
useScreenDimension,
useTranslation,
} from "@hooks";
import { Card, LinkWithIcon, Share } from "@molecules";
import { Card, EmptyStateDrepDirectory, LinkWithIcon, Share } from "@molecules";
import {
correctAdaFormat,
isSameDRep,
Expand Down Expand Up @@ -55,7 +50,7 @@ export const DRepDetails = ({ isConnected }: DRepDetailsProps) => {
});
const dRep = dRepData?.[0];

if (dRep === undefined || isDRepListLoading)
if (isDRepListLoading)
return (
<Box
sx={{
Expand All @@ -70,7 +65,19 @@ export const DRepDetails = ({ isConnected }: DRepDetailsProps) => {
</Box>
);

if (!dRep) return <Navigate to={PATHS.error} />;
if (!dRep)
return (
<Box
sx={{
alignItems: "center",
display: "flex",
flex: 1,
justifyContent: "center",
}}
>
<EmptyStateDrepDirectory />
</Box>
);

const { view, status, votingPower, type } = dRep;

Expand Down
30 changes: 8 additions & 22 deletions govtool/frontend/src/pages/DRepDirectoryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useGetAdaHolderVotingPowerQuery,
useGetDRepListInfiniteQuery,
} from "@hooks";
import { Card, DataActionsBar } from "@molecules";
import { DataActionsBar, EmptyStateDrepDirectory } from "@molecules";
import { AutomatedVotingOptions, DRepCard } from "@organisms";
import { correctAdaFormat, formHexToBech32, isSameDRep } from "@utils";
import { DRepListSort, DRepStatus } from "@models";
Expand Down Expand Up @@ -65,7 +65,12 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
const { dRepData: yourselfDRepList } = useGetDRepListInfiniteQuery({
searchPhrase: myDRepId,
});
const yourselfDRep = yourselfDRepList?.[0];

const yourselfDRep =
!!isConnected &&
(debouncedSearchText === myDRepId || debouncedSearchText === "")
? yourselfDRepList?.[0]
: undefined;

const {
dRepData: dRepList,
Expand Down Expand Up @@ -194,26 +199,7 @@ export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({
flex: 1,
}}
>
{dRepList?.length === 0 && (
<Card
border
elevation={0}
sx={{
alignItems: "center",
display: "flex",
flexDirection: "column",
gap: 1,
py: 5,
}}
>
<Typography fontSize={22}>
{t("dRepDirectory.noResultsForTheSearchTitle")}
</Typography>
<Typography fontWeight={400}>
{t("dRepDirectory.noResultsForTheSearchDescription")}
</Typography>
</Card>
)}
{dRepList?.length === 0 && <EmptyStateDrepDirectory />}
{dRepListToDisplay?.map((dRep) => {
if (
isSameDRep(dRep, myDrep?.view) ||
Expand Down
6 changes: 6 additions & 0 deletions govtool/frontend/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ declare global {

type ArrayElement<ArrayType extends readonly unknown[]> =
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;

type GovernanceActionLink = {
"@type": string;
label: string;
uri: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function createTempDRepAuth(page: Page, wallet: ShelleyWallet) {

export async function createTempAdaHolderAuth(
page: Page,
wallet: ShelleyWallet
wallet: ShelleyWallet,
) {
await importWallet(page, wallet.json());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Page } from "@playwright/test";

export default async function createWallet(
page: Page,
config?: CardanoTestWalletConfig
config?: CardanoTestWalletConfig,
) {
const wallet = (await ShelleyWallet.generate()).json();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StaticWallet } from "@types";

export async function importWallet(
page: Page,
wallet: StaticWallet | CardanoTestWallet
wallet: StaticWallet | CardanoTestWallet,
) {
await page.addInitScript((wallet) => {
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import path = require("path");

export default async function loadDemosExtension(
page: Page,
enableStakeSigning = false
enableStakeSigning = false,
) {
const demosBundleScriptPath = path.resolve(
__dirname,
"../../node_modules/@cardanoapi/cardano-test-wallet/script.js"
"../../node_modules/@cardanoapi/cardano-test-wallet/script.js",
);
let walletConfig: CardanoTestWalletConfig = {
enableStakeSigning,
Expand Down
5 changes: 5 additions & 0 deletions tests/govtool-frontend/playwright/lib/helpers/cardano.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function lovelaceToAda(lovelace: number) {
if (lovelace === 0) return 0;

return lovelace / 1e6;
}
Loading

0 comments on commit f307ebd

Please sign in to comment.