Skip to content

Commit

Permalink
Prettier updates
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Mar 7, 2024
1 parent 7720d94 commit daf34df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions netlify/functions/tokenPrices.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Config = {
};

const SUPPORTED_NETWORKS = ['ethereum'] as const;
type SupportedNetworks = typeof SUPPORTED_NETWORKS[number];
type SupportedNetworks = (typeof SUPPORTED_NETWORKS)[number];

function sanitizeUserInput(tokensString: string, network: SupportedNetworks) {
const rawTokenAddresses = tokensString.split(',');
Expand All @@ -38,7 +38,7 @@ async function splitData(
config: Config,
tokens: string[],
responseBodyCallback: (address: string, price: number) => void,
network: SupportedNetworks
network: SupportedNetworks,
) {
// Try to get all of the tokens from our store.
// Any token address that we don't have a record for will
Expand All @@ -48,15 +48,15 @@ async function splitData(
tokenAddress =>
config.store.getWithMetadata(`${network}/${tokenAddress}`, {
type: 'json',
}) as Promise<TokenPriceWithMetadata> | null
)
}) as Promise<TokenPriceWithMetadata> | null,
),
);

// Filter out the null values, leaving us with an array of
// TokenPricesWithMetadata. All of these TokenPrices will be either
// expired or unexpired.
const cachedTokenPrices = possibleCachedTokenPrices.filter(
(possible): possible is TokenPriceWithMetadata => possible !== null
(possible): possible is TokenPriceWithMetadata => possible !== null,
);

// Let's pull out all of the expired addresses from our cache.
Expand All @@ -68,7 +68,7 @@ async function splitData(
// we don't have any record of in our cache.
const uncachedTokenAddresses = tokens.filter(
address =>
!cachedTokenPrices.find(cachedTokenPrice => cachedTokenPrice.data.tokenAddress === address)
!cachedTokenPrices.find(cachedTokenPrice => cachedTokenPrice.data.tokenAddress === address),
);

// We'll update our response with those cached expired and
Expand All @@ -82,7 +82,7 @@ async function splitData(

function getTokenPricesUrl(tokens: string[], network: SupportedNetworks) {
const tokenPricesUrl = `${PUBLIC_DEMO_API_BASE_URL}simple/token_price/${network}/${AUTH_QUERY_PARAM}&vs_currencies=usd&contract_addresses=${tokens.join(
','
',',
)}`;
return tokenPricesUrl;
}
Expand All @@ -96,20 +96,20 @@ async function storeTokenPrice(
config: Config,
tokenAddress: string,
price: number,
network: SupportedNetworks
network: SupportedNetworks,
) {
await config.store.setJSON(
`${network}/${tokenAddress}`,
{ tokenAddress, price },
{ metadata: { fetched: config.nowSeconds } }
{ metadata: { fetched: config.nowSeconds } },
);
}

async function processTokenPricesResponse(
config: Config,
tokenPricesResponseJson: Record<string, { usd?: number }>,
responseBodyCallback: (address: string, price: number) => void,
network: SupportedNetworks
network: SupportedNetworks,
) {
const coinGeckoResponseAddresses = Object.keys(tokenPricesResponseJson);
for await (const tokenAddress of coinGeckoResponseAddresses) {
Expand All @@ -130,7 +130,7 @@ async function processUnknownAddresses(
config: Config,
needPricesTokenAddresses: string[],
responseAddresses: string[],
network: SupportedNetworks
network: SupportedNetworks,
) {
const unknownAddresses = needPricesTokenAddresses
.filter(x => !responseAddresses.includes(x))
Expand All @@ -144,7 +144,7 @@ async function coinGeckoRequestAndResponse(
config: Config,
url: string,
responseBodyCallback: (address: string, price: number) => void,
network: SupportedNetworks
network: SupportedNetworks,
) {
// Make the request to CoinGecko.
// Response is of shape:
Expand All @@ -165,7 +165,7 @@ async function coinGeckoRequestAndResponse(
config,
ethPriceResponseJson,
responseBodyCallback,
network
network,
);

return responseAddresses;
Expand Down Expand Up @@ -211,7 +211,7 @@ export default async function getTokenPrices(request: Request) {
(address, price) => {
responseBody[address] = price;
},
networkParam
networkParam,
);

// If there are no expired token prices, and no token addresses that we
Expand Down Expand Up @@ -239,7 +239,7 @@ export default async function getTokenPrices(request: Request) {
(address, price) => {
responseBody[address] = price;
},
networkParam
networkParam,
);
} catch (e) {
console.error('Error while querying CoinGecko', e);
Expand All @@ -256,7 +256,7 @@ export default async function getTokenPrices(request: Request) {
(address, price) => {
responseBody[address] = price;
},
networkParam
networkParam,
);
} catch (e) {
console.error('Error while querying CoinGecko', e);
Expand Down
4 changes: 2 additions & 2 deletions src/providers/App/hooks/usePriceAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function usePriceAPI() {
}
if (tokensAddresses.length > 0) {
const pricesResponse = await fetch(
`/.netlify/functions/tokenPrices?tokens=${tokensAddresses.join(',')}&network=ethereum`
`/.netlify/functions/tokenPrices?tokens=${tokensAddresses.join(',')}&network=ethereum`,
);

const pricesResponseBody = await pricesResponse.json();
Expand All @@ -46,7 +46,7 @@ export default function usePriceAPI() {
return;
}
},
[chainId, t]
[chainId, t],
);
return { getTokenPrices };
}

0 comments on commit daf34df

Please sign in to comment.