Skip to content

Commit

Permalink
Fix error handling and other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Aug 28, 2023
1 parent dc10a50 commit fb4a88d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/data/subgraph/requests/daoQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const myDaosRequest = async (
): Promise<MyDaosResponse | undefined> => {
let daos: MyDaosResponse = []

if (!memberAddress) return
if (!memberAddress) throw new Error('No user address provided')

try {
const data = await Promise.all(
Expand Down
50 changes: 30 additions & 20 deletions apps/web/src/data/subgraph/requests/exploreQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,41 @@ import {
} from '../sdk.generated'
import { MyDaosResponse } from './daoQuery'

export type ExploreDaoWithChainId = ExploreDaoFragment & { chainId?: CHAIN_ID }
export type ExploreDaoWithChainId = ExploreDaoFragment & { chainId: CHAIN_ID }

export interface ExploreDaosResponse {
daos: ExploreDaoWithChainId[]
hasNextPage: boolean
}

export const userDaosFilter = async (
export const exploreMyDaosRequest = async (
memberAddress: string
): Promise<ExploreDaosResponse | undefined> => {
const userDaos = await axios
.get<MyDaosResponse>(`/api/daos/${memberAddress}`)
.then((x) => x.data)

const daoChains = new Set(userDaos.map((x) => x.chainId))

const data = await Promise.all(
Array.from(daoChains).map(async (chainId) => {
const daosByChain = userDaos
.filter((x) => x.chainId === chainId)
.map((x) => x.collectionAddress)
const res = await SDK.connect(chainId).myDaosPage({ daos: daosByChain })
return res.auctions.map((x) => ({ ...x, chainId }))
})
)
try {
const userDaos = await axios
.get<MyDaosResponse>(`/api/daos/${memberAddress}`)
.then((x) => x.data)

const daoChains = new Set(userDaos.map((x) => x.chainId))

const data = await Promise.all(
Array.from(daoChains).map(async (chainId) => {
const daosByChain = userDaos
.filter((x) => x.chainId === chainId)
.map((x) => x.collectionAddress)
const res = await SDK.connect(chainId).myDaosPage({ daos: daosByChain })
return res.auctions.map((x) => ({ ...x, chainId }))
})
)

const auctions = data.flat().sort((a, b) => a.dao.name.localeCompare(b.dao.name))
return { daos: auctions, hasNextPage: false }
const auctions = data.flat().sort((a, b) => a.dao.name.localeCompare(b.dao.name))
return { daos: auctions, hasNextPage: false }
} catch (error) {
console.error(error)
Sentry.captureException(error)
await Sentry.flush(2000)
return undefined
}
}

export const exploreDaosRequest = async (
Expand Down Expand Up @@ -86,7 +93,10 @@ export const exploreDaosRequest = async (
})

if (!data.auctions) return undefined
return { daos: data.auctions, hasNextPage: data.auctions.length === first }
return {
daos: data.auctions.map((x) => ({ ...x, chainId })),
hasNextPage: data.auctions.length === first,
}
} catch (error) {
console.error(error)
Sentry.captureException(error)
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/modules/dao/components/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const About: React.FC = () => {
Founders
</Text>

{typeof founders !== 'undefined' && founders?.length > 0 ? (
{founders && founders?.length > 0 ? (
<Grid columns={isMobile ? 1 : 2} mt="x6" gap="x4">
{founders
.filter((founder) => founder.ownershipPct > 0)
Expand Down
8 changes: 3 additions & 5 deletions apps/web/src/modules/dao/components/Explore/ExploreMyDaos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import useSWR from 'swr'

import SWR_KEYS from 'src/constants/swrKeys'
import { userDaosFilter } from 'src/data/subgraph/requests/exploreQueries'
import { exploreMyDaosRequest } from 'src/data/subgraph/requests/exploreQueries'
import { useLayoutStore } from 'src/stores'

import { DaoCard } from '../DaoCard'
Expand All @@ -18,7 +18,7 @@ export const ExploreMyDaos = () => {

const { data, error, isValidating } = useSWR(
signerAddress ? [SWR_KEYS.DYNAMIC.MY_DAOS_PAGE(signerAddress as string)] : null,
() => userDaosFilter(signerAddress as string),
() => exploreMyDaosRequest(signerAddress as string),
{ revalidateOnFocus: false }
)

Expand All @@ -35,11 +35,9 @@ export const ExploreMyDaos = () => {
const bid = dao.highestBid?.amount ?? undefined
const bidInEth = bid ? ethers.utils.formatEther(bid) : undefined

if (!dao.chainId) return null

return (
<DaoCard
chainId={dao.chainId}
chainId={dao.chainId!}
tokenId={dao.token?.tokenId ?? undefined}
key={dao.dao.tokenAddress}
tokenImage={dao.token?.image ?? undefined}
Expand Down

0 comments on commit fb4a88d

Please sign in to comment.