From 82148586853ad2c54c54736115577436e9169524 Mon Sep 17 00:00:00 2001 From: Sam Keen Date: Fri, 24 Mar 2023 14:56:56 +0000 Subject: [PATCH] feat(governance): lp vote now reflected on proposal cards (#3256) --- .../src/integration/flow/proposal-forms.cy.ts | 2 +- .../governance/src/i18n/translations/dev.json | 5 +- .../proposal-votes-table.spec.tsx | 4 +- .../proposals-list-item-details.spec.tsx | 76 +++++++++++++++++++ .../proposals-list-item-details.tsx | 31 +++++++- .../components/vote-details/vote-details.tsx | 22 ++++++ 6 files changed, 131 insertions(+), 9 deletions(-) diff --git a/apps/governance-e2e/src/integration/flow/proposal-forms.cy.ts b/apps/governance-e2e/src/integration/flow/proposal-forms.cy.ts index 1fdee286a..2f9df3041 100644 --- a/apps/governance-e2e/src/integration/flow/proposal-forms.cy.ts +++ b/apps/governance-e2e/src/integration/flow/proposal-forms.cy.ts @@ -341,7 +341,7 @@ context( 'Currently expected to pass' ); getProposalInformationFromTable('Expected to pass') - .contains('👍 by Token vote') + .contains('👍 by token vote') .should('be.visible'); }); diff --git a/apps/governance/src/i18n/translations/dev.json b/apps/governance/src/i18n/translations/dev.json index 997a23218..239b02022 100644 --- a/apps/governance/src/i18n/translations/dev.json +++ b/apps/governance/src/i18n/translations/dev.json @@ -221,8 +221,9 @@ "votePending": "Casting vote", "voteError": "Something went wrong, and your vote was not seen by the network", "back": "back", - "byTokenVote": "by Token vote", - "byLiquidityVote": "by Liquidity vote", + "byTokenVote": "by token vote", + "byLiquidityVote": "by liquidity vote", + "byLPVote": "by LP vote", "youDidNotVote": "Voting has ended. You did not vote", "voteState_Yes": "For", "voteState_No": "Against", diff --git a/apps/governance/src/routes/proposals/components/proposal-votes-table/proposal-votes-table.spec.tsx b/apps/governance/src/routes/proposals/components/proposal-votes-table/proposal-votes-table.spec.tsx index 0286d3e94..2ee8764df 100644 --- a/apps/governance/src/routes/proposals/components/proposal-votes-table/proposal-votes-table.spec.tsx +++ b/apps/governance/src/routes/proposals/components/proposal-votes-table/proposal-votes-table.spec.tsx @@ -86,7 +86,7 @@ describe('Proposal Votes Table', () => { it('displays if an update market proposal will pass by token vote', () => { renderComponent(updateMarketProposal, updateMarketProposalType); - expect(screen.getByText('👍 by Token vote')).toBeInTheDocument(); + expect(screen.getByText('👍 by token vote')).toBeInTheDocument(); }); it('displays if an update market proposal will pass by LP vote', () => { @@ -110,6 +110,6 @@ describe('Proposal Votes Table', () => { }), updateMarketProposalType ); - expect(screen.getByText('👍 by Liquidity vote')).toBeInTheDocument(); + expect(screen.getByText('👍 by liquidity vote')).toBeInTheDocument(); }); }); diff --git a/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.spec.tsx b/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.spec.tsx index 81d353ca8..7bbdbe608 100644 --- a/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.spec.tsx +++ b/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.spec.tsx @@ -136,6 +136,82 @@ describe('Proposals list item details', () => { ); }); + it('Renders proposal state: Update market proposal - set to pass by LP vote', () => { + renderComponent( + generateProposal({ + state: ProposalState.STATE_OPEN, + terms: { + change: { + __typename: 'UpdateMarket', + }, + }, + votes: { + yes: { + ...generateYesVotes(0), + totalEquityLikeShareWeight: '1000', + }, + no: { + ...generateNoVotes(0), + totalEquityLikeShareWeight: '0', + }, + }, + }) + ); + expect(screen.getByTestId('vote-status')).toHaveTextContent( + 'Set to pass by LP vote' + ); + }); + + it('Renders proposal state: Update market proposal - set to pass by token vote', () => { + renderComponent( + generateProposal({ + state: ProposalState.STATE_OPEN, + terms: { + change: { + __typename: 'UpdateMarket', + }, + }, + votes: { + yes: { + ...generateYesVotes(1000, 1000), + totalEquityLikeShareWeight: '0', + }, + no: { + ...generateNoVotes(0), + totalEquityLikeShareWeight: '0', + }, + }, + }) + ); + expect(screen.getByTestId('vote-status')).toHaveTextContent( + 'Set to pass by token vote' + ); + }); + + it('Renders proposal state: Update market proposal - set to fail', () => { + renderComponent( + generateProposal({ + state: ProposalState.STATE_OPEN, + terms: { + change: { + __typename: 'UpdateMarket', + }, + }, + votes: { + yes: { + ...generateYesVotes(0), + totalEquityLikeShareWeight: '0', + }, + no: { + ...generateNoVotes(0), + totalEquityLikeShareWeight: '0', + }, + }, + }) + ); + expect(screen.getByTestId('vote-status')).toHaveTextContent('Set to fail'); + }); + it('Renders proposal state: Open - 5 minutes left to vote', () => { renderComponent( generateProposal({ diff --git a/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.tsx b/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.tsx index 0c17acd97..181d58efd 100644 --- a/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.tsx +++ b/apps/governance/src/routes/proposals/components/proposals-list-item/proposals-list-item-details.tsx @@ -41,12 +41,22 @@ export const ProposalsListItemDetails = ({ proposal: ProposalFieldsFragment | ProposalQuery['proposal']; }) => { const state = proposal?.state; - const { willPassByTokenVote, majorityMet, participationMet } = - useVoteInformation({ - proposal, - }); + const { + willPassByTokenVote, + willPassByLPVote, + majorityMet, + participationMet, + } = useVoteInformation({ + proposal, + }); const { t } = useTranslation(); const { voteState } = useUserVote(proposal?.id); + const isUpdateMarket = proposal?.terms.change.__typename === 'UpdateMarket'; + const updateMarketWillPass = willPassByTokenVote || willPassByLPVote; + const updateMarketVotePassMethod = willPassByTokenVote + ? t('byTokenVote') + : t('byLPVote'); + let proposalStatus: ReactNode; let voteDetails: ReactNode; let voteStatus: ReactNode; @@ -128,6 +138,19 @@ export const ProposalsListItemDetails = ({ ); voteStatus = + (isUpdateMarket && + (updateMarketWillPass ? ( + <> + {t('Set to')}{' '} + + {t('pass')} {updateMarketVotePassMethod} + + + ) : ( + <> + {t('Set to')} {t('fail')} + + ))) || (!participationMet && ) || (!majorityMet && ) || (willPassByTokenVote ? ( diff --git a/apps/governance/src/routes/proposals/components/vote-details/vote-details.tsx b/apps/governance/src/routes/proposals/components/vote-details/vote-details.tsx index 9a96f3c9e..db91ea186 100644 --- a/apps/governance/src/routes/proposals/components/vote-details/vote-details.tsx +++ b/apps/governance/src/routes/proposals/components/vote-details/vote-details.tsx @@ -32,6 +32,7 @@ export const VoteDetails = ({ totalTokensPercentage, participationMet, totalTokensVoted, + totalLPTokensPercentage, noPercentage, noLPPercentage, yesPercentage, @@ -41,6 +42,8 @@ export const VoteDetails = ({ requiredMajorityPercentage, requiredMajorityLPPercentage, requiredParticipation, + requiredParticipationLP, + participationLPMet, } = useVoteInformation({ proposal }); const { t } = useTranslation(); @@ -101,6 +104,25 @@ export const VoteDetails = ({ + +

+ {t('participation')} + {': '} + {participationLPMet ? ( + {t('met')} + ) : ( + {t('notMet')} + )}{' '} + {formatNumber(totalLPTokensPercentage, defaultDecimals)}% + + {requiredParticipationLP && ( + <> + ({formatNumber(requiredParticipationLP, defaultDecimals)}%{' '} + {t('governanceRequired')}) + + )} + +

)}