Skip to content

Commit

Permalink
Merge pull request #441 from cardano-foundation/feat/make-vote-contex…
Browse files Browse the repository at this point in the history
…t-optional

feat(cip-1694-ui): make vote context optional
  • Loading branch information
vetalcore authored Oct 9, 2023
2 parents 49b48d6 + f30729a commit 056718c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
20 changes: 9 additions & 11 deletions ui/cip-1694/src/pages/Vote/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const VotePage = () => {
const numOfCategories = event?.categories?.length;
const activeCategoryIndex = findIndex(event?.categories, ['id', activeCategoryId]);
const [isToggledReceipt, toggleReceipt] = useToggle(false);
const couldAddContext = activeCategoryIndex === 0 && isReceiptFetched && !receipt;
const dispatch = useDispatch();

const fetchChainTip = useCallback(async () => {
Expand Down Expand Up @@ -232,6 +233,8 @@ export const VotePage = () => {
});
} catch (error) {
console.log(error?.message || error);
} finally {
setVoteContext('');
}
}, [voteContext]);

Expand Down Expand Up @@ -266,7 +269,9 @@ export const VotePage = () => {
const requestVoteObject = await signMessagePromisified(canonicalVoteInput);
await voteService.castAVoteWithDigitalSignature(requestVoteObject);
dispatch(setIsVoteSubmittedModalVisible({ isVisible: true }));
await submitVoteContextForm();
if (couldAddContext && voteContext) {
await submitVoteContextForm();
}
setVoteSubmitted(true);
if (numOfCategories === 1 || activeCategoryIndex === numOfCategories - 1) {
await fetchReceipt({});
Expand Down Expand Up @@ -307,7 +312,6 @@ export const VotePage = () => {
const showSubmitButton =
event && isConnected && event?.notStarted === false && event?.finished === false && !showViewReceiptButton;
const showPagination = isConnected && receipt && activeCategoryId === receipt?.category && numOfCategories > 1;
const shouldAddContext = activeCategoryIndex === 0 && isReceiptFetched && !receipt;

return (
<>
Expand Down Expand Up @@ -386,7 +390,7 @@ export const VotePage = () => {
onChangeOption={onChangeOption}
/>
</Grid>
{shouldAddContext && (
{couldAddContext && (
<Grid item>
<VoteContextInput
disabled={!optionId}
Expand Down Expand Up @@ -456,17 +460,11 @@ export const VotePage = () => {
{showSubmitButton && (
<Button
className={cn(styles.button, {
[styles.disabled]: !optionId || !isReceiptFetched || (shouldAddContext && !voteContext),
[styles.disabled]: !optionId || !isReceiptFetched,
})}
size="large"
variant="contained"
disabled={
!optionId ||
!isReceiptFetched ||
isCastingAVote ||
!tip?.absoluteSlot ||
(shouldAddContext && !voteContext)
}
disabled={!optionId || !isReceiptFetched || isCastingAVote || !tip?.absoluteSlot}
onClick={() => handleSubmit()}
data-testid="proposal-submit-button"
>
Expand Down
10 changes: 1 addition & 9 deletions ui/cip-1694/src/pages/Vote/__tests__/Vote.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ describe('For ongoing event:', () => {

const cta = within(votePage).queryByTestId('proposal-submit-button');
expect(cta).not.toBeNull();
expect(cta.closest('button')).toBeDisabled();

expect(within(votePage).queryByTestId('vote-context-label').textContent).toEqual(
'Do you have any additional comments or details about your voting decision?'
Expand Down Expand Up @@ -509,19 +508,12 @@ describe('For ongoing event:', () => {
fireEvent.click(options[0]);
});

const voteContext = 'voteContext';

await act(async () => {
fireEvent.change(screen.queryByTestId('vote-context-input').querySelector('textarea'), {
target: { value: voteContext },
});
});

const cta = within(votePage).queryByTestId('proposal-submit-button');
await act(async () => {
fireEvent.click(cta);
});

expect(mockSubmitVoteContextForm).not.toBeCalled();
expect(mockGetVoteReceipt).toBeCalledTimes(2);
});

Expand Down

0 comments on commit 056718c

Please sign in to comment.