From d4989d472949e052bf07487ae0e1ebdb377d96ac Mon Sep 17 00:00:00 2001 From: 0xdef1cafe <88504456+0xdef1cafe@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:29:50 +1000 Subject: [PATCH] chore: remove debug charts error (#5014) --- .../useBalanceChartData.ts | 45 +------------------ 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/src/hooks/useBalanceChartData/useBalanceChartData.ts b/src/hooks/useBalanceChartData/useBalanceChartData.ts index 0f01ca31bd8..ea406015b6d 100644 --- a/src/hooks/useBalanceChartData/useBalanceChartData.ts +++ b/src/hooks/useBalanceChartData/useBalanceChartData.ts @@ -13,7 +13,7 @@ import values from 'lodash/values' import without from 'lodash/without' import { useEffect, useMemo, useState } from 'react' import { useFetchPriceHistories } from 'hooks/useFetchPriceHistories/useFetchPriceHistories' -import { bn, bnOrZero } from 'lib/bignumber/bignumber' +import { bnOrZero } from 'lib/bignumber/bignumber' import { priceAtDate } from 'lib/charts' import type { RebaseHistory } from 'lib/investor/investor-foxy' import type { SupportedFiatCurrencies } from 'lib/market-service' @@ -430,8 +430,6 @@ export const useBalanceChartData: UseBalanceChartData = args => { selectedCurrency, }) - debugCharts({ assets, calculatedBuckets, timeframe, txs }) - const chartData = bucketsToChartData(calculatedBuckets) setBalanceChartData(chartData) @@ -453,44 +451,3 @@ export const useBalanceChartData: UseBalanceChartData = args => { return { balanceChartData, balanceChartDataLoading } } - -type DebugChartsArgs = { - assets: AssetsById - timeframe: HistoryTimeframe - calculatedBuckets: Bucket[] - txs: Tx[] -} - -type DebugCharts = (args: DebugChartsArgs) => void - -const debugCharts: DebugCharts = ({ assets, calculatedBuckets, timeframe, txs }) => { - if (timeframe !== HistoryTimeframe.ALL) return - /** - * there is a long tail of potentially obscure bugs in the charts - * the best way to address this is log when it happens, and fix the edge cases - */ - if (!txs?.length) return // no chart if no txs - const firstTxTimestamp = txs[0].blockTime * 1000 // unchained uses seconds - const firstBucket = calculatedBuckets[0] - const startOfChartTimestamp = firstBucket.start.valueOf() - const shouldHaveZeroBalance = firstTxTimestamp > startOfChartTimestamp - if (!shouldHaveZeroBalance) return - Object.entries(firstBucket.balance.crypto).forEach(([assetId, balance]) => { - if (balance.eq(0)) return // this is expected, charts should be zero at the beginning - /** - * at this point, we have a non zero balance for an asset at the start of the chart - * but the earlierst tx is after the start of the chart - this should not happen - * and something is wrong - */ - const asset = assets[assetId] - const baseUnitBalance = balance.toString() - const baseUnitHuman = balance.div(bn(10).exponentiatedBy(asset?.precision ?? 1)).toString() - console.error('NON-ZERO BALANCE AT START OF CHART', { - asset, - assetId, - baseUnitBalance, - baseUnitHuman, - balance, - }) - }) -}