Skip to content

Commit

Permalink
Merge pull request #45 from akiraonstarknet/combine-pools
Browse files Browse the repository at this point in the history
Fix filters bug
  • Loading branch information
akiraonstarknet authored Sep 7, 2024
2 parents 428ed88 + 2db4f69 commit 6926317
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 32 deletions.
6 changes: 3 additions & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
const nextConfig = {
// output: 'export',
compiler: {
removeConsole: {
exclude: ['error'],
},
// removeConsole: {
// exclude: ['error'],
// },
},
async rewrites() {
return [
Expand Down
6 changes: 6 additions & 0 deletions src/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -207,6 +208,11 @@ export function CategoryFilters() {

return (
<Box width={'100%'}>
{/* <Text color={'white'}>Protocols: {JSON.stringify(protocolFilters)}</Text>
<Text color={'white'}>Category: {JSON.stringify(categoriesFilter)}</Text>
<Text color={'white'}>Risk: {JSON.stringify(riskLevelFilters)}</Text>
<Text color={'white'}>Types: {JSON.stringify(poolTypeFilters)}</Text> */}

{/* Stable pools */}
<Tag
size="lg"
Expand Down
12 changes: 8 additions & 4 deletions src/components/Pools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Thead,
Tr,
} from '@chakra-ui/react';
import { useAtomValue } from 'jotai';
import { useAtomValue, useSetAtom } from 'jotai';
import { useMemo } from 'react';
import {
Pagination,
Expand All @@ -24,7 +24,11 @@ import {
PaginationPageGroup,
} from '@ajna/pagination';
import { CategoryFilters, ProtocolFilters } from '@/components/Filters';
import { allPoolsAtomUnSorted, filteredPools } from '@/store/protocols';
import {
allPoolsAtomUnSorted,
filteredPools,
sortAtom,
} from '@/store/protocols';
import YieldCard from './YieldCard';

export default function Pools() {
Expand All @@ -41,7 +45,7 @@ export default function Pools() {
return _filteredPools.slice(startIndex, startIndex + ITEMS_PER_PAGE);
}, [_filteredPools, currentPage]);

// const setSortingOption = useSetAtom(sortAtom);
const setSortingOption = useSetAtom(sortAtom);

return (
<Box float="left" width={'100%'}>
Expand Down Expand Up @@ -97,7 +101,7 @@ export default function Pools() {
<Tr fontSize={'18px'} color={'white'} bg="bg">
<Th>Pool name</Th>
<Th textAlign={'right'}>
{/* <HeaderSorter
{/* <HeaderSorter
heading='APY'
mainColor='color2Text' inActiveColor='#d9d9f726'
onClick={(order: 'asc' | 'desc') => {
Expand Down
24 changes: 21 additions & 3 deletions src/components/YieldCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)}
>
<GridItem colSpan={3} rowSpan={props.showProtocolName ? 2 : 1}>
<StrategyInfo
Expand Down Expand Up @@ -410,6 +413,22 @@ function StrategyMobileCard(props: YieldCardProps) {
);
}

function getLinkProps(pool: PoolInfo, showProtocolName?: boolean) {
return {
href: pool.protocol.link,
target: '_blank',
onClick: () => {
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;

Expand All @@ -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)}
>
<Td>
<StrategyInfo
Expand Down
42 changes: 20 additions & 22 deletions src/store/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,10 @@ export const allPoolsAtomWithStrategiesUnSorted = atom((get) => {

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);
Expand Down Expand Up @@ -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;
});
});

0 comments on commit 6926317

Please sign in to comment.