Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch all vaults and filter on funded #93

Merged
merged 2 commits into from
May 3, 2024
Merged
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
20 changes: 15 additions & 5 deletions src/app/hooks/use-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,23 @@ export function useEthereum(): UseEthereumReturnType {
}

async function getAllFundedVaults(ethereumNetwork: EthereumNetwork): Promise<RawVault[]> {
const FUNDED_STATUS = 1;
try {
const dlcManagerContract = await getDefaultProvider(ethereumNetwork, 'DLCManager');
const vaults: RawVault[] = await dlcManagerContract.getFundedDLCs(0, 10000);
const filteredVaults = vaults.filter(
vault => vault.uuid != '0x0000000000000000000000000000000000000000000000000000000000000000'
);
return filteredVaults;
const numToFetch = 50;
let totalFetched = 0;
const fundedVaults: RawVault[] = [];
// eslint-disable-next-line no-constant-condition
while (true) {
const fetchedVaults: RawVault[] = await dlcManagerContract.getAllDLCs(
totalFetched,
totalFetched + numToFetch
);
fundedVaults.push(...fetchedVaults.filter(vault => vault.status === FUNDED_STATUS));
totalFetched += numToFetch;
if (fetchedVaults.length !== numToFetch) break;
}
return fundedVaults;
} catch (error) {
throw new EthereumError(`Could not fetch Funded Vaults: ${error}`);
}
Expand Down
Loading