Skip to content

Commit

Permalink
Merge pull request #3028 from jk-labs-inc/staging
Browse files Browse the repository at this point in the history
patch PR 1 of week ending 12/10/24
  • Loading branch information
siobh9 authored Dec 5, 2024
2 parents f221114 + 71bb1c8 commit d4f1785
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,27 @@ const SubmissionQualifierMessage: FC<SubmissionQualifierMessageProps> = ({
if (isContestOpen) {
if (canSubmit) {
return (
<p className="text-[16px] text-secondary-11">
good news: you qualify to submit a response once the contest opens
</p>
<p className="text-[16px] text-secondary-11">good news: you qualify to enter this contest once it opens</p>
);
}
if (!currentUserQualifiedToSubmit) {
return (
<p className="text-[16px] text-secondary-11">
unfortunately, your wallet wasn’t allowlisted to submit in this contest.
</p>
);
return <p className="text-[16px] text-secondary-11">you're not allowlisted to enter this contest</p>;
}
}

if (contestStatus === ContestStatus.SubmissionOpen) {
if (hasReachedMaxSubmissions) {
return <p className="text-[16px] text-secondary-11">you’ve reached your max submissions with this account</p>;
return <p className="text-[16px] text-secondary-11">you’ve reached your max entries with this account</p>;
}
if (!currentUserQualifiedToSubmit) {
if (canVote) {
return (
<p className="text-[16px] text-secondary-11">
unfortunately, your wallet wasn’t allowlisted to submit in this contest, but you <i>were</i> allowlisted to
vote
you're not allowlisted to enter this contest, but you can vote in it once voting opens
</p>
);
}
return (
<p className="text-[16px] text-secondary-11">
unfortunately, your wallet wasn’t allowlisted to submit in this contest.
</p>
);
return <p className="text-[16px] text-secondary-11">you're not allowlisted to enter this contest</p>;
}
}

Expand Down
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.

Loading

0 comments on commit d4f1785

Please sign in to comment.