Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update sort logic for detail modal #2532

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/pages/MarketOverview/DetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { shortenAddress } from 'utils'
import { formatDisplayNumber } from 'utils/numbers'

import { ContentChangable, TabItem } from './styles'
import useFilter from './useFilter'

// () => setShowTokenId(null)
export default function DetailModal({
Expand All @@ -37,6 +38,8 @@ export default function DetailModal({
const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`)
const { data: quoteData } = useGetQuoteByChainQuery()
const [selectedPrice, setSelectedPrice] = useState<'buy' | 'sell'>('buy')
const { filters } = useFilter()
const selectedChainId = filters.chainId

return (
<Modal isOpen={!!tokenToShow} onDismiss={onDismiss} width="100%" maxWidth="600px">
Expand Down Expand Up @@ -180,7 +183,13 @@ export default function DetailModal({

{tokenToShow.tokens
.filter(token => MAINNET_NETWORKS.includes(+token.chainId))
.sort((a, b) => b.priceBuy - a.priceBuy)
.sort((a, b) => {
if (selectedChainId) {
if (+a.chainId === +selectedChainId) return -1
if (+b.chainId === +selectedChainId) return 1
}
return b.priceBuy - a.priceBuy
})
.map(token => {
const quoteSymbol = quoteData?.data?.onchainPrice?.usdQuoteTokenByChainId?.[token.chainId]?.symbol
const address =
Expand Down Expand Up @@ -323,7 +332,7 @@ export const PriceChange = ({ priceChange }: { priceChange: number | undefined }
animate={!!lastPriceChange && animate}
up={!!lastPriceChange && !!priceChange && priceChange - lastPriceChange >= 0}
>
{!priceChange ? '--' : priceChange.toFixed(2) + '%'}
{!priceChange ? '--' : formatDisplayNumber(priceChange, { style: 'decimal', fractionDigits: 2 }) + '%'}
</ContentChangable>
)
}
9 changes: 5 additions & 4 deletions src/pages/MarketOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ButtonEmpty } from 'components/Button'
import Divider from 'components/Divider'
import InfoHelper from 'components/InfoHelper'
import Pagination from 'components/Pagination'
import SearchInput from 'components/SearchInput'
import Search from 'components/Search'
import { MouseoverTooltip } from 'components/Tooltip'
import { MAINNET_NETWORKS } from 'constants/networks'
import { NETWORKS_INFO } from 'hooks/useChainsConfig'
Expand Down Expand Up @@ -152,10 +152,11 @@ export default function MarketOverview() {
</Tag>
))}
</Flex>
<SearchInput
<Search
placeholder="Search by token name, symbol or address"
value={input}
onChange={val => setInput(val)}
searchValue={input}
allowClear
onSearch={val => setInput(val)}
style={{ height: '36px' }}
/>
</Flex>
Expand Down
Loading