Skip to content

Commit f3a00f4

Browse files
committed
feat(#3080): change drep registration transaction confirmation
1 parent 657af82 commit f3a00f4

File tree

8 files changed

+106
-17
lines changed

8 files changed

+106
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ changes.
1616

1717
### Changed
1818

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

2123
## [v2.0.13](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.13) 2025-02-27
2224

23-
2425
### Added
2526

2627
### Fixed

govtool/backend/sql/get-transaction-status.sql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,22 @@ SELECT
66
JOIN tx ON voting_procedure.tx_id = tx.id
77
WHERE tx.hash = decode(?, 'hex')
88
), '[]'::json
9-
) AS voting_procedures;
9+
) AS voting_procedures,
10+
COALESCE(
11+
(SELECT NULLIF(jsonb_agg(
12+
jsonb_build_object(
13+
'drep_registration', to_jsonb(drep_registration.*),
14+
'off_chain_vote_drep_data',
15+
(SELECT NULLIF(jsonb_agg(to_jsonb(off_chain_vote_drep_data)), '[]'::jsonb)
16+
FROM off_chain_vote_data
17+
JOIN off_chain_vote_drep_data
18+
ON off_chain_vote_drep_data.off_chain_vote_data_id = off_chain_vote_data.id
19+
WHERE off_chain_vote_data.voting_anchor_id = drep_registration.voting_anchor_id
20+
)
21+
)
22+
), '[]'::jsonb)
23+
FROM drep_registration
24+
JOIN tx ON drep_registration.tx_id = tx.id
25+
WHERE tx.hash = decode(?, 'hex')
26+
), NULL
27+
) AS drep_registrations

govtool/backend/src/VVA/Transaction.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ getTransactionStatus ::
3535
=> Text
3636
-> m (Maybe TransactionStatus)
3737
getTransactionStatus transactionId = withPool $ \conn -> do
38-
result <- liftIO $ SQL.query conn getTransactionStatusSql (transactionId, transactionId)
38+
result <- liftIO $ SQL.query conn getTransactionStatusSql (transactionId, transactionId, transactionId)
3939
case result of
40-
[(transactionConfirmed, votingProcedure)] -> do
41-
return $ Just $ TransactionStatus transactionConfirmed votingProcedure
40+
[(transactionConfirmed, votingProcedure, drepRegistration)] -> do
41+
return $ Just $ TransactionStatus transactionConfirmed votingProcedure drepRegistration
4242
_ -> return Nothing

govtool/backend/src/VVA/Types.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,19 @@ instance FromRow Proposal where
188188

189189
data TransactionStatus = TransactionStatus
190190
{ transactionConfirmed :: Bool
191-
, votingProcedure :: Maybe Value
191+
, votingProcedure :: Maybe Value
192+
, drepRegistration :: Maybe Value
192193
}
193194

194195
instance FromRow TransactionStatus where
195-
fromRow = TransactionStatus <$> field <*> field
196+
fromRow = TransactionStatus <$> field <*> field <*> field
196197

197198
instance ToJSON TransactionStatus where
198-
toJSON TransactionStatus {transactionConfirmed, votingProcedure} =
199+
toJSON TransactionStatus {transactionConfirmed, votingProcedure, drepRegistration} =
199200
object
200201
[ "transactionConfirmed" .= transactionConfirmed
201202
, "votingProcedure" .= votingProcedure
203+
, "drepRegistration" .= drepRegistration
202204
]
203205

204206
data CacheEnv

govtool/frontend/src/context/pendingTransaction/usePendingTransaction.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ import { StatusModalState } from "@organisms";
1212
import { useQueryClient } from "react-query";
1313
import { useModal, useSnackbar } from "..";
1414
import { TransactionState } from "./types";
15-
import { getDesiredResult, getQueryKey, refetchData } from "./utils";
15+
import {
16+
getDesiredResult,
17+
getQueryKey,
18+
invalidateQuery,
19+
refetchData,
20+
} from "./utils";
1621

