Skip to content

Commit

Permalink
Merge pull request #381 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraRodziewicz authored Mar 4, 2024
2 parents 9ae8d87 + ba7311e commit c86dadb
Show file tree
Hide file tree
Showing 45 changed files with 982 additions and 781 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ jobs:
- name: Notify on Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.DEPLOY_NOTIFY_SLACK_WEBHOOK_URL }}
PIPELINE_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [[ "${{ inputs.environment }}" == "staging" ]]; then export DOMAIN=staging.govtool.byron.network; fi;
if [[ "${{ inputs.environment }}" == "beta" ]]; then export DOMAIN=sanchogov.tools; fi;
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ changes.
- Fixed CSP settings to allow error reports with Sentry [Issue 291](https://github.com/IntersectMBO/govtool/issues/291).

### Changed
- `drep/list` and `drep/info` endpoints now return additional data such as metadata url and hash, and voting power [Issue 223](https://github.com/IntersectMBO/govtool/issues/223)
- `isRegistered` and `wasRegistered` fields in the drep/info endpoint changed to `isRegisteredAsDRep` and `wasRegisteredAsDRep` respectively [Issue 212](https://github.com/IntersectMBO/govtool/issues/212)
- Update Cardano-Serialization-Lib to 12.0.0-alpha.16 [Issue 156](https://github.com/IntersectMBO/govtool/issues/156)
- Changed and improved working conventions docs, PR template and codeowners file, addressing [Issue 88](https://github.com/IntersectMBO/govtool/issues/88).
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Learn more; [docs.sanchogov.tools](https://docs.sanchogov.tools/).
## 📍 Navigation
- [GovTool Backend](./govtool/backend/README.md)
- [GovTool Frontend](./govtool/frontend/README.md)
- [GovTool deployment setup](./scripts/govtool/README.md)
- [Documentation](./docs/)
- [Tests](./tests/)

Expand Down
22 changes: 21 additions & 1 deletion govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,36 @@ WasRegisteredAsSoleVoter AS (
WHERE
drep_hash.raw = DRepId.raw
AND drep_registration.voting_anchor_id IS NULL)) AS value
), CurrentMetadata AS (
SELECT voting_anchor.url as url, encode(voting_anchor.data_hash, 'hex') as data_hash
FROM LatestRegistrationEntry
LEFT JOIN voting_anchor
ON voting_anchor.id = LatestRegistrationEntry.voting_anchor_id
LIMIT 1
), CurrentVotingPower AS (
SELECT amount as amount
FROM drep_hash
JOIN DRepId
ON drep_hash.raw = DRepId.raw
LEFT JOIN drep_distr
ON drep_distr.hash_id = drep_hash.id
ORDER BY drep_distr.epoch_no DESC
LIMIT 1
)
SELECT
IsRegisteredAsDRep.value,
WasRegisteredAsDRep.value,
IsRegisteredAsSoleVoter.value,
WasRegisteredAsSoleVoter.value,
CurrentDeposit.value
CurrentDeposit.value,
CurrentMetadata.url,
CurrentMetadata.data_hash,
CurrentVotingPower.amount
FROM
IsRegisteredAsDRep
CROSS JOIN IsRegisteredAsSoleVoter
CROSS JOIN WasRegisteredAsDRep
CROSS JOIN WasRegisteredAsSoleVoter
CROSS JOIN CurrentDeposit
CROSS JOIN CurrentMetadata
CROSS JOIN CurrentVotingPower
15 changes: 13 additions & 2 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
WITH DRepDistr AS (
SELECT
*,
ROW_NUMBER() OVER(PARTITION BY drep_hash.id ORDER BY drep_distr.epoch_no DESC) AS rn
FROM drep_distr
JOIN drep_hash
on drep_hash.id = drep_distr.hash_id
)

SELECT
encode(dh.raw, 'hex'),
va.url,
encode(va.data_hash, 'hex'),
dr_deposit.deposit
dr_deposit.deposit,
DRepDistr.amount
FROM drep_hash dh
JOIN (
SELECT dr.id, dr.drep_hash_id, dr.deposit,
Expand All @@ -18,4 +28,5 @@ LEFT JOIN (
) as dr_voting_anchor
on dr_voting_anchor.drep_hash_id = dh.id and dr_voting_anchor.rn = 1
left JOIN voting_anchor va ON va.id = dr_voting_anchor.voting_anchor_id

LEFT JOIN DRepDistr
on DRepDistr.hash_id = dh.id and DRepDistr.rn = 1
5 changes: 4 additions & 1 deletion govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ server = drepList
drepList :: App m => m [DRep]
drepList = do
CacheEnv {dRepListCache} <- asks vvaCache
map (\(Types.DRepRegistration drep_hash url data_hash deposit) -> DRep (DRepHash drep_hash) url data_hash deposit)
map (\(Types.DRepRegistration drep_hash url data_hash deposit votingPower) -> DRep (DRepHash drep_hash) url data_hash deposit votingPower)
<$> cacheRequest dRepListCache () DRep.listDReps

getVotingPower :: App m => HexText -> m Integer
Expand Down Expand Up @@ -158,6 +158,9 @@ drepInfo (unHexText -> dRepId) = do
, dRepInfoResponseIsRegisteredAsSoleVoter = dRepInfoIsRegisteredAsSoleVoter
, dRepInfoResponseWasRegisteredAsSoleVoter = dRepInfoWasRegisteredAsSoleVoter
, dRepInfoResponseDeposit = dRepInfoDeposit
, dRepInfoResponseUrl = dRepInfoUrl
, dRepInfoResponseDataHash = HexText <$> dRepInfoDataHash
, dRepInfoResponseVotingPower = dRepInfoVotingPower
}

getCurrentDelegation :: App m => HexText -> m (Maybe HexText)
Expand Down
12 changes: 10 additions & 2 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ data DRepInfoResponse = DRepInfoResponse
, dRepInfoResponseIsRegisteredAsSoleVoter :: Bool
, dRepInfoResponseWasRegisteredAsSoleVoter :: Bool
, dRepInfoResponseDeposit :: Maybe Integer
, dRepInfoResponseUrl :: Maybe Text
, dRepInfoResponseDataHash :: Maybe HexText
, dRepInfoResponseVotingPower :: Maybe Integer
} deriving (Generic, Show)

deriveJSON (jsonOptions "dRepInfoResponse") ''DRepInfoResponse
Expand All @@ -390,7 +393,10 @@ exampleDRepInfoResponse =
<> "\"wasRegisteredAsDRep\": true,"
<> "\"isRegisteredAsSoleVoter\": true,"
<> "\"wasRegisteredAsSoleVoter\": true,"
<> "\"deposit\": 2000000}"
<> "\"deposit\": 2000000,"
<> "\"url\": \"https://drep.metadata.xyz\","
<> "\"dataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"votingPower\": 1000000}"

instance ToSchema DRepInfoResponse where
declareNamedSchema proxy = do
Expand Down Expand Up @@ -512,6 +518,7 @@ data DRep = DRep
, dRepUrl :: Maybe Text
, dRepMetadataHash :: Maybe Text
, dRepDeposit :: Integer
, dRepVotingPower :: Maybe Integer
} deriving (Generic, Show)


Expand All @@ -522,7 +529,8 @@ exampleDrep =
"{\"drepId\": \"d3a62ffe9c214e1a6a9809f7ab2a104c117f85e1f171f8f839d94be5\","
<> "\"url\": \"https://proposal.metadata.xyz\","
<> "\"metadataHash\": \"9af10e89979e51b8cdc827c963124a1ef4920d1253eef34a1d5cfe76438e3f11\","
<> "\"deposit\": 0}"
<> "\"deposit\": 0,"
<> "\"votingPower\": 0}"

instance ToSchema DRep where
declareNamedSchema _ = pure $ NamedSchema (Just "DRep") $ mempty
Expand Down
17 changes: 14 additions & 3 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ listDReps ::
m [DRepRegistration]
listDReps = withPool $ \conn -> do
results <- liftIO $ SQL.query_ conn listDRepsSql
return [DRepRegistration drepHash url dataHash (floor @Scientific deposit) | (drepHash, url, dataHash, deposit) <- results]
return [DRepRegistration drepHash url dataHash (floor @Scientific deposit) votingPower | (drepHash, url, dataHash, deposit, votingPower) <- results]

getVotesSql :: SQL.Query
getVotesSql = sqlFrom $(embedFile "sql/get-votes.sql")
Expand Down Expand Up @@ -99,12 +99,23 @@ getDRepInfo
getDRepInfo drepId = withPool $ \conn -> do
result <- liftIO $ SQL.query conn getDRepInfoSql (SQL.Only drepId)
case result of
[(isRegisteredAsDRep, wasRegisteredAsDRep, isRegisteredAsSoleVoter, wasRegisteredAsSoleVoter, deposit)] ->
[ ( isRegisteredAsDRep
, wasRegisteredAsDRep
, isRegisteredAsSoleVoter
, wasRegisteredAsSoleVoter
, deposit
, url
, dataHash
, votingPower
)] ->
return $ DRepInfo
{ dRepInfoIsRegisteredAsDRep = fromMaybe False isRegisteredAsDRep
, dRepInfoWasRegisteredAsDRep = fromMaybe False wasRegisteredAsDRep
, dRepInfoIsRegisteredAsSoleVoter = fromMaybe False isRegisteredAsSoleVoter
, dRepInfoWasRegisteredAsSoleVoter = fromMaybe False wasRegisteredAsSoleVoter
, dRepInfoDeposit = deposit
, dRepInfoUrl = url
, dRepInfoDataHash = dataHash
, dRepInfoVotingPower = votingPower
}
[] -> return $ DRepInfo False False False False Nothing
[] -> return $ DRepInfo False False False False Nothing Nothing Nothing Nothing
4 changes: 4 additions & 0 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ data DRepInfo = DRepInfo
, dRepInfoIsRegisteredAsSoleVoter :: Bool
, dRepInfoWasRegisteredAsSoleVoter :: Bool
, dRepInfoDeposit :: Maybe Integer
, dRepInfoUrl :: Maybe Text
, dRepInfoDataHash :: Maybe Text
, dRepInfoVotingPower :: Maybe Integer
}

data DRepRegistration = DRepRegistration
{ dRepRegistrationDrepHash :: Text
, dRepRegistrationUrl :: Maybe Text
, dRepRegistrationDataHash :: Maybe Text
, dRepRegistrationDeposit :: Integer
, dRepRegistrationVotingPower :: Maybe Integer
}

data Proposal = Proposal
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
html,
body {
margin: 0;
overscroll-behavior-y: none;
padding: 0;
}
</style>
Expand Down
28 changes: 13 additions & 15 deletions govtool/frontend/src/components/molecules/ActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ export const ActionCard: FC<ActionCardProps> = ({ ...props }) => {
title,
} = props;
const { isMobile, screenWidth } = useScreenDimension();
const MOBILE_AND_WIDE_CONDITION = isMobile || screenWidth >= 1920;

const {
palette: { boxShadow2 },
} = theme;

return (
<Box
p={4.25}
borderRadius={3}
display="flex"
flexDirection="column"
flexGrow={1}
maxWidth={798}
p={4.25}
sx={{ boxShadow: `5px 5px 15px 5px ${boxShadow2}` }}
borderRadius={3}
width="-webkit-fill-available"
>
<Box display="flex" flexDirection="column" flex={1}>
{imageURL ? (
Expand All @@ -56,16 +57,16 @@ export const ActionCard: FC<ActionCardProps> = ({ ...props }) => {
width={imageWidth}
height={imageHeight}
style={{
alignSelf: MOBILE_AND_WIDE_CONDITION ? "center" : "start",
alignSelf: screenWidth < 640 ? "center" : "start",
}}
/>
) : null}
{title ? (
<Typography
fontWeight={isMobile ? 600 : 500}
sx={{
mt: MOBILE_AND_WIDE_CONDITION ? 4 : 2.5,
textAlign: MOBILE_AND_WIDE_CONDITION ? "center" : "left",
mt: screenWidth < 640 ? 4 : 2.5,
textAlign: screenWidth < 640 ? "center" : "left",
}}
variant={isMobile ? "title2" : "headline5"}
>
Expand All @@ -78,24 +79,21 @@ export const ActionCard: FC<ActionCardProps> = ({ ...props }) => {
sx={{
mb: 4.25,
mt: 1.75,
textAlign: MOBILE_AND_WIDE_CONDITION ? "center" : "left",
textAlign: screenWidth < 640 ? "center" : "left",
}}
variant={isMobile ? "body2" : "body1"}
>
{description}
</Typography>
) : null}
</Box>
<Box
display="flex"
flexDirection={MOBILE_AND_WIDE_CONDITION ? "column" : "row"}
>
<Box display="flex" flexDirection={screenWidth < 640 ? "column" : "row"}>
{firstButtonLabel ? (
<Button
data-testid={dataTestIdFirstButton}
onClick={firstButtonAction}
sx={{
width: MOBILE_AND_WIDE_CONDITION ? "100%" : "auto",
width: screenWidth < 640 ? "100%" : "auto",
}}
>
{firstButtonLabel}
Expand All @@ -106,9 +104,9 @@ export const ActionCard: FC<ActionCardProps> = ({ ...props }) => {
onClick={secondButtonAction}
sx={{
visibility: secondButtonLabel ? "visible" : "hidden",
ml: MOBILE_AND_WIDE_CONDITION ? 0 : 2,
mt: MOBILE_AND_WIDE_CONDITION ? 2 : 0,
width: MOBILE_AND_WIDE_CONDITION ? "100%" : "auto",
ml: screenWidth < 640 ? 0 : 2,
mt: screenWidth < 640 ? 2 : 0,
width: screenWidth < 640 ? "100%" : "auto",
display: !secondButtonLabel && screenWidth < 768 ? "none" : "block",
}}
variant="outlined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,15 @@ export const CenteredBoxPageWrapper: FC<PropsWithChildren<Props>> = ({
<Background isReverted>
<Box display={"flex"} minHeight={"100vh"} flexDirection="column">
<DashboardTopNav
imageSRC={ICONS.appLogoIcon}
imageWidth={isMobile ? undefined : 42}
imageHeight={isMobile ? 24 : 35}
title={pageTitle}
isVotingPowerHidden={isVotingPowerHidden}
/>
<Box
display={"flex"}
justifyContent={"center"}
flexDirection={"column"}
mt={isMobile ? 0 : 7}
height={isMobile ? "100%" : "auto"}
sx={{ marginTop: "97px" }}
>
{isMobile && (
<Box borderBottom={1} borderColor={"#fff"}>
<Typography
variant="body2"
sx={{
ml: 2,
my: "26px",
fontSize: "24px",
fontWeight: 400,
}}
>
{pageTitle}
</Typography>
</Box>
)}
<Link
data-testid={"back-button"}
sx={{
Expand Down
29 changes: 4 additions & 25 deletions govtool/frontend/src/components/molecules/DashboardActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
flex={1}
flexDirection="column"
p={3}
maxWidth={524}
position="relative"
sx={{ boxShadow: `5px 5px 15px 5px ${boxShadow2}` }}
>
Expand Down Expand Up @@ -192,15 +193,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
) : (
<Box
display="flex"
flexDirection={
screenWidth < 768
? "column"
: screenWidth < 1024
? "row"
: screenWidth < 1440
? "column"
: "row"
}
flexDirection={screenWidth < 640 ? "column" : "row"}
>
{firstButtonLabel ? (
<LoadingButton
Expand All @@ -211,14 +204,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
size="large"
variant={firstButtonVariant}
sx={{
mr:
screenWidth < 768
? 0
: screenWidth < 1024 && secondButtonLabel
? 2
: screenWidth >= 1440 && secondButtonLabel
? 2
: 0,
mr: screenWidth < 640 ? 0 : 2,
width: isMobile ? "100%" : "auto",
}}
>
Expand All @@ -234,14 +220,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
variant={secondButtonVariant}
sx={{
width: isMobile ? "100%" : "auto",
marginTop:
screenWidth < 768
? 1
: screenWidth < 1024
? 0
: screenWidth < 1440
? 1
: 0,
marginTop: screenWidth < 640 ? 1 : 0,
}}
>
{secondButtonLabel}
Expand Down
Loading

0 comments on commit c86dadb

Please sign in to comment.