Skip to content

Commit a84acbe

Browse files
authored
Merge pull request #14616 from ethereum/l2StatFix
txCosts using layer2Data
2 parents b57929b + f529512 commit a84acbe

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/lib/api/fetchGrowThePie.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { GrowThePieData } from "../types"
1+
import type { GrowThePieData } from "@/lib/types"
2+
3+
import { layer2Data } from "@/data/networks/networks"
24

35
type DataItem = {
46
metric_key: string
@@ -44,18 +46,22 @@ export const fetchGrowThePie = async (): Promise<GrowThePieData> => {
4446
let totalTxCount = 0
4547
let weightedSum = 0
4648

47-
mostRecentData.forEach((item) => {
48-
if (item.metric_key !== TXCOSTS_MEDIAN_USD) return
49-
50-
const txCountItem = mostRecentData.find(
51-
(txItem) =>
52-
txItem.metric_key === TXCOUNT && txItem.origin_key === item.origin_key
49+
mostRecentData
50+
.filter((item) =>
51+
layer2Data.some((l2) => l2.growthepieID === item.origin_key)
5352
)
54-
if (!txCountItem) return
53+
.forEach((item) => {
54+
if (item.metric_key !== TXCOSTS_MEDIAN_USD) return
55+
56+
const txCountItem = mostRecentData.find(
57+
(txItem) =>
58+
txItem.metric_key === TXCOUNT && txItem.origin_key === item.origin_key
59+
)
60+
if (!txCountItem) return
5561

56-
totalTxCount += txCountItem.value
57-
weightedSum += item.value * txCountItem.value
58-
})
62+
totalTxCount += txCountItem.value
63+
weightedSum += item.value * txCountItem.value
64+
})
5965

6066
// The weighted average of txcosts_median_usd, by txcount on each network (origin_key)
6167
const weightedAverage = totalTxCount ? weightedSum / totalTxCount : 0

0 commit comments

Comments
 (0)