Skip to content

Commit 9a5d0f7

Browse files
committed
WIP
1 parent af1ca81 commit 9a5d0f7

File tree

6 files changed

+55
-31
lines changed

6 files changed

+55
-31
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
select exists (select * from tx where tx.hash = decode(?, 'hex'))
1+
SELECT
2+
EXISTS (SELECT 1 FROM tx WHERE tx.hash = decode(?, 'hex')) AS tx_exists,
3+
COALESCE(
4+
(SELECT json_agg(voting_procedure.*)
5+
FROM voting_procedure
6+
JOIN tx ON voting_procedure.tx_id = tx.id
7+
WHERE tx.hash = decode(?, 'hex')
8+
), '[]'::json
9+
) AS voting_procedures;

govtool/backend/src/VVA/API.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,12 @@ getCurrentEpochParams = do
416416

417417
getTransactionStatus :: App m => HexText -> m GetTransactionStatusResponse
418418
getTransactionStatus (unHexText -> transactionId) = do
419-
x <- Transaction.getTransactionStatus transactionId
420-
case x of
421-
Types.TransactionConfirmed -> return $ GetTransactionStatusResponse True
422-
Types.TransactionUnconfirmed -> return $ GetTransactionStatusResponse False
423-
419+
info <- Transaction.getTransactionStatus transactionId
420+
return $ GetTransactionStatusResponse
421+
{ transactionExists = txExists info
422+
, votingProcedures = votingProcedures info
423+
}
424+
424425
throw500 :: App m => m ()
425426
throw500 = throwError $ CriticalError "intentional system break for testing purposes"
426427

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -650,28 +650,39 @@ instance ToSchema GetProposalResponse where
650650
& example
651651
?~ toJSON exampleGetProposalResponse
652652

653-
newtype GetTransactionStatusResponse
654-
= GetTransactionStatusResponse { getTransactionstatusResponseTransactionConfirmed :: Bool }
655-
deriving (Generic, Show)
656-
657-
658-
deriveJSON (jsonOptions "getTransactionstatusResponse") ''GetTransactionStatusResponse
659-
660-
exampleGetTransactionStatusResponse :: Text
661-
exampleGetTransactionStatusResponse = "{ \"transactionConfirmed\": True }"
653+
data GetTransactionStatusResponse = GetTransactionStatusResponse
654+
{ transactionExists :: Bool
655+
, votingProcedures :: Maybe Value
656+
}
657+
658+
instance FromJSON GetTransactionStatusResponse where
659+
parseJSON = withObject "GetTransactionStatusResponse" $ \o -> do
660+
transactionExists <- o .: "transactionExists"
661+
votingProcedures <- o .:? "votingProcedures"
662+
pure $ GetTransactionStatusResponse {..}
663+
664+
instance ToJSON GetTransactionStatusResponse where
665+
toJSON GetTransactionStatusResponse {..} =
666+
object
667+
[ "transactionExists" .= transactionExists
668+
, "votingProcedures" .= votingProcedures
669+
]
670+
671+
exampleGetTransactionStatusResponse :: GetTransactionStatusResponse
672+
exampleGetTransactionStatusResponse =
673+
GetTransactionStatusResponse
674+
{ transactionExists = True
675+
, votingProcedures = Just $ object ["key" .= ("value" :: Text)]
676+
}
662677

663678
instance ToSchema GetTransactionStatusResponse where
664-
declareNamedSchema proxy = do
665-
NamedSchema name_ schema_ <-
666-
genericDeclareNamedSchema
667-
( fromAesonOptions $
668-
jsonOptions "getTransactionstatusResponse"
669-
)
670-
proxy
679+
declareNamedSchema _ = do
680+
textSchema <- declareNamedSchema (Proxy :: Proxy Text)
671681
return $
672-
NamedSchema name_ $
673-
schema_
674-
& description ?~ "GetTransactionStatus Response"
682+
NamedSchema (Just "GetTransactionStatusResponse") $
683+
mempty
684+
& type_ ?~ OpenApiObject
685+
& description ?~ "Get Transaction Status Response"
675686
& example
676687
?~ toJSON exampleGetTransactionStatusResponse
677688

@@ -913,4 +924,3 @@ instance ToSchema GetNetworkMetricsResponse where
913924
& description ?~ "GetNetworkMetricsResponse"
914925
& example
915926
?~ toJSON exampleGetNetworkMetricsResponse
916-

govtool/backend/src/VVA/Transaction.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ getTransactionStatus ::
3535
getTransactionStatus transactionId = withPool $ \conn -> do
3636
result <- liftIO $ SQL.query conn getTransactionStatusSql (SQL.Only transactionId)
3737
case result of
38-
[SQL.Only True] -> return TransactionConfirmed
39-
[SQL.Only False] -> return TransactionUnconfirmed
40-
x -> throwError $ CriticalError ("Expected exactly one result from get-transaction-status.sql but got " <> pack (show (length x)) <> " of them. This should never happen")
38+
[info] -> return info
39+
x -> throwError $ CriticalError ("Expected exactly one result from get-transaction-status.sql but got " <> pack (show (length x)) <> " of them. This should never happen")

govtool/backend/src/VVA/Types.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ instance FromRow Proposal where
184184
<*> field
185185
<*> field
186186

187-
data TransactionStatus = TransactionConfirmed | TransactionUnconfirmed
187+
data TransactionStatus = TransactionStatus
188+
{ txExists :: Bool
189+
, votingProcedures :: Maybe Value
190+
}
191+
192+
instance FromRow TransactionStatus where
193+
fromRow = TransactionStatus <$> field <*> field
188194

189195
data CacheEnv
190196
= CacheEnv

govtool/frontend/src/components/organisms/DashboardGovernanceActionsVotedOn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const DashboardGovernanceActionsVotedOn = ({
4646
}
4747
return data;
4848
}, [data, searchPhrase, pendingTransaction.vote]);
49-
49+
console.log({ filteredData, pendingTransaction });
5050
return areDRepVotesLoading ? (
5151
<Box py={4} display="flex" justifyContent="center">
5252
<CircularProgress />

0 commit comments

Comments
 (0)