fix: add back floor to search results (#5087)

* add back floor to search results

* fix search by address

* slice const
This commit is contained in:
Charles Bachmeier 2022-11-04 12:16:35 -07:00 committed by GitHub
parent 4b1b6098f3
commit 7f2bb6c6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

@ -134,6 +134,7 @@ export const SearchBarDropdown = ({
stats: {
total_supply: collection.totalSupply,
one_day_change: collection.floorChange,
floor_price: formatEthPrice(collection.floor?.toString()),
},
}))
.slice(0, isNFTPage ? 3 : 2)

@ -2,6 +2,8 @@ import { isAddress } from '@ethersproject/address'
import { GenieCollection } from '../../types'
const MAX_SEARCH_RESULTS = 6
export const fetchSearchCollections = async (addressOrName: string, recursive = false): Promise<GenieCollection[]> => {
const url = `${process.env.REACT_APP_GENIE_V3_API_URL}/searchCollections`
const isName = !isAddress(addressOrName.toLowerCase())
@ -39,10 +41,21 @@ export const fetchSearchCollections = async (addressOrName: string, recursive =
body: JSON.stringify(payload),
})
if (isName) {
const data = (await r.json()) as { data: GenieCollection[] }
return data?.data ? data.data.slice(0, 6) : []
const data = await r.json()
const formattedData = data?.data
? data.data.map((collection: { stats: Record<string, unknown>; floorPrice: string }) => {
return {
...collection,
stats: {
...collection.stats,
floor_price: collection.floorPrice,
},
}
})
: []
return formattedData.slice(0, MAX_SEARCH_RESULTS)
}
const data = await r.json()
return data.data ? [data.data[0]] : []
return data.data ? [{ ...data.data[0], stats: { ...data.data[0].stats, floor_price: data.data[0].floorPrice } }] : []
}