-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathgetGasStationMetadata.ts
More file actions
40 lines (36 loc) · 1018 Bytes
/
getGasStationMetadata.ts
File metadata and controls
40 lines (36 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import axios from 'axios';
import { getCleanApiAddress } from 'apiCalls/configuration/getCleanApiAddress';
import { GAS_STATION_ENDPOINT } from 'apiCalls/endpoints';
import { NetworkType } from 'types/network.types';
interface IGasStationApiResponse {
lastBlock: number;
fast: number;
faster: number;
}
export async function getGasStationMetadataFromApi(
shard: number,
customApiAddress?: string
): Promise<NetworkType['gasStationMetadata'] | null> {
const apiAddress = getCleanApiAddress(customApiAddress);
const gasStationUrl = `${apiAddress}/${GAS_STATION_ENDPOINT}/${shard}`;
try {
const { data } = await axios.get<IGasStationApiResponse>(gasStationUrl);
if (data) {
return {
[shard]: {
lastBlock: data.lastBlock,
fast: data.fast,
faster: data.faster
}
};
}
return null;
} catch (err) {
console.error(
'Error fetching gas station metadata from:',
gasStationUrl,
err
);
return null;
}
}