Skip to content

Commit

Permalink
chore: turn off live updates (#3020)
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedfool authored Dec 5, 2024
1 parent 80fdd83 commit b488b5f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 225 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import useContestEvents from "@hooks/useContestEvents";
import { ContestStateEnum, useContestStateStore } from "@hooks/useContestState/store";
import { ContestStatus, useContestStatusStore } from "@hooks/useContestStatus/store";
import ContestCountdown from "./components/Countdown";
Expand All @@ -8,7 +7,6 @@ const ContestStickyCards = () => {
const contestStatus = useContestStatusStore(state => state.contestStatus);
const { contestState } = useContestStateStore(state => state);
const isContestCanceled = contestState === ContestStateEnum.Canceled;
const { displayReloadBanner } = useContestEvents();

if (isContestCanceled || contestStatus === ContestStatus.VotingClosed) {
return (
Expand All @@ -19,9 +17,7 @@ const ContestStickyCards = () => {
}

return (
<div
className={`flex flex-col bg-true-black sticky ${displayReloadBanner ? "top-[105px]" : "-top-[1px]"} z-10 mt-8`}
>
<div className="flex flex-col bg-true-black sticky -top-[1px] z-10 mt-8">
<div className="flex gap-4 py-4">
<ContestCountdown />
<VotingContestQualifier />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const ListProposalsContainer = ({ enabledPreview, children }: ListProposalsConta
case EntryPreview.IMAGE_AND_TITLE:
case EntryPreview.TWEET:
const childrenArray = React.Children.toArray(children);
const leftColumn = childrenArray.filter((_, index) => index % 2 === 0);
const rightColumn = childrenArray.filter((_, index) => index % 2 !== 0);
const firstColumn = childrenArray.filter((_, index) => index % 3 === 0);
const secondColumn = childrenArray.filter((_, index) => index % 3 === 1);
const thirdColumn = childrenArray.filter((_, index) => index % 3 === 2);

if (isMobile) {
return <div className="flex flex-col gap-4">{children}</div>;
Expand All @@ -27,14 +28,21 @@ const ListProposalsContainer = ({ enabledPreview, children }: ListProposalsConta
return (
<div className="flex gap-4">
<div className="flex-1 flex flex-col gap-4">
{leftColumn.map((child, index) => (
{firstColumn.map((child, index) => (
<div key={index} className="break-inside-avoid">
{child}
</div>
))}
</div>
<div className="flex-1 flex flex-col gap-4">
{rightColumn.map((child, index) => (
{secondColumn.map((child, index) => (
<div key={index} className="break-inside-avoid">
{child}
</div>
))}
</div>
<div className="flex-1 flex flex-col gap-4">
{thirdColumn.map((child, index) => (
<div key={index} className="break-inside-avoid">
{child}
</div>
Expand Down
42 changes: 19 additions & 23 deletions packages/react-app-revamp/hooks/useCastVotes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ interface CombinedAnalyticsParams extends UserAnalyticsParams, RewardsAnalyticsP

export function useCastVotes() {
const {
canUpdateVotesInRealTime,
charge,
contestAbi: abi,
version,
Expand Down Expand Up @@ -174,30 +173,27 @@ export function useCastVotes() {
hash: receipt.transactionHash,
});

// We need this to update the votes either if there is more than 2 hours
if (!canUpdateVotesInRealTime) {
const voteResponse = (await readContract(config, {
address: contestAddress as `0x${string}`,
abi: DeployedContestContract.abi,
functionName: "proposalVotes",
args: [pickedProposal],
})) as bigint[];
const voteResponse = (await readContract(config, {
address: contestAddress as `0x${string}`,
abi: DeployedContestContract.abi,
functionName: "proposalVotes",
args: [pickedProposal],
})) as bigint[];

const forVotes = voteResponse[0] as bigint;
const againstVotes = voteResponse[1] as bigint;
const finalVotes = forVotes - againstVotes;
const votes = Number(formatEther(finalVotes));
const existingProposal = listProposalsData.find(proposal => proposal.id === pickedProposal);
const forVotes = voteResponse[0] as bigint;
const againstVotes = voteResponse[1] as bigint;
const finalVotes = forVotes - againstVotes;
const votes = Number(formatEther(finalVotes));
const existingProposal = listProposalsData.find(proposal => proposal.id === pickedProposal);

if (existingProposal) {
updateProposal(
{
...existingProposal,
netVotes: votes,
},
listProposalsData,
);
}
if (existingProposal) {
updateProposal(
{
...existingProposal,
netVotes: votes,
},
listProposalsData,
);
}

await updateCurrentUserVotes(abi, version, anyoneCanVote);
Expand Down
22 changes: 0 additions & 22 deletions packages/react-app-revamp/hooks/useContest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export function useContest() {
setVotesClose,
setVotesOpen,
setSubmissionsOpen,
setCanUpdateVotesInRealTime,
setCharge,
setVotingRequirements,
setContestAbi,
Expand Down Expand Up @@ -206,27 +205,6 @@ export function useContest() {
setDownvotingAllowed(isDownvotingAllowed);
setContestState(contestState);

// We want to track VoteCast event only 2H before the end of the contest, and only if alchemy support is enabled and if alchemy is configured
if (isBefore(new Date(), closingVoteDate) && alchemyRpc && isAlchemyConfigured) {
if (differenceInMinutes(closingVoteDate, new Date()) <= 120) {
setCanUpdateVotesInRealTime(true);
} else {
setCanUpdateVotesInRealTime(false);

let delayBeforeVotesCanBeUpdated =
differenceInMilliseconds(closingVoteDate, new Date()) - minutesToMilliseconds(120);

// Cap the delay at the maximum allowable value to prevent overflow
delayBeforeVotesCanBeUpdated = Math.min(delayBeforeVotesCanBeUpdated, MAX_MS_TIMEOUT);

setTimeout(() => {
setCanUpdateVotesInRealTime(true);
}, delayBeforeVotesCanBeUpdated);
}
} else {
setCanUpdateVotesInRealTime(false);
}

setError(null);
setIsSuccess(true);
setIsLoading(false);
Expand Down
4 changes: 0 additions & 4 deletions packages/react-app-revamp/hooks/useContest/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface ContestState {
contestMaxProposalCount: number;
downvotingAllowed: boolean;
sortingEnabled: boolean;
canUpdateVotesInRealTime: boolean;
supportsRewardsModule: boolean;
submissionMerkleRoot: string;
votingMerkleRoot: string;
Expand All @@ -40,7 +39,6 @@ export interface ContestState {
rewardsAbi: Abi | null;
canEditTitleAndDescription: boolean;
setSupportsRewardsModule: (value: boolean) => void;
setCanUpdateVotesInRealTime: (value: boolean) => void;
setDownvotingAllowed: (isAllowed: boolean) => void;
setSortingEnabled: (isAllowed: boolean) => void;
setContestPrompt: (prompt: string) => void;
Expand Down Expand Up @@ -87,7 +85,6 @@ export const createContestStore = () =>
contestMaxProposalCount: 0,
downvotingAllowed: false,
sortingEnabled: false,
canUpdateVotesInRealTime: false,
votingRequirements: null,
submissionRequirements: null,
isV3: false,
Expand All @@ -99,7 +96,6 @@ export const createContestStore = () =>
rewardsAbi: null,
canEditTitleAndDescription: false,
setSupportsRewardsModule: value => set({ supportsRewardsModule: value }),
setCanUpdateVotesInRealTime: value => set({ canUpdateVotesInRealTime: value }),
setDownvotingAllowed: isAllowed => set({ downvotingAllowed: isAllowed }),
setSortingEnabled: isAllowed => set({ sortingEnabled: isAllowed }),
setContestPrompt: prompt => set({ contestPrompt: prompt }),
Expand Down
150 changes: 0 additions & 150 deletions packages/react-app-revamp/hooks/useContestEvents/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/react-app-revamp/hooks/useProposal/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface ProposalState {
totalPagesPaginationProposals: number;
currentPagePaginationProposals: number;
hasPaginationProposalsNextPage: boolean;
canUpdateVotesInRealTime: boolean;
submissionsCount: number;
sortBy: SortOptions | null;
addProposalId: (id: string) => void;
Expand All @@ -56,7 +55,6 @@ interface ProposalState {
setTotalPagesPaginationProposals: (value: number) => void;
setCurrentPagePaginationProposals: (value: number) => void;
setHasPaginationProposalsNextPage: (value: boolean) => void;
setCanUpdateVotesInRealTime: (value: boolean) => void;
setSortBy: (sortBy: SortOptions | null) => void;
}

Expand All @@ -75,7 +73,6 @@ export const createProposalStore = () =>
totalPagesPaginationProposals: 0,
currentPagePaginationProposals: 0,
hasPaginationProposalsNextPage: false,
canUpdateVotesInRealTime: false,
submissionsCount: 0,
sortBy: null,
setSubmissionsCount: value => set({ submissionsCount: value }),
Expand All @@ -93,7 +90,6 @@ export const createProposalStore = () =>
setTotalPagesPaginationProposals: newTotal => set({ totalPagesPaginationProposals: newTotal }),
setHasPaginationProposalsNextPage: hasNextPage => set({ hasPaginationProposalsNextPage: hasNextPage }),
addProposalId: id => set(state => ({ listProposalsIds: [...state.listProposalsIds, id] })),
setCanUpdateVotesInRealTime: value => set({ canUpdateVotesInRealTime: value }),
setIsListProposalsLoading: value => set({ isListProposalsLoading: value }),
setIsListProposalsError: value => set({ isListProposalsError: value }),
setIsListProposalsSuccess: value => set({ isListProposalsSuccess: value }),
Expand Down
Loading

0 comments on commit b488b5f

Please sign in to comment.