Skip to content

Commit

Permalink
Fix/63: Replace ts-ignore (yearn#69)
Browse files Browse the repository at this point in the history
* refactor: Remove unused API pages

These pages are no longer used now that internal pages have been deprecated

* refactor: Remove unused dependency

Axios was only ever used in an API page that has been removed, rest of the project makes requests using fetch api

* refactor: Adjust types

Added more specific types around locaization, removed types used only in now deleted pages

* refactor: Make import paths more concise

* refactor: Remove all eslint-disable comments in pages

* refactor: Remove remaining eslint-disable comments in site files

Removed all eslint-disable comments, aside from one in next.config.js

* Update pages/api/vaults.tsx

Agreed this looks good

Co-authored-by: Major <90963895+Majorfi@users.noreply.github.com>

* Update pages/api/vaults.tsx

Co-authored-by: Major <90963895+Majorfi@users.noreply.github.com>

Co-authored-by: Major <90963895+Majorfi@users.noreply.github.com>
  • Loading branch information
0xMirim and Majorfi committed Aug 29, 2022
1 parent 99be35b commit 8751b66
Show file tree
Hide file tree
Showing 27 changed files with 97 additions and 464 deletions.
4 changes: 1 addition & 3 deletions components/Strategies.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import React, {ReactElement} from 'react';
import {parseMarkdown} from 'utils';
import HeadIconRocket from 'components/icons/HeadIconRocket';
import useLocalization from 'contexts/useLocalization';
import {TVaultStrategy} from 'types/index';
import {TVaultStrategy} from 'types';

type TStrategies = {
strategiesData: TVaultStrategy[]
Expand Down
2 changes: 1 addition & 1 deletion components/Vaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Strategies from 'components/Strategies';
import IconChevron from 'components/icons/IconChevron';
import IconLinkOut from 'components/icons/IconLinkOut';
import IconRetired from 'components/icons/IconRetired';
import {TVaultWithStrats} from 'types/index';
import {TVaultWithStrats} from 'types';

type TVault = {
vault: TVaultWithStrats
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dependencies": {
"@headlessui/react": "^1.6.6",
"@yearn-finance/web-lib": "^0.13.5",
"axios": "^0.27.2",
"ethcall": "^4.8.2",
"ethers": "^5.6.9",
"next": "^12.2.5",
Expand Down
16 changes: 5 additions & 11 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import React, {ReactElement, ReactFragment} from 'react';
import Document, {Html, Head, Main, NextScript, DocumentContext} from 'next/document';

type TInitialProps = {
html: string;
head?: (JSX.Element | null)[] | undefined;
styles?: ReactElement[] | ReactFragment | undefined;
}
import React, {ReactElement} from 'react';
import Document, {Html, Head, Main, NextScript, DocumentContext, DocumentInitialProps} from 'next/document';

class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext): Promise<TInitialProps> {
const initialProps = await Document.getInitialProps(ctx);
return {...initialProps} as any; // eslint-disable-line
static async getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> {
const initialProps: DocumentInitialProps = await Document.getInitialProps(ctx);
return {...initialProps};
}

render(): ReactElement {
Expand Down
46 changes: 21 additions & 25 deletions pages/api/ape-vaults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/prefer-for-of */
import {Contract} from 'ethcall';
import {providers} from '@yearn-finance/web-lib/utils';
import {toAddress} from 'utils';
Expand All @@ -23,35 +22,37 @@ export function getProvider(chain = 1): ethers.providers.JsonRpcProvider {
return new ethers.providers.InfuraProvider('homestead', '9aa3d95b3bc440fa88ea12eaa4456161');
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function fetchStrategies({vaultAddress, network}: {vaultAddress: string, network: number}) {
async function fetchStrategies({vaultAddress, network}: {vaultAddress: string, network: number}): Promise<string[]> {
const vaultContract = new Contract(
vaultAddress,
[{'stateMutability': 'view', 'type': 'function', 'name': 'withdrawalQueue', 'inputs': [{'name': 'arg0', 'type': 'uint256'}], 'outputs': [{'name': '', 'type': 'address'}], 'gas': '4057'}]
);
const strategiesIndex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
const calls = [];
for (let i = 0; i < strategiesIndex.length; i++) {
calls.push(vaultContract.withdrawalQueue(strategiesIndex[i]));
for (const strategyIndex of strategiesIndex) {
calls.push(vaultContract.withdrawalQueue(strategyIndex));
}
const ethcallProvider = await providers.newEthCallProvider(getProvider(network));
const callResult = await ethcallProvider.tryAll(calls);
return callResult.filter((a): boolean => a !== ethers.constants.AddressZero);
const addresses = callResult.filter((a): boolean => a !== ethers.constants.AddressZero) as string[];

return addresses;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function fetchNames({addresses, network}: {addresses: string[], network: number}) {
async function fetchNames({addresses, network}: {addresses: string[], network: number}): Promise<string[]> {
const calls = [];
for (let index = 0; index < addresses.length; index++) {
for (const address of addresses) {
const strategyContract = new Contract(
addresses[index],
address,
[{'inputs':[], 'name':'name', 'outputs':[{'internalType':'string', 'name':'', 'type':'string'}], 'stateMutability':'view', 'type':'function'}]
);
calls.push(strategyContract.name());
}
const ethcallProvider = await providers.newEthCallProvider(getProvider(network));
const callResult = await ethcallProvider.tryAll(calls);
return callResult.filter((a): boolean => a !== ethers.constants.AddressZero);
const strategyNames = callResult.filter((a): boolean => a !== ethers.constants.AddressZero) as string[];

return strategyNames;
}


Expand All @@ -60,8 +61,8 @@ async function getVaultStrategies({vaultAddress, network, stratTree}: {vaultAddr

const strategies = [];
let hasMissingStrategiesDescriptions = false;
for (let i = 0; i < vaultStrategies.length; i++) {
const strategyAddress = toAddress(vaultStrategies[i] as string);
for (const strategy of vaultStrategies) {
const strategyAddress = toAddress(strategy);
const details = stratTree[strategyAddress];
if (details) {
if (!details?.description) {
Expand All @@ -84,17 +85,15 @@ async function getVaultStrategies({vaultAddress, network, stratTree}: {vaultAddr
}
}
const strategyWithNoName = [];
for (let index = 0; index < strategies.length; index++) {
const strategy = strategies[index];
for (const strategy of strategies) {
if (!strategy.name) {
strategyWithNoName.push(strategy.address);
}
}
const noNameNames = await fetchNames({addresses: strategyWithNoName, network});

let noNameIndex = 0;
for (let index = 0; index < strategies.length; index++) {
const strategy = strategies[index];
for (const strategy of strategies) {
if (!strategy.name) {
strategy.noIPFS = true;
strategy.name = noNameNames[noNameIndex++] as string;
Expand All @@ -108,10 +107,8 @@ async function getStrategies({network}: {network: number}): Promise<TVaultWithSt
const allStrategiesAddr: TStrategyMetadata[] = await (await fetch(`${process.env.META_API_URL}/${network}/strategies/all`)).json();
const stratTree: TStratTree = {};

for (let index = 0; index < allStrategiesAddr.length; index++) {
const stratDetails = allStrategiesAddr[index];
for (let jindex = 0; jindex < (stratDetails.addresses).length; jindex++) {
const address = stratDetails.addresses[jindex];
for (const stratDetails of allStrategiesAddr) {
for (const address of stratDetails.addresses) {
stratTree[toAddress(address)] = {
description: stratDetails.description,
name: stratDetails.name
Expand All @@ -123,8 +120,7 @@ async function getStrategies({network}: {network: number}): Promise<TVaultWithSt
const vaultsWithStrats = [];
const filteredVaults = vaults.filter((e): boolean => e.status !== 'endorsed');

for (let index = 0; index < filteredVaults.length; index++) {
const vault: TApeVault = filteredVaults[index];
for (const vault of filteredVaults) {
const [strategies, hasMissingStrategiesDescriptions] = await getVaultStrategies({
vaultAddress: vault.address,
network,
Expand All @@ -147,8 +143,8 @@ async function getStrategies({network}: {network: number}): Promise<TVaultWithSt

const vaultsMapping: {[key: number]: TVaultWithStrats[] } = {};
const vaultsMappingAccess: {[key: number]: number} = {};
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async function handler(req: NextApiRequest, res: NextApiResponse){

export default async function handler(req: NextApiRequest, res: NextApiResponse): Promise<void> {
const {revalidate} = req.query;
const network = Number(req.query.network);

Expand Down
73 changes: 0 additions & 73 deletions pages/api/protocols.tsx

This file was deleted.

89 changes: 0 additions & 89 deletions pages/api/strategies.tsx

This file was deleted.

0 comments on commit 8751b66

Please sign in to comment.