Skip to content

Commit

Permalink
Merge remote-tracking branch 'clearcontracts/main' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
mesudip committed Nov 27, 2024
2 parents 90b0e19 + 9e5f461 commit 53e55c6
Show file tree
Hide file tree
Showing 34 changed files with 505 additions and 140 deletions.
6 changes: 0 additions & 6 deletions __mocks__/getRepresentatives/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const getRepresentativesHandlers = [
is_alternate: false,
workshop_id: BigInt(1).toString(),
email: '[email protected]',
color: '#000000',
wallet_address: 'addr1isdufnpoasidjfopmaimdfmopisadj',
name: 'John Johnson',
},
Expand All @@ -21,7 +20,6 @@ export const getRepresentativesHandlers = [
is_alternate: true,
workshop_id: BigInt(1).toString(),
email: '[email protected]',
color: '#000000',
wallet_address: 'addr1oqwieuroijfvaondsfipoaapoidjf',
name: 'Mike Mickelson',
},
Expand All @@ -32,7 +30,6 @@ export const getRepresentativesHandlers = [
is_alternate: false,
workshop_id: BigInt(2).toString(),
email: '[email protected]',
color: '#000000',
wallet_address: 'addr1kidjfsadjfoadspjfoaidsfadsop',
name: 'Jack Jackson',
},
Expand All @@ -43,7 +40,6 @@ export const getRepresentativesHandlers = [
is_alternate: true,
workshop_id: BigInt(2).toString(),
email: '[email protected]',
color: '#000000',
wallet_address: 'addr1iwoiuwqxpoieujsoidpjfkfjhpqowmfoa',
name: 'Robert Robertson',
},
Expand All @@ -54,7 +50,6 @@ export const getRepresentativesHandlers = [
is_alternate: false,
workshop_id: BigInt(3).toString(),
email: '[email protected]',
color: '#000000',
wallet_address: 'addr1opijpoiuoimnlkjipoujpoimlkkm',
name: 'Connor Connorson',
},
Expand All @@ -65,7 +60,6 @@ export const getRepresentativesHandlers = [
is_alternate: true,
workshop_id: BigInt(3).toString(),
email: '[email protected]',
color: '#000000',
wallet_address: 'addr1adfasdfwerwqersdvfzxfvsadf',
name: 'Kyle Kyleson',
},
Expand Down
20 changes: 10 additions & 10 deletions __mocks__/updateUser/errorHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const updateUserActiveVoteHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message:
'You cannot update user information while a Poll is actively voting.',
},
Expand All @@ -17,7 +17,7 @@ export const updateUserNoNameHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Name must be provided.',
},
{ status: 400 },
Expand All @@ -29,7 +29,7 @@ export const updateUserNoEmailHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Email must be provided.',
},
{ status: 400 },
Expand All @@ -41,7 +41,7 @@ export const updateUserNoWalletAddressHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Wallet address must be provided.',
},
{ status: 400 },
Expand All @@ -53,7 +53,7 @@ export const updateUserTooLongNameHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Name must be less than 100 characters.',
},
{ status: 400 },
Expand All @@ -65,7 +65,7 @@ export const updateUserTooLongEmailHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Email must be less than 100 characters.',
},
{ status: 400 },
Expand All @@ -77,7 +77,7 @@ export const updateUserTooLongWalletAddressHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Wallet Address must be less than 100 characters.',
},
{ status: 400 },
Expand All @@ -89,7 +89,7 @@ export const updateUserInternalErrorHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
pollId: BigInt(-1).toString(),
userId: BigInt(-1).toString(),
message: 'Error updating User Information.',
},
{ status: 500 },
Expand All @@ -101,7 +101,7 @@ export const updateUserInvalidSessionHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
success: false,
userId: BigInt(-1).toString(),
message:
'You must be signed in as an Organizer update user information.',
},
Expand All @@ -114,7 +114,7 @@ export const updateUserNotOrganizerHandler = [
http.post('/api/updateUser', async () => {
return HttpResponse.json(
{
success: false,
userId: BigInt(-1).toString(),
message: 'You must be an Organizer to update user information.',
},
{ status: 401 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Toaster } from 'react-hot-toast';
import { expect, test } from 'vitest';

import { ManageRepresentativesTable } from '@/components/coordinator/manageRepresentativesTable';

test('strips whitespace from wallet address', async () => {
const user = userEvent.setup();
render(
<>
<Toaster />
<ManageRepresentativesTable toggleRefresh={() => {}} />
</>,
);

const editButton = await screen.findByTestId('edit-representative-info-1');
await user.click(editButton);

const input = screen.getByDisplayValue('addr1isdufnpoasidjfopmaimdfmopisadj');
await user.clear(input);
await user.type(input, ' coStakeAddress ');

const saveButton = await screen.findByTestId('save-representative-info-1');
await user.click(saveButton);

// Wait for the success toast to appear
const successToast = await screen.findByText('User info updated!');
expect(successToast).toBeDefined();

const newWalletAddress = await screen.findByText('coStakeAddress');
expect(newWalletAddress).toBeDefined();
});
Binary file added public/cardano.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 62 additions & 14 deletions src/components/buttons/connectWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ import { paths } from '@/paths';
import { connectWallet } from '@/lib/connectWallet';
import { getUser } from '@/lib/helpers/getUser';

interface Props {
isHomepage?: boolean;
}

/**
* A button to connect a wallet to a variety of cip-30 compatible wallets
* @returns Connect Wallet Button
*/
export function ConnectWalletButton(): JSX.Element {
export function ConnectWalletButton(props: Props): JSX.Element {
const { isHomepage } = props;
const [open, setOpen] = useState(false);
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [connecting, setConnecting] = useState(false);
Expand Down Expand Up @@ -192,16 +197,34 @@ export function ConnectWalletButton(): JSX.Element {
</Typography>
)}
<Button
variant={session.status === 'authenticated' ? 'outlined' : 'contained'}
color={session.status === 'authenticated' ? 'success' : 'secondary'}
variant={isHomepage ? 'contained' : 'outlined'}
color={
isHomepage
? 'secondary'
: session.status === 'authenticated'
? 'success'
: 'warning'
}
sx={{
px: isHomepage
? {
xs: 12,
sm: 16,
}
: 2,
py: isHomepage ? 2 : 1,
borderRadius: '40px',
}}
disabled={connecting}
id="connect-wallet"
aria-controls={open ? 'basic-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
endIcon={
session.status === 'authenticated' ? (
isHomepage ? (
<></>
) : session.status === 'authenticated' ? (
<Box
sx={{
fontSize: '0.85rem !important',
Expand All @@ -212,39 +235,64 @@ export function ConnectWalletButton(): JSX.Element {
<CircleRounded fontSize="inherit" />
</Box>
) : (
<></>
<Box
sx={{
fontSize: '0.85rem !important',
}}
justifyContent="center"
display="flex"
>
<CircleRounded fontSize="inherit" />
</Box>
)
}
data-testid="connect-wallet-button"
>
<Typography
noWrap
sx={{
maxWidth: '150px',
textWrap: 'nowrap',
textOverflow: 'ellipsis',
minWidth: '70px',
overflow: 'hidden',
color:
session.status === 'authenticated'
? theme.palette.success.main
: theme.palette.text.secondary,
fontWeight: 500,
color: isHomepage
? theme.palette.secondary.contrastText
: theme.palette.success.contrastText,
}}
>
{session.status === 'authenticated'
? session.data.user.stakeAddress
: 'Connect Wallet'}
? session.data.user.name
: isHomepage
? 'Connect a wallet'
: '-'}
</Typography>
</Button>
{session.status === 'authenticated' && (
{isHomepage ? (
<></>
) : session.status === 'authenticated' ? (
<Typography
color="success"
fontWeight="500"
display={{
xs: 'none',
md: 'flex',
}}
>
Wallet connected
</Typography>
) : (
<Typography
color="warning"
fontWeight="500"
display={{
xs: 'none',
md: 'flex',
}}
>
Wallet not connected
</Typography>
)}

{wallets}
</Box>
);
Expand Down
5 changes: 2 additions & 3 deletions src/components/buttons/deletePollButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from 'react';
import { useRouter } from 'next/router';
import { DeleteRounded } from '@mui/icons-material';
import Button from '@mui/material/Button';
import { useSession } from 'next-auth/react';
import toast from 'react-hot-toast';
Expand Down Expand Up @@ -45,12 +44,12 @@ export function DeletePollButton(props: Props): JSX.Element {
return (
<Button
onClick={handleDeleteVote}
variant="text"
variant="contained"
disabled={isSubmitting}
data-testid="delete-poll-button"
color="error"
>
<DeleteRounded />
Yes, Delete
</Button>
);
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/components/buttons/downloadPollVotesButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export function DownloadPollVotesButton(props: Props): JSX.Element {
return (
<Button
type="button"
variant="contained"
variant="outlined"
color="primary"
onClick={handleClick}
data-testid="download-poll-votes-btn"
>
Download Votes
Download CSV
</Button>
);
}
5 changes: 3 additions & 2 deletions src/components/buttons/downloadUserVotesButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export function DownloadUserVotesButton(props: Props): JSX.Element {
return (
<Button
type="button"
variant="contained"
variant="outlined"
color="primary"
onClick={handleClick}
data-testid="download-user-votes-btn"
>
Download Votes
Download CSV
</Button>
);
}
Loading

0 comments on commit 53e55c6

Please sign in to comment.