Skip to content

Commit

Permalink
handle conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanlesich committed Oct 21, 2023
2 parents 27918f2 + 7695580 commit 74f5748
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 108 deletions.
73 changes: 0 additions & 73 deletions apps/web/scripts/start_tunnel.js

This file was deleted.

17 changes: 11 additions & 6 deletions apps/web/src/data/notifsHasura/actions/subscribeToNotif.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { isAddress } from 'viem'

import { AddressType, CHAIN_ID } from 'src/typings'
import { NotificationType } from 'src/typings/pushWebhookTypes'
import { createHasuraClient } from 'src/utils/hasura'
import { isValidNetworkId } from 'src/utils/helpers'
import { createEventId } from 'src/utils/pushWebhook'

import { addEventMutation, addEventUserMutation, addUserMutation } from '../gql/mutations'
import { getEvent, getEventUser } from './getEvent'
import { getUser } from './getUser'

// extra validation to ensure correct data is passed
// if (!isAddress(userAddress)) throw new Error('invalid user address')
// if (!isAddress(collectionAddress)) throw new Error('invalid collection address')
// if (!Object.values(NotificationType)[eventType]) throw new Error('invalid event type')
// if (!isValidNetworkId(chainId)) throw new Error('invalid network id')
export const subscribeToNotif = async (
_userAddress: AddressType,
_collectionAddress: AddressType,
chainId: CHAIN_ID,
eventType: NotificationType
) => {
try {
// extra run-time validation to ensure correct data is passed to db
if (!isAddress(_userAddress)) throw new Error('invalid user address')
if (!isAddress(_collectionAddress)) throw new Error('invalid collection address')
if (!Object.values(NotificationType).includes(eventType))
throw new Error('invalid event type')
if (!isValidNetworkId(chainId)) throw new Error('invalid network id')

const userAddress = _userAddress.toLowerCase() as AddressType
const collectionAddress = _collectionAddress.toLowerCase() as AddressType
const eventId = createEventId(collectionAddress, chainId, eventType)
Expand All @@ -28,7 +33,6 @@ export const subscribeToNotif = async (
await getEvent(eventId),
await getEventUser(eventId, userAddress),
])
console.log({ userExists, eventExists, subscriptionExists })

if (subscriptionExists && userExists && eventExists) {
throw new Error('Already subscribed')
Expand All @@ -50,6 +54,7 @@ export const subscribeToNotif = async (

const client = createHasuraClient()

// uses batch request to ensure all mutations are executed
return await client.batchRequests(batch)
} catch (error: any) {
console.error(error)
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/data/subgraph/queries/dashboardQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ query dashboard($where: DAOTokenOwner_filter, $first: Int, $skip: Int) {
voteEnd
voteStart
expiresAt
votes {
voter
}
}
currentAuction {
...CurrentAuction
Expand Down
46 changes: 46 additions & 0 deletions apps/web/src/data/subgraph/sdk.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ export type DashboardQuery = {
values: Array<any>
snapshotBlockNumber: any
transactionHash: any
votes: Array<{ __typename?: 'ProposalVote'; voter: any }>
dao: { __typename?: 'DAO'; governorAddress: any; tokenAddress: any }
}>
currentAuction?: {
Expand Down Expand Up @@ -2239,6 +2240,24 @@ export type ProposalOgMetadataQuery = {
}>
}

export type ProposalVotesQueryVariables = Exact<{
proposalId: Scalars['ID']
}>

export type ProposalVotesQuery = {
__typename?: 'Query'
proposal?: {
__typename?: 'Proposal'
votes: Array<{
__typename?: 'ProposalVote'
voter: any
support: ProposalVoteSupport
weight: number
reason?: string | null
}>
} | null
}

export type ProposalsQueryVariables = Exact<{
where?: InputMaybe<Proposal_Filter>
first: Scalars['Int']
Expand Down Expand Up @@ -2585,6 +2604,9 @@ export const DashboardDocument = gql`
voteEnd
voteStart
expiresAt
votes {
voter
}
}
currentAuction {
...CurrentAuction
Expand Down Expand Up @@ -2663,6 +2685,16 @@ export const ProposalOgMetadataDocument = gql`
${ProposalFragmentDoc}
${ProposalVoteFragmentDoc}
`
export const ProposalVotesDocument = gql`
query proposalVotes($proposalId: ID!) {
proposal(id: $proposalId) {
votes {
...ProposalVote
}
}
}
${ProposalVoteFragmentDoc}
`
export const ProposalsDocument = gql`
query proposals($where: Proposal_filter, $first: Int!, $skip: Int) {
proposals(
Expand Down Expand Up @@ -2937,6 +2969,20 @@ export function getSdk(
'query'
)
},
proposalVotes(
variables: ProposalVotesQueryVariables,
requestHeaders?: Dom.RequestInit['headers']
): Promise<ProposalVotesQuery> {
return withWrapper(
(wrappedRequestHeaders) =>
client.request<ProposalVotesQuery>(ProposalVotesDocument, variables, {
...requestHeaders,
...wrappedRequestHeaders,
}),
'proposalVotes',
'query'
)
},
proposals(
variables: ProposalsQueryVariables,
requestHeaders?: Dom.RequestInit['headers']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const animation = {
const VOTING_DELAY_AND_PERIOD_AUTHORIZED_USERS = [
'0x7498e6e471f31e869f038D8DBffbDFdf650c3F95',
'0x2767500a75D90D711b2Ac27b3a032a0dAa40e4B2',
'0x3B60e31CFC48a9074CD5bEbb26C9EAa77650a43F',
]

export const AuctionSettingsForm: React.FC<AuctionSettingsFormProps> = ({ title }) => {
Expand Down
74 changes: 63 additions & 11 deletions apps/web/src/modules/dashboard/DaoProposalCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Flex, Text } from '@zoralabs/zord'
import { Box, Flex, PopUp, Text } from '@zoralabs/zord'
import Link from 'next/link'
import { useMemo, useState } from 'react'

import { Icon } from 'src/components/Icon'
import { ProposalState } from 'src/data/contract/requests/getProposalState'
import { ProposalFragment } from 'src/data/subgraph/sdk.generated'
import { AddressType, CHAIN_ID } from 'src/typings'
Expand All @@ -12,18 +14,25 @@ type DaoProposalCardProps = ProposalFragment & {
tokenAddress: AddressType
proposalState: ProposalState
currentChainSlug?: string
userAddress?: AddressType
votes: {
voter: string
}[]
}

export const DaoProposalCard = ({
title,
proposalNumber,
tokenAddress,
chainId,
proposalState,
voteEnd,
voteStart,
expiresAt,
currentChainSlug,
userAddress,
chainId,
proposalId,
votes,
}: DaoProposalCardProps) => {
return (
<Link
Expand All @@ -42,6 +51,7 @@ export const DaoProposalCard = ({
cursor={'pointer'}
py={{ '@initial': 'x3', '@768': 'x6' }}
px={{ '@initial': 'x6', '@768': 'x3' }}
position={'relative'}
>
<Text
fontSize={18}
Expand All @@ -52,15 +62,16 @@ export const DaoProposalCard = ({
>
{proposalNumber}
</Text>

<Text
fontSize={18}
fontWeight="label"
mr={'auto'}
mb={{ '@initial': 'x2', '@768': 'x0' }}
>
{title}
</Text>
<Flex mr={'auto'} align="center" mb={{ '@initial': 'x2', '@768': 'x0' }}>
<Text fontSize={18} fontWeight="label" mr="x2">
{title}
</Text>
<NeedsVote
userAddress={userAddress}
proposalState={proposalState}
votes={votes}
/>
</Flex>
<Flex
justify={'space-between'}
width={{ '@initial': '100%', '@768': 'unset' }}
Expand All @@ -85,3 +96,44 @@ export const DaoProposalCard = ({
</Link>
)
}

type NeedsVoteProps = {
userAddress?: AddressType
proposalState: ProposalState
votes: { voter: string }[]
}
const NeedsVote = ({ userAddress, proposalState, votes }: NeedsVoteProps) => {
const [showTooltip, setShowTooltip] = useState(false)

const hasVoted = useMemo(() => {
if (proposalState !== ProposalState.Active) return undefined

return votes.some((vote) => vote.voter === userAddress?.toLowerCase())
}, [proposalState, votes, userAddress])

if (hasVoted == null) return null

return (
<Flex>
<Box
cursor="pointer"
style={{ zIndex: 102 }}
onMouseOver={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
>
<Icon
id={hasVoted ? 'checkInCircle' : 'warning-16'}
fill={hasVoted ? 'positive' : 'warning'}
style={{
transform: hasVoted ? 'scale(0.8)' : 'scale(1)',
}}
size={hasVoted ? 'md' : 'sm'}
/>
</Box>

<PopUp open={showTooltip} trigger={<></>} placement="right">
<Text>{hasVoted ? 'Vote Submitted' : 'Vote Needed'}</Text>
</PopUp>
</Flex>
)
}
5 changes: 4 additions & 1 deletion apps/web/src/modules/dashboard/DaoProposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react'

import { Avatar } from 'src/components/Avatar'
import { PUBLIC_ALL_CHAINS } from 'src/constants/defaultChains'
import { AddressType } from 'src/typings'

import { DaoProposalCard } from './DaoProposalCard'
import { DashboardDaoProps } from './Dashboard'
Expand All @@ -18,7 +19,8 @@ export const DaoProposals = ({
name,
proposals,
chainId,
}: DashboardDaoProps) => {
userAddress,
}: DashboardDaoProps & { userAddress?: AddressType }) => {
const daoImageSrc = React.useMemo(() => {
return daoImage ? getFetchableUrl(daoImage) : null
}, [daoImage])
Expand Down Expand Up @@ -75,6 +77,7 @@ export const DaoProposals = ({
currentChainSlug={currentChainSlug}
tokenAddress={tokenAddress}
proposalState={proposal.proposalState}
userAddress={userAddress}
/>
))}
</Box>
Expand Down
Loading

0 comments on commit 74f5748

Please sign in to comment.