Skip to content

Commit

Permalink
[#2013] randomize DRep list
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Sep 18, 2024
1 parent 405f70e commit 3192cf4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Numeric.Natural (Natural)

import Servant.API
import Servant.Server
import System.Random (randomRIO)

import Text.Read (readMaybe)

Expand Down Expand Up @@ -153,6 +154,7 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do

let sortDReps = case mSortMode of
Nothing -> id
Just Random -> sortOn (\_ -> randomRIO (0, 1 :: Double)) dreps
Just VotingPower -> sortOn $ \Types.DRepRegistration {..} ->
Down dRepRegistrationVotingPower
Just RegistrationDate -> sortOn $ \Types.DRepRegistration {..} ->
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ instance ToParamSchema GovernanceActionType where
& enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [GovernanceActionType])


data DRepSortMode = VotingPower | RegistrationDate | Status deriving (Bounded, Enum, Eq, Generic, Read, Show)
data DRepSortMode = Random | VotingPower | RegistrationDate | Status deriving (Bounded, Enum, Eq, Generic, Read, Show)

instance FromJSON DRepSortMode where
parseJSON (Aeson.String dRepSortMode) = pure $ fromJust $ readMaybe (Text.unpack dRepSortMode)
Expand Down
1 change: 1 addition & 0 deletions govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ library
, http-client-tls
, vector
, async
, random

exposed-modules: VVA.Config
, VVA.CommandLine
Expand Down

0 comments on commit 3192cf4

Please sign in to comment.