From acbdf306a48b9b63cc4798c322b38d7943dbfbdf Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:57:36 +0100 Subject: [PATCH 01/20] fix: ignore .env.testnet --- src/build-a-bull/.gitignore | 2 +- src/xgov-dapp/.gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build-a-bull/.gitignore b/src/build-a-bull/.gitignore index 796af641..ac721d7c 100644 --- a/src/build-a-bull/.gitignore +++ b/src/build-a-bull/.gitignore @@ -22,4 +22,4 @@ dist-ssr *.sln *.sw? -.env +.env* diff --git a/src/xgov-dapp/.gitignore b/src/xgov-dapp/.gitignore index 796af641..ac721d7c 100644 --- a/src/xgov-dapp/.gitignore +++ b/src/xgov-dapp/.gitignore @@ -22,4 +22,4 @@ dist-ssr *.sln *.sw? -.env +.env* From b2dc55efb8d1fa460f04e4b04f2e41c438c2cb5a Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:57:10 +0100 Subject: [PATCH 02/20] feat: ENG-63 Sorts passed proposals to the top --- .../src/features/vote/VoteResults.tsx | 58 ++++++++++--------- .../src/features/vote/VoteResults.tsx | 58 ++++++++++--------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/build-a-bull/src/features/vote/VoteResults.tsx b/src/build-a-bull/src/features/vote/VoteResults.tsx index acc34c5b..81307830 100644 --- a/src/build-a-bull/src/features/vote/VoteResults.tsx +++ b/src/build-a-bull/src/features/vote/VoteResults.tsx @@ -47,6 +47,15 @@ export const VoteResults = ({ const optionIDsToCounts = votingRoundResults !== undefined ? generateOptionIDsToCountsMapping(votingRoundResults) : {} + const countVotesTally = (question: Question) => { + return question.options.length > 0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0 + } + + const passedToTopSort = (q1: Question, q2: Question) => { + if (!q1.metadata?.threshold || !q2.metadata?.threshold) return 0 + return countVotesTally(q2) / q2.metadata.threshold - countVotesTally(q1) / q1.metadata.threshold + } + // clone the voting round metadata and adjust the threshold to be out of total votes instead of total voting power // we clone the metadata so that we don't mutate the original metadata const votingRoundMetadataClone = useMemo(() => { @@ -179,6 +188,7 @@ export const VoteResults = ({ ? !isReserveList(q, optionIDsToCounts[q.options[0].id]) : true, ) + .sort((q1, q2) => passedToTopSort(q1, q2)) .map((question) => (
{question.metadata && ( @@ -190,11 +200,7 @@ export const VoteResults = ({ link={question.metadata.link} threshold={question.metadata.threshold} ask={question.metadata.ask} - votesTally={ - question.options.length > 0 && optionIDsToCounts[question.options[0].id] - ? optionIDsToCounts[question.options[0].id] - : 0 - } + votesTally={countVotesTally(question)} hasClosed={true} /> )} @@ -220,28 +226,26 @@ export const VoteResults = ({ ))} {!isLoadingVotingRoundResults && - reserveList.map((question) => ( -
- {question.metadata && ( - 0 && optionIDsToCounts[question.options[0].id] - ? optionIDsToCounts[question.options[0].id] - : 0 - } - hasClosed={true} - forcePass={passedReserveList.has(question.id)} - /> - )} -
- ))} + reserveList + .sort((q1, q2) => passedToTopSort(q1, q2)) + .map((question) => ( +
+ {question.metadata && ( + + )} +
+ ))} )}
diff --git a/src/xgov-dapp/src/features/vote/VoteResults.tsx b/src/xgov-dapp/src/features/vote/VoteResults.tsx index a66289a6..153bbfcf 100644 --- a/src/xgov-dapp/src/features/vote/VoteResults.tsx +++ b/src/xgov-dapp/src/features/vote/VoteResults.tsx @@ -47,6 +47,15 @@ export const VoteResults = ({ const optionIDsToCounts = votingRoundResults !== undefined ? generateOptionIDsToCountsMapping(votingRoundResults) : {} + const countVotesTally = (question: Question) => { + return question.options.length > 0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0 + } + + const passedToTopSort = (q1: Question, q2: Question) => { + if (!q1.metadata?.threshold || !q2.metadata?.threshold) return 0 + return countVotesTally(q2) / q2.metadata.threshold - countVotesTally(q1) / q1.metadata.threshold + } + // clone the voting round metadata and adjust the threshold to be out of total votes instead of total voting power // we clone the metadata so that we don't mutate the original metadata const votingRoundMetadataClone = useMemo(() => { @@ -181,6 +190,7 @@ export const VoteResults = ({ ? !isReserveList(q, optionIDsToCounts[q.options[0].id]) : true, ) + .sort((q1, q2) => passedToTopSort(q1, q2)) .map((question) => (
{question.metadata && ( @@ -192,11 +202,7 @@ export const VoteResults = ({ link={question.metadata.link} threshold={question.metadata.threshold} ask={question.metadata.ask} - votesTally={ - question.options.length > 0 && optionIDsToCounts[question.options[0].id] - ? optionIDsToCounts[question.options[0].id] - : 0 - } + votesTally={countVotesTally(question)} hasClosed={true} /> )} @@ -222,28 +228,26 @@ export const VoteResults = ({ ))} {!isLoadingVotingRoundResults && - reserveList.map((question) => ( -
- {question.metadata && ( - 0 && optionIDsToCounts[question.options[0].id] - ? optionIDsToCounts[question.options[0].id] - : 0 - } - hasClosed={true} - forcePass={passedReserveList.has(question.id)} - /> - )} -
- ))} + reserveList + .sort((q1, q2) => passedToTopSort(q1, q2)) + .map((question) => ( +
+ {question.metadata && ( + + )} +
+ ))} )}
From d3e01433bd5aba0146044ca146b9cd4fad55a6a3 Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:43:41 +0100 Subject: [PATCH 03/20] fix: ignore .env.testnet specifically --- src/build-a-bull/.gitignore | 3 ++- src/xgov-dapp/.gitignore | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/build-a-bull/.gitignore b/src/build-a-bull/.gitignore index ac721d7c..7c1b52e7 100644 --- a/src/build-a-bull/.gitignore +++ b/src/build-a-bull/.gitignore @@ -22,4 +22,5 @@ dist-ssr *.sln *.sw? -.env* +.env +.env.testnet \ No newline at end of file diff --git a/src/xgov-dapp/.gitignore b/src/xgov-dapp/.gitignore index ac721d7c..7c1b52e7 100644 --- a/src/xgov-dapp/.gitignore +++ b/src/xgov-dapp/.gitignore @@ -22,4 +22,5 @@ dist-ssr *.sln *.sw? -.env* +.env +.env.testnet \ No newline at end of file From d534fbbd268d583238786f7ad5d893a31a3b6e44 Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:51:53 +0100 Subject: [PATCH 04/20] fix: includes only .env.*.template --- src/build-a-bull/.gitignore | 4 ++-- src/xgov-dapp/.gitignore | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/build-a-bull/.gitignore b/src/build-a-bull/.gitignore index 7c1b52e7..e67baa45 100644 --- a/src/build-a-bull/.gitignore +++ b/src/build-a-bull/.gitignore @@ -22,5 +22,5 @@ dist-ssr *.sln *.sw? -.env -.env.testnet \ No newline at end of file +.env* +!.env*.template \ No newline at end of file diff --git a/src/xgov-dapp/.gitignore b/src/xgov-dapp/.gitignore index 7c1b52e7..e67baa45 100644 --- a/src/xgov-dapp/.gitignore +++ b/src/xgov-dapp/.gitignore @@ -22,5 +22,5 @@ dist-ssr *.sln *.sw? -.env -.env.testnet \ No newline at end of file +.env* +!.env*.template \ No newline at end of file From d368094097c6f57578faf4484a91432a21159cee Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Thu, 7 Dec 2023 19:01:53 +0100 Subject: [PATCH 05/20] fix: add whitespace ending --- src/build-a-bull/.gitignore | 2 +- src/xgov-dapp/.gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build-a-bull/.gitignore b/src/build-a-bull/.gitignore index e67baa45..7f7e442e 100644 --- a/src/build-a-bull/.gitignore +++ b/src/build-a-bull/.gitignore @@ -23,4 +23,4 @@ dist-ssr *.sw? .env* -!.env*.template \ No newline at end of file +!.env*.template diff --git a/src/xgov-dapp/.gitignore b/src/xgov-dapp/.gitignore index e67baa45..7f7e442e 100644 --- a/src/xgov-dapp/.gitignore +++ b/src/xgov-dapp/.gitignore @@ -23,4 +23,4 @@ dist-ssr *.sw? .env* -!.env*.template \ No newline at end of file +!.env*.template From 31c7d4c9b1a612f20acf0e7ae51eb48992a36657 Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Mon, 11 Dec 2023 11:16:29 +0100 Subject: [PATCH 06/20] feat: ensures forcePassed are sorted to top as well --- src/build-a-bull/src/features/vote/VoteResults.tsx | 6 +++++- src/xgov-dapp/src/features/vote/VoteResults.tsx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/build-a-bull/src/features/vote/VoteResults.tsx b/src/build-a-bull/src/features/vote/VoteResults.tsx index 81307830..d853bd3b 100644 --- a/src/build-a-bull/src/features/vote/VoteResults.tsx +++ b/src/build-a-bull/src/features/vote/VoteResults.tsx @@ -56,6 +56,10 @@ export const VoteResults = ({ return countVotesTally(q2) / q2.metadata.threshold - countVotesTally(q1) / q1.metadata.threshold } + const passedToTopSortReserve = (q1: Question, q2: Question, passedReserveList: Set) => { + return passedReserveList.has(q2.id) ? 100 : passedReserveList.has(q1.id) ? -100 : passedToTopSort(q1, q2) + } + // clone the voting round metadata and adjust the threshold to be out of total votes instead of total voting power // we clone the metadata so that we don't mutate the original metadata const votingRoundMetadataClone = useMemo(() => { @@ -227,7 +231,7 @@ export const VoteResults = ({ ))} {!isLoadingVotingRoundResults && reserveList - .sort((q1, q2) => passedToTopSort(q1, q2)) + .sort((q1, q2) => passedToTopSortReserve(q1, q2, passedReserveList)) .map((question) => (
{question.metadata && ( diff --git a/src/xgov-dapp/src/features/vote/VoteResults.tsx b/src/xgov-dapp/src/features/vote/VoteResults.tsx index 153bbfcf..b096edcc 100644 --- a/src/xgov-dapp/src/features/vote/VoteResults.tsx +++ b/src/xgov-dapp/src/features/vote/VoteResults.tsx @@ -56,6 +56,10 @@ export const VoteResults = ({ return countVotesTally(q2) / q2.metadata.threshold - countVotesTally(q1) / q1.metadata.threshold } + const passedToTopSortReserve = (q1: Question, q2: Question, passedReserveList: Set) => { + return passedReserveList.has(q2.id) ? 100 : passedReserveList.has(q1.id) ? -100 : passedToTopSort(q1, q2) + } + // clone the voting round metadata and adjust the threshold to be out of total votes instead of total voting power // we clone the metadata so that we don't mutate the original metadata const votingRoundMetadataClone = useMemo(() => { @@ -229,7 +233,7 @@ export const VoteResults = ({ ))} {!isLoadingVotingRoundResults && reserveList - .sort((q1, q2) => passedToTopSort(q1, q2)) + .sort((q1, q2) => passedToTopSortReserve(q1, q2, passedReserveList)) .map((question) => (
{question.metadata && ( From 77220bb551b74d4c62deae774aa5a61bbe78b737 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 21:02:47 +0000 Subject: [PATCH 07/20] chore: remove chips from results, remove home nav --- src/build-a-bull/src/components/siteHeader.tsx | 1 - src/build-a-bull/src/features/vote/VoteResults.tsx | 1 + src/build-a-bull/src/shared/ProposalCard.tsx | 6 ++++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/build-a-bull/src/components/siteHeader.tsx b/src/build-a-bull/src/components/siteHeader.tsx index df9ed57f..ee714b97 100644 --- a/src/build-a-bull/src/components/siteHeader.tsx +++ b/src/build-a-bull/src/components/siteHeader.tsx @@ -21,7 +21,6 @@ interface Link { const createNavigation = () => [ - { name: 'Home', href: '/', protect: false }, { name: 'Create', href: '/create', protect: true }, ] as Link[] diff --git a/src/build-a-bull/src/features/vote/VoteResults.tsx b/src/build-a-bull/src/features/vote/VoteResults.tsx index 3287bf89..a4b93d4a 100644 --- a/src/build-a-bull/src/features/vote/VoteResults.tsx +++ b/src/build-a-bull/src/features/vote/VoteResults.tsx @@ -122,6 +122,7 @@ export const VoteResults = ({ link={question.metadata.link} threshold={question.metadata.threshold} ask={question.metadata.ask} + skipTags={true} votesTally={ question.options.length > 0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0 } diff --git a/src/build-a-bull/src/shared/ProposalCard.tsx b/src/build-a-bull/src/shared/ProposalCard.tsx index e2378d5f..c8273b8b 100644 --- a/src/build-a-bull/src/shared/ProposalCard.tsx +++ b/src/build-a-bull/src/shared/ProposalCard.tsx @@ -16,6 +16,7 @@ export type ProposalCardProps = { totalVotes?: number | undefined hasClosed?: boolean forcePass?: boolean + skipTags?: boolean } export const ProposalCard = ({ @@ -30,6 +31,7 @@ export const ProposalCard = ({ totalVotes = 0, hasClosed = false, forcePass = false, + skipTags = false, }: ProposalCardProps) => { // Handle collapse state const [isOverflow, setIsOverflow] = useState(false) @@ -51,8 +53,8 @@ export const ProposalCard = ({
- {hasPassed && } - {hasClosed && !hasPassed && } + {hasPassed && !skipTags && } + {hasClosed && !hasPassed && !skipTags && }
From fa7b72e60b1e14df12dae3e9aef467a2fd7a0f29 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 21:06:11 +0000 Subject: [PATCH 08/20] chore: remove back buttons --- src/build-a-bull/src/features/vote/VoteResults.tsx | 5 ----- src/build-a-bull/src/features/vote/index.tsx | 5 ----- 2 files changed, 10 deletions(-) diff --git a/src/build-a-bull/src/features/vote/VoteResults.tsx b/src/build-a-bull/src/features/vote/VoteResults.tsx index a4b93d4a..a695042d 100644 --- a/src/build-a-bull/src/features/vote/VoteResults.tsx +++ b/src/build-a-bull/src/features/vote/VoteResults.tsx @@ -67,11 +67,6 @@ export const VoteResults = ({ return (
-
- - < Back to Voting sessions - -
{votingRoundMetadata?.title} - Results diff --git a/src/build-a-bull/src/features/vote/index.tsx b/src/build-a-bull/src/features/vote/index.tsx index 74585c9b..dd3eabff 100644 --- a/src/build-a-bull/src/features/vote/index.tsx +++ b/src/build-a-bull/src/features/vote/index.tsx @@ -316,11 +316,6 @@ function Vote({ sort: sortProp = 'none' }: { sort?: 'ascending' | 'descending' | return (
-
- - < Back to events - -
{error && ( From 0c61c212b3cc39c96466105fe9e67cb7ba02f1ab Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 21:07:12 +0000 Subject: [PATCH 09/20] chore: redirect to live voting round --- src/build-a-bull/src/features/rounds/index.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/build-a-bull/src/features/rounds/index.tsx b/src/build-a-bull/src/features/rounds/index.tsx index 8a6cc904..b8419ae0 100644 --- a/src/build-a-bull/src/features/rounds/index.tsx +++ b/src/build-a-bull/src/features/rounds/index.tsx @@ -2,7 +2,7 @@ import { useWallet } from '@makerx/use-wallet' import { Alert, Button, Skeleton, Typography } from '@mui/material' import sortBy from 'lodash.sortby' import { useEffect, useState } from 'react' -import { Link } from 'react-router-dom' +import { Link, useNavigate } from 'react-router-dom' import { VotingRoundGlobalState, fetchVotingRoundGlobalStatesByCreators } from '@/shared/VotingRoundContract' import { VoteType } from '@/shared/types' import { getHasVoteEnded, getHasVoteStarted } from '@/shared/vote' @@ -36,6 +36,15 @@ const VotingRounds = () => { const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) + // Redirect to live round + const navigate = useNavigate() + useEffect(() => { + const appId = import.meta.env.VITE_ALGOD_NETWORK === 'testnet' ? '499163907' : '' + if (import.meta.env.VITE_ENVIRONMENT !== 'dev') { + navigate(`/vote/${appId}`) + } + }, []) + useEffect(() => { let addressesToFetch = [] as string[] if (showMyRounds && activeAddress) { From fbb8a2be92f709e1a0f6dec2c7b5ed51f67487c4 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 21:36:03 +0000 Subject: [PATCH 10/20] chore: remove vote details and add total votes --- .../src/features/vote/VoteResults.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/build-a-bull/src/features/vote/VoteResults.tsx b/src/build-a-bull/src/features/vote/VoteResults.tsx index a695042d..afa9a0b2 100644 --- a/src/build-a-bull/src/features/vote/VoteResults.tsx +++ b/src/build-a-bull/src/features/vote/VoteResults.tsx @@ -2,14 +2,12 @@ import FileDownloadIcon from '@mui/icons-material/FileDownload' import { Alert, Button, Skeleton, Typography } from '@mui/material' import { saveAs } from 'file-saver' import Papa from 'papaparse' -import { useState } from 'react' -import { Link } from 'react-router-dom' +import { useMemo, useState } from 'react' import { VotingRoundMetadata } from '@/shared/IPFSGateway' import { VotingRoundGlobalState } from '@/shared/VotingRoundContract' import { ProposalCard } from '@/shared/ProposalCard' import { VotingRoundResult } from '@/shared/types' import { generateOptionIDsToCountsMapping } from '@/utils/common' -import { VoteDetails } from './VoteDetails' import VotingStats from './VotingStats' import { VotingTime } from './VotingTime' @@ -33,7 +31,15 @@ export const VoteResults = ({ const [error, setError] = useState(null) const optionIDsToCounts = votingRoundResults !== undefined ? generateOptionIDsToCountsMapping(votingRoundResults) : {} - + function getTotalVotes() { + return votingRoundResults && votingRoundMetadata + ? votingRoundResults.reduce((c, r) => { + const isYesOption = votingRoundMetadata.questions.map((q) => q.options[0]).some((el) => el.id === r.optionId) + return isYesOption ? c + r.count : c + }, 0) + : 0 + } + const totalVotes = useMemo(() => getTotalVotes(), [votingRoundResults, votingRoundMetadata]) const generateProposalsResultsCsv = async () => { if (votingRoundMetadata) { setIsDownloadingProposalsCsv(true) @@ -71,14 +77,7 @@ export const VoteResults = ({
{votingRoundMetadata?.title} - Results
-
- -
+
0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0 } From 501bee69cb9369e06f5bd6ba65bb4ad14e2cfd43 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 21:40:22 +0000 Subject: [PATCH 11/20] chore: skip redirect on local only --- src/build-a-bull/src/features/rounds/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/build-a-bull/src/features/rounds/index.tsx b/src/build-a-bull/src/features/rounds/index.tsx index b8419ae0..fd06ecbc 100644 --- a/src/build-a-bull/src/features/rounds/index.tsx +++ b/src/build-a-bull/src/features/rounds/index.tsx @@ -39,8 +39,9 @@ const VotingRounds = () => { // Redirect to live round const navigate = useNavigate() useEffect(() => { + // TODO: add production voting round const appId = import.meta.env.VITE_ALGOD_NETWORK === 'testnet' ? '499163907' : '' - if (import.meta.env.VITE_ENVIRONMENT !== 'dev') { + if (import.meta.env.VITE_ENVIRONMENT !== 'local') { navigate(`/vote/${appId}`) } }, []) From 5d1bcd8493cf20ff09456f4ca9b785f54d40691b Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 21:46:45 +0000 Subject: [PATCH 12/20] chore: fix lint errors --- src/build-a-bull/src/components/siteHeader.tsx | 5 +---- src/build-a-bull/src/features/vote/index.tsx | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/build-a-bull/src/components/siteHeader.tsx b/src/build-a-bull/src/components/siteHeader.tsx index ee714b97..d66606f9 100644 --- a/src/build-a-bull/src/components/siteHeader.tsx +++ b/src/build-a-bull/src/components/siteHeader.tsx @@ -19,10 +19,7 @@ interface Link { onClick?: () => void } -const createNavigation = () => - [ - { name: 'Create', href: '/create', protect: true }, - ] as Link[] +const createNavigation = () => [{ name: 'Create', href: '/create', protect: true }] as Link[] function NavLink(props: { currentClasses: string; defaultClasses: string; link: Link; displayName?: string }) { const classes = 'no-underline text-black' diff --git a/src/build-a-bull/src/features/vote/index.tsx b/src/build-a-bull/src/features/vote/index.tsx index dd3eabff..99720d44 100644 --- a/src/build-a-bull/src/features/vote/index.tsx +++ b/src/build-a-bull/src/features/vote/index.tsx @@ -8,7 +8,7 @@ import ShuffleOnIcon from '@mui/icons-material/ShuffleOn' import { Alert, Box, Button, Checkbox, IconButton, Link, Skeleton, Typography } from '@mui/material' import clsx from 'clsx' import { useEffect, useMemo, useState } from 'react' -import { Link as RouterLink, useNavigate, useParams } from 'react-router-dom' +import { useNavigate, useParams } from 'react-router-dom' import { Question, VotingRoundMetadata, fetchVotingRoundMetadata } from '@/shared/IPFSGateway' import { TallyCounts, From b4e35a94f0393b27442c84a4a30a657771f72860 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 22:13:48 +0000 Subject: [PATCH 13/20] fix: use type-guard for appId --- src/build-a-bull/src/features/rounds/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build-a-bull/src/features/rounds/index.tsx b/src/build-a-bull/src/features/rounds/index.tsx index fd06ecbc..90b0d6cd 100644 --- a/src/build-a-bull/src/features/rounds/index.tsx +++ b/src/build-a-bull/src/features/rounds/index.tsx @@ -40,8 +40,8 @@ const VotingRounds = () => { const navigate = useNavigate() useEffect(() => { // TODO: add production voting round - const appId = import.meta.env.VITE_ALGOD_NETWORK === 'testnet' ? '499163907' : '' - if (import.meta.env.VITE_ENVIRONMENT !== 'local') { + const appId = import.meta.env.VITE_ALGOD_NETWORK === 'testnet' ? 499163907 : undefined + if (import.meta.env.VITE_ENVIRONMENT !== 'local' && typeof appId === 'number') { navigate(`/vote/${appId}`) } }, []) From a9273e1db2d1c85ff79c6085155634fa0c698d7e Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 22:55:37 +0000 Subject: [PATCH 14/20] fix: remove effect from redirect --- src/build-a-bull/src/features/rounds/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/build-a-bull/src/features/rounds/index.tsx b/src/build-a-bull/src/features/rounds/index.tsx index 90b0d6cd..57522f0c 100644 --- a/src/build-a-bull/src/features/rounds/index.tsx +++ b/src/build-a-bull/src/features/rounds/index.tsx @@ -10,6 +10,8 @@ import { useCreatorAddresses } from '@/features/wallet/state' import { VotingRoundSection } from './VotingRoundSection' import { VotingRoundStatus } from './VotingRoundTile' +const NETWORK = import.meta.env.VITE_ALGOD_NETWORK + export const VotingRoundTileLoading = () => ( <> @@ -38,13 +40,11 @@ const VotingRounds = () => { // Redirect to live round const navigate = useNavigate() - useEffect(() => { - // TODO: add production voting round - const appId = import.meta.env.VITE_ALGOD_NETWORK === 'testnet' ? 499163907 : undefined - if (import.meta.env.VITE_ENVIRONMENT !== 'local' && typeof appId === 'number') { - navigate(`/vote/${appId}`) - } - }, []) + // TODO: add production voting round + const appId = NETWORK === 'testnet' ? 499163907 : 'must be added' + if (import.meta.env.VITE_ENVIRONMENT !== 'local' && typeof appId === 'number') { + navigate(`/vote/${appId}`) + } useEffect(() => { let addressesToFetch = [] as string[] From 63eacfe420721e200826066f422da42589971aeb Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 17:55:57 -0600 Subject: [PATCH 15/20] chore: trigger fresh build after cleanup add fake mainnet appId --- src/build-a-bull/src/features/rounds/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build-a-bull/src/features/rounds/index.tsx b/src/build-a-bull/src/features/rounds/index.tsx index 57522f0c..ada78db6 100644 --- a/src/build-a-bull/src/features/rounds/index.tsx +++ b/src/build-a-bull/src/features/rounds/index.tsx @@ -41,8 +41,8 @@ const VotingRounds = () => { // Redirect to live round const navigate = useNavigate() // TODO: add production voting round - const appId = NETWORK === 'testnet' ? 499163907 : 'must be added' - if (import.meta.env.VITE_ENVIRONMENT !== 'local' && typeof appId === 'number') { + const appId = NETWORK === 'testnet' ? 499163907 : 1158913461 + if (import.meta.env.VITE_ENVIRONMENT !== 'local') { navigate(`/vote/${appId}`) } From 1d60a03989aae5f2c5c237e08518c48014535349 Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Mon, 11 Dec 2023 18:10:18 -0600 Subject: [PATCH 16/20] fix: use window.location in place of import.meta.env todo: investigate issues with import.meta --- src/build-a-bull/src/features/rounds/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/build-a-bull/src/features/rounds/index.tsx b/src/build-a-bull/src/features/rounds/index.tsx index ada78db6..3e21532e 100644 --- a/src/build-a-bull/src/features/rounds/index.tsx +++ b/src/build-a-bull/src/features/rounds/index.tsx @@ -10,8 +10,6 @@ import { useCreatorAddresses } from '@/features/wallet/state' import { VotingRoundSection } from './VotingRoundSection' import { VotingRoundStatus } from './VotingRoundTile' -const NETWORK = import.meta.env.VITE_ALGOD_NETWORK - export const VotingRoundTileLoading = () => ( <> @@ -41,7 +39,7 @@ const VotingRounds = () => { // Redirect to live round const navigate = useNavigate() // TODO: add production voting round - const appId = NETWORK === 'testnet' ? 499163907 : 1158913461 + const appId = window.location.hostname.includes('testnet') ? 499163907 : 1158913461 if (import.meta.env.VITE_ENVIRONMENT !== 'local') { navigate(`/vote/${appId}`) } From 221e48c0ea38dd4fc1446b41cef3b4f50acc8667 Mon Sep 17 00:00:00 2001 From: HashMapsData2Value <83883690+HashMapsData2Value@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:21:41 +0100 Subject: [PATCH 17/20] feat: sort in VoteResults bab --- .../src/features/vote/VoteResults.tsx | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/build-a-bull/src/features/vote/VoteResults.tsx b/src/build-a-bull/src/features/vote/VoteResults.tsx index afa9a0b2..ea39cd5d 100644 --- a/src/build-a-bull/src/features/vote/VoteResults.tsx +++ b/src/build-a-bull/src/features/vote/VoteResults.tsx @@ -39,6 +39,16 @@ export const VoteResults = ({ }, 0) : 0 } + + const countVotesTally = (question: Question) => { + return question.options.length > 0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0 + } + + const passedToTopSort = (q1: Question, q2: Question) => { + if (!q1.metadata?.threshold || !q2.metadata?.threshold) return 0 + return countVotesTally(q2) / q2.metadata.threshold - countVotesTally(q1) / q1.metadata.threshold + } + const totalVotes = useMemo(() => getTotalVotes(), [votingRoundResults, votingRoundMetadata]) const generateProposalsResultsCsv = async () => { if (votingRoundMetadata) { @@ -105,27 +115,27 @@ export const VoteResults = ({ ))} {!isLoadingVotingRoundResults && - votingRoundMetadata?.questions.map((question) => ( -
- {question.metadata && ( - 0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0 - } - hasClosed={true} - /> - )} -
- ))} + votingRoundMetadata?.questions + .sort((q1, q2) => passedToTopSort(q1, q2)) + .map((question) => ( +
+ {question.metadata && ( + + )} +
+ ))}
+
)} {votingRoundMetadata?.description && {votingRoundMetadata.description}} {votingRoundMetadata?.informationUrl && ( From 2f8c2e219143a7b7fb311103b1ff027ce694c54b Mon Sep 17 00:00:00 2001 From: Michael Feher Date: Tue, 12 Dec 2023 11:41:22 -0600 Subject: [PATCH 20/20] chore: add disaster recovery documentation --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 25f7a381..abf19300 100644 --- a/README.md +++ b/README.md @@ -262,3 +262,15 @@ We recommend using the following IAM policy, which gives the least access possib ] } ``` +# Disaster Recovery + +During a deployment, there is a chance for a race condition between the CDK S3 deployer and CloudFront invalidation. +It is intermittent and is being tracked in [an issue in the cdk library](https://github.com/aws/aws-cdk/issues/15891). +If the deployment fails to update the Custom::CDKBucketDeployment, use the following process: + +1. Log into the effected AWS account and navigate to CloudFormation +2. Select the failed deployment and use the `Stack options` drop down to select `Continue update rollback` + 1. In the `Continue update rollback`, make sure to expand `Advanced` and select `skip` for the failing resource + 2. Trigger the rollback +3. Re-run the failed deployment from the CI/CD platform (GithubActions). This may require a second deployment to ensure the cache is invalidated +