Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Atatakai authored and Atatakai committed Jul 30, 2024
1 parent f55328a commit 40ffd82
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
16 changes: 8 additions & 8 deletions apps/govern/common-util/functions/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export const getUnixNextWeekStartTimestamp = () => {
const dayOfWeek = now.getDay();
const daysUntilNextThursday = (4 - dayOfWeek + 7) % 7;

const nextThursday = new Date(now);
nextThursday.setDate(now.getDate() + daysUntilNextThursday);
nextThursday.setHours(0, 0, 0, 0);
const result = new Date(now);
result.setDate(now.getDate() + daysUntilNextThursday);
result.setHours(0, 0, 0, 0);

return nextThursday.getTime() / 1000;
return result.getTime() / 1000;
};

// Returns the closest Thursday in the past
Expand All @@ -18,10 +18,10 @@ export const getUnixWeekStartTimestamp = () => {
const now = new Date();
const dayOfWeek = now.getDay();
const daysSinceThursday = ((dayOfWeek + 2) % 7) + 1;
const thursday = new Date(now);
const result = new Date(now);

thursday.setDate(now.getDate() - daysSinceThursday);
thursday.setHours(0, 0, 0, 0);
result.setDate(now.getDate() - daysSinceThursday);
result.setHours(0, 0, 0, 0);

return thursday.getTime() / 1000;
return result.getTime() / 1000;
};
2 changes: 1 addition & 1 deletion apps/govern/components/Contracts/ContractsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const getColumns = ({
{
title: (
<NextWeekTooltip>
{`Next week's weight`}{' '}
Next week&apos;s weight
<InfoCircleOutlined className="ml-8" style={{ color: COLOR.GREY_2 }} />
</NextWeekTooltip>
),
Expand Down
6 changes: 3 additions & 3 deletions apps/govern/components/Contracts/EditVotes/validations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getRemovedNomineesError = (removedNominees: Address[], allocations: Alloca
</Flex>
);

const NO_veOLAS_ERROR = `You don't have enough veOLAS to vote`;
const NO_VEOLAS_ERROR = `You don't have enough veOLAS to vote`;

// Checks if any of the nominees were removed from voting
export const checkNoRemovedNominees = async (allocations: Allocation[]) => {
Expand Down Expand Up @@ -59,7 +59,7 @@ export const checkNoDisabledContracts = async (allocations: Allocation[]) => {
export const checkNotNegativeSlope = async (account: Address) => {
const isNegativeSlope = await checkNegativeSlope(account);
if (isNegativeSlope) {
notification.error({ message: NO_veOLAS_ERROR });
notification.error({ message: NO_VEOLAS_ERROR });
return false;
}

Expand All @@ -70,7 +70,7 @@ export const checkNotNegativeSlope = async (account: Address) => {
export const checkLockNotExpired = async (account: Address) => {
const isLockExpired = await checkLockExpired(account);
if (isLockExpired) {
notification.error({ message: NO_veOLAS_ERROR });
notification.error({ message: NO_VEOLAS_ERROR });
return false;
}

Expand Down
17 changes: 10 additions & 7 deletions apps/govern/hooks/useFetchStakingContractsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import { useNominees } from './useNominees';
import { useNomineesMetadata } from './useNomineesMetadata';
import { useNomineesWeights } from './useNomineesWeights';

const WEEK = 604_800;
const WEEK_IN_SECONDS = 604_800;

const getCurrentWeightTimestamp = (timeSum: number | undefined) => {
if (!timeSum) return null;
// If timeSum is in the future, subtract a week from it
if (timeSum * 1000 > Date.now()) return timeSum - WEEK_IN_SECONDS;
return timeSum;
};

export const useFetchStakingContractsList = () => {
const dispatch = useAppDispatch();
Expand All @@ -26,6 +33,7 @@ export const useFetchStakingContractsList = () => {
const { data: nominees } = useNominees();

// Get last scheduled time (next week) from the contract
// Has the timestamp when the last votes should be applied
const { data: timeSum } = useReadContract({
address: (VOTE_WEIGHTING.addresses as Record<number, Address>)[mainnet.id],
abi: VOTE_WEIGHTING.abi,
Expand All @@ -39,12 +47,7 @@ export const useFetchStakingContractsList = () => {
// Get contracts current week weights
const { data: currentWeight } = useNomineesWeights(
nominees || [],
timeSum
? // If timeSum is in the future, subtract a week from it
timeSum * 1000 > Date.now()
? timeSum - WEEK
: timeSum
: null,
getCurrentWeightTimestamp(timeSum),
);

// Get contracts next week weights
Expand Down

0 comments on commit 40ffd82

Please sign in to comment.