Skip to content

Commit

Permalink
fix: upd vaults fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Nov 10, 2024
1 parent e290375 commit 2829943
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions apps/common/hooks/useFetchYearnVaults.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useEffect, useState} from 'react';
import {useFetch} from '@builtbymom/web3/hooks/useFetch';
import {toAddress} from '@builtbymom/web3/utils';
import {useDeepCompareMemo} from '@react-hookz/web';
Expand All @@ -24,6 +25,9 @@ function useFetchYearnVaults(chainIDs?: number[] | undefined): {
mutate: KeyedMutator<TYDaemonVaults>;
} {
const {yDaemonBaseUri: yDaemonBaseUriWithoutChain} = useYDaemonBaseURI();
const [allVaults, set_allVaults] = useState<TYDaemonVaults>([]);
const [currentPage, set_currentPage] = useState<number>(1);
const limit = 200;

const {
data: vaults,
Expand All @@ -37,11 +41,25 @@ function useFetchYearnVaults(chainIDs?: number[] | undefined): {
strategiesDetails: 'withDetails',
strategiesCondition: 'inQueue',
chainIDs: chainIDs ? chainIDs.join(',') : [1, 10, 137, 250, 8453, 42161].join(','),
limit: '2500'
limit: limit.toString(),
page: currentPage.toString()
})}`,
schema: yDaemonVaultsSchema
});

useEffect(() => {
let hasMore = true;
if (vaults) {
if (vaults.length < limit) {
hasMore = false;
}
set_allVaults(prev => [...prev, ...vaults]);
if (hasMore) {
set_currentPage(prev => prev + 1);
}
}
}, [vaults]);

// const vaultsMigrations: TYDaemonVaults = useMemo(() => [], []);
const {data: vaultsMigrations} = useFetch<TYDaemonVaults>({
endpoint: `${yDaemonBaseUriWithoutChain}/vaults?${new URLSearchParams({
Expand All @@ -58,17 +76,17 @@ function useFetchYearnVaults(chainIDs?: number[] | undefined): {
});

const vaultsObject = useDeepCompareMemo((): TDict<TYDaemonVault> => {
if (!vaults) {
if (!allVaults) {
return {};
}
const _vaultsObject = (vaults || []).reduce((acc: TDict<TYDaemonVault>, vault): TDict<TYDaemonVault> => {
const _vaultsObject = (allVaults || []).reduce((acc: TDict<TYDaemonVault>, vault): TDict<TYDaemonVault> => {
if (!vault.migration.available) {
acc[toAddress(vault.address)] = vault;
}
return acc;
}, {});
return _vaultsObject;
}, [vaults]);
}, [allVaults]);

const vaultsMigrationsObject = useDeepCompareMemo((): TDict<TYDaemonVault> => {
if (!vaultsMigrations) {
Expand Down

0 comments on commit 2829943

Please sign in to comment.