diff --git a/src/blockchain.ts b/src/blockchain.ts index c1ce774..91ae1f5 100644 --- a/src/blockchain.ts +++ b/src/blockchain.ts @@ -34,14 +34,18 @@ const blockGasPricesObservable = new Observable((observer) => { const averageGasPricesObservable = blockGasPricesObservable.pipe( scan((acc, curr) => [...acc.slice(-19), curr], [] as GasPrices[]), map((blocks) => { - const fastSum = blocks.reduce((sum, block) => sum + block.fast, 0); - const averageSum = blocks.reduce((sum, block) => sum + block.average, 0); - const slowSum = blocks.reduce((sum, block) => sum + block.slow, 0); + const { fast, average, slow } = blocks + .reduce((sum, block) => + ({ + fast: sum.fast + block.fast, + average: sum.average + block.average, + slow: sum.slow + block.slow + }), { fast: 0, average: 0, slow: 0 } as GasPrices); return { - fast: Math.round(fastSum / blocks.length), - average: Math.round(averageSum / blocks.length), - slow: Math.round(slowSum / blocks.length), - }; + fast: Math.round(fast / blocks.length), + average: Math.round(average / blocks.length), + slow: Math.round(slow / blocks.length), + } as GasPrices; }) );