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

fix: fix searching by drep name #2297

Merged
merged 3 commits into from
Oct 31, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ changes.

### Fixed

-
- Fix searching by DRep Given name
- Fix displaying the wallet connected modal

### Changed

Expand Down
18 changes: 12 additions & 6 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,21 @@ delegationToResponse Types.Delegation {..} =
drepList :: App m => Maybe Text -> [DRepStatus] -> Maybe DRepSortMode -> Maybe Natural -> Maybe Natural -> m ListDRepsResponse
drepList mSearchQuery statuses mSortMode mPage mPageSize = do
CacheEnv {dRepListCache} <- asks vvaCache
dreps <- cacheRequest dRepListCache () (DRep.listDReps mSearchQuery)
dreps <- cacheRequest dRepListCache (fromMaybe "" mSearchQuery) (DRep.listDReps mSearchQuery)

let filterDRepsByQuery = case mSearchQuery of
Nothing -> filter $ \Types.DRepRegistration {..} -> dRepRegistrationType == Types.DRep
Nothing -> filter $ \Types.DRepRegistration {..} ->
dRepRegistrationType == Types.DRep
Just query -> filter $ \Types.DRepRegistration {..} ->
case dRepRegistrationType of
Types.SoleVoter -> query == dRepRegistrationView || query == dRepRegistrationDRepHash
Types.DRep -> query `isInfixOf` dRepRegistrationView
|| query `isInfixOf` dRepRegistrationDRepHash
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

let filterDRepsByStatus = case statuses of
[] -> id
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ data CacheEnv
, dRepGetVotesCache :: Cache.Cache Text ([Vote], [Proposal])
, dRepInfoCache :: Cache.Cache Text DRepInfo
, dRepVotingPowerCache :: Cache.Cache Text Integer
, dRepListCache :: Cache.Cache () [DRepRegistration]
, dRepListCache :: Cache.Cache Text [DRepRegistration]
, networkMetricsCache :: Cache.Cache () NetworkMetrics
}

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 @@ -118,7 +118,7 @@ const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {
);

return (
<DataActionsBarContext.Provider value={contextValue} key={pathname}>
<DataActionsBarContext.Provider value={contextValue}>
{children}
</DataActionsBarContext.Provider>
);
Expand Down
Loading