From bf27078082681613e7eb823ec33362dc03000315 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 5 Jun 2024 14:25:18 +0500 Subject: [PATCH 1/4] chore: use decimal places with token values --- src/pages/InterProtocol.tsx | 59 +++++++++++++++++++++++++------------ src/utils.tsx | 19 ++++++++---- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/pages/InterProtocol.tsx b/src/pages/InterProtocol.tsx index b6f8928..4caef8e 100644 --- a/src/pages/InterProtocol.tsx +++ b/src/pages/InterProtocol.tsx @@ -7,16 +7,21 @@ import { ValueCardGrid } from '@/components/ValueCardGrid'; import { PageHeader } from '@/components/PageHeader'; import { PageContent } from '@/components/PageContent'; import { colors } from '@/components/palette'; -import { formatPercent, roundPrice, formatPrice, formatIST, subQueryFetcher, fetchDataFromUrl } from '@/utils'; -import { INTER_DASHBOARD_QUERY } from '@/queries'; import { - GET_INTERCHAIN_BALANCES_URL, -} from '@/constants'; + formatPercent, + roundPrice, + formatPrice, + formatIST, + subQueryFetcher, + fetchDataFromUrl, + getTokenDivisor, +} from '@/utils'; +import { INTER_DASHBOARD_QUERY } from '@/queries'; +import { GET_INTERCHAIN_BALANCES_URL } from '@/constants'; import InterProtocolSkeleton from '@/components/InterProtocolSkeleton'; import { AccountData, InterProtocolResponse } from '@/types/interprotocol-types'; import { OraclePriceNode } from '@/types/vault-types'; - const RADIAN = Math.PI / 180; const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, payload }: any) => { @@ -36,7 +41,6 @@ const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, per ); }; - function getInterchainBalance(data: AccountData[]): number { const balanceList = data .map((account) => ({ @@ -81,19 +85,31 @@ export function InterProtocol() { {}, ); + const istTokenDivisor = getTokenDivisor(boardAuxes, 'IST'); + const psmMinted = - dashboardResponse.psmMetrics.nodes.reduce((agg, node) => agg + Number(node.mintedPoolBalance), 0) / 1_000_000; - const psmAnchor = dashboardResponse.psmMetrics.nodes.reduce( - (agg, node) => agg + Number(node.anchorPoolBalance) / 10 ** (boardAuxes[node.denom] || 6), - 0, - ); - const vaultMinted = - dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => agg + Number(node.totalDebt), 0) / 1_000_000; + dashboardResponse.psmMetrics.nodes.reduce((agg, node) => agg + Number(node.mintedPoolBalance), 0) / istTokenDivisor; + + const psmAnchor = dashboardResponse.psmMetrics.nodes.reduce((agg, node) => { + const decimalPlaces = (boardAuxes && boardAuxes[node.denom]) || 6; + const anchorPoolBalance = Number(node.anchorPoolBalance) / 10 ** decimalPlaces; + return agg + anchorPoolBalance; + }, 0); + + const vaultMinted = dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => { + const tokenDivisor = getTokenDivisor(boardAuxes, node.liquidatingCollateralBrand); + return agg + Number(node.totalDebt) / tokenDivisor; + }, 0); + const totalMinted = psmMinted + vaultMinted; const vaultMintLimit = - dashboardResponse.vaultManagerGovernances.nodes.reduce((agg, node) => agg + Number(node.debtLimit), 0) / 1_000_000; - const psmMintLimit = dashboardResponse.psmGovernances.nodes.reduce((agg, node) => agg + Number(node.mintLimit), 0) / 1_000_000; + dashboardResponse.vaultManagerGovernances.nodes.reduce((agg, node) => agg + Number(node.debtLimit), 0) / + istTokenDivisor; + + const psmMintLimit = + dashboardResponse.psmGovernances.nodes.reduce((agg, node) => agg + Number(node.mintLimit), 0) / istTokenDivisor; + const totalMintLimit = vaultMintLimit + psmMintLimit; // bottom cards @@ -101,18 +117,23 @@ export function InterProtocol() { (agg, node) => agg + node.allocations.nodes.reduce((agg_, node_) => { + const tokenDivisor = getTokenDivisor(boardAuxes, node_.denom); const allocationInUsd = - ((Number(node_.value) / 1_000_000) * Number(oraclePrices[node_.denom]?.typeOutAmount || 1_000_000)) / 1_000_000; + ((Number(node_.value) / tokenDivisor) * Number(oraclePrices[node_.denom]?.typeOutAmount || tokenDivisor)) / + tokenDivisor; return agg_ + allocationInUsd; }, 0), 0, ); const reserveShortfall = - dashboardResponse.reserveMetrics.nodes.reduce((agg, node) => agg + Number(node.shortfallBalance), 0) / 1_000_000; + dashboardResponse.reserveMetrics.nodes.reduce((agg, node) => agg + Number(node.shortfallBalance), 0) / + istTokenDivisor; const totalLockedCollateral = dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => { + const tokenDivisor = getTokenDivisor(boardAuxes, node.liquidatingCollateralBrand); + const collateralInUsd = - ((Number(node.totalCollateral) / 1_000_000) * - Number(oraclePrices[node.liquidatingCollateralBrand]?.typeOutAmount) || 0) / 1_000_000; + ((Number(node.totalCollateral) / tokenDivisor) * + Number(oraclePrices[node.liquidatingCollateralBrand]?.typeOutAmount) || 0) / tokenDivisor; return agg + collateralInUsd; }, 0); diff --git a/src/utils.tsx b/src/utils.tsx index c0e14b5..1396c89 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -184,13 +184,11 @@ export const getDateKey = (date: Date, daysToSubtract: number = 0) => { dateObject.setDate(dateObject.getDate() - daysToSubtract); const startDateFormatDate = dateObject.toISOString().slice(0, 10); const startDateKey = Number(startDateFormatDate.replaceAll('-', '')); - return {key: startDateKey, formattedDate: startDateFormatDate}; -} + return { key: startDateKey, formattedDate: startDateFormatDate }; +}; export const range = (stop: number) => [...Object(Array(stop)).keys()]; - - const fillMissingDays = (startDate: Date, endDate: Date, formattedData: FormattedGraphData[]): void => { const timeDifferenceInMilliseconds = endDate.getTime() - startDate.getTime(); const daysDifference = Math.ceil(timeDifferenceInMilliseconds / (1000 * 60 * 60 * 24)); @@ -205,7 +203,10 @@ const fillMissingDays = (startDate: Date, endDate: Date, formattedData: Formatte } } }; -export const populateMissingDays = (graphDataMap: Record, GRAPH_DAYS: number): FormattedGraphData[] => { +export const populateMissingDays = ( + graphDataMap: Record, + GRAPH_DAYS: number, +): FormattedGraphData[] => { const sortedGraphDataList = Object.values(graphDataMap).sort((a, b) => a.key - b.key); const formattedData: FormattedGraphData[] = []; @@ -248,4 +249,10 @@ export function createNumberWithLeadingZeroes(numOfZeroes: number) { } } -export const parseBigInt = (str: string) => Number(str.slice(0, -1)) +export const parseBigInt = (str: string) => Number(str.slice(0, -1)); + +export const getTokenDivisor = (boardAuxes: { [key: string]: number }, tokenName: string) => { + const decimalPlaces = (boardAuxes && boardAuxes[tokenName]) || 6; + const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces); + return tokenDivisor; +}; From f42d015ef7121e8e94bc7d18bc0ed0220d7b5fb2 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Wed, 5 Jun 2024 15:29:43 +0500 Subject: [PATCH 2/4] chore: add optional chaining --- src/pages/InterProtocol.tsx | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/pages/InterProtocol.tsx b/src/pages/InterProtocol.tsx index 4caef8e..42b3a28 100644 --- a/src/pages/InterProtocol.tsx +++ b/src/pages/InterProtocol.tsx @@ -80,35 +80,36 @@ export function InterProtocol() { {}, ); - const boardAuxes: { [key: string]: number } = dashboardResponse.boardAuxes.nodes.reduce( - (agg, node) => ({ ...agg, [node.allegedName]: node.decimalPlaces }), + const boardAuxes: { [key: string]: number } = dashboardResponse?.boardAuxes?.nodes?.reduce( + (agg, node) => ({ ...agg, [node?.allegedName]: node?.decimalPlaces }), {}, ); const istTokenDivisor = getTokenDivisor(boardAuxes, 'IST'); const psmMinted = - dashboardResponse.psmMetrics.nodes.reduce((agg, node) => agg + Number(node.mintedPoolBalance), 0) / istTokenDivisor; + dashboardResponse?.psmMetrics?.nodes?.reduce((agg, node) => agg + Number(node?.mintedPoolBalance), 0) / + istTokenDivisor; const psmAnchor = dashboardResponse.psmMetrics.nodes.reduce((agg, node) => { - const decimalPlaces = (boardAuxes && boardAuxes[node.denom]) || 6; - const anchorPoolBalance = Number(node.anchorPoolBalance) / 10 ** decimalPlaces; + const tokenDivisor = getTokenDivisor(boardAuxes, node?.denom); + const anchorPoolBalance = Number(node?.anchorPoolBalance) / tokenDivisor; return agg + anchorPoolBalance; }, 0); const vaultMinted = dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => { - const tokenDivisor = getTokenDivisor(boardAuxes, node.liquidatingCollateralBrand); - return agg + Number(node.totalDebt) / tokenDivisor; + const tokenDivisor = getTokenDivisor(boardAuxes, node?.liquidatingCollateralBrand); + return agg + Number(node?.totalDebt) / tokenDivisor; }, 0); const totalMinted = psmMinted + vaultMinted; const vaultMintLimit = - dashboardResponse.vaultManagerGovernances.nodes.reduce((agg, node) => agg + Number(node.debtLimit), 0) / + dashboardResponse?.vaultManagerGovernances?.nodes?.reduce((agg, node) => agg + Number(node?.debtLimit), 0) / istTokenDivisor; const psmMintLimit = - dashboardResponse.psmGovernances.nodes.reduce((agg, node) => agg + Number(node.mintLimit), 0) / istTokenDivisor; + dashboardResponse?.psmGovernances?.nodes?.reduce((agg, node) => agg + Number(node?.mintLimit), 0) / istTokenDivisor; const totalMintLimit = vaultMintLimit + psmMintLimit; @@ -116,24 +117,25 @@ export function InterProtocol() { const totalReserve = dashboardResponse.reserveMetrics.nodes.reduce( (agg, node) => agg + - node.allocations.nodes.reduce((agg_, node_) => { - const tokenDivisor = getTokenDivisor(boardAuxes, node_.denom); + node?.allocations?.nodes.reduce((agg_, node_) => { + const tokenDivisor = getTokenDivisor(boardAuxes, node_?.denom); const allocationInUsd = - ((Number(node_.value) / tokenDivisor) * Number(oraclePrices[node_.denom]?.typeOutAmount || tokenDivisor)) / + ((Number(node_?.value) / tokenDivisor) * Number(oraclePrices[node_?.denom]?.typeOutAmount || tokenDivisor)) / tokenDivisor; return agg_ + allocationInUsd; }, 0), 0, ); const reserveShortfall = - dashboardResponse.reserveMetrics.nodes.reduce((agg, node) => agg + Number(node.shortfallBalance), 0) / + dashboardResponse?.reserveMetrics?.nodes?.reduce((agg, node) => agg + Number(node?.shortfallBalance), 0) / istTokenDivisor; - const totalLockedCollateral = dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => { - const tokenDivisor = getTokenDivisor(boardAuxes, node.liquidatingCollateralBrand); + const totalLockedCollateral = dashboardResponse?.vaultManagerMetrics?.nodes?.reduce((agg, node) => { + const tokenDivisor = getTokenDivisor(boardAuxes, node?.liquidatingCollateralBrand); const collateralInUsd = - ((Number(node.totalCollateral) / tokenDivisor) * - Number(oraclePrices[node.liquidatingCollateralBrand]?.typeOutAmount) || 0) / tokenDivisor; + ((Number(node?.totalCollateral) / tokenDivisor) * + Number(oraclePrices[node?.liquidatingCollateralBrand]?.typeOutAmount)) / + Number(oraclePrices[node?.liquidatingCollateralBrand]?.typeInAmount); return agg + collateralInUsd; }, 0); From 81b1a324ebe3caefadc6ac65d55e81a3fd5b6c0f Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Thu, 6 Jun 2024 14:30:14 +0500 Subject: [PATCH 3/4] test: update test snaps --- src/pages/InterProtocol.tsx | 4 +- tests/__snapshots__/Reserve.test.tsx.snap | 180 +++++++++++----------- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/pages/InterProtocol.tsx b/src/pages/InterProtocol.tsx index 42b3a28..f2e88f1 100644 --- a/src/pages/InterProtocol.tsx +++ b/src/pages/InterProtocol.tsx @@ -134,8 +134,8 @@ export function InterProtocol() { const collateralInUsd = ((Number(node?.totalCollateral) / tokenDivisor) * - Number(oraclePrices[node?.liquidatingCollateralBrand]?.typeOutAmount)) / - Number(oraclePrices[node?.liquidatingCollateralBrand]?.typeInAmount); + Number(oraclePrices[node?.liquidatingCollateralBrand]?.typeOutAmount) || 1) / + Number(oraclePrices[node?.liquidatingCollateralBrand]?.typeInAmount || 1); return agg + collateralInUsd; }, 0); diff --git a/tests/__snapshots__/Reserve.test.tsx.snap b/tests/__snapshots__/Reserve.test.tsx.snap index 74877c8..6958360 100644 --- a/tests/__snapshots__/Reserve.test.tsx.snap +++ b/tests/__snapshots__/Reserve.test.tsx.snap @@ -1449,7 +1449,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="83.83333333333333" > - 03/08 + 03/09 @@ -1485,7 +1485,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="91.5" > - 03/09 + 03/10 @@ -1521,7 +1521,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="99.16666666666666" > - 03/10 + 03/11 @@ -1557,7 +1557,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="106.83333333333333" > - 03/11 + 03/12 @@ -1593,7 +1593,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="114.5" > - 03/12 + 03/13 @@ -1629,7 +1629,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="122.16666666666667" > - 03/13 + 03/14 @@ -1665,7 +1665,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="129.83333333333334" > - 03/14 + 03/15 @@ -1701,7 +1701,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="137.50000000000003" > - 03/15 + 03/16 @@ -1737,7 +1737,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="145.16666666666669" > - 03/16 + 03/17 @@ -1773,7 +1773,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="152.83333333333334" > - 03/17 + 03/18 @@ -1809,7 +1809,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="160.50000000000003" > - 03/18 + 03/19 @@ -1845,7 +1845,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="168.16666666666669" > - 03/19 + 03/20 @@ -1881,7 +1881,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="175.83333333333334" > - 03/20 + 03/21 @@ -1917,7 +1917,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="183.50000000000003" > - 03/21 + 03/22 @@ -1953,7 +1953,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="191.16666666666669" > - 03/22 + 03/23 @@ -1989,7 +1989,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="198.83333333333334" > - 03/23 + 03/24 @@ -2025,7 +2025,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="206.50000000000003" > - 03/24 + 03/25 @@ -2061,7 +2061,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="214.16666666666669" > - 03/25 + 03/26 @@ -2097,7 +2097,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="221.83333333333334" > - 03/26 + 03/27 @@ -2133,7 +2133,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="229.50000000000003" > - 03/27 + 03/28 @@ -2169,7 +2169,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="237.16666666666669" > - 03/28 + 03/29 @@ -2205,7 +2205,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="244.83333333333334" > - 03/29 + 03/30 @@ -2241,7 +2241,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="252.50000000000003" > - 03/30 + 03/31 @@ -2277,7 +2277,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="260.1666666666667" > - 03/31 + 04/01 @@ -2313,7 +2313,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="267.8333333333333" > - 04/01 + 04/02 @@ -2349,7 +2349,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="275.5" > - 04/02 + 04/03 @@ -2385,7 +2385,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="283.1666666666667" > - 04/03 + 04/04 @@ -2421,7 +2421,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="290.8333333333333" > - 04/04 + 04/05 @@ -2457,7 +2457,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="298.5" > - 04/05 + 04/06 @@ -2493,7 +2493,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="306.1666666666667" > - 04/06 + 04/07 @@ -2529,7 +2529,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="313.8333333333333" > - 04/07 + 04/08 @@ -2565,7 +2565,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="321.5" > - 04/08 + 04/09 @@ -2601,7 +2601,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="329.1666666666667" > - 04/09 + 04/10 @@ -2637,7 +2637,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="336.8333333333333" > - 04/10 + 04/11 @@ -2673,7 +2673,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="344.5" > - 04/11 + 04/12 @@ -2709,7 +2709,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="352.1666666666667" > - 04/12 + 04/13 @@ -2745,7 +2745,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="359.8333333333333" > - 04/13 + 04/14 @@ -2781,7 +2781,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="367.5" > - 04/14 + 04/15 @@ -2817,7 +2817,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="375.1666666666667" > - 04/15 + 04/16 @@ -2853,7 +2853,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="382.8333333333333" > - 04/16 + 04/17 @@ -2889,7 +2889,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="390.5" > - 04/17 + 04/18 @@ -2925,7 +2925,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="398.1666666666667" > - 04/18 + 04/19 @@ -2961,7 +2961,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="405.8333333333333" > - 04/19 + 04/20 @@ -2997,7 +2997,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="413.5" > - 04/20 + 04/21 @@ -3033,7 +3033,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="421.1666666666667" > - 04/21 + 04/22 @@ -3069,7 +3069,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="428.8333333333333" > - 04/22 + 04/23 @@ -3105,7 +3105,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="436.5" > - 04/23 + 04/24 @@ -3141,7 +3141,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="444.1666666666667" > - 04/24 + 04/25 @@ -3177,7 +3177,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="451.8333333333333" > - 04/25 + 04/26 @@ -3213,7 +3213,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="459.5" > - 04/26 + 04/27 @@ -3249,7 +3249,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="467.1666666666667" > - 04/27 + 04/28 @@ -3285,7 +3285,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="474.8333333333333" > - 04/28 + 04/29 @@ -3321,7 +3321,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="482.5" > - 04/29 + 04/30 @@ -3357,7 +3357,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="490.1666666666667" > - 04/30 + 05/01 @@ -3393,7 +3393,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="497.8333333333333" > - 05/01 + 05/02 @@ -3429,7 +3429,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="505.5" > - 05/02 + 05/03 @@ -3465,7 +3465,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="513.1666666666667" > - 05/03 + 05/04 @@ -3501,7 +3501,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="520.8333333333334" > - 05/04 + 05/05 @@ -3537,7 +3537,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="528.5000000000001" > - 05/05 + 05/06 @@ -3573,7 +3573,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="536.1666666666667" > - 05/06 + 05/07 @@ -3609,7 +3609,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="543.8333333333334" > - 05/07 + 05/08 @@ -3645,7 +3645,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="551.5000000000001" > - 05/08 + 05/09 @@ -3681,7 +3681,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="559.1666666666667" > - 05/09 + 05/10 @@ -3717,7 +3717,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="566.8333333333334" > - 05/10 + 05/11 @@ -3753,7 +3753,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="574.5000000000001" > - 05/11 + 05/12 @@ -3789,7 +3789,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="582.1666666666667" > - 05/12 + 05/13 @@ -3825,7 +3825,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="589.8333333333334" > - 05/13 + 05/14 @@ -3861,7 +3861,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="597.5000000000001" > - 05/14 + 05/15 @@ -3897,7 +3897,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="605.1666666666667" > - 05/15 + 05/16 @@ -3933,7 +3933,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="612.8333333333334" > - 05/16 + 05/17 @@ -3969,7 +3969,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="620.5000000000001" > - 05/17 + 05/18 @@ -4005,7 +4005,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="628.1666666666667" > - 05/18 + 05/19 @@ -4041,7 +4041,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="635.8333333333334" > - 05/19 + 05/20 @@ -4077,7 +4077,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="643.5000000000001" > - 05/20 + 05/21 @@ -4113,7 +4113,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="651.1666666666667" > - 05/21 + 05/22 @@ -4149,7 +4149,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="658.8333333333334" > - 05/22 + 05/23 @@ -4185,7 +4185,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="666.5000000000001" > - 05/23 + 05/24 @@ -4221,7 +4221,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="674.1666666666667" > - 05/24 + 05/25 @@ -4257,7 +4257,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="681.8333333333334" > - 05/25 + 05/26 @@ -4293,7 +4293,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="689.5000000000001" > - 05/26 + 05/27 @@ -4329,7 +4329,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="697.1666666666667" > - 05/27 + 05/28 @@ -4365,7 +4365,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="704.8333333333334" > - 05/28 + 05/29 @@ -4401,7 +4401,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="712.5000000000001" > - 05/29 + 05/30 @@ -4437,7 +4437,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="720.1666666666667" > - 05/30 + 05/31 @@ -4473,7 +4473,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="727.8333333333334" > - 05/31 + 06/01 @@ -4509,7 +4509,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="735.5000000000001" > - 06/01 + 06/02 @@ -4545,7 +4545,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="743.1666666666667" > - 06/02 + 06/03 @@ -4581,7 +4581,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="750.8333333333334" > - 06/03 + 06/04 @@ -4617,7 +4617,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="758.5000000000001" > - 06/04 + 06/05 @@ -4653,7 +4653,7 @@ exports[`Reserve Dashboard Snapshot tests should match snapshot when data is loa dy="0.71em" x="766.1666666666667" > - 06/05 + 06/06 From 90369ec45857b159dda9d9084e2341328831811d Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Thu, 6 Jun 2024 15:53:39 +0500 Subject: [PATCH 4/4] chore: use NaN as token divisor if boardAuxes is falsy --- src/utils.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils.tsx b/src/utils.tsx index 1396c89..e449a0f 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -251,8 +251,18 @@ export function createNumberWithLeadingZeroes(numOfZeroes: number) { export const parseBigInt = (str: string) => Number(str.slice(0, -1)); -export const getTokenDivisor = (boardAuxes: { [key: string]: number }, tokenName: string) => { - const decimalPlaces = (boardAuxes && boardAuxes[tokenName]) || 6; - const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces); - return tokenDivisor; +/** + * The function computes the token divisor for a given token name. + * + * If boardAuxes is falsy (null or undefined), the function returns a NaN value + * to reflect anomalies in the data on the UI. + * + */ +export const getTokenDivisor = (boardAuxes: { [key: string]: number } | null, tokenName: string): number => { + if (!boardAuxes) { + return NaN; + } + + const decimalPlaces = boardAuxes[tokenName] ?? 6; + return createNumberWithLeadingZeroes(decimalPlaces); };