UNPKG

@cranberry-money/shared-utils

Version:

Shared utility functions for Blueberry platform

23 lines 1.2 kB
import { LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED, } from '@cranberry-money/shared-constants'; export function calculateLiquidationProgress(liquidations) { const total = liquidations.length; const pending = liquidations.filter(l => l.liquidationStatus === LIQUIDATION_STATUS_PENDING).length; const inProgress = liquidations.filter(l => [LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED].includes(l.liquidationStatus)).length; const completed = liquidations.filter(l => l.liquidationStatus === LIQUIDATION_STATUS_SETTLED).length; const failed = liquidations.filter(l => l.liquidationStatus === LIQUIDATION_STATUS_FAILED).length; const completionRate = total > 0 ? (completed / total) * 100 : 0; return { total, pending, inProgress, completed, failed, completionRate, }; } export function getTotalEstimatedValue(liquidations) { return liquidations.reduce((total, liquidation) => { return total + parseFloat(liquidation.estimatedValue || '0'); }, 0); } //# sourceMappingURL=withdrawal.js.map