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

GovTool - v2.0.6 #2645

Merged
merged 10 commits into from
Jan 16, 2025
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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ changes.

-

## [v2.0.6](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.6) 2025-01-16

### Added

- Add support for base64 encoded images [Issue 2633](https://github.com/IntersectMBO/govtool/issues/2633)
- Add searching for metadata [Issue 2634](https://github.com/IntersectMBO/govtool/issues/2634)
- Allow delegation to inactive DRep [Issue 2589](https://github.com/IntersectMBO/govtool/issues/2589)

### Fixed

- Fix searching by full DRep IDs on wrong prefix cut [Issue 2639](https://github.com/IntersectMBO/govtool/issues/2639)
- Trim whitespace from search bar input [Issue 2472](https://github.com/IntersectMBO/govtool/issues/2472)

### Changed

-

### Removed

-

## [v2.0.5](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.5) 2025-01-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-2.0.5/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-2.0.6/x/vva-be/build/vva-be/vva-be /usr/local/bin
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile.qovery
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-2.0.5/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-2.0.6/x/vva-be/build/vva-be/vva-be /usr/local/bin

# Expose the necessary port
EXPOSE 9876
Expand Down
6 changes: 5 additions & 1 deletion govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ WHERE
COALESCE(?, '') = '' OR
(CASE WHEN LENGTH(?) % 2 = 0 AND ? ~ '^[0-9a-fA-F]+$' THEN dh.raw = decode(?, 'hex') ELSE false END) OR
dh.view ILIKE ? OR
off_chain_vote_drep_data.given_name ILIKE ?
off_chain_vote_drep_data.given_name ILIKE ? OR
off_chain_vote_drep_data.payment_address ILIKE ? OR
off_chain_vote_drep_data.objectives ILIKE ? OR
off_chain_vote_drep_data.motivations ILIKE ? OR
off_chain_vote_drep_data.qualifications ILIKE ?
)
GROUP BY
block_first_register.epoch_no,
Expand Down
15 changes: 7 additions & 8 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do

let filterDRepsByQuery = case mSearchQuery of
Nothing -> filter $ \Types.DRepRegistration {..} ->
dRepRegistrationType == Types.DRep
dRepRegistrationType /= Types.SoleVoter
Just query -> filter $ \Types.DRepRegistration {..} ->
let searchLower = Text.toLower query
viewLower = Text.toLower dRepRegistrationView
hashLower = Text.toLower dRepRegistrationDRepHash
nameLower = maybe "" Text.toLower dRepRegistrationGivenName
in case dRepRegistrationType of
Types.SoleVoter -> searchLower == viewLower || searchLower == hashLower
Types.DRep -> searchLower `isInfixOf` viewLower
|| searchLower `isInfixOf` hashLower
|| searchLower `isInfixOf` nameLower
in case dRepRegistrationType of
Types.SoleVoter ->
searchLower == viewLower || searchLower == hashLower
Types.DRep ->
True


let filterDRepsByStatus = case statuses of
[] -> id
Expand Down Expand Up @@ -187,7 +187,6 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do
total = length allValidDReps :: Int

let elements = take pageSize $ drop (page * pageSize) allValidDReps

return $ ListDRepsResponse
{ listDRepsResponsePage = fromIntegral page
, listDRepsResponsePageSize = fromIntegral pageSize
Expand Down
17 changes: 11 additions & 6 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ listDReps ::
listDReps mSearchQuery = withPool $ \conn -> do
let searchParam = fromMaybe "" mSearchQuery
results <- liftIO $ SQL.query conn listDRepsSql
( searchParam
, searchParam
, searchParam
, searchParam
, "%" <> searchParam <> "%"
, "%" <> searchParam <> "%"
( searchParam -- COALESCE(?, '')
, searchParam -- LENGTH(?)
, searchParam -- AND ?
, searchParam -- decode(?, 'hex')
, "%" <> searchParam <> "%" -- dh.view
, "%" <> searchParam <> "%" -- given_name
, "%" <> searchParam <> "%" -- payment_address
, "%" <> searchParam <> "%" -- objectives
, "%" <> searchParam <> "%" -- motivations
, "%" <> searchParam <> "%" -- qualifications
)

timeZone <- liftIO getCurrentTimeZone
return
[ DRepRegistration drepHash drepView isScriptBased url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date) metadataError paymentAddress givenName objectives motivations qualifications imageUrl imageHash
Expand Down
5 changes: 3 additions & 2 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ data DRepInfo
, dRepInfoImageHash :: Maybe Text
}

data DRepStatus = Active | Inactive | Retired deriving (Eq, Ord)
data DRepStatus = Active | Inactive | Retired deriving (Show, Eq, Ord)

data DRepType = DRep | SoleVoter deriving (Eq)
data DRepType = DRep | SoleVoter deriving (Show, Eq)

data DRepRegistration
= DRepRegistration
Expand All @@ -121,6 +121,7 @@ data DRepRegistration
, dRepRegistrationImageUrl :: Maybe Text
, dRepRegistrationImageHash :: Maybe Text
}
deriving (Show)

data Proposal
= Proposal
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.6
name: vva-be
version: 2.0.5
version: 2.0.6

-- A short (one-line) description of the package.
-- synopsis:
Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion govtool/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@govtool/frontend",
"private": true,
"version": "2.0.5",
"version": "2.0.6",
"type": "module",
"scripts": {
"build": "vite build",
Expand Down
99 changes: 55 additions & 44 deletions govtool/frontend/src/components/molecules/DataMissingHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Avatar, Box, SxProps } from "@mui/material";

import { Typography } from "@atoms";
import { MetadataValidationStatus } from "@models";
import { getMetadataDataMissingStatusTranslation } from "@/utils";
import {
getBase64ImageDetails,
getMetadataDataMissingStatusTranslation,
} from "@/utils";
import { ICONS } from "@/consts";

type DataMissingHeaderProps = {
Expand All @@ -19,54 +22,62 @@ export const DataMissingHeader = ({
titleStyle,
isDRep,
image,
}: DataMissingHeaderProps) => (
<Box
sx={{
display: "grid",
gridTemplateColumns: "1fr auto",
gap: 2,
alignItems: "center",
mb: 2,
}}
data-testid="governance-action-details-card-header"
>
}: DataMissingHeaderProps) => {
const base64Image = getBase64ImageDetails(image ?? "");

return (
<Box
sx={{
flexDirection: {
xxs: "column",
md: "row",
},
alignItems: {
md: "center",
},
display: "flex",
display: "grid",
gridTemplateColumns: "1fr auto",
gap: 2,
alignItems: "center",
mb: 2,
}}
data-testid="governance-action-details-card-header"
>
{isDRep && (
<Avatar
alt="drep-image"
src={image || ICONS.defaultDRepIcon}
sx={{ width: 80, height: 80 }}
data-testid="drep-image"
/>
)}
<Typography
<Box
sx={{
...(isDRep && { ml: { md: 3 } }),
...(isDRep && { mt: { xxs: 2, md: 0 } }),
textOverflow: "ellipsis",
fontWeight: 600,
...(isDataMissing && { color: "errorRed" }),
...titleStyle,
flexDirection: {
xxs: "column",
md: "row",
},
alignItems: {
md: "center",
},
display: "flex",
}}
variant="title2"
>
{(isDataMissing &&
getMetadataDataMissingStatusTranslation(
isDataMissing as MetadataValidationStatus,
)) ||
title}
</Typography>
{isDRep && (
<Avatar
alt="drep-image"
src={
(base64Image.isValidBase64Image
? `${base64Image.base64Prefix}${image}`
: image) || ICONS.defaultDRepIcon
}
sx={{ width: 80, height: 80 }}
data-testid="drep-image"
/>
)}
<Typography
sx={{
...(isDRep && { ml: { md: 3 } }),
...(isDRep && { mt: { xxs: 2, md: 0 } }),
textOverflow: "ellipsis",
fontWeight: 600,
...(isDataMissing && { color: "errorRed" }),
...titleStyle,
}}
variant="title2"
>
{(isDataMissing &&
getMetadataDataMissingStatusTranslation(
isDataMissing as MetadataValidationStatus,
)) ||
title}
</Typography>
</Box>
</Box>
</Box>
);
);
};
13 changes: 10 additions & 3 deletions govtool/frontend/src/components/organisms/DRepCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
correctDRepDirectoryFormat,
ellipsizeText,
encodeCIP129Identifier,
getBase64ImageDetails,
getMetadataDataMissingStatusTranslation,
} from "@utils";

Expand Down Expand Up @@ -64,6 +65,8 @@ export const DRepCard = ({
bech32Prefix: isScriptBased ? "drep_script" : "drep",
});

const base64Image = getBase64ImageDetails(image ?? "");

return (
<Card
{...(isMe && {
Expand Down Expand Up @@ -119,7 +122,11 @@ export const DRepCard = ({
<Box flexDirection="row" minWidth={0} display="flex">
<Avatar
alt="drep-image"
src={image || ICONS.defaultDRepIcon}
src={
(base64Image.isValidBase64Image
? `${base64Image.base64Prefix}${image}`
: image) || ICONS.defaultDRepIcon
}
data-testid="drep-image"
/>
<Box
Expand Down Expand Up @@ -291,7 +298,7 @@ export const DRepCard = ({
{t("viewDetails")}
</Button>
)}
{status === "Active" &&
{["Active", "Inactive"].includes(status) &&
isConnected &&
onDelegate &&
!isMyDrep &&
Expand All @@ -304,7 +311,7 @@ export const DRepCard = ({
{t("delegate")}
</Button>
)}
{status === "Active" && !isConnected && (
{["Active", "Inactive"].includes(status) && !isConnected && (
<Button
data-testid={`${view}-connect-to-delegate-button`}
onClick={openChooseWalletModal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const DRepDetailsCard = ({
{/* BASIC INFO END */}

{/* BUTTONS */}
{isConnected && status === "Active" && !isMyDrep && (
{isConnected && ["Active", "Inactive"].includes(status) && !isMyDrep && (
<Button
data-testid="delegate-button"
disabled={!!pendingTransaction?.delegate}
Expand All @@ -161,7 +161,7 @@ export const DRepDetailsCard = ({
{t("delegate")}
</Button>
)}
{!isConnected && status === "Active" && (
{!isConnected && ["Active", "Inactive"].includes(status) && (
<Button
data-testid="connect-to-delegate-button"
onClick={() =>
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/context/dataActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface ProviderProps {
const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {
const isAdjusting = useRef<boolean>(false);
const [searchText, setSearchText] = useState<string>("");
const debouncedSearchText = useDebounce(searchText, 300);
const debouncedSearchText = useDebounce(searchText.trim(), 300);
const [filtersOpen, setFiltersOpen] = useState<boolean>(false);
const [chosenFilters, setChosenFilters] = useState<string[]>([]);
const [sortOpen, setSortOpen] = useState<boolean>(false);
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/utils/drepSearchPhraseProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const dRepSearchPhraseProcessor = async (phrase: string) => {

drepIDPhrase = txID;
}
if (drepIDPhrase.startsWith("22") || drepIDPhrase.startsWith("23")) {
if (drepIDPhrase.length === 58) {
return drepIDPhrase.slice(2);
}

Expand Down
Loading
Loading