Skip to content
Open

Fixes #373

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
4 changes: 2 additions & 2 deletions src/components/Aggregator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const Routes = styled.div<{ visible: boolean }>`
text-align: left;
overflow-y: scroll;
width: 100%;
min-height: 100%;
height: 100%;
overflow-x: hidden;
align-self: stretch;
max-width: 30rem;
Expand Down Expand Up @@ -611,7 +611,7 @@ export function AggregatorContainer() {
!Number.isNaN(Number(balance.data.formatted)) &&
balance.data.value &&
selectedRoute?.fromAmount
? +selectedRoute.fromAmount > Number(balance.data.value)
? +Number(selectedRoute.fromAmount) > Number(balance.data.value)
: false;

const slippageIsWorng = Number.isNaN(Number(slippage)) || slippage === '';
Expand Down
29 changes: 28 additions & 1 deletion src/components/Icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,31 @@ const SmolCheck = (
</svg>
);

export { GasIcon, CrossIcon, ArrowIcon, AggIcons, LlamaIcon, SmolCheck };
const UpDownArrow = (props) => (
<div style={{ display: 'inline-block', marginLeft: '4px' }}>
<svg
viewBox="0 0 1024 1024"
width="10px"
focusable="false"
data-icon="caret-up"
fill="gray"
aria-hidden="true"
style={{ position: 'relative', top: '0.7px' }}
>
<path d="M858.9 689L530.5 308.2c-9.4-10.9-27.5-10.9-37 0L165.1 689c-12.2 14.2-1.2 35 18.5 35h656.8c19.7 0 30.7-20.8 18.5-35z"></path>
</svg>
<svg
viewBox="0 0 1024 1024"
width="10px"
focusable="false"
data-icon="caret-down"
fill="gray"
aria-hidden="true"
style={{ position: 'relative', bottom: '0.7px' }}
>
<path d="M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"></path>
</svg>
</div>
);

export { GasIcon, CrossIcon, ArrowIcon, AggIcons, LlamaIcon, SmolCheck, UpDownArrow };
77 changes: 40 additions & 37 deletions src/components/Lending/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { last } from 'lodash';
import { ArrowDownIcon, ArrowUpIcon, ExternalLinkIcon, QuestionIcon } from '@chakra-ui/icons';
import { IPool } from '~/types';
import { useLendingProps } from '~/queries/useLendingProps';
import NextLink from 'next/link';

const ChainIcon = styled.img`
width: 24px;
Expand All @@ -31,45 +32,47 @@ const YieldsRow = ({ data, index, style, amountsProvided }) => {
} = row;

return (
<RowContainer style={style} onClick={() => (url ? window.open(url, '_blank') : null)}>
<YieldsCell style={{ marginLeft: '24px', minWidth: '50px' }}>
<Tooltip label={row.chain} aria-label={row.chain} placement="top">
<RowContainer style={style}>
<NextLink href={url ?? '/'} target="_blank" rel="noreferrer noopener">
<YieldsCell style={{ marginLeft: '24px', minWidth: '50px' }}>
<Tooltip label={row.chain} aria-label={row.chain} placement="top">
<ChainIcon
src={`https://icons.llamao.fi/icons/chains/rsz_${row.chain.toLowerCase()}?w=48&h=48`}
alt={row.chain}
/>
</Tooltip>
</YieldsCell>
<YieldsCell style={{ overflow: 'hidden', display: 'block', textAlign: 'center' }}>
<Tooltip label={`${row.symbol} ➞ ${row.borrowPool?.symbol}`} aria-label={row.symbol} placement="top">
<span>
{row.symbol} ➞ {row.borrowPool?.symbol}
</span>
</Tooltip>
</YieldsCell>
<YieldsCell>
<ChainIcon
src={`https://icons.llamao.fi/icons/chains/rsz_${row.chain.toLowerCase()}?w=48&h=48`}
alt={row.chain}
src={`https://icons.llamao.fi/icons/protocols/${row.project}?w=48&h=48`}
style={{ position: 'absolute' }}
alt={row.project}
/>
</Tooltip>
</YieldsCell>
<YieldsCell style={{ overflow: 'hidden', display: 'block', textAlign: 'center' }}>
<Tooltip label={`${row.symbol} ➞ ${row.borrowPool?.symbol}`} aria-label={row.symbol} placement="top">
<span>
{row.symbol} ➞ {row.borrowPool?.symbol}
</span>
</Tooltip>
</YieldsCell>
<YieldsCell>
<ChainIcon
src={`https://icons.llamao.fi/icons/protocols/${row.project}?w=48&h=48`}
style={{ position: 'absolute' }}
alt={row.project}
/>
<span style={{ marginLeft: '28px' }}>{name}</span>
</YieldsCell>
<YieldsCell
style={{
color: amountsProvided ? (row.totalApy > 0 ? 'rgba(0, 255, 0, 0.6)' : 'rgba(255, 0, 0, 0.6)') : undefined
}}
>
{amountsProvided ? (
row.totalApy?.toFixed(2) + '%'
) : (
<Tooltip label="Please provide the amount you'd like to lend and borrow to see the APY.">
<QuestionIcon width="16px" height="16px" />
</Tooltip>
)}
</YieldsCell>
<YieldsCell>{'$' + formatAmountString(row.borrowPool?.totalAvailableUsd)}</YieldsCell>
<YieldsCell>{formatAmountString(row?.ltv * 100)}%</YieldsCell>
<span style={{ marginLeft: '28px' }}>{name}</span>
</YieldsCell>
<YieldsCell
style={{
color: amountsProvided ? (row.totalApy > 0 ? 'rgba(0, 255, 0, 0.6)' : 'rgba(255, 0, 0, 0.6)') : undefined
}}
>
{amountsProvided ? (
row.totalApy?.toFixed(2) + '%'
) : (
<Tooltip label="Please provide the amount you'd like to lend and borrow to see the APY.">
<QuestionIcon width="16px" height="16px" />
</Tooltip>
)}
</YieldsCell>
<YieldsCell>{'$' + formatAmountString(row.borrowPool?.totalAvailableUsd)}</YieldsCell>
<YieldsCell>{formatAmountString(row?.ltv * 100)}%</YieldsCell>
</NextLink>
</RowContainer>
);
};
Expand Down
121 changes: 70 additions & 51 deletions src/components/Yields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Filter } from 'react-feather';
import { ArrowBackIcon, ArrowDownIcon, ArrowUpIcon } from '@chakra-ui/icons';
import { useYieldProps } from '~/queries/useYieldProps';
import { useGetTokenList } from '~/queries/useGetTokenList';
import Link from 'next/link';
import { UpDownArrow } from '../Icons';

