File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change 1
- import type { GrowThePieData } from "../types"
1
+ import type { GrowThePieData } from "@/lib/types"
2
+
3
+ import { layer2Data } from "@/data/networks/networks"
2
4
3
5
type DataItem = {
4
6
metric_key : string
@@ -44,18 +46,22 @@ export const fetchGrowThePie = async (): Promise<GrowThePieData> => {
44
46
let totalTxCount = 0
45
47
let weightedSum = 0
46
48
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 )
53
52
)
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
55
61
56
- totalTxCount += txCountItem . value
57
- weightedSum += item . value * txCountItem . value
58
- } )
62
+ totalTxCount += txCountItem . value
63
+ weightedSum += item . value * txCountItem . value
64
+ } )
59
65
60
66
// The weighted average of txcosts_median_usd, by txcount on each network (origin_key)
61
67
const weightedAverage = totalTxCount ? weightedSum / totalTxCount : 0
You can’t perform that action at this time.
0 commit comments