Skip to content

Commit

Permalink
Add missing typing for axios calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Mar 19, 2024
1 parent e32695f commit 4f25615
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 16 deletions.
4 changes: 3 additions & 1 deletion api/src/routes/v1/nodes/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const route = createRoute({

export default new OpenAPIHono().openapi(route, async (c) => {
const response = await cacheResponse(60 * 2, cacheKeys.getMainnetNodes, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/mainnet-nodes.json"); //TODO: Add typing
const res = await axios.get<{ id: string; api: string; rpc: string }[]>(
"https://raw.githubusercontent.com/akash-network/cloudmos/main/config/mainnet-nodes.json"
);
return res.data;
});
return c.json(response);
Expand Down
4 changes: 3 additions & 1 deletion api/src/routes/v1/nodes/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const route = createRoute({

export default new OpenAPIHono().openapi(route, async (c) => {
const response = await cacheResponse(60 * 2, cacheKeys.getSandboxNodes, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/sandbox-nodes.json");
const res = await axios.get<{ id: string; api: string; rpc: string }[]>(
"https://raw.githubusercontent.com/akash-network/cloudmos/main/config/sandbox-nodes.json"
);
return res.data;
});
return c.json(response);
Expand Down
4 changes: 3 additions & 1 deletion api/src/routes/v1/nodes/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const route = createRoute({

export default new OpenAPIHono().openapi(route, async (c) => {
const response = await cacheResponse(60 * 2, cacheKeys.getTestnetNodes, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/testnet-nodes.json");
const res = await axios.get<{ id: string; api: string; rpc: string }[]>(
"https://raw.githubusercontent.com/akash-network/cloudmos/main/config/testnet-nodes.json"
);
return res.data;
});
return c.json(response);
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/v1/version/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const route = createRoute({

export default new OpenAPIHono().openapi(route, async (c) => {
const response = await cacheResponse(60 * 5, cacheKeys.getMainnetVersion, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/net/master/mainnet/version.txt");
const res = await axios.get<string>("https://raw.githubusercontent.com/akash-network/net/master/mainnet/version.txt");
return res.data;
});
return c.text(response);
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/v1/version/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const route = createRoute({

export default new OpenAPIHono().openapi(route, async (c) => {
const response = await cacheResponse(60 * 5, cacheKeys.getSandboxVersion, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/net/master/sandbox/version.txt");
const res = await axios.get<string>("https://raw.githubusercontent.com/akash-network/net/master/sandbox/version.txt");
return res.data;
});
return c.text(response);
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/v1/version/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const route = createRoute({

export default new OpenAPIHono().openapi(route, async (c) => {
const response = await cacheResponse(60 * 5, cacheKeys.getTestnetVersion, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/net/master/testnet-02/version.txt");
const res = await axios.get<string>("https://raw.githubusercontent.com/akash-network/net/master/testnet-02/version.txt");
return res.data;
});
return c.text(response);
Expand Down
8 changes: 4 additions & 4 deletions api/src/services/external/githubService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from "@octokit/rest";
import { cacheKeys, cacheResponse } from "@src/caching/helpers";
import { ProviderAttributesSchema } from "@src/types/provider";
import { Auditor, ProviderAttributesSchema } from "@src/types/provider";
import { env } from "@src/utils/env";
import axios from "axios";

Expand All @@ -23,17 +23,17 @@ export const getProviderAttributesSchema = async (): Promise<ProviderAttributesS
const response = await cacheResponse(
30,
cacheKeys.getProviderAttributesSchema,
async () => await axios.get("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/provider-attributes.json")
async () => await axios.get<ProviderAttributesSchema>("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/provider-attributes.json")
);

return response.data;
};

export async function getAuditors() {
const response = await cacheResponse(60 * 5, cacheKeys.getAuditors, async () => {
const res = await axios.get("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/auditors.json");
const res = await axios.get<Auditor[]>("https://raw.githubusercontent.com/akash-network/cloudmos/main/config/auditors.json");
return res.data;
});

return response;
}
}
13 changes: 7 additions & 6 deletions api/src/services/external/marketDataService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CoinGeckoCoinsResponse } from "@src/types/coingeckoCoinsResponse";
import axios from "axios";

interface AktMarketData {
Expand All @@ -13,14 +14,14 @@ export async function getMarketData(): Promise<AktMarketData> {
const endpointUrl = "https://api.coingecko.com/api/v3/coins/akash-network";
// TODO USDC https://api.coingecko.com/api/v3/coins/usd-coin
console.log("Fetching latest market data from " + endpointUrl);
const response = await axios.get(endpointUrl);
const response = await axios.get<CoinGeckoCoinsResponse>(endpointUrl);

return {
price: parseFloat(response.data.market_data.current_price.usd),
volume: parseInt(response.data.market_data.total_volume.usd),
marketCap: parseInt(response.data.market_data.market_cap.usd),
price: response.data.market_data.current_price.usd,
volume: response.data.market_data.total_volume.usd,
marketCap: response.data.market_data.market_cap.usd,
marketCapRank: response.data.market_cap_rank,
priceChange24h: parseFloat(response.data.market_data.price_change_24h),
priceChangePercentage24: parseFloat(response.data.market_data.price_change_percentage_24h)
priceChange24h: response.data.market_data.price_change_24h,
priceChangePercentage24: response.data.market_data.price_change_percentage_24h
};
}
13 changes: 13 additions & 0 deletions api/src/types/coingeckoCoinsResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type CoinGeckoCoinsResponse = {
id: string;
symbol: string;
name: string;
market_cap_rank: number;
market_data: {
current_price: { usd: number };
total_volume: { usd: number };
market_cap: { usd: number };
price_change_24h: number;
price_change_percentage_24h: number;
};
};

0 comments on commit 4f25615

Please sign in to comment.