From df0e9ad03beb8a300049cf369ad0005241b4ed4e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 21 Aug 2022 17:03:03 +0200 Subject: [PATCH] Bugfix/fix division by zero in benchmarks calculation (#1177) * Fix division by zero error * Update changelog --- CHANGELOG.md | 4 ++++ apps/api/src/app/benchmark/benchmark.service.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ed47791..76ec7cffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Integrated the commands `database:setup` and `database:migrate` into the container start +### Fixed + +- Fixed a division by zero error in the benchmarks calculation + ### Todo - Apply manual data migration (`yarn database:migrate`) is not needed anymore diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index f7a10d8e5..2e8ee61d4 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -48,9 +48,13 @@ export class BenchmarkService { benchmarks = allTimeHighs.map((allTimeHigh, index) => { const { marketPrice } = quotes[benchmarkAssets[index].symbol]; - const performancePercentFromAllTimeHigh = new Big(marketPrice) - .div(allTimeHigh) - .minus(1); + let performancePercentFromAllTimeHigh = new Big(0); + + if (allTimeHigh) { + performancePercentFromAllTimeHigh = new Big(marketPrice) + .div(allTimeHigh) + .minus(1); + } return { marketCondition: this.getMarketCondition(