Skip to content

Commit

Permalink
feat: Get all vaults from multiple chains
Browse files Browse the repository at this point in the history
  • Loading branch information
karelianpie committed Sep 25, 2023
1 parent fa0faf5 commit cd7d604
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/common/contexts/useYearn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const YearnContext = createContext<TYearnContext>({
export const YearnContextApp = memo(function YearnContextApp({children}: { children: ReactElement }): ReactElement {
const {safeChainID} = useChainID();
const {yDaemonBaseUri} = useYDaemonBaseURI({chainID: safeChainID});
const {yDaemonBaseUri: yDaemonBaseUriWithoutChain} = useYDaemonBaseURI();
const result = useYDaemonStatus({chainID: safeChainID});
const {address, currentPartner} = useWeb3();
const [zapSlippage, set_zapSlippage] = useLocalStorage<number>('yearn.fi/zap-slippage', DEFAULT_SLIPPAGE);
Expand All @@ -91,14 +92,14 @@ export const YearnContextApp = memo(function YearnContextApp({children}: { child
});

const {data: vaults, isLoading: isLoadingVaultList, mutate: mutateVaultList} = useFetch<TYDaemonVaults>({
endpoint: `${yDaemonBaseUri}/vaults/all?${new URLSearchParams({
endpoint: `${yDaemonBaseUriWithoutChain}/vaults/all?${new URLSearchParams({
hideAlways: 'true',
orderBy: 'apy.net_apy',
orderDirection: 'desc',
strategiesDetails: 'withDetails',
strategiesRisk: 'withRisk',
strategiesCondition: 'inQueue'
})}`,
})}&chainIDs=${[1, 10].join(',')}`,
schema: yDaemonVaultsSchema
});

Expand Down
15 changes: 13 additions & 2 deletions apps/vaults/components/list/VaultsListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import Link from 'next/link';
import {useStakingRewards} from '@vaults/contexts/useStakingRewards';
import {Renderable} from '@yearn-finance/web-lib/components/Renderable';
import {useChainID} from '@yearn-finance/web-lib/hooks/useChainID';
import {IconArbitrumChain} from '@yearn-finance/web-lib/icons/chains/IconArbitrumChain';
import {IconBaseChain} from '@yearn-finance/web-lib/icons/chains/IconBaseChain';
import {IconEtherumChain} from '@yearn-finance/web-lib/icons/chains/IconEtherumChain';
import {IconFantomChain} from '@yearn-finance/web-lib/icons/chains/IconFantomChain';
import {IconOptimismChain} from '@yearn-finance/web-lib/icons/chains/IconOptimismChain';
import {toAddress} from '@yearn-finance/web-lib/utils/address';
import {ETH_TOKEN_ADDRESS, WETH_TOKEN_ADDRESS, WFTM_TOKEN_ADDRESS} from '@yearn-finance/web-lib/utils/constants';
import {toBigInt} from '@yearn-finance/web-lib/utils/format.bigNumber';
Expand All @@ -17,6 +21,14 @@ import {getVaultName} from '@common/utils';
import type {ReactElement} from 'react';
import type {TYDaemonVault} from '@common/schemas/yDaemonVaultsSchemas';

export const ChainIconMap = new Map<number, ReactElement>([
[1, <IconEtherumChain />],
[10, <IconOptimismChain />],
[250, <IconFantomChain />],
[8453, <IconBaseChain />],
[42161, <IconArbitrumChain />]
]);

export function VaultAPR({currentVault}: {currentVault: TYDaemonVault}): ReactElement {
const isEthMainnet = currentVault.chainID === 1;

Expand Down Expand Up @@ -153,8 +165,7 @@ export function VaultsListRow({currentVault}: {currentVault: TYDaemonVault}): Re
<Link key={`${currentVault.address}`} href={`/vaults/${safeChainID}/${toAddress(currentVault.address)}`}>
<div className={'yearn--table-wrapper cursor-pointer transition-colors hover:bg-neutral-300'}>
<div className={'flex max-w-[32px] flex-row items-center'}>
{/* {currentVault.chainID} */}
<IconEtherumChain />
{ChainIconMap.get(currentVault.chainID) ?? <IconEtherumChain />}
</div>
<div className={'yearn--table-token-section'}>
<div className={'yearn--table-token-section-item'}>
Expand Down

0 comments on commit cd7d604

Please sign in to comment.