From 171e7534209ac92491e58e1c7ba76ec13e607612 Mon Sep 17 00:00:00 2001 From: Kristof Csillag Date: Thu, 19 Sep 2024 13:44:01 +0200 Subject: [PATCH] More language updates --- .../PollCard/PollAccessIndicator.tsx | 12 ++--- frontend/src/components/PollCard/index.tsx | 2 +- frontend/src/constants/config.ts | 6 +-- frontend/src/hooks/useExtendedPoll.ts | 6 +-- .../pages/CreatePollPage/useCreatePollForm.ts | 53 +++++++++--------- .../pages/DashboardPage/useDashboardData.ts | 2 +- frontend/src/pages/PollPage/ActivePoll.tsx | 27 +++++----- frontend/src/pages/PollPage/CompletedPoll.tsx | 2 +- .../src/pages/PollPage/ThanksForVoting.tsx | 36 ++++++------- frontend/src/pages/PollPage/hook.ts | 54 ++++++++++--------- frontend/src/pages/PollPage/index.tsx | 8 +-- frontend/src/utils/date.utils.ts | 2 +- 12 files changed, 107 insertions(+), 103 deletions(-) diff --git a/frontend/src/components/PollCard/PollAccessIndicator.tsx b/frontend/src/components/PollCard/PollAccessIndicator.tsx index 874d4b8..82b5fa2 100644 --- a/frontend/src/components/PollCard/PollAccessIndicator.tsx +++ b/frontend/src/components/PollCard/PollAccessIndicator.tsx @@ -11,7 +11,7 @@ import { designDecisions } from '../../constants/config' export const PollAccessIndicator: FC<{ isOpen: boolean isRestricted: boolean - hideClosedNoAccess?: boolean + hideRestrictedNoAccess?: boolean isPending: boolean isBroken: boolean explanation: string | undefined @@ -29,14 +29,14 @@ export const PollAccessIndicator: FC<{ isCompleted, isMine, retest, - hideClosedNoAccess, + hideRestrictedNoAccess, }) => { return ( <> {isOpen && !designDecisions.hideOpenPollIndicator && ( )} - {isRestricted && !(!hasAccess && hideClosedNoAccess) && ( + {isRestricted && !(!hasAccess && hideRestrictedNoAccess) && ( void -}> = ({ isMine, permissions, isActive, hideClosedNoAccess, retest }) => { +}> = ({ isMine, permissions, isActive, hideRestrictedNoAccess, retest }) => { const { explanation, error, canVote } = permissions return ( = ({ acti Active {isPastDue && } ) : ( -
+
Completed
) diff --git a/frontend/src/constants/config.ts b/frontend/src/constants/config.ts index db84813..97eb026 100644 --- a/frontend/src/constants/config.ts +++ b/frontend/src/constants/config.ts @@ -106,7 +106,7 @@ export { VITE_IPFS_GATEWAY, } -export const MIN_CLOSE_TIME_MINUTES = 3 +export const MIN_COMPLETION_TIME_MINUTES = 3 export const demoPoll1 = { id: 'demo', @@ -180,8 +180,8 @@ export const getDemoPoll = (): ExtendedPoll => randomchoice([demoPoll1, demoPoll export const demoSettings = { timeForVoting: 610, - waitSecondsBeforeFormallyClosing: 5, - jumpToSecondsBeforeClosing: 5, + waitSecondsBeforeFormallyCompleting: 5, + jumpToSecondsBeforeCompletion: 5, timeContractionSeconds: 5, } diff --git a/frontend/src/hooks/useExtendedPoll.ts b/frontend/src/hooks/useExtendedPoll.ts index 22fd324..2842596 100644 --- a/frontend/src/hooks/useExtendedPoll.ts +++ b/frontend/src/hooks/useExtendedPoll.ts @@ -115,9 +115,9 @@ export const useExtendedPoll = ( return results }, [poll, voteCounts, winningChoice, votes]) - const closeDemoPoll = () => { + const completeDemoPoll = () => { if (!poll) return - // Let's formally close the poll + // Let's formally complete the poll setPoll({ ...poll, proposal: { @@ -153,7 +153,7 @@ export const useExtendedPoll = ( pollResults, deadline, setDeadline, - closeDemoPoll, + completeDemoPoll, gaslessEnabled, gaslessPossible, gvAddresses, diff --git a/frontend/src/pages/CreatePollPage/useCreatePollForm.ts b/frontend/src/pages/CreatePollPage/useCreatePollForm.ts index fbe1eed..b05d9ef 100644 --- a/frontend/src/pages/CreatePollPage/useCreatePollForm.ts +++ b/frontend/src/pages/CreatePollPage/useCreatePollForm.ts @@ -36,7 +36,7 @@ import { useContracts } from '../../hooks/useContracts' import classes from './index.module.css' import { DateUtils } from '../../utils/date.utils' import { useTime } from '../../hooks/useTime' -import { designDecisions, MIN_CLOSE_TIME_MINUTES } from '../../constants/config' +import { designDecisions, MIN_COMPLETION_TIME_MINUTES } from '../../constants/config' import { AclOptions } from '../../types' import { renderAddress } from '../../components/Addresses' import { useNavigate } from 'react-router-dom' @@ -383,7 +383,7 @@ export const useCreatePollForm = () => { const gasFreeExplanation = useLabel({ name: 'gasFreeExplanation', initialValue: - 'We calculate and suggest the amount of ROSE needed for gas based on the amount of users that are expected to vote. Any remaining ROSE from the gas sponsoring wallet will be refunded to you once the poll is closed.', + 'We calculate and suggest the amount of ROSE needed for gas based on the amount of users that are expected to vote. Any remaining ROSE from the gas sponsoring wallet will be refunded to you once the poll is completed.', visible: gasFree.value, classnames: classes.explanation, }) @@ -472,51 +472,52 @@ export const useCreatePollForm = () => { disableIfOnlyOneVisibleChoice: designDecisions.disableSelectsWithOnlyOneVisibleOption, } as const) - const hasCloseDate = useBooleanField({ - name: 'hasCloseDate', - label: 'Fixed close date', + const hasCompletionDate = useBooleanField({ + name: 'hasCompletionDate', + label: 'Fixed completion date', onValueChange: value => { - if (value) pollCloseDate.setValue(new Date(Date.now() + 1000 * 3600)) + if (value) pollCompletionDate.setValue(new Date(Date.now() + 1000 * 3600)) }, }) const { now } = useTime() - const pollCloseDate = useDateField({ - name: 'pollCloseDate', - label: `Poll close date (Time zone: ${Intl.DateTimeFormat().resolvedOptions().timeZone})`, - visible: hasCloseDate.value, + const pollCompletionDate = useDateField({ + name: 'pollCompletionDate', + label: `Poll completion date (Time zone: ${Intl.DateTimeFormat().resolvedOptions().timeZone})`, + visible: hasCompletionDate.value, validateOnChange: true, showValidationStatus: false, validators: value => { const deadline = value.getTime() / 1000 const remaining = DateUtils.calculateRemainingTimeFrom(deadline, now) const { isPastDue, totalSeconds } = remaining - if (isPastDue || totalSeconds < MIN_CLOSE_TIME_MINUTES * 60) { - return `Please set a time at least ${MIN_CLOSE_TIME_MINUTES} minutes in the future!` + if (isPastDue || totalSeconds < MIN_COMPLETION_TIME_MINUTES * 60) { + return `Please set a time at least ${MIN_COMPLETION_TIME_MINUTES} minutes in the future!` } }, }) - const hasValidCloseDate = hasCloseDate.value && !!pollCloseDate.value && !pollCloseDate.hasProblems + const hasValidCompletionDate = + hasCompletionDate.value && !!pollCompletionDate.value && !pollCompletionDate.hasProblems - const pollCloseLabel = useLabel({ - name: 'pollCloseLabel', - visible: hasValidCloseDate, + const pollCompletionLabel = useLabel({ + name: 'pollCompletionLabel', + visible: hasValidCompletionDate, initialValue: '??', }) useEffect(() => { - void pollCloseDate.validate({ forceChange: true, reason: 'change' }) - }, [hasCloseDate.value, now]) + void pollCompletionDate.validate({ forceChange: true, reason: 'change' }) + }, [hasCompletionDate.value, now]) useEffect(() => { - if (hasValidCloseDate) { - const deadline = pollCloseDate.value.getTime() / 1000 + if (hasValidCompletionDate) { + const deadline = pollCompletionDate.value.getTime() / 1000 const remaining = DateUtils.calculateRemainingTimeFrom(deadline, now) - pollCloseLabel.setValue(DateUtils.getTextDescriptionOfTime(remaining) ?? '') + pollCompletionLabel.setValue(DateUtils.getTextDescriptionOfTime(remaining) ?? '') } - }, [hasCloseDate.value, hasValidCloseDate, now]) + }, [hasCompletionDate.value, hasValidCompletionDate, now]) const creationStatus = useLabel({ name: 'creationStatus', @@ -545,9 +546,9 @@ export const useCreatePollForm = () => { results: [ resultDisplayType, authorResultDisplayType, - hasCloseDate, - pollCloseDate, - pollCloseLabel, + hasCompletionDate, + pollCompletionDate, + pollCompletionLabel, creationStatus, ], } @@ -619,7 +620,7 @@ export const useCreatePollForm = () => { aclOptions, subsidizeAmount: gasFree.value ? parseEther(amountOfSubsidy.value) : undefined, publishVotes: resultDisplayType.value === 'percentages_and_votes', - completionTime: hasCloseDate.value ? pollCloseDate.value : undefined, + completionTime: hasCompletionDate.value ? pollCompletionDate.value : undefined, } // console.log('Will create poll with props:', pollProps) diff --git a/frontend/src/pages/DashboardPage/useDashboardData.ts b/frontend/src/pages/DashboardPage/useDashboardData.ts index 571aa36..6acfcb0 100644 --- a/frontend/src/pages/DashboardPage/useDashboardData.ts +++ b/frontend/src/pages/DashboardPage/useDashboardData.ts @@ -52,7 +52,7 @@ type VisibilityInCircumstances = Record> * Explanation about filtering on the dashboard * * The poll cards on the dashboard are filtered according to three criteria: - * 1. Poll status: open or closed + * 1. Poll status: active or completed * 2. Text search (in name and description) * 3. Poll accessibility (i.e. permissions) * diff --git a/frontend/src/pages/PollPage/ActivePoll.tsx b/frontend/src/pages/PollPage/ActivePoll.tsx index 6e2ddde..c00384c 100644 --- a/frontend/src/pages/PollPage/ActivePoll.tsx +++ b/frontend/src/pages/PollPage/ActivePoll.tsx @@ -35,13 +35,13 @@ export const ActivePoll: FC = ({ isMine, permissions, checkPermissions, - canClose, - isClosing, + canComplete, + isCompleting, completePoll, topUp, }) => { // console.log("hasWallet?", hasWallet, "hasWalletOnWrongNetwork?",hasWalletOnWrongNetwork) - // console.log('isMine?', isMine, 'canClose?', canClose) + // console.log('isMine?', isMine, 'canComplete?', canComplete) const { name, @@ -63,11 +63,11 @@ export const ActivePoll: FC = ({ [canSelect, selectedChoice, setSelectedChoice], ) - const handleClose = useCallback(() => { - if (canClose && window.confirm("Are you sure you want to close this poll? This can't be undone.")) { + const handleComplete = useCallback(() => { + if (canComplete && window.confirm("Are you sure you want to complete this poll? This can't be undone.")) { void completePoll() } - }, [close]) + }, [canComplete, completePoll]) const handleTopup = (address: string) => { const amountString = window.prompt( @@ -97,7 +97,7 @@ export const ActivePoll: FC = ({ permissions={permissions} isActive={true} retest={checkPermissions} - hideClosedNoAccess={true} + hideRestrictedNoAccess={true} />
@@ -140,10 +140,11 @@ export const ActivePoll: FC = ({ ))} {remainingTimeString &&

{remainingTimeString}

} - {publishVotes &&
Votes will be made public when the poll is closed.
} + {publishVotes &&
Votes will be made public when the poll is completed.
} {isPastDue && (

- Voting results will be available when {isMine ? 'you close' : 'the owner formally closes'} the poll. + Voting results will be available when {isMine ? 'you compplete' : 'the owner formally completes'}{' '} + the poll.

)} {hasWallet && !hasWalletOnWrongNetwork && !getVerdict(canAclVote, false) ? ( @@ -179,12 +180,12 @@ export const ActivePoll: FC = ({ {isMine && ( )} {!hasWallet && !isPastDue && } diff --git a/frontend/src/pages/PollPage/CompletedPoll.tsx b/frontend/src/pages/PollPage/CompletedPoll.tsx index fe7a9db..bfb322d 100644 --- a/frontend/src/pages/PollPage/CompletedPoll.tsx +++ b/frontend/src/pages/PollPage/CompletedPoll.tsx @@ -26,7 +26,7 @@ export const CompletedPoll: FC< permissions={permissions} isActive={false} retest={checkPermissions} - hideClosedNoAccess={true} + hideRestrictedNoAccess={true} /> diff --git a/frontend/src/pages/PollPage/ThanksForVoting.tsx b/frontend/src/pages/PollPage/ThanksForVoting.tsx index 749d50b..0f2a8c9 100644 --- a/frontend/src/pages/PollPage/ThanksForVoting.tsx +++ b/frontend/src/pages/PollPage/ThanksForVoting.tsx @@ -24,12 +24,12 @@ const StatusInfo: FC<{ remainingTime: RemainingTime | undefined remainingTimeString: string | undefined isMine: boolean | undefined - canClose: boolean + canComplete: boolean complete: () => void - isClosing: boolean -}> = ({ remainingTime, remainingTimeString, isMine, canClose, complete, isClosing }) => { - const handleClose = () => { - if (canClose && window.confirm("Are you you you want to close this poll? This can't be undone.")) { + isCompleting: boolean +}> = ({ remainingTime, remainingTimeString, isMine, canComplete, complete, isCompleting }) => { + const handleComplete = () => { + if (canComplete && window.confirm("Are you you you want to complete this poll? This can't be undone.")) { complete() } } @@ -40,9 +40,9 @@ const StatusInfo: FC<{ return ( <>

{remainingTimeString}

-

Voting results will be available when you close the poll.

- ) @@ -50,14 +50,14 @@ const StatusInfo: FC<{ return ( <>

{remainingTimeString}

-

Voting results will be available when the owner formally closes the poll.

+

Voting results will be available when the owner formally completes the poll.

) } } else { return ( <> -

Poll closes in:

+

Poll completes in:

) @@ -66,14 +66,14 @@ const StatusInfo: FC<{ if (isMine) { return ( <> -

Voting results will be available when you close the poll.

- ) } else { - return

Voting results will be available when the owner closes the poll.

+ return

Voting results will be available when the owner completes the poll.

} } } @@ -86,9 +86,9 @@ export const ThanksForVote: FC = ({ isMine, permissions, checkPermissions, - canClose, + canComplete, completePoll, - isClosing, + isCompleting, }) => { const { name, @@ -124,9 +124,9 @@ export const ThanksForVote: FC = ({ remainingTime={remainingTime} remainingTimeString={remainingTimeString} isMine={isMine} - canClose={canClose} + canComplete={canComplete} complete={completePoll} - isClosing={isClosing} + isCompleting={isCompleting} /> ) diff --git a/frontend/src/pages/PollPage/hook.ts b/frontend/src/pages/PollPage/hook.ts index f95b7e3..77e4a46 100644 --- a/frontend/src/pages/PollPage/hook.ts +++ b/frontend/src/pages/PollPage/hook.ts @@ -24,8 +24,8 @@ export const usePollData = (pollId: string) => { const [isVoting, setIsVoting] = useState(false) const [hasVoted, setHasVoted] = useState(false) - const [isClosing, setIsClosing] = useState(false) - const [hasClosed, setHasClosed] = useState(false) + const [isCompleting, setIsCompleting] = useState(false) + const [hasCompleted, setHasCompleted] = useState(false) const [selectedChoice, setSelectedChoice] = useState() const [existingVote, setExistingVote] = useState(undefined) @@ -45,7 +45,7 @@ export const usePollData = (pollId: string) => { poll, deadline, setDeadline, - closeDemoPoll, + completeDemoPoll, votes, voteCounts, winningChoice, @@ -86,7 +86,7 @@ export const usePollData = (pollId: string) => { canVote = (!!eth.state.address || isDemo) && - !isClosing && + !isCompleting && winningChoice === undefined && selectedChoice !== undefined && existingVote === undefined && @@ -97,7 +97,7 @@ export const usePollData = (pollId: string) => { !remainingTime?.isPastDue && winningChoice === undefined && // (eth.state.address === undefined || existingVote === undefined) && - !isClosing && + !isCompleting && winningChoice === undefined && existingVote === undefined && getVerdict(permissions.canVote, false) @@ -106,20 +106,20 @@ export const usePollData = (pollId: string) => { const hasWallet = isDemo || (isHomeChain && userAddress !== ZeroAddress) const hasWalletOnWrongNetwork = !isDemo && !isHomeChain && userAddress !== ZeroAddress - const canClose = permissions.canManage && (!deadline || isPastDue) + const canComplete = permissions.canManage && (!deadline || isPastDue) - // console.log("canAclManage?", canAclManage, "deadline:", deadline, "isPastDue?", isPastDue, "canClose?", canClose) + // console.log("canAclManage?", canAclManage, "deadline:", deadline, "isPastDue?", isPastDue, "canComplete?", canComplete) const completePoll = async () => { if (!signerDao) throw new Error("Can't complete poll with no poll manager.") - setIsClosing(true) + setIsCompleting(true) try { await doCompletePoll(eth, signerDao, proposalId) - setHasClosed(true) + setHasCompleted(true) } catch (e) { - console.log('Error closing poll:', e) + console.log('Error completing poll:', e) } finally { - setIsClosing(false) + setIsCompleting(false) } } @@ -128,14 +128,16 @@ export const usePollData = (pollId: string) => { if ( !!deadline && !!remainingSeconds && - remainingSeconds > demoSettings.jumpToSecondsBeforeClosing + demoSettings.timeContractionSeconds + remainingSeconds > demoSettings.jumpToSecondsBeforeCompletion + demoSettings.timeContractionSeconds ) { // Let's quickly get rid of the remaining time. tuneValue({ startValue: deadline, transitionTime: demoSettings.timeContractionSeconds, endValue: - Date.now() / 1000 + demoSettings.jumpToSecondsBeforeClosing + demoSettings.timeContractionSeconds, + Date.now() / 1000 + + demoSettings.jumpToSecondsBeforeCompletion + + demoSettings.timeContractionSeconds, stepInMs: 100, setValue: setDeadline, easing: true, @@ -146,7 +148,7 @@ export const usePollData = (pollId: string) => { } else if (!remainingSeconds) { console.log('Not speeding up time, since there is are no remainingSeconds.') } else { - const threshold = demoSettings.jumpToSecondsBeforeClosing + demoSettings.timeContractionSeconds + const threshold = demoSettings.jumpToSecondsBeforeCompletion + demoSettings.timeContractionSeconds if (remainingSeconds <= threshold) { console.log( 'Not speeding up time, since we would need at least', @@ -334,16 +336,16 @@ export const usePollData = (pollId: string) => { } useEffect( - // Close the demo time if nothing more is going to happen + // Complete the demo time if nothing more is going to happen () => { if ( isDemo && poll?.proposal.active && remainingTime?.isPastDue && - remainingTime.totalSeconds < demoSettings.waitSecondsBeforeFormallyClosing + 5 && - remainingTime.totalSeconds >= demoSettings.waitSecondsBeforeFormallyClosing + remainingTime.totalSeconds < demoSettings.waitSecondsBeforeFormallyCompleting + 5 && + remainingTime.totalSeconds >= demoSettings.waitSecondsBeforeFormallyCompleting ) { - closeDemoPoll() + completeDemoPoll() } }, [deadline, now], @@ -352,22 +354,22 @@ export const usePollData = (pollId: string) => { // if (!isDemo && userAddress === "0x0000000000000000000000000000000000000000") { useEffect(() => { - // Reload poll after closing, expecting results - if (hasClosed) { + // Reload poll after completion, expecting results + if (hasCompleted) { if (!poll) { // console.log("No poll loaded, waiting to load") } else if (poll.proposal.active) { - // console.log("Apparently, we have closed a poll, but we still perceive it as active, so scheduling a reload...") + // console.log("Apparently, we have completed a poll, but we still perceive it as active, so scheduling a reload...") setTimeout(() => { // console.log("Reloading now") invalidateProposal() }, 5 * 1000) } else { // console.log("We no longer perceive it as active, so we can stop reloading") - setHasClosed(false) + setHasCompleted(false) } } - }, [hasClosed, poll]) + }, [hasCompleted, poll]) return { userAddress, @@ -408,10 +410,10 @@ export const usePollData = (pollId: string) => { existingVote, topUp, - canClose, + canComplete, completePoll, - isClosing, - hasClosed, + isCompleting, + hasCompleted, voteCounts, winningChoice, diff --git a/frontend/src/pages/PollPage/index.tsx b/frontend/src/pages/PollPage/index.tsx index 81cad5f..83450ec 100644 --- a/frontend/src/pages/PollPage/index.tsx +++ b/frontend/src/pages/PollPage/index.tsx @@ -20,7 +20,7 @@ const WaitingForResults: FC = () => { return ( Waiting for results to land...} /> @@ -31,7 +31,7 @@ const WaitingForResults: FC = () => { export const PollPage: FC = () => { const { pollId } = useParams() const pollData = usePollData(pollId!) - const { isLoading, error, poll, active, hasVoted, existingVote, hasClosed, pollResults } = pollData + const { isLoading, error, poll, active, hasVoted, existingVote, hasCompleted, pollResults } = pollData if (error) { return ( @@ -40,8 +40,8 @@ export const PollPage: FC = () => { ) } - // Closed poll, now waiting for results - if (hasClosed) return + // Completed poll, now waiting for results + if (hasCompleted) return // Currently loading stuff if (isLoading || !poll?.ipfsParams) return diff --git a/frontend/src/utils/date.utils.ts b/frontend/src/utils/date.utils.ts index cdb1fd2..6c91658 100644 --- a/frontend/src/utils/date.utils.ts +++ b/frontend/src/utils/date.utils.ts @@ -54,7 +54,7 @@ export abstract class DateUtils { if (remaining.isPastDue) { return `Voting finished ${timeString} ago.` } else { - return `Poll closes in ${timeString}.` + return `Poll completes in ${timeString}.` } } }