Skip to content

Commit 33a63fc

Browse files
committed
feat(#2634): add metadata searching;
fix(#2639): fix searching for full drep id
1 parent 1e78a63 commit 33a63fc

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ changes.
1212

1313
### Added
1414

15-
-
15+
- Add searching for metadata [Issue 2634](https://github.com/IntersectMBO/govtool/issues/2634)
1616

1717
### Fixed
1818

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

2121
### Changed
2222

govtool/backend/sql/list-dreps.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ WHERE
167167
COALESCE(?, '') = '' OR
168168
(CASE WHEN LENGTH(?) % 2 = 0 AND ? ~ '^[0-9a-fA-F]+$' THEN dh.raw = decode(?, 'hex') ELSE false END) OR
169169
dh.view ILIKE ? OR
170-
off_chain_vote_drep_data.given_name ILIKE ?
170+
off_chain_vote_drep_data.given_name ILIKE ? OR
171+
off_chain_vote_drep_data.payment_address ILIKE ? OR
172+
off_chain_vote_drep_data.objectives ILIKE ? OR
173+
off_chain_vote_drep_data.motivations ILIKE ? OR
174+
off_chain_vote_drep_data.qualifications ILIKE ?
171175
)
172176
GROUP BY
173177
block_first_register.epoch_no,

govtool/backend/src/VVA/API.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do
144144

145145
let filterDRepsByQuery = case mSearchQuery of
146146
Nothing -> filter $ \Types.DRepRegistration {..} ->
147-
dRepRegistrationType == Types.DRep
147+
dRepRegistrationType /= Types.SoleVoter
148148
Just query -> filter $ \Types.DRepRegistration {..} ->
149149
let searchLower = Text.toLower query
150150
viewLower = Text.toLower dRepRegistrationView
151151
hashLower = Text.toLower dRepRegistrationDRepHash
152-
nameLower = maybe "" Text.toLower dRepRegistrationGivenName
153-
in case dRepRegistrationType of
154-
Types.SoleVoter -> searchLower == viewLower || searchLower == hashLower
155-
Types.DRep -> searchLower `isInfixOf` viewLower
156-
|| searchLower `isInfixOf` hashLower
157-
|| searchLower `isInfixOf` nameLower
152+
in case dRepRegistrationType of
153+
Types.SoleVoter ->
154+
searchLower == viewLower || searchLower == hashLower
155+
Types.DRep ->
156+
True
157+
158158

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

189189
let elements = take pageSize $ drop (page * pageSize) allValidDReps
190-
191190
return $ ListDRepsResponse
192191
{ listDRepsResponsePage = fromIntegral page
193192
, listDRepsResponsePageSize = fromIntegral pageSize

govtool/backend/src/VVA/DRep.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ listDReps ::
4444
listDReps mSearchQuery = withPool $ \conn -> do
4545
let searchParam = fromMaybe "" mSearchQuery
4646
results <- liftIO $ SQL.query conn listDRepsSql
47-
( searchParam
48-
, searchParam
49-
, searchParam
50-
, searchParam
51-
, "%" <> searchParam <> "%"
52-
, "%" <> searchParam <> "%"
47+
( searchParam -- COALESCE(?, '')
48+
, searchParam -- LENGTH(?)
49+
, searchParam -- AND ?
50+
, searchParam -- decode(?, 'hex')
51+
, "%" <> searchParam <> "%" -- dh.view
52+
, "%" <> searchParam <> "%" -- given_name
53+
, "%" <> searchParam <> "%" -- payment_address
54+
, "%" <> searchParam <> "%" -- objectives
55+
, "%" <> searchParam <> "%" -- motivations
56+
, "%" <> searchParam <> "%" -- qualifications
5357
)
58+
5459
timeZone <- liftIO getCurrentTimeZone
5560
return
5661
[ DRepRegistration drepHash drepView isScriptBased url dataHash (floor @Scientific deposit) votingPower status drepType txHash (localTimeToUTC timeZone date) metadataError paymentAddress givenName objectives motivations qualifications imageUrl imageHash

govtool/backend/src/VVA/Types.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ data DRepInfo
9595
, dRepInfoImageHash :: Maybe Text
9696
}
9797

98-
data DRepStatus = Active | Inactive | Retired deriving (Eq, Ord)
98+
data DRepStatus = Active | Inactive | Retired deriving (Show, Eq, Ord)
9999

100-
data DRepType = DRep | SoleVoter deriving (Eq)
100+
data DRepType = DRep | SoleVoter deriving (Show, Eq)
101101

102102
data DRepRegistration
103103
= DRepRegistration
@@ -121,6 +121,7 @@ data DRepRegistration
121121
, dRepRegistrationImageUrl :: Maybe Text
122122
, dRepRegistrationImageHash :: Maybe Text
123123
}
124+
deriving (Show)
124125

125126
data Proposal
126127
= Proposal

govtool/frontend/src/utils/drepSearchPhraseProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const dRepSearchPhraseProcessor = async (phrase: string) => {
2222

2323
drepIDPhrase = txID;
2424
}
25-
if (drepIDPhrase.startsWith("22") || drepIDPhrase.startsWith("23")) {
25+
if (drepIDPhrase.length === 58) {
2626
return drepIDPhrase.slice(2);
2727
}
2828

0 commit comments

Comments
 (0)