Skip to content

Commit

Permalink
Merge pull request #1012 from IntersectMBO/932-voting-power-not-corre…
Browse files Browse the repository at this point in the history
…ct-on-automated-options-picking-up-users-voting-power

[#932] Automated voting options voting power fix
  • Loading branch information
JanJaroszczak authored May 14, 2024
2 parents 7c6003b + c9788e5 commit a6d6060
Show file tree
Hide file tree
Showing 6 changed files with 43 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,8 @@ export const AutomatedVotingOptions = ({

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

const { networkMetrics } = useGetNetworkMetrics();

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

Expand Down Expand Up @@ -117,7 +119,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 +154,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 a6d6060

Please sign in to comment.