Skip to content

Commit

Permalink
Merge pull request #216 from DAOmasons/extraConnect
Browse files Browse the repository at this point in the history
connect wallet in vote page
  • Loading branch information
jordanlesich authored Jun 13, 2024
2 parents 72aea34 + 3fc7589 commit 86ec125
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
53 changes: 52 additions & 1 deletion src/components/voting/ShipVotingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ import { useVoting } from '../../hooks/useVoting';
import { useMemo } from 'react';
import { PostedRecord } from '../../queries/getRecordsByTag';
import { formatEther } from 'viem';
import { Avatar, Box, Flex, Paper, Text, useMantineTheme } from '@mantine/core';
import {
Avatar,
Box,
Button,
Flex,
Group,
Modal,
Paper,
Stack,
Text,
useMantineTheme,
} from '@mantine/core';
import { PortfolioReport } from '../dashboard/ship/PortfolioReport';
import { ContestStatus, ReportStatus, VotingStage } from '../../types/common';
import { VotingFooter } from './VotingFooter';
import { FacilitatorFooter } from './FacilitatorFooter';
import { DashGrant } from '../../resolvers/grantResolvers';
import { useAccount, useConnect } from 'wagmi';
import { useDisclosure } from '@mantine/hooks';
import { IconExclamationCircle } from '@tabler/icons-react';

export const ShipVotingPanel = ({
ship,
Expand All @@ -36,6 +50,7 @@ export const ShipVotingPanel = ({
const { contest, contestStatus, refetchGsVotes, votingStage } = useVoting();
const theme = useMantineTheme();
const { userData } = useUserData();
const { isConnected } = useAccount();

const shipChoiceId = useMemo(() => {
return contest?.choices.find((choice) => choice.shipId === ship.id)?.id;
Expand Down Expand Up @@ -103,6 +118,42 @@ export const ShipVotingPanel = ({
isVotingActive={votingStage === VotingStage.Active}
/>
)}
{!isConnected && <IsNotConnected />}
</Box>
);
};

const IsNotConnected = () => {
const [opened, { open, close }] = useDisclosure(false);
const { connect, connectors } = useConnect();

return (
<Box>
<Group justify="flex-end" w="100%" mt="xl">
<Button
onClick={open}
variant="light"
size="md"
leftSection={<IconExclamationCircle />}
>
Connect Wallet
</Button>
</Group>
<Modal opened={opened} onClose={close} centered title="Connect Wallet">
<Stack>
{[...connectors]?.reverse()?.map((connector) => (
<Button
key={connector.uid}
onClick={() => {
close();
connect({ connector });
}}
>
{connector.name}
</Button>
))}
</Stack>
</Modal>
</Box>
);
};
5 changes: 4 additions & 1 deletion src/pages/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Logo from '../assets/Logo.svg?react';

import { IconExclamationCircle } from '@tabler/icons-react';
import { DashGrant } from '../resolvers/grantResolvers';
import { useAccount } from 'wagmi';

export type VotingFormValues = z.infer<typeof votingSchema>;

Expand Down Expand Up @@ -151,6 +152,8 @@ const VotingOpen = ({

const isMobile = useMobile();

const { isConnected } = useAccount();

useEffect(
() => {
if (!ships) return;
Expand Down Expand Up @@ -188,7 +191,7 @@ const VotingOpen = ({
<Flex w="100%">
<MainSection>
<Box pos="relative">
<VoteAffix formValues={form.values} />
{isConnected && <VoteAffix formValues={form.values} />}

<PageTitle title="Vote" />
<Button
Expand Down

0 comments on commit 86ec125

Please sign in to comment.