Skip to content

Commit cc19f98

Browse files
authored
Merge pull request #8166 from LuisUrrutia/fix/l2beat-api
Change L2Beat API
2 parents c77926c + 53aaf6c commit cc19f98

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/lambda/l2beat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { HandlerResponse } from "@netlify/functions"
44

55
export const lambda = async (): Promise<HandlerResponse> => {
66
try {
7-
const response = await axios.get(`https://l2beat.com/api/tvl.json`)
7+
const response = await axios.get(`https://api.l2beat.com/api/tvl`)
88
if (response.status < 200 || response.status >= 300) {
99
return { statusCode: response.status, body: response.statusText }
1010
}

src/pages/layer-2.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,16 @@ const StatDivider = styled.div`
186186
margin: 2rem 0;
187187
}
188188
`
189-
190-
interface L2DataResponse {
189+
interface L2DataResponseItem {
191190
daily: {
192191
data: Array<[string, number, number]>
193192
}
194193
}
194+
interface L2DataResponse {
195+
layers2s: L2DataResponseItem
196+
combined: L2DataResponseItem
197+
bridges: L2DataResponseItem
198+
}
195199

196200
interface FeeDataResponse {
197201
data: Array<{ id: string; results: { feeTransferEth: number } }>
@@ -214,20 +218,23 @@ const Layer2Page = ({ data }: PageProps<Queries.Layer2PageQuery>) => {
214218
`${GATSBY_FUNCTIONS_PATH}/l2beat`
215219
)
216220

221+
const dailyData = l2BeatData.layers2s.daily.data
222+
217223
// formatted TVL from L2beat API formatted
218224
const TVL = new Intl.NumberFormat(localeForStatsBoxNumbers, {
219225
style: "currency",
220226
currency: "USD",
221227
notation: "compact",
222228
minimumSignificantDigits: 2,
223229
maximumSignificantDigits: 3,
224-
}).format(l2BeatData.daily.data[l2BeatData.daily.data.length - 1][1])
230+
}).format(dailyData[dailyData.length - 1][1])
231+
225232
setTVL(`${TVL}`)
226233
// Calculate percent change ((new value - old value) / old value) *100)
227234
const percentage =
228-
((l2BeatData.daily.data[l2BeatData.daily.data.length - 1][1] -
229-
l2BeatData.daily.data[l2BeatData.daily.data.length - 31][1]) /
230-
l2BeatData.daily.data[l2BeatData.daily.data.length - 31][1]) *
235+
((dailyData[dailyData.length - 1][1] -
236+
dailyData[dailyData.length - 31][1]) /
237+
dailyData[dailyData.length - 31][1]) *
231238
100
232239
setL2PercentChange(
233240
percentage > 0

0 commit comments

Comments
 (0)