Skip to content

Commit

Permalink
[#932] Automated voting options voting power fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJaroszczak committed May 13, 2024
1 parent 5959680 commit 7fd51e9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
import { Typography } from "@atoms";
import { ICONS } from "@consts";
import { PendingTransaction } from "@context";
import { useTranslation } from "@hooks";
import { useGetNetworkMetrics, useTranslation } from "@hooks";
import { AutomatedVotingCard } from "@molecules";
import { openInNewTab } from "@/utils";
import { correctAdaFormat, openInNewTab } from "@/utils";
import {
AutomatedVotingOptionCurrentDelegation,
AutomatedVotingOptionDelegationId,
Expand Down Expand Up @@ -42,6 +42,15 @@ export const AutomatedVotingOptions = ({

const [isOpen, setIsOpen] = useState<boolean>(false);

const {
networkMetrics,
// areNetworkMetricsLoading,
} = useGetNetworkMetrics();

// console.log("networkMetrics", networkMetrics);
// console.log("alwaysAbstainVotingPower", alwaysAbstainVotingPower);
// console.log("alwaysNoConfidenceVotingPower", alwaysNoConfidenceVotingPower);

// TODO: Change to certain automated voted option if available
const onClickInfo = () => openInNewTab("https://docs.sanchogov.tools/");

Expand Down Expand Up @@ -117,7 +126,11 @@ export const AutomatedVotingOptions = ({
})
: t("dRepDirectory.abstainCardDefaultTitle")
}
votingPower={votingPower}
votingPower={
networkMetrics
? correctAdaFormat(networkMetrics?.alwaysAbstainVotingPower)
: ""
}
transactionId={
pendingTransaction?.delegate?.resourceId ===
AutomatedVotingOptionDelegationId.abstain
Expand Down Expand Up @@ -148,7 +161,13 @@ export const AutomatedVotingOptions = ({
})
: t("dRepDirectory.noConfidenceDefaultTitle")
}
votingPower={votingPower}
votingPower={
networkMetrics
? correctAdaFormat(
networkMetrics?.alwaysNoConfidenceVotingPower,
)
: ""
}
transactionId={
pendingTransaction?.delegate?.resourceId ===
AutomatedVotingOptionDelegationId.no_confidence
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/consts/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const QUERY_KEYS = {
useGetDRepListInfiniteKey: "useGetDRepListInfiniteKey",
useGetDRepVotesKey: "useGetDRepVotesKey",
useGetDRepVotingPowerKey: "useGetDRepVotingPowerKey",
useGetNetworkMetricsKey: "useGetNetworkMetricsKey",
useGetProposalKey: "useGetProposalKey",
useGetProposalsKey: "useGetProposalsKey",
useGetProposalsInfiniteKey: "useGetProposalsInfiniteKey",
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/hooks/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./useGetVoterInfoQuery";
export * from "./useGetDRepListQuery";
export * from "./useGetDRepVotesQuery";
export * from "./useGetDRepVotingPowerQuery";
export * from "./useGetNetworkMetrics";
export * from "./useGetProposalQuery";
export * from "./useGetProposalsQuery";
export * from "./useGetProposalsInfiniteQuery";
Expand Down
17 changes: 17 additions & 0 deletions govtool/frontend/src/hooks/queries/useGetNetworkMetrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useQuery } from "react-query";

import { getNetworkMetrics } from "@services";
import { QUERY_KEYS } from "@consts";
import { useCardano } from "@/context";

export const useGetNetworkMetrics = () => {
const { isEnabled } = useCardano();

const { data } = useQuery({
queryKey: QUERY_KEYS.useGetNetworkMetricsKey,
queryFn: () => getNetworkMetrics(),
enabled: isEnabled,
});

return { networkMetrics: data };
};
7 changes: 7 additions & 0 deletions govtool/frontend/src/services/requests/getNetworkMetrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { API } from "../API";

export const getNetworkMetrics = async () => {
const response = await API.get("/network/metrics");

return response.data;
};
1 change: 1 addition & 0 deletions govtool/frontend/src/services/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from "./postDRepRemoveVote";
export * from "./postDRepRetire";
export * from "./postDRepVote";
export * from "./metadataValidation";
export * from "./getNetworkMetrics";

0 comments on commit 7fd51e9

Please sign in to comment.