Skip to content

Commit

Permalink
Merge pull request #947 from IntersectMBO/897-bug-slow-delegation-issue
Browse files Browse the repository at this point in the history
[#897] Slow delegation issue // usePendingTransaction fixes
  • Loading branch information
JanJaroszczak committed May 7, 2024
2 parents 189e27c + 492b2a0 commit b919a42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const usePendingTransaction = ({

if (status.transactionConfirmed) {
clearInterval(interval);

if (isEnabled) {
const desiredResult = getDesiredResult(type, resourceId);
const queryKey = getQueryKey(type, transaction);
Expand All @@ -89,7 +90,13 @@ export const usePendingTransaction = ({
while (!isDBSyncUpdated && count < DB_SYNC_MAX_ATTEMPTS) {
count++;
// eslint-disable-next-line no-await-in-loop
const data = await refetchData(type, queryClient, queryKey);
const data = await refetchData(
type,
queryClient,
queryKey,
resourceId,
);

if (desiredResult === data) {
addSuccessAlert(t(`alerts.${type}.success`));
resetTransaction();
Expand Down
10 changes: 8 additions & 2 deletions govtool/frontend/src/context/pendingTransaction/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const refetchData = async (
type: TransactionType,
queryClient: QueryClient,
queryKey: QueryKey | undefined,
resourceId: string | undefined,
) => {
if (queryKey === undefined) return;

Expand All @@ -58,10 +59,15 @@ export const refetchData = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data = await queryClient.getQueryData<any>(queryKey);

if (type === "delegate") return data;
if (type === "delegate") {
if (resourceId === "no confidence" || resourceId === "abstain") {
return data.dRepView;
}
return data.dRepHash;
}
if (type === "registerAsDrep" || type === "retireAsDrep")
return data.isRegisteredAsDRep;
if (type === "registerAsDirectVoter" || type === "retireAsDirectVoter")
return data.isRegisteredAsDirectVoter;
return data.isRegisteredAsSoleVoter;
return undefined;
};
5 changes: 1 addition & 4 deletions govtool/frontend/src/hooks/useDelegateToDrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ export const useDelegateTodRep = () => {
);
certBuilder.add(retirementCert);
}
const result = await buildSignSubmitConwayCertTx({
await buildSignSubmitConwayCertTx({
certBuilder,
type: "delegate",
resourceId: dRepId,
voter,
});
if (result) {
addSuccessAlert(t("alerts.delegate.success"));
}
} catch (error) {
openWalletErrorModal({
error,
Expand Down

0 comments on commit b919a42

Please sign in to comment.