17-
const TIME_TO_EXPIRE_TRANSACTION = 3 * 60 * 1000; // 3 MINUTES
22+
const TIME_TO_EXPIRE_TRANSACTION = 5 * 60 * 1000; // 5 MINUTES
1823
const TRANSACTION_REFRESH_TIME = 15 * 1000; // 15 SECONDS
1924
const DB_SYNC_REFRESH_TIME = 3 * 1000; // 3 SECONDS
2025
const DB_SYNC_MAX_ATTEMPTS = 10;
@@ -80,7 +85,15 @@ export const usePendingTransaction = ({
8085

8186
if (
8287
status.transactionConfirmed &&
83-
(type === "vote" ? status.votingProcedure.length > 0 : true)
88+
((type === "vote" && status.votingProcedure.length > 0) ||
89+
(type === "registerAsDrep" &&
90+
status.drepRegistration[0]?.off_chain_vote_drep_data) ||
91+
(type === "retireAsDrep" &&
92+
status.drepRegistration[0]?.drep_registration) ||
93+
(type === "registerAsDirectVoter" &&
94+
status.drepRegistration[0]?.drep_registration) ||
95+
(type === "retireAsDirectVoter" &&
96+
status.drepRegistration[0]?.drep_registration))
8497
) {
8598
clearInterval(interval);
8699

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

103116
if (desiredResult === data) {
117+
// eslint-disable-next-line no-await-in-loop
118+
await invalidateQuery(type, queryClient);
104119
addSuccessAlert(t(`alerts.${type}.success`));
105120
resetTransaction();
106121
isDBSyncUpdated = true;
@@ -155,7 +170,7 @@ export const usePendingTransaction = ({
155170
setTransaction(newTransaction);
156171
setItemToLocalStorage(`${PENDING_TRANSACTION_KEY}_${stakeKey}`, {
157172
...newTransaction,
158-
resourceId: newTransaction.resourceId || null,
173+
resourceId: newTransaction.resourceId ?? null,
159174
});
160175
};
161176

govtool/frontend/src/context/pendingTransaction/utils.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ export const getQueryKey = (
4848
case "retireAsDirectVoter":
4949
return [QUERY_KEYS.useGetDRepInfoKey, transaction?.transactionHash];
5050
case "delegate":
51-
return [
52-
QUERY_KEYS.getAdaHolderCurrentDelegationKey,
53-
transaction?.transactionHash,
54-
];
5551
case "vote":
5652
return [
5753
QUERY_KEYS.getAdaHolderCurrentDelegationKey,
@@ -62,6 +58,21 @@ export const getQueryKey = (
6258
}
6359
};
6460

61+
export const getQueryKeyToInvalidate = (type: TransactionType) => {
62+
switch (type) {
63+
case "registerAsDrep":
64+
case "retireAsDrep":
65+
case "registerAsDirectVoter":
66+
case "retireAsDirectVoter":
67+
return QUERY_KEYS.useGetDRepListInfiniteKey;
68+
case "delegate":
69+
case "vote":
70+
return QUERY_KEYS.useGetProposalsInfiniteKey;
71+
default:
72+
return undefined;
73+
}
74+
};
75+
6576
export const refetchData = async (
6677
type: TransactionType,
6778
queryClient: QueryClient,
@@ -94,3 +105,11 @@ export const refetchData = async (
94105
}
95106
return undefined;
96107
};
108+
109+
export const invalidateQuery = async (
110+
type: TransactionType,
111+
queryClient: QueryClient,
112+
) => {
113+
const queryKey = getQueryKeyToInvalidate(type);
114+
if (queryKey) await queryClient.invalidateQueries(queryKey);
115+
};

govtool/frontend/src/hooks/queries/useGetDrepDetailsQuery.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ export const useGetDRepDetailsQuery = (
99
) => {
1010
const { dRepData, isDRepListLoading } = useGetDRepListInfiniteQuery(
1111
{ searchPhrase: dRepId ?? undefined },
12-
{ enabled: options?.enabled || !!dRepId, ...options },
12+
{
13+
enabled: options?.enabled || !!dRepId,
14+
...options,
15+
keepPreviousData: false,
16+
refetchOnWindowFocus: true,
17+
cacheTime: 0,
18+
staleTime: 0,
19+
},
1320
);
1421

1522
return { dRep: dRepData?.[0], isLoading: isDRepListLoading };

govtool/frontend/src/models/api.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ export type TransactionStatus = {
7676
voting_anchor_id: number | null;
7777
}[]
7878
| [];
79+
drepRegistration:
80+
| {
81+
drep_registration:
82+
| {
83+
cert_index: number;
84+
deposit: number;
85+
drep_hash_id: number;
86+
id: number;
87+
tx_id: number;
88+
voting_anchor_id: number;
89+
}[]
90+
| [];
91+
off_chain_vote_drep_data:
92+
| {
93+
given_name: string;
94+
id: number;
95+
image_hash: string | null;
96+
image_url: string | null;
97+
motivations: string;
98+
objectives: string;
99+
off_chain_vote_data_id: number;
100+
payment_address: string | null;
101+
qualifications: string;
102+
}[]
103+
| [];
104+
}[]
105+
| [];
79106
};
80107

81108
export type NetworkMetrics = {

0 commit comments

Comments
 (0)