const ChainIcon = styled.img`
width: 24px;
Expand All @@ -23,30 +25,29 @@ const ChainIcon = styled.img`
`;

const YieldsRow = ({ data, index, style }) => (
<RowContainer
style={style}
onClick={() => window?.open(`https://defillama.com/yields/pool/${data[index].pool}`, '_blank')}
>
<YieldsCell>
<Tooltip label={data[index].symbol} placement={'top'}>
{data[index].symbol}
</Tooltip>
</YieldsCell>
<YieldsCell style={{ marginLeft: '30px' }}>
<ChainIcon
src={`https://icons.llamao.fi/icons/protocols/${data[index].project}?w=48&h=48`}
alt={data[index].project}
/>
</YieldsCell>
<YieldsCell style={{ marginLeft: '30px' }}>
<ChainIcon
src={`https://icons.llamao.fi/icons/chains/rsz_${data[index].chain.toLowerCase()}?w=48&h=48`}
alt={data[index].chain}
/>
</YieldsCell>
<YieldsCell>{data[index].apyMean30d.toFixed(2)}%</YieldsCell>
<YieldsCell>{'$' + formatAmountString(data[index].tvlUsd)}</YieldsCell>
</RowContainer>
<Link href={`https://defillama.com/yields/pool/${data[index].pool}`} target="_blank" rel="noreferrer noopener">
<RowContainer style={style}>
<YieldsCell>
<Tooltip label={data[index].symbol} placement={'top'}>
{data[index].symbol}
</Tooltip>
</YieldsCell>
<YieldsCell style={{ marginLeft: '30px' }}>
<ChainIcon
src={`https://icons.llamao.fi/icons/protocols/${data[index].project}?w=48&h=48`}
alt={data[index].project}
/>
</YieldsCell>
<YieldsCell style={{ marginLeft: '30px' }}>
<ChainIcon
src={`https://icons.llamao.fi/icons/chains/rsz_${data[index].chain.toLowerCase()}?w=48&h=48`}
alt={data[index].chain}
/>
</YieldsCell>
<YieldsCell>{data[index].apyMean30d.toFixed(2)}%</YieldsCell>
<YieldsCell>{'$' + formatAmountString(data[index].tvlUsd)}</YieldsCell>
</RowContainer>
</Link>
);

const Yields = ({ tokens, isLoading, data: { data: initialData, config } }) => {
Expand Down Expand Up @@ -133,39 +134,47 @@ const Yields = ({ tokens, isLoading, data: { data: initialData, config } }) => {
/>
) : (
<div>
<ArrowBackIcon
width={'24px'}
height={'24px'}
ml="-4px"
mb="1"
cursor={'pointer'}
onClick={() => {
setIsSearch(true);
router?.push({ query: { ...router.query, tab: 'earn', search: '' } }, undefined, { shallow: true });
}}
/>
<Box display={'flex'} justifyContent={'space-between'} alignItems={'center'} mb="6">
<Text display={'flex'} fontSize={'20px'} gap="4px">
Earn with{' '}
<Text fontWeight={'500'} color={'gray.500'}>
{search}
<div style={{ display: 'flex', alignItems: 'center', marginBottom: '6px' }}>
<ArrowBackIcon
width={'24px'}
height={'24px'}
mr="4px"
mb="1"
cursor={'pointer'}
onClick={() => {
setIsSearch(true);
router?.push({ query: { ...router.query, tab: 'earn', search: '' } }, undefined, {
shallow: true
});
}}
/>
<Box display={'flex'} justifyContent={'space-between'} alignItems={'center'} width={'100%'}>
<Text display={'flex'} fontSize={'20px'} gap="4px">
Earn with{' '}
<Text fontWeight={'500'} color={'gray.500'}>
{search}
</Text>
</Text>
</Text>

<IconButton
aria-label="Filters"
icon={<Filter />}
bgColor={'rgb(20, 22, 25)'}
onClick={() => setShowFilters(true)}
/>
</Box>
<IconButton
aria-label="Filters"
icon={<Filter />}
bgColor={'inherit'}
onClick={() => setShowFilters(true)}
/>
</Box>
</div>

<Divider width="100%" position="absolute" top="108px" left="0" borderColor={'#2C2F36'} />
<ColumnHeader>
<YieldsCell>Symbol</YieldsCell>
<YieldsCell>Project</YieldsCell>
<YieldsCell style={{ marginLeft: '16px' }}>Chain</YieldsCell>
<YieldsCell
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
marginLeft: '20px',
minWidth: '90px',
color: sortBy === 'apyMean30d' ? 'white' : 'inherit',
Expand All @@ -181,11 +190,19 @@ const Yields = ({ tokens, isLoading, data: { data: initialData, config } }) => {
) : (
<ArrowDownIcon mb="1" />
)
) : null}
) : (
<UpDownArrow />
)}
</YieldsCell>
<YieldsCell
onClick={() => handleSort('tvlUsd')}
style={{ color: sortBy === 'tvlUsd' ? 'white' : 'inherit', cursor: 'pointer' }}
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
color: sortBy === 'tvlUsd' ? 'white' : 'inherit',
cursor: 'pointer'
}}
>
TVL{' '}
{sortBy === 'tvlUsd' ? (
Expand All @@ -194,7 +211,9 @@ const Yields = ({ tokens, isLoading, data: { data: initialData, config } }) => {
) : (
<ArrowDownIcon mb="1" />
)
) : null}
) : (
<UpDownArrow />
)}
</YieldsCell>
</ColumnHeader>
{data?.length ? (
Expand Down
10 changes: 6 additions & 4 deletions src/queries/useGetRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export async function getAdapterRoutes({ adapter, chain, from, to, amount, extra
: adapter.getQuote;
if (adapter.isOutputAvailable) {
price = await quouteFunc(chain, from, to, amount, extra);
if (price) {
amountIn = price.amountIn;
if (!price.amountIn) {
console.error(`${adapter.name} returned price without amountIn for output trade`);
return defaultRouteResponse({ adapter, amount });
}
amountIn = price.amountIn;
} else if (isOutputDefined && !adapter.isOutputAvailable) {
return defaultRouteResponse({ adapter, amount });
} else {
Expand All @@ -94,7 +96,7 @@ export async function getAdapterRoutes({ adapter, chain, from, to, amount, extra
return defaultRouteResponse({ adapter, amount });
}

if (!amountIn) throw Error('amountIn is not defined');
if (!amountIn || amountIn === '0') throw Error('amountIn is not defined');

const txData = adapter?.getTxData?.(price) ?? '';
let l1Gas: number | 'Unknown' = 0;
Expand Down Expand Up @@ -171,7 +173,7 @@ export function useGetRoutes({
lastFetched:
res
.filter((d) => d.isSuccess && !d.isFetching && d.dataUpdatedAt > 0)
.sort((a, b) => a.dataUpdatedAt - b.dataUpdatedAt)?.[0]?.dataUpdatedAt ?? Date.now(),
.sort((a, b) => b.dataUpdatedAt - a.dataUpdatedAt)?.[0]?.dataUpdatedAt ?? Date.now(),
loadingRoutes,
data,
isLoading: res.length > 0 && data.length === 0
Expand Down