Skip to content

Commit

Permalink
chore: Fix linting in token-lists package
Browse files Browse the repository at this point in the history
  • Loading branch information
Chef-Cheems committed Jul 9, 2021
1 parent 22647f7 commit b2d63e1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5,495 deletions.
2 changes: 1 addition & 1 deletion packages/token-lists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"checksum:pcs-top-15": "yarn build && node ./dist checksum pancakeswap-top-15",
"generate:pcs-top-15": "yarn test && yarn build && node ./dist generate pancakeswap-top-15",
"makelist:pcs-top-15": "yarn checksum:pcs-top-15 && yarn generate:pcs-top-15",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"fetch:pcs-top-100": "yarn build && node ./dist fetch",
"test": "jest",
"ci-check": "yarn build && node ./dist ci-check"
Expand All @@ -33,7 +34,6 @@
"devDependencies": {
"@babel/preset-env": "^7.14.1",
"@babel/preset-typescript": "^7.13.0",
"@pancakeswap-libs/eslint-config-pancake": "^1.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.23",
Expand Down
51 changes: 28 additions & 23 deletions packages/token-lists/src/top-100.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getAddress } from "@ethersproject/address";

// Interface for Bitquery GraphQL response.
interface BitqueryEntity {
// eslint-disable-next-line camelcase
Total_USD: number;
baseCurrency: {
address: string;
Expand All @@ -28,7 +29,7 @@ const blacklist: string[] = [

/**
* Return today / 1 month ago ISO-8601 DateTime.
*
*
* @returns string[]
*/
const getDateRange = (): string[] => {
Expand All @@ -43,10 +44,10 @@ const getDateRange = (): string[] => {
/**
* Fetch Top100 Tokens traded on PancakeSwap v2, ordered by trading volume,
* for the past 30 days, filtered to remove default / broken tokens.
*
*
* @returns BitqueryEntity[]]
*/
const getTokens = async () => {
const getTokens = async (): Promise<BitqueryEntity[]> => {
try {
const [today, monthAgo] = getDateRange();

Expand Down Expand Up @@ -75,41 +76,45 @@ const getTokens = async () => {
{
from: monthAgo,
till: today,
blacklist: blacklist,
blacklist,
}
);

return ethereum.dexTrades;
} catch (error) {
console.error(`Error when fetching Top100 Tokens by volume for the past 30 days, error: ${error.message}`);
return error;
}
};

/**
* Main function.
* Fetch tokems, build list, save list.
*/
const main = async () => {
const tokens = await getTokens();
const main = async (): Promise<void> => {
try {
const tokens = await getTokens();

const sanitizedTokens = tokens.reduce((list, item: BitqueryEntity) => {
const checksummedAddress = getAddress(item.baseCurrency.address);
const sanitizedTokens = tokens.reduce((list, item: BitqueryEntity) => {
const checksummedAddress = getAddress(item.baseCurrency.address);

const updatedToken = {
name: item.baseCurrency.name,
symbol: item.baseCurrency.symbol.toUpperCase(),
address: checksummedAddress,
chainId: 56,
decimals: item.baseCurrency.decimals,
logoURI: `https://assets.trustwalletapp.com/blockchains/smartchain/assets/${checksummedAddress}/logo.png`,
};
return [...list, updatedToken];
}, []);
const updatedToken = {
name: item.baseCurrency.name,
symbol: item.baseCurrency.symbol.toUpperCase(),
address: checksummedAddress,
chainId: 56,
decimals: item.baseCurrency.decimals,
logoURI: `https://assets.trustwalletapp.com/blockchains/smartchain/assets/${checksummedAddress}/logo.png`,
};
return [...list, updatedToken];
}, []);

const tokenListPath = `${path.resolve()}/src/tokens/pancakeswap-top-100.json`;
console.info("Saving updated list to ", tokenListPath);
const stringifiedList = JSON.stringify(sanitizedTokens, null, 2);
fs.writeFileSync(tokenListPath, stringifiedList);
const tokenListPath = `${path.resolve()}/src/tokens/pancakeswap-top-100.json`;
console.info("Saving updated list to ", tokenListPath);
const stringifiedList = JSON.stringify(sanitizedTokens, null, 2);
fs.writeFileSync(tokenListPath, stringifiedList);
} catch (error) {
console.error(`Error when fetching Top100 Tokens by volume for the past 30 days, error: ${error.message}`);
}
};

export default main;
Loading

0 comments on commit b2d63e1

Please sign in to comment.