Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Nov 26, 2024
1 parent ef8bd0e commit 9606288
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
10 changes: 9 additions & 1 deletion govtool/backend/sql/get-transaction-status.sql
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
select exists (select * from tx where tx.hash = decode(?, 'hex'))
SELECT
EXISTS (SELECT 1 FROM tx WHERE tx.hash = decode(?, 'hex')) AS tx_exists,
COALESCE(
(SELECT json_agg(voting_procedure.*)
FROM voting_procedure
JOIN tx ON voting_procedure.tx_id = tx.id
WHERE tx.hash = decode(?, 'hex')
), '[]'::json
) AS voting_procedures;
11 changes: 6 additions & 5 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,12 @@ getCurrentEpochParams = do

getTransactionStatus :: App m => HexText -> m GetTransactionStatusResponse
getTransactionStatus (unHexText -> transactionId) = do
x <- Transaction.getTransactionStatus transactionId
case x of
Types.TransactionConfirmed -> return $ GetTransactionStatusResponse True
Types.TransactionUnconfirmed -> return $ GetTransactionStatusResponse False

info <- Transaction.getTransactionStatus transactionId
return $ GetTransactionStatusResponse
{ transactionExists = txExists info
, votingProcedures = votingProcedures info
}

throw500 :: App m => m ()
throw500 = throwError $ CriticalError "intentional system break for testing purposes"

Expand Down
50 changes: 30 additions & 20 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -650,28 +650,39 @@ instance ToSchema GetProposalResponse where
& example
?~ toJSON exampleGetProposalResponse

newtype GetTransactionStatusResponse
= GetTransactionStatusResponse { getTransactionstatusResponseTransactionConfirmed :: Bool }
deriving (Generic, Show)


deriveJSON (jsonOptions "getTransactionstatusResponse") ''GetTransactionStatusResponse

exampleGetTransactionStatusResponse :: Text
exampleGetTransactionStatusResponse = "{ \"transactionConfirmed\": True }"
data GetTransactionStatusResponse = GetTransactionStatusResponse
{ transactionExists :: Bool
, votingProcedures :: Maybe Value
}

instance FromJSON GetTransactionStatusResponse where
parseJSON = withObject "GetTransactionStatusResponse" $ \o -> do
transactionExists <- o .: "transactionExists"
votingProcedures <- o .:? "votingProcedures"
pure $ GetTransactionStatusResponse {..}

instance ToJSON GetTransactionStatusResponse where
toJSON GetTransactionStatusResponse {..} =
object
[ "transactionExists" .= transactionExists
, "votingProcedures" .= votingProcedures
]

exampleGetTransactionStatusResponse :: GetTransactionStatusResponse
exampleGetTransactionStatusResponse =
GetTransactionStatusResponse
{ transactionExists = True
, votingProcedures = Just $ object ["key" .= ("value" :: Text)]
}

instance ToSchema GetTransactionStatusResponse where
declareNamedSchema proxy = do
NamedSchema name_ schema_ <-
genericDeclareNamedSchema
( fromAesonOptions $
jsonOptions "getTransactionstatusResponse"
)
proxy
declareNamedSchema _ = do
textSchema <- declareNamedSchema (Proxy :: Proxy Text)
return $
NamedSchema name_ $
schema_
& description ?~ "GetTransactionStatus Response"
NamedSchema (Just "GetTransactionStatusResponse") $
mempty
& type_ ?~ OpenApiObject
& description ?~ "Get Transaction Status Response"
& example
?~ toJSON exampleGetTransactionStatusResponse

Expand Down Expand Up @@ -923,4 +934,3 @@ instance ToSchema GetNetworkMetricsResponse where
& description ?~ "GetNetworkMetricsResponse"
& example
?~ toJSON exampleGetNetworkMetricsResponse

5 changes: 2 additions & 3 deletions govtool/backend/src/VVA/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ getTransactionStatus ::
getTransactionStatus transactionId = withPool $ \conn -> do
result <- liftIO $ SQL.query conn getTransactionStatusSql (SQL.Only transactionId)
case result of
[SQL.Only True] -> return TransactionConfirmed
[SQL.Only False] -> return TransactionUnconfirmed
x -> throwError $ CriticalError ("Expected exactly one result from get-transaction-status.sql but got " <> pack (show (length x)) <> " of them. This should never happen")
[info] -> return info
x -> throwError $ CriticalError ("Expected exactly one result from get-transaction-status.sql but got " <> pack (show (length x)) <> " of them. This should never happen")
8 changes: 7 additions & 1 deletion govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ instance FromRow Proposal where
<*> field
<*> field

data TransactionStatus = TransactionConfirmed | TransactionUnconfirmed
data TransactionStatus = TransactionStatus
{ txExists :: Bool
, votingProcedures :: Maybe Value
}

instance FromRow TransactionStatus where
fromRow = TransactionStatus <$> field <*> field

data CacheEnv
= CacheEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const DashboardGovernanceActionsVotedOn = ({
}
return data;
}, [data, searchPhrase, pendingTransaction.vote]);

console.log({ filteredData, pendingTransaction });

Check failure on line 49 in govtool/frontend/src/components/organisms/DashboardGovernanceActionsVotedOn.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return areDRepVotesLoading ? (
<Box py={4} display="flex" justifyContent="center">
<CircularProgress />
Expand Down

0 comments on commit 9606288

Please sign in to comment.