Skip to content
Snippets Groups Projects
Commit c83a4e42 authored by Lukas's avatar Lukas
Browse files

Update date time pickers on votes history dialog

parent 875998f9
No related branches found
No related tags found
2 merge requests!491Lbudginas/#391 new date time picker,!486Lbudginas/#374 calendar dates selection bug
......@@ -27,6 +27,12 @@ import { useHiveChainContext } from "@/contexts/HiveChainContext";
import { convertVestsToHP } from "@/utils/Calculations";
import fetchingService from "@/services/FetchingService";
interface Supply {
amount: string;
nai: string;
precision: number;
}
type VotersDialogProps = {
accountName: string;
isVotesHistoryOpen: boolean;
......@@ -57,8 +63,20 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
);
const [toDate, setToDate] = useState<Date>(moment().toDate());
const [isHP, setIsHP] = useState<boolean>(true); // Toggle state
const [totalVestingShares, setTotalVestingShares] = useState<Supply>({
amount: "0",
nai: "",
precision: 0,
});
const [totalVestingFundHive, setTotalVestingFundHive] = useState<Supply>({
amount: "0",
nai: "",
precision: 0,
});
const { hiveChain } = useHiveChainContext();
const { witnessDetails } = useWitnessDetails(accountName, true) as any;
const { votesHistory, isVotesHistoryLoading } = useWitnessVotesHistory(
accountName,
isVotesHistoryOpen,
......@@ -67,38 +85,30 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
liveDataEnabled
);
useEffect(() => {
setPage(1);
if (votesHistory && votesHistory?.length > PAGE_SIZE) {
setDisplayData(votesHistory.slice(0, PAGE_SIZE - 1));
} else {
setDisplayData(votesHistory);
}
}, [votesHistory]);
const handlePageChange = (page: number) => {
setPage(page);
setDisplayData(
votesHistory?.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE - 1)
);
};
interface Supply {
amount: string;
nai: string;
precision: number;
}
const [totalVestingShares, setTotalVestingShares] = useState<Supply>({
amount: "0",
nai: "",
precision: 0,
});
const [totalVestingFundHive, setTotalVestingFundHive] = useState<Supply>({
amount: "0",
nai: "",
precision: 0,
});
const { hiveChain } = useHiveChainContext();
const fetchHivePower = (value: string, isHP: boolean): string => {
if (isHP) {
if (!hiveChain) return "";
return convertVestsToHP(
hiveChain,
value,
totalVestingFundHive,
totalVestingShares
);
}
return formatNumber(parseInt(value), true, false) + " Vests"; // Return raw vests if not toggled to HP
};
useEffect(() => {
if (moment(fromDate).isSame(toDate) || moment(fromDate).isAfter(toDate)) {
setFromDate(moment(fromDate).subtract(1, "hours").toDate());
}
}, [fromDate, toDate]);
useEffect(() => {
const fetchDynamicGlobalProperties = async () => {
......@@ -115,18 +125,14 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
fetchDynamicGlobalProperties();
}, []);
const fetchHivePower = (value: string, isHP: boolean): string => {
if (isHP) {
if (!hiveChain) return "";
return convertVestsToHP(
hiveChain,
value,
totalVestingFundHive,
totalVestingShares
);
useEffect(() => {
setPage(1);
if (votesHistory && votesHistory?.length > PAGE_SIZE) {
setDisplayData(votesHistory.slice(0, PAGE_SIZE - 1));
} else {
setDisplayData(votesHistory);
}
return formatNumber(parseInt(value), true, false) + " Vests"; // Return raw vests if not toggled to HP
};
}, [votesHistory]);
return (
<Dialog
......
import { useQuery } from "@tanstack/react-query";
import moment from "moment";
import { config } from "@/Config";
import fetchingService from "@/services/FetchingService";
......@@ -10,6 +11,9 @@ const useWitnessVotesHistory = (
toDate: Date,
liveDataEnabled: boolean
) => {
const isDatesCorrect =
!moment(fromDate).isSame(toDate) && !moment(fromDate).isAfter(toDate);
const fetchVotesHist = async () =>
await fetchingService.getWitnessVotesHistory(
accountName,
......@@ -34,7 +38,7 @@ const useWitnessVotesHistory = (
liveDataEnabled,
],
queryFn: fetchVotesHist,
enabled: !!accountName && isModalOpen,
enabled: !!accountName && isModalOpen && isDatesCorrect,
refetchInterval: liveDataEnabled ? config.accountRefreshInterval : false,
refetchOnWindowFocus: false,
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment