From 2db4f69ae5a038f890d199eb6071e1088ce58241 Mon Sep 17 00:00:00 2001 From: akiraonstarknet Date: Sat, 7 Sep 2024 11:01:58 +0530 Subject: [PATCH] Fix filters bug --- next.config.mjs | 6 +++--- src/components/Filters.tsx | 6 ++++++ src/components/Pools.tsx | 12 +++++++---- src/components/YieldCard.tsx | 24 ++++++++++++++++++--- src/store/protocols.ts | 42 +++++++++++++++++------------------- 5 files changed, 58 insertions(+), 32 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index c7615d2..0c0fa0a 100755 --- a/next.config.mjs +++ b/next.config.mjs @@ -2,9 +2,9 @@ const nextConfig = { // output: 'export', compiler: { - removeConsole: { - exclude: ['error'], - }, + // removeConsole: { + // exclude: ['error'], + // }, }, async rewrites() { return [ diff --git a/src/components/Filters.tsx b/src/components/Filters.tsx index 5b4d4db..b693e1b 100755 --- a/src/components/Filters.tsx +++ b/src/components/Filters.tsx @@ -135,6 +135,7 @@ export function ProtocolFilters() { export function CategoryFilters() { const updateFilters = useSetAtom(updateFiltersAtom); + const protocolFilters = useAtomValue(filterAtoms.protocolsAtom); const categoriesFilter = useAtomValue(filterAtoms.categoriesAtom); const riskLevelFilters = useAtomValue(filterAtoms.riskAtom); const poolTypeFilters = useAtomValue(filterAtoms.typesAtom); @@ -207,6 +208,11 @@ export function CategoryFilters() { return ( + {/* Protocols: {JSON.stringify(protocolFilters)} + Category: {JSON.stringify(categoriesFilter)} + Risk: {JSON.stringify(riskLevelFilters)} + Types: {JSON.stringify(poolTypeFilters)} */} + {/* Stable pools */} @@ -97,7 +101,7 @@ export default function Pools() { Pool name - {/* { diff --git a/src/components/YieldCard.tsx b/src/components/YieldCard.tsx index 3659ad6..dc8a2f5 100644 --- a/src/components/YieldCard.tsx +++ b/src/components/YieldCard.tsx @@ -31,6 +31,7 @@ import { UserStats, userStatsAtom } from '@/store/utils.atoms'; import { getPoolInfoFromStrategy } from '@/store/protocols'; import { TriangleDownIcon, TriangleUpIcon } from '@chakra-ui/icons'; import { useState } from 'react'; +import mixpanel from 'mixpanel-browser'; interface YieldCardProps { pool: PoolInfo; @@ -363,6 +364,8 @@ function StrategyMobileCard(props: YieldCardProps) { padding={'20px'} gap={2} borderBottom={'1px solid var(--chakra-colors-bg)'} + as={'a'} + {...getLinkProps(pool, props.showProtocolName)} > { + mixpanel.track('Pool clicked', { + pool: pool.pool.name, + protocol: pool.protocol.name, + yield: pool.apr, + risk: pool.additional.riskFactor, + tvl: pool.tvl, + showProtocolName, + }); + }, + }; +} export default function YieldCard(props: YieldCardProps) { const { pool, index } = props; @@ -419,9 +438,8 @@ export default function YieldCard(props: YieldCardProps) { color={'white'} bg={index % 2 == 0 ? 'color1_50p' : 'color2_50p'} display={{ base: 'none', md: 'table-row' }} - as="a" - href={pool.protocol.link} - target="_blank" + as={'a'} + {...getLinkProps(pool, props.showProtocolName)} > { const SORT_OPTIONS = ['DEFAULT', 'APR', 'TVL', 'RISK']; -export const sortAtom = atom( - { - field: SORT_OPTIONS[0], - order: 'asc', - loading: false, - }, - (get, set, args: { field: string; order: 'asc' | 'desc' }) => { - console.log('sorting', 'triggered'); - set(sortAtom, args); - get(filteredPools); - }, -); +export const sortAtom = atom({ + field: SORT_OPTIONS[0], + order: 'asc', +}); export const sortPoolsAtom = atom((get) => { const pools = get(allPoolsAtomWithStrategiesUnSorted); @@ -261,26 +253,32 @@ export const filteredPools = atom((get) => { return pools.filter((pool) => { // category filter - if (categories.includes(ALL_FILTER)) return true; - if (categories.includes(pool.category.valueOf())) return true; + if ( + !categories.includes(ALL_FILTER) && + !categories.includes(pool.category.valueOf()) + ) + return false; // type filter - if (types.includes(ALL_FILTER)) return true; - if (types.includes(pool.type.valueOf())) return true; + if (!types.includes(ALL_FILTER) && !types.includes(pool.type.valueOf())) + return false; // protocol filter - if (protocols.includes(ALL_FILTER)) return true; - if (protocols.includes(pool.protocol.name)) return true; + if ( + !protocols.includes(ALL_FILTER) && + !protocols.includes(pool.protocol.name) + ) + return false; // risk filter - if (riskLevels.includes(ALL_FILTER)) return true; if ( - riskLevels.includes( + !riskLevels.includes(ALL_FILTER) && + !riskLevels.includes( Math.round(pool.additional.riskFactor).toFixed(0).toString(), ) ) { - return true; + return false; } - return false; + return true; }); });