Skip to content

Commit b16d941

Browse files
authored
Merge pull request #4045 from IntersectMBO/develop
v2.0.35
2 parents 50ff9dc + 012046b commit b16d941

39 files changed

+678
-240
lines changed

govtool/backend/app/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ startApp vvaConfig sentryService = do
115115
$ setOnException (exceptionHandler vvaConfig sentryService) defaultSettings
116116
cacheEnv <- do
117117
let newCache = Cache.newCache (Just $ TimeSpec (fromIntegral (cacheDurationSeconds vvaConfig)) 0)
118+
let newDRepListCache = Cache.newCache (Just $ TimeSpec (fromIntegral (dRepListCacheDurationSeconds vvaConfig)) 0)
118119
proposalListCache <- newCache
119120
getProposalCache <- newCache
120121
currentEpochCache <- newCache
@@ -123,7 +124,7 @@ startApp vvaConfig sentryService = do
123124
dRepGetVotesCache <- newCache
124125
dRepInfoCache <- newCache
125126
dRepVotingPowerCache <- newCache
126-
dRepListCache <- newCache
127+
dRepListCache <- newDRepListCache
127128
networkMetricsCache <- newCache
128129
networkInfoCache <- newCache
129130
networkTotalStakeCache <- newCache

govtool/backend/example-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"port" : 9999,
1111
"host" : "localhost",
1212
"cachedurationseconds": 20,
13+
"dreplistcachedurationseconds": 600,
1314
"sentrydsn": "https://username:[email protected]/id",
1415
"sentryenv": "dev"
1516
}

govtool/backend/sql/list-dreps.sql

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ LatestVoteEpoch AS (
3232
JOIN tx ON tx.id = lvp.tx_id
3333
JOIN block ON block.id = tx.block_id
3434
),
35+
VotesLastYear AS (
36+
SELECT
37+
vp.drep_voter AS drep_id,
38+
COUNT(DISTINCT vp.gov_action_proposal_id) AS votes_last_year
39+
FROM voting_procedure vp
40+
JOIN tx ON tx.id = vp.tx_id
41+
JOIN block ON block.id = tx.block_id
42+
WHERE block.time >= now() - INTERVAL '1 year'
43+
GROUP BY vp.drep_voter
44+
),
3545
RankedDRepRegistration AS (
3646
SELECT DISTINCT ON (dr.drep_hash_id)
3747
dr.id,
@@ -127,6 +137,7 @@ DRepData AS (
127137
off_chain_vote_drep_data.qualifications,
128138
off_chain_vote_drep_data.image_url,
129139
off_chain_vote_drep_data.image_hash,
140+
COALESCE(vly.votes_last_year, 0) AS votes_last_year,
130141
COALESCE(
131142
(
132143
SELECT jsonb_agg(
@@ -239,6 +250,7 @@ DRepData AS (
239250
LEFT JOIN tx AS tx_first_register ON tx_first_register.id = dr_first_register.tx_id
240251
LEFT JOIN block AS block_first_register ON block_first_register.id = tx_first_register.block_id
241252
LEFT JOIN LatestVoteEpoch lve ON lve.drep_id = dh.id
253+
LEFT JOIN VotesLastYear vly ON vly.drep_id = dh.id
242254
CROSS JOIN DRepActivity
243255
GROUP BY
244256
dh.raw,
@@ -265,6 +277,7 @@ DRepData AS (
265277
off_chain_vote_drep_data.qualifications,
266278
off_chain_vote_drep_data.image_url,
267279
off_chain_vote_drep_data.image_hash,
280+
vly.votes_last_year,
268281
(
269282
SELECT jsonb_agg(
270283
jsonb_build_object(
@@ -317,10 +330,6 @@ WHERE
317330
(
318331
COALESCE(?, '') = '' OR
319332
(CASE WHEN LENGTH(?) % 2 = 0 AND ? ~ '^[0-9a-fA-F]+$' THEN drep_hash = ? ELSE false END) OR
320-
view ILIKE ? OR
321-
given_name ILIKE ? OR
322-
payment_address ILIKE ? OR
323-
objectives ILIKE ? OR
324-
motivations ILIKE ? OR
325-
qualifications ILIKE ?
333+
(CASE WHEN lower(?) ~ '^drep1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]+$' THEN view = lower(?) ELSE FALSE END) OR
334+
given_name ILIKE ?
326335
)

govtool/backend/src/VVA/API.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ drepRegistrationToDrep Types.DRepRegistration {..} =
160160
dRepQualifications = dRepRegistrationQualifications,
161161
dRepImageUrl = dRepRegistrationImageUrl,
162162
dRepImageHash = HexText <$> dRepRegistrationImageHash,
163+
dRepVotesLastYear = dRepRegistrationVotesLastYear,
163164
dRepIdentityReferences = DRepReferences <$> dRepRegistrationIdentityReferences,
164165
dRepLinkReferences = DRepReferences <$> dRepRegistrationLinkReferences
165166
}
@@ -205,6 +206,8 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do
205206
Just Random -> fmap snd . sortOn fst . Prelude.zip randomizedOrderList
206207
Just VotingPower -> sortOn $ \Types.DRepRegistration {..} ->
207208
Down dRepRegistrationVotingPower
209+
Just Activity -> sortOn $ \Types.DRepRegistration {..} ->
210+
Down dRepRegistrationVotesLastYear
208211
Just RegistrationDate -> sortOn $ \Types.DRepRegistration {..} ->
209212
Down dRepRegistrationLatestRegistrationDate
210213
Just Status -> sortOn $ \Types.DRepRegistration {..} ->

govtool/backend/src/VVA/API/Types.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ instance ToParamSchema GovernanceActionType where
205205
& enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [GovernanceActionType])
206206

207207

208-
data DRepSortMode = Random | VotingPower | RegistrationDate | Status deriving
208+
data DRepSortMode = Random | VotingPower | Activity | RegistrationDate | Status deriving
209209
( Bounded
210210
, Enum
211211
, Eq
@@ -917,6 +917,7 @@ data DRep
917917
, dRepQualifications :: Maybe Text
918918
, dRepImageUrl :: Maybe Text
919919
, dRepImageHash :: Maybe HexText
920+
, dRepVotesLastYear :: Maybe Integer
920921
, dRepIdentityReferences :: Maybe DRepReferences
921922
, dRepLinkReferences :: Maybe DRepReferences
922923
}
@@ -944,6 +945,7 @@ exampleDrep =
944945
<> "\"qualifications\": \"Some Qualifications\","
945946
<> "\"qualifications\": \"Some Qualifications\","
946947
<> "\"imageUrl\": \"https://image.url\","
948+
<> "\"votesLastYear\": 15,"
947949
<> "\"imageHash\": \"9198b1b204273ba5c67a13310b5a806034160f6a063768297e161d9b759cad61\"}"
948950

949951
-- ToSchema instance for DRep

govtool/backend/src/VVA/Config.hs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,21 @@ instance DefaultConfig DBConfig where
6868
data VVAConfigInternal
6969
= VVAConfigInternal
7070
{ -- | db-sync database access.
71-
vVAConfigInternalDbsyncconfig :: DBConfig
71+
vVAConfigInternalDbsyncconfig :: DBConfig
7272
-- | Server port.
73-
, vVAConfigInternalPort :: Int
73+
, vVAConfigInternalPort :: Int
7474
-- | Server host.
75-
, vVAConfigInternalHost :: Text
75+
, vVAConfigInternalHost :: Text
7676
-- | Request cache duration
77-
, vVaConfigInternalCacheDurationSeconds :: Int
77+
, vVaConfigInternalCacheDurationSeconds :: Int
78+
-- | DRep List request cache duration
79+
, vVaConfigInternalDRepListCacheDurationSeconds :: Int
7880
-- | Sentry DSN
79-
, vVAConfigInternalSentrydsn :: String
81+
, vVAConfigInternalSentrydsn :: String
8082
-- | Sentry environment
81-
, vVAConfigInternalSentryEnv :: String
83+
, vVAConfigInternalSentryEnv :: String
8284
-- | Pinata API JWT
83-
, vVAConfigInternalPinataApiJwt :: Maybe Text
85+
, vVAConfigInternalPinataApiJwt :: Maybe Text
8486
}
8587
deriving (FromConfig, Generic, Show)
8688

@@ -92,6 +94,7 @@ instance DefaultConfig VVAConfigInternal where
9294
vVAConfigInternalPort = 3000,
9395
vVAConfigInternalHost = "localhost",
9496
vVaConfigInternalCacheDurationSeconds = 20,
97+
vVaConfigInternalDRepListCacheDurationSeconds = 600,
9598
vVAConfigInternalSentrydsn = "https://username:[email protected]/id",
9699
vVAConfigInternalSentryEnv = "development",
97100
vVAConfigInternalPinataApiJwt = Nothing
@@ -101,19 +104,21 @@ instance DefaultConfig VVAConfigInternal where
101104
data VVAConfig
102105
= VVAConfig
103106
{ -- | db-sync database credentials.
104-
dbSyncConnectionString :: Text
107+
dbSyncConnectionString :: Text
105108
-- | Server port.
106-
, serverPort :: Int
109+
, serverPort :: Int
107110
-- | Server host.
108-
, serverHost :: Text
111+
, serverHost :: Text
109112
-- | Request cache duration
110-
, cacheDurationSeconds :: Int
113+
, cacheDurationSeconds :: Int
114+
-- | DRep List request cache duration
115+
, dRepListCacheDurationSeconds :: Int
111116
-- | Sentry DSN
112-
, sentryDSN :: String
117+
, sentryDSN :: String
113118
-- | Sentry environment
114-
, sentryEnv :: String
119+
, sentryEnv :: String
115120
-- | Pinata API JWT
116-
, pinataApiJwt :: Maybe Text
121+
, pinataApiJwt :: Maybe Text
117122
}
118123
deriving (Generic, Show, ToJSON)
119124

@@ -153,6 +158,7 @@ convertConfig VVAConfigInternal {..} =
153158
serverPort = vVAConfigInternalPort,
154159
serverHost = vVAConfigInternalHost,
155160
cacheDurationSeconds = vVaConfigInternalCacheDurationSeconds,
161+
dRepListCacheDurationSeconds = vVaConfigInternalDRepListCacheDurationSeconds,
156162
sentryDSN = vVAConfigInternalSentrydsn,
157163
sentryEnv = vVAConfigInternalSentryEnv,
158164
pinataApiJwt = vVAConfigInternalPinataApiJwt

govtool/backend/src/VVA/DRep.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ data DRepQueryResult
5959
, queryQualifications :: Maybe Text
6060
, queryImageUrl :: Maybe Text
6161
, queryImageHash :: Maybe Text
62+
, queryVotesLastYear :: Maybe Integer
6263
, queryIdentityReferences :: Maybe Value
6364
, queryLinkReferences :: Maybe Value
6465
}
@@ -69,7 +70,7 @@ instance FromRow DRepQueryResult where
6970
<$> field <*> field <*> field <*> field <*> field <*> field
7071
<*> field <*> field <*> field <*> field <*> field <*> field
7172
<*> field <*> field <*> field <*> field <*> field <*> field
72-
<*> field <*> field <*> field <*> field
73+
<*> field <*> field <*> field <*> field <*> field
7374

7475
sqlFrom :: ByteString -> SQL.Query
7576
sqlFrom bs = fromString $ unpack $ Text.decodeUtf8 bs
@@ -86,12 +87,9 @@ listDReps mSearchQuery = withPool $ \conn -> do
8687
, searchParam -- LENGTH(?)
8788
, searchParam -- AND ?
8889
, searchParam -- decode(?, 'hex')
89-
, "%" <> searchParam <> "%" -- dh.view
90+
, searchParam -- lower(?)
91+
, searchParam -- lower(?)
9092
, "%" <> searchParam <> "%" -- given_name
91-
, "%" <> searchParam <> "%" -- payment_address
92-
, "%" <> searchParam <> "%" -- objectives
93-
, "%" <> searchParam <> "%" -- motivations
94-
, "%" <> searchParam <> "%" -- qualifications
9593
) :: IO [DRepQueryResult])
9694

9795
timeZone <- liftIO getCurrentTimeZone
@@ -116,6 +114,7 @@ listDReps mSearchQuery = withPool $ \conn -> do
116114
(queryQualifications result)
117115
(queryImageUrl result)
118116
(queryImageHash result)
117+
(queryVotesLastYear result)
119118
(queryIdentityReferences result)
120119
(queryLinkReferences result)
121120
| result <- results

govtool/backend/src/VVA/Types.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ data DRepRegistration
160160
, dRepRegistrationQualifications :: Maybe Text
161161
, dRepRegistrationImageUrl :: Maybe Text
162162
, dRepRegistrationImageHash :: Maybe Text
163+
, dRepRegistrationVotesLastYear :: Maybe Integer
163164
, dRepRegistrationIdentityReferences :: Maybe Value
164165
, dRepRegistrationLinkReferences :: Maybe Value
165166
}
@@ -187,6 +188,7 @@ instance FromRow DRepRegistration where
187188
<*> field -- dRepRegistrationQualifications
188189
<*> field -- dRepRegistrationImageUrl
189190
<*> field -- dRepRegistrationImageHash
191+
<*> field -- dRepRegistrationVotesLastYear
190192
<*> field -- dRepRegistrationIdentityReferences
191193
<*> field -- dRepRegistrationLinkReferences
192194

govtool/frontend/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

govtool/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@emotion/styled": "^11.11.0",
2828
"@emurgo/cardano-serialization-lib-asmjs": "^14.1.1",
2929
"@hookform/resolvers": "^3.3.1",
30-
"@intersect.mbo/govtool-outcomes-pillar-ui": "v1.5.6",
30+
"@intersect.mbo/govtool-outcomes-pillar-ui": "v1.5.7",
3131
"@intersect.mbo/intersectmbo.org-icons-set": "^1.0.8",
3232
"@intersect.mbo/pdf-ui": "1.0.13-beta",
3333
"@mui/icons-material": "^5.14.3",

0 commit comments

Comments
 (0)