Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ changes.

### Changed

- Change transaction confirmation to be based on existing off chain data for drep registration [Issue 3080](https://github.com/IntersectMBO/govtool/issues/3080)

### Removed

- Remove ratification threshold for Info Action for Consitutional Committee [Issue 3108](https://github.com/IntersectMBO/govtool/issues/3108)
Expand Down
20 changes: 19 additions & 1 deletion govtool/backend/sql/get-transaction-status.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,22 @@ SELECT
JOIN tx ON voting_procedure.tx_id = tx.id
WHERE tx.hash = decode(?, 'hex')
), '[]'::json
) AS voting_procedures;
) AS voting_procedures,
COALESCE(
(SELECT NULLIF(jsonb_agg(
jsonb_build_object(
'drep_registration', to_jsonb(drep_registration.*),
'off_chain_vote_drep_data',
(SELECT NULLIF(jsonb_agg(to_jsonb(off_chain_vote_drep_data)), '[]'::jsonb)
FROM off_chain_vote_data
JOIN off_chain_vote_drep_data
ON off_chain_vote_drep_data.off_chain_vote_data_id = off_chain_vote_data.id
WHERE off_chain_vote_data.voting_anchor_id = drep_registration.voting_anchor_id
)
)
), '[]'::jsonb)
FROM drep_registration
JOIN tx ON drep_registration.tx_id = tx.id
WHERE tx.hash = decode(?, 'hex')
), NULL
) AS drep_registrations
6 changes: 3 additions & 3 deletions govtool/backend/src/VVA/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ getTransactionStatus ::
=> Text
-> m (Maybe TransactionStatus)
getTransactionStatus transactionId = withPool $ \conn -> do
result <- liftIO $ SQL.query conn getTransactionStatusSql (transactionId, transactionId)
result <- liftIO $ SQL.query conn getTransactionStatusSql (transactionId, transactionId, transactionId)
case result of
[(transactionConfirmed, votingProcedure)] -> do
return $ Just $ TransactionStatus transactionConfirmed votingProcedure
[(transactionConfirmed, votingProcedure, drepRegistration)] -> do
return $ Just $ TransactionStatus transactionConfirmed votingProcedure drepRegistration
_ -> return Nothing
8 changes: 5 additions & 3 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@ instance FromRow Proposal where

data TransactionStatus = TransactionStatus
{ transactionConfirmed :: Bool
, votingProcedure :: Maybe Value
, votingProcedure :: Maybe Value
, drepRegistration :: Maybe Value
}

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

instance ToJSON TransactionStatus where
toJSON TransactionStatus {transactionConfirmed, votingProcedure} =
toJSON TransactionStatus {transactionConfirmed, votingProcedure, drepRegistration} =
object
[ "transactionConfirmed" .= transactionConfirmed
, "votingProcedure" .= votingProcedure
, "drepRegistration" .= drepRegistration
]

data CacheEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import { StatusModalState } from "@organisms";
import { useQueryClient } from "react-query";
import { useModal, useSnackbar } from "..";
import { TransactionState } from "./types";
import { getDesiredResult, getQueryKey, refetchData } from "./utils";
import {
getDesiredResult,
getQueryKey,
invalidateQuery,
refetchData,
} from "./utils";

const TIME_TO_EXPIRE_TRANSACTION = 3 * 60 * 1000; // 3 MINUTES
const TIME_TO_EXPIRE_TRANSACTION = 5 * 60 * 1000; // 5 MINUTES
const TRANSACTION_REFRESH_TIME = 15 * 1000; // 15 SECONDS
const DB_SYNC_REFRESH_TIME = 3 * 1000; // 3 SECONDS
const DB_SYNC_MAX_ATTEMPTS = 10;
Expand Down Expand Up @@ -80,7 +85,15 @@ export const usePendingTransaction = ({

if (
status.transactionConfirmed &&
(type === "vote" ? status.votingProcedure.length > 0 : true)
((type === "vote" && status.votingProcedure.length > 0) ||
(type === "registerAsDrep" &&
status.drepRegistration[0]?.off_chain_vote_drep_data) ||
(type === "retireAsDrep" &&
status.drepRegistration[0]?.drep_registration) ||
(type === "registerAsDirectVoter" &&
status.drepRegistration[0]?.drep_registration) ||
(type === "retireAsDirectVoter" &&
status.drepRegistration[0]?.drep_registration))
) {
clearInterval(interval);

Expand All @@ -101,6 +114,8 @@ export const usePendingTransaction = ({
);

if (desiredResult === data) {
// eslint-disable-next-line no-await-in-loop
await invalidateQuery(type, queryClient);
addSuccessAlert(t(`alerts.${type}.success`));
resetTransaction();
isDBSyncUpdated = true;
Expand Down Expand Up @@ -155,7 +170,7 @@ export const usePendingTransaction = ({
setTransaction(newTransaction);
setItemToLocalStorage(`${PENDING_TRANSACTION_KEY}_${stakeKey}`, {
...newTransaction,
resourceId: newTransaction.resourceId || null,
resourceId: newTransaction.resourceId ?? null,
});
};

Expand Down
27 changes: 23 additions & 4 deletions govtool/frontend/src/context/pendingTransaction/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export const getQueryKey = (
case "retireAsDirectVoter":
return [QUERY_KEYS.useGetDRepInfoKey, transaction?.transactionHash];
case "delegate":
return [
QUERY_KEYS.getAdaHolderCurrentDelegationKey,
transaction?.transactionHash,
];
case "vote":
return [
QUERY_KEYS.getAdaHolderCurrentDelegationKey,
Expand All @@ -62,6 +58,21 @@ export const getQueryKey = (
}
};

export const getQueryKeyToInvalidate = (type: TransactionType) => {
switch (type) {
case "registerAsDrep":
case "retireAsDrep":
case "registerAsDirectVoter":
case "retireAsDirectVoter":
return QUERY_KEYS.useGetDRepListInfiniteKey;
case "delegate":
case "vote":
return QUERY_KEYS.useGetProposalsInfiniteKey;
default:
return undefined;
}
};

export const refetchData = async (
type: TransactionType,
queryClient: QueryClient,
Expand Down Expand Up @@ -94,3 +105,11 @@ export const refetchData = async (
}
return undefined;
};

export const invalidateQuery = async (
type: TransactionType,
queryClient: QueryClient,
) => {
const queryKey = getQueryKeyToInvalidate(type);
if (queryKey) await queryClient.invalidateQueries(queryKey);
};
9 changes: 8 additions & 1 deletion govtool/frontend/src/hooks/queries/useGetDrepDetailsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ export const useGetDRepDetailsQuery = (
) => {
const { dRepData, isDRepListLoading } = useGetDRepListInfiniteQuery(
{ searchPhrase: dRepId ?? undefined },
{ enabled: options?.enabled || !!dRepId, ...options },
{
enabled: options?.enabled || !!dRepId,
...options,
keepPreviousData: false,
refetchOnWindowFocus: true,
cacheTime: 0,
staleTime: 0,
},
);

return { dRep: dRepData?.[0], isLoading: isDRepListLoading };
Expand Down
27 changes: 27 additions & 0 deletions govtool/frontend/src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ export type TransactionStatus = {
voting_anchor_id: number | null;
}[]
| [];
drepRegistration:
| {
drep_registration:
| {
cert_index: number;
deposit: number;
drep_hash_id: number;
id: number;
tx_id: number;
voting_anchor_id: number;
}[]
| [];
off_chain_vote_drep_data:
| {
given_name: string;
id: number;
image_hash: string | null;
image_url: string | null;
motivations: string;
objectives: string;
off_chain_vote_data_id: number;
payment_address: string | null;
qualifications: string;
}[]
| [];
}[]
| [];
};

export enum Network {
Expand Down