From 16916e16c5e08b5bbc9c1093f4c8e12fd2fc218f Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 7 Jun 2024 16:08:27 +0500 Subject: [PATCH 1/3] chore add a fallback if item.active does not exist --- src/pages/Liquidated.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pages/Liquidated.tsx b/src/pages/Liquidated.tsx index 0b56e1f..99cca03 100644 --- a/src/pages/Liquidated.tsx +++ b/src/pages/Liquidated.tsx @@ -64,11 +64,14 @@ export function Liquidated() { const graphDataList = populateMissingDays(graphDataMap, GRAPH_DAYS); - const summedGraphDataList = graphDataList.map((item) => ({ - ...item, - active: sum(Object.values(item.active)), - liquidated: sum(Object.values(item.active)), - })); + const summedGraphDataList = graphDataList.map((item) => { + const total = item.active ? sum(Object.values(item.active)) : 0; + return { + ...item, + active: total, + liquidated: total, + }; + }); return ( <> @@ -77,7 +80,7 @@ export function Liquidated() { - {/* */} +
From 4a171da98223442458249d6ebb915dc96cd58df2 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 7 Jun 2024 16:13:56 +0500 Subject: [PATCH 2/3] test: update snaps --- src/pages/Liquidated.tsx | 8 +- src/types/common.ts | 1 + src/utils.tsx | 2 +- src/widgets/LiquidatedVaults.tsx | 7 +- tests/__snapshots__/Liquidated.test.tsx.snap | 5661 ++++++++++++++++++ 5 files changed, 5673 insertions(+), 6 deletions(-) diff --git a/src/pages/Liquidated.tsx b/src/pages/Liquidated.tsx index 99cca03..0259b75 100644 --- a/src/pages/Liquidated.tsx +++ b/src/pages/Liquidated.tsx @@ -65,11 +65,13 @@ export function Liquidated() { const graphDataList = populateMissingDays(graphDataMap, GRAPH_DAYS); const summedGraphDataList = graphDataList.map((item) => { - const total = item.active ? sum(Object.values(item.active)) : 0; + const totalActive = item.active ? sum(Object.values(item.active)) : NaN; + const totalLiquidated = item.liquidated ? sum(Object.values(item.liquidated)) : NaN; + return { ...item, - active: total, - liquidated: total, + active: totalActive, + liquidated: totalLiquidated, }; }); diff --git a/src/types/common.ts b/src/types/common.ts index 7b2c2c0..5194e87 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -3,6 +3,7 @@ export type FormattedGraphData = { x: string; key: number; active?: any; + liquidated?: any; }; export type DailyOracles = { diff --git a/src/utils.tsx b/src/utils.tsx index 3681214..ccab9ac 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -249,7 +249,7 @@ 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)); /** diff --git a/src/widgets/LiquidatedVaults.tsx b/src/widgets/LiquidatedVaults.tsx index b22291f..ae69347 100644 --- a/src/widgets/LiquidatedVaults.tsx +++ b/src/widgets/LiquidatedVaults.tsx @@ -41,9 +41,10 @@ export function LiquidatedVaults({ title = 'Liquidated Vaults', data, boardAuxes const vaultStateSuffix = vaultData?.currentState?.state === VAULT_STATES.CLOSED ? ' (Closed)' : ''; const vaultState = vaultData.state[0].toUpperCase() + vaultData.state.slice(1) + vaultStateSuffix; + console.log("YYYYYYYYYYYY", vaultData) const liquidationRatio = - parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginNumerator) / - parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginDenominator); + parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginNumerator || '') / + parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginDenominator || ''); const istDivisor = getTokenDivisor(boardAuxes, 'IST'); const tokenDivisor = getTokenDivisor(boardAuxes, vaultData.denom); @@ -52,6 +53,8 @@ export function LiquidatedVaults({ title = 'Liquidated Vaults', data, boardAuxes const collateralAmount = vaultData.liquidatingState.balance / tokenDivisor; const liquidationPrice = (istDebtAmount * liquidationRatio) / collateralAmount; const collateralAmountReturned = (vaultData.liquidatingState.balance - vaultData.balance) / tokenDivisor; + console.log("YYYYYYYYYYYY 5555") + const oraclePriceRatio = parseBigInt(vaultData.oraclePrice?.typeOutAmount) / parseBigInt(vaultData.oraclePrice?.typeInAmount); const collateralAmountReturnedUsd = collateralAmountReturned * oraclePriceRatio; diff --git a/tests/__snapshots__/Liquidated.test.tsx.snap b/tests/__snapshots__/Liquidated.test.tsx.snap index 923045b..b04444f 100644 --- a/tests/__snapshots__/Liquidated.test.tsx.snap +++ b/tests/__snapshots__/Liquidated.test.tsx.snap @@ -36,6 +36,5638 @@ exports[`Liquidation Dashboard Snapshot tests should match snapshot when data is +
+
+

+ Vault States +

+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 02/10 + + + + + + + + 02/11 + + + + + + + + 02/12 + + + + + + + + 02/13 + + + + + + + + 02/14 + + + + + + + + 02/15 + + + + + + + + 02/16 + + + + + + + + 02/17 + + + + + + + + 02/18 + + + + + + + + 02/19 + + + + + + + + 02/20 + + + + + + + + 02/21 + + + + + + + + 02/22 + + + + + + + + 02/23 + + + + + + + + 02/24 + + + + + + + + 02/25 + + + + + + + + 02/26 + + + + + + + + 02/27 + + + + + + + + 02/28 + + + + + + + + 02/29 + + + + + + + + 03/01 + + + + + + + + 03/02 + + + + + + + + 03/03 + + + + + + + + 03/04 + + + + + + + + 03/05 + + + + + + + + 03/06 + + + + + + + + 03/07 + + + + + + + + 03/08 + + + + + + + + 03/09 + + + + + + + + 03/10 + + + + + + + + 03/11 + + + + + + + + 03/12 + + + + + + + + 03/13 + + + + + + + + 03/14 + + + + + + + + 03/15 + + + + + + + + 03/16 + + + + + + + + 03/17 + + + + + + + + 03/18 + + + + + + + + 03/19 + + + + + + + + 03/20 + + + + + + + + 03/21 + + + + + + + + 03/22 + + + + + + + + 03/23 + + + + + + + + 03/24 + + + + + + + + 03/25 + + + + + + + + 03/26 + + + + + + + + 03/27 + + + + + + + + 03/28 + + + + + + + + 03/29 + + + + + + + + 03/30 + + + + + + + + 03/31 + + + + + + + + 04/01 + + + + + + + + 04/02 + + + + + + + + 04/03 + + + + + + + + 04/04 + + + + + + + + 04/05 + + + + + + + + 04/06 + + + + + + + + 04/07 + + + + + + + + 04/08 + + + + + + + + 04/09 + + + + + + + + 04/10 + + + + + + + + 04/11 + + + + + + + + 04/12 + + + + + + + + 04/13 + + + + + + + + 04/14 + + + + + + + + 04/15 + + + + + + + + 04/16 + + + + + + + + 04/17 + + + + + + + + 04/18 + + + + + + + + 04/19 + + + + + + + + 04/20 + + + + + + + + 04/21 + + + + + + + + 04/22 + + + + + + + + 04/23 + + + + + + + + 04/24 + + + + + + + + 04/25 + + + + + + + + 04/26 + + + + + + + + 04/27 + + + + + + + + 04/28 + + + + + + + + 04/29 + + + + + + + + 04/30 + + + + + + + + 05/01 + + + + + + + + 05/02 + + + + + + + + 05/03 + + + + + + + + 05/04 + + + + + + + + 05/05 + + + + + + + + 05/06 + + + + + + + + 05/07 + + + + + + + + 05/08 + + + + + + + + 05/09 + + + + + + + + + + + + + 0 + + + + + + + + 75 + + + + + + + + 150 + + + + + + + + 225 + + + + + + + + 300 + + + + + + + + + + + + + 0 + + + + + + + + 75 + + + + + + + + 150 + + + + + + + + 225 + + + + + + + + 300 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
    +
  • + + + + + + + Active + +
  • +
  • + + + + + + + Liquidated + +
  • +
+
+ +
+
+
+

@@ -615,6 +6247,35 @@ exports[`Liquidation Dashboard Snapshot tests should match snapshot when data is +
+
+

+ Vault States +

+
+
+
+
+
+
+
+

From d3759fd7b68e8eee94314e5474c930badd64964d Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 7 Jun 2024 18:47:01 +0500 Subject: [PATCH 3/3] fix: use aggregate of item.liquidated --- src/pages/Liquidated.tsx | 8 +- src/widgets/LiquidatedVaults.tsx | 7 +- tests/__snapshots__/Liquidated.test.tsx.snap | 5661 ------------------ 3 files changed, 6 insertions(+), 5670 deletions(-) diff --git a/src/pages/Liquidated.tsx b/src/pages/Liquidated.tsx index 0259b75..5340e4c 100644 --- a/src/pages/Liquidated.tsx +++ b/src/pages/Liquidated.tsx @@ -65,13 +65,13 @@ export function Liquidated() { const graphDataList = populateMissingDays(graphDataMap, GRAPH_DAYS); const summedGraphDataList = graphDataList.map((item) => { - const totalActive = item.active ? sum(Object.values(item.active)) : NaN; - const totalLiquidated = item.liquidated ? sum(Object.values(item.liquidated)) : NaN; + const totalActive = item.active ? sum(Object.values(item.active)) : 0; + const totalLiquidated = item.liquidated ? sum(Object.values(item.liquidated)) : 0; return { ...item, active: totalActive, - liquidated: totalLiquidated, + liquidated: totalLiquidated }; }); @@ -82,7 +82,7 @@ export function Liquidated() { - + {/* */}
diff --git a/src/widgets/LiquidatedVaults.tsx b/src/widgets/LiquidatedVaults.tsx index ae69347..b22291f 100644 --- a/src/widgets/LiquidatedVaults.tsx +++ b/src/widgets/LiquidatedVaults.tsx @@ -41,10 +41,9 @@ export function LiquidatedVaults({ title = 'Liquidated Vaults', data, boardAuxes const vaultStateSuffix = vaultData?.currentState?.state === VAULT_STATES.CLOSED ? ' (Closed)' : ''; const vaultState = vaultData.state[0].toUpperCase() + vaultData.state.slice(1) + vaultStateSuffix; - console.log("YYYYYYYYYYYY", vaultData) const liquidationRatio = - parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginNumerator || '') / - parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginDenominator || ''); + parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginNumerator) / + parseBigInt(vaultData.vaultManagerGovernance?.liquidationMarginDenominator); const istDivisor = getTokenDivisor(boardAuxes, 'IST'); const tokenDivisor = getTokenDivisor(boardAuxes, vaultData.denom); @@ -53,8 +52,6 @@ export function LiquidatedVaults({ title = 'Liquidated Vaults', data, boardAuxes const collateralAmount = vaultData.liquidatingState.balance / tokenDivisor; const liquidationPrice = (istDebtAmount * liquidationRatio) / collateralAmount; const collateralAmountReturned = (vaultData.liquidatingState.balance - vaultData.balance) / tokenDivisor; - console.log("YYYYYYYYYYYY 5555") - const oraclePriceRatio = parseBigInt(vaultData.oraclePrice?.typeOutAmount) / parseBigInt(vaultData.oraclePrice?.typeInAmount); const collateralAmountReturnedUsd = collateralAmountReturned * oraclePriceRatio; diff --git a/tests/__snapshots__/Liquidated.test.tsx.snap b/tests/__snapshots__/Liquidated.test.tsx.snap index b04444f..923045b 100644 --- a/tests/__snapshots__/Liquidated.test.tsx.snap +++ b/tests/__snapshots__/Liquidated.test.tsx.snap @@ -36,5638 +36,6 @@ exports[`Liquidation Dashboard Snapshot tests should match snapshot when data is
-
-
-

- Vault States -

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 02/10 - - - - - - - - 02/11 - - - - - - - - 02/12 - - - - - - - - 02/13 - - - - - - - - 02/14 - - - - - - - - 02/15 - - - - - - - - 02/16 - - - - - - - - 02/17 - - - - - - - - 02/18 - - - - - - - - 02/19 - - - - - - - - 02/20 - - - - - - - - 02/21 - - - - - - - - 02/22 - - - - - - - - 02/23 - - - - - - - - 02/24 - - - - - - - - 02/25 - - - - - - - - 02/26 - - - - - - - - 02/27 - - - - - - - - 02/28 - - - - - - - - 02/29 - - - - - - - - 03/01 - - - - - - - - 03/02 - - - - - - - - 03/03 - - - - - - - - 03/04 - - - - - - - - 03/05 - - - - - - - - 03/06 - - - - - - - - 03/07 - - - - - - - - 03/08 - - - - - - - - 03/09 - - - - - - - - 03/10 - - - - - - - - 03/11 - - - - - - - - 03/12 - - - - - - - - 03/13 - - - - - - - - 03/14 - - - - - - - - 03/15 - - - - - - - - 03/16 - - - - - - - - 03/17 - - - - - - - - 03/18 - - - - - - - - 03/19 - - - - - - - - 03/20 - - - - - - - - 03/21 - - - - - - - - 03/22 - - - - - - - - 03/23 - - - - - - - - 03/24 - - - - - - - - 03/25 - - - - - - - - 03/26 - - - - - - - - 03/27 - - - - - - - - 03/28 - - - - - - - - 03/29 - - - - - - - - 03/30 - - - - - - - - 03/31 - - - - - - - - 04/01 - - - - - - - - 04/02 - - - - - - - - 04/03 - - - - - - - - 04/04 - - - - - - - - 04/05 - - - - - - - - 04/06 - - - - - - - - 04/07 - - - - - - - - 04/08 - - - - - - - - 04/09 - - - - - - - - 04/10 - - - - - - - - 04/11 - - - - - - - - 04/12 - - - - - - - - 04/13 - - - - - - - - 04/14 - - - - - - - - 04/15 - - - - - - - - 04/16 - - - - - - - - 04/17 - - - - - - - - 04/18 - - - - - - - - 04/19 - - - - - - - - 04/20 - - - - - - - - 04/21 - - - - - - - - 04/22 - - - - - - - - 04/23 - - - - - - - - 04/24 - - - - - - - - 04/25 - - - - - - - - 04/26 - - - - - - - - 04/27 - - - - - - - - 04/28 - - - - - - - - 04/29 - - - - - - - - 04/30 - - - - - - - - 05/01 - - - - - - - - 05/02 - - - - - - - - 05/03 - - - - - - - - 05/04 - - - - - - - - 05/05 - - - - - - - - 05/06 - - - - - - - - 05/07 - - - - - - - - 05/08 - - - - - - - - 05/09 - - - - - - - - - - - - - 0 - - - - - - - - 75 - - - - - - - - 150 - - - - - - - - 225 - - - - - - - - 300 - - - - - - - - - - - - - 0 - - - - - - - - 75 - - - - - - - - 150 - - - - - - - - 225 - - - - - - - - 300 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
    -
  • - - - - - - - Active - -
  • -
  • - - - - - - - Liquidated - -
  • -
-
- -
-
-
-

@@ -6247,35 +615,6 @@ exports[`Liquidation Dashboard Snapshot tests should match snapshot when data is
-
-
-

- Vault States -

-
-
-
-
-
-
-
-