diff --git a/src/hooks/orderbook/useDrawOrderbookHistograms.ts b/src/hooks/orderbook/useDrawOrderbookHistograms.ts index 7f1c7a4..9c8a2c2 100644 --- a/src/hooks/orderbook/useDrawOrderbookHistograms.ts +++ b/src/hooks/orderbook/useDrawOrderbookHistograms.ts @@ -10,6 +10,7 @@ import { getAppTheme } from '@/state/configsSelectors'; import { ROW_HEIGHT, ROW_PADDING_RIGHT, type RowData } from '@/views/Orderbook/OrderbookRow'; import { MustBigNumber } from '@/lib/numbers'; +import { log } from '@/lib/telemetry'; export const useDrawOrderbookHistograms = ({ data, @@ -107,15 +108,29 @@ export const useDrawOrderbookHistograms = ({ const barWidth = value ? (value / histogramRange) * histogramBarWidth : 0; const { gradient, bar } = getXYValues({ barWidth, canvasWidth, gradientMultiplier }); - const linearGradient = ctx.createLinearGradient( - gradient.x1, - ROW_HEIGHT / 2, - gradient.x2, - ROW_HEIGHT / 2 - ); - linearGradient.addColorStop(0, histogramAccentColor); - linearGradient.addColorStop(1, 'rgba(0, 0, 0, 0)'); - ctx.fillStyle = linearGradient; + let linearGradient; + + try { + linearGradient = ctx.createLinearGradient( + gradient.x1, + ROW_HEIGHT / 2, + gradient.x2, + ROW_HEIGHT / 2 + ); + + linearGradient.addColorStop(0, histogramAccentColor); + linearGradient.addColorStop(1, 'rgba(0, 0, 0, 0)'); + ctx.fillStyle = linearGradient; + } catch (err) { + log('Orderbook/createLinearGradient', err, { + x1: gradient.x1, + y1: ROW_HEIGHT / 2, + x2: gradient.x2, + y2: ROW_HEIGHT / 2, + }); + + ctx.fillStyle = 'rgba(0, 0, 0, 0)'; + } ctx.beginPath(); diff --git a/src/views/Orderbook.tsx b/src/views/Orderbook.tsx index bdb6d35..9f77570 100644 --- a/src/views/Orderbook.tsx +++ b/src/views/Orderbook.tsx @@ -74,7 +74,9 @@ export const Orderbook = ({ if (asksSlice.length < numRows) { const emptyRows = new Array(numRows - asksSlice.length).fill(getEmptyRow('ask')); asksSlice.push(...emptyRows); - } else if (bidsSlice.length < numRows) { + } + + if (bidsSlice.length < numRows) { const emptyRows = new Array(numRows - bidsSlice.length).fill(getEmptyRow('bid')); bidsSlice.unshift(...emptyRows); }