Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#932] Automated voting options voting power fix #1012

Merged
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
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";
Loading