Skip to content

Commit

Permalink
feat(#2634): add metadata searching;
Browse files Browse the repository at this point in the history
fix(#2639): fix searching for full drep id
  • Loading branch information
MSzalowski committed Jan 15, 2025
1 parent 5973428 commit e6d9b72
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ changes.
### 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)

### Fixed

-
- Fix searching by full DRep IDs on wrong prefix cut [Issue 2639](https://github.com/IntersectMBO/govtool/issues/2639)

### Changed

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/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

0 comments on commit e6d9b72

Please sign in to comment.