diff --git a/apps/vaults/components/details/tabs/VaultDetailsStrategies.tsx b/apps/vaults/components/details/tabs/VaultDetailsStrategies.tsx index 2d47f85da..559b7264f 100755 --- a/apps/vaults/components/details/tabs/VaultDetailsStrategies.tsx +++ b/apps/vaults/components/details/tabs/VaultDetailsStrategies.tsx @@ -180,17 +180,14 @@ function VaultDetailsStrategy({currentVault, strategy}: TProps): ReactElement {
-

{'Historical APR'}

-
- - - -
+ + +
@@ -201,20 +198,12 @@ function VaultDetailsStrategy({currentVault, strategy}: TProps): ReactElement { function isExceptionStrategy(strategy: TYDaemonVaultStrategy): boolean { // Curve DAO Fee and Bribes Reinvest - return strategy.address.toString() === '0x23724D764d8b3d26852BA20d3Bc2578093d2B022' && !!strategy.details?.inQueue; + return strategy.address.toString() === '0x23724D764d8b3d26852BA20d3Bc2578093d2B022'; } export function VaultDetailsStrategies({currentVault}: {currentVault: TYDaemonVault}): ReactElement { const [searchValue, set_searchValue] = useState(''); - const [shouldHide0DebtStrategies, set_shouldHide0DebtStrategies] = useState(true); - - const hide0DebtStrategyFilter = (strategy: TYDaemonVaultStrategy): boolean => { - return !shouldHide0DebtStrategies || Number(strategy.details?.totalDebt) > 0 || isExceptionStrategy(strategy); - }; - - const nameSearchFilter = ({name, displayName}: TYDaemonVaultStrategy): boolean => { - return !searchValue || `${name} ${displayName}`.toLowerCase().includes(searchValue); - }; + const [shouldDisplayInactiveStrategies, set_shouldDisplayInactiveStrategies] = useState(true); const sortedStrategies = useMemo((): TYDaemonVault['strategies'] => { return (currentVault.strategies || []).sort( @@ -222,7 +211,21 @@ export function VaultDetailsStrategies({currentVault}: {currentVault: TYDaemonVa ); }, [currentVault.strategies]); - const filteredStrategies = (sortedStrategies || []).filter(hide0DebtStrategyFilter).filter(nameSearchFilter); + const filteredStrategies = useMemo((): TYDaemonVault['strategies'] => { + return (sortedStrategies || []) + .filter((strategy): boolean => { + if (!searchValue) { + return true; + } + return `${strategy.name} ${strategy.displayName}`.toLowerCase().includes(searchValue); + }) + .filter((strategy): boolean => { + if (!shouldDisplayInactiveStrategies) { + return Number(strategy.details?.totalDebt) > 0 || isExceptionStrategy(strategy); + } + return true; + }); + }, [searchValue, shouldDisplayInactiveStrategies, sortedStrategies]); return (
@@ -239,16 +242,16 @@ export function VaultDetailsStrategies({currentVault}: {currentVault: TYDaemonVa
{'Hide 0 debt strategies'} { - set_shouldHide0DebtStrategies((prev): boolean => !prev); + set_shouldDisplayInactiveStrategies((prev): boolean => !prev); }} />
- {filteredStrategies.map( + {(filteredStrategies || []).map( (strategy): ReactElement => ( - - { - e.className = `${e.className} activeDot`; - delete e.dataKey; - return ; - }} - /> - - { - const { - payload: {value} - } = e; - e.fill = '#5B5B5B'; - e.className = 'text-xxs md:text-xs font-number z-10 '; - e.alignmentBaseline = 'middle'; - delete e.verticalAnchor; - delete e.visibleTicksCount; - delete e.tickFormatter; - const formatedValue = formatPercent(value); - return {formatedValue}; - }} - /> - { - const {active: isTooltipActive, payload, label} = e; - if (!isTooltipActive || !payload) { - return <>; - } - if (payload.length > 0) { - const [{value, payload: innerPayload}] = payload; - const {gain, loss} = innerPayload; - const diff = toBigInt(gain) - toBigInt(loss); - const normalizedDiff = formatToNormalizedValue(diff, vaultDecimals); + <> +

{'Historical APR'}

+
+ + + { + e.className = `${e.className} activeDot`; + delete e.dataKey; + return ; + }} + /> + + { + const { + payload: {value} + } = e; + e.fill = '#5B5B5B'; + e.className = 'text-xxs md:text-xs font-number z-10 '; + e.alignmentBaseline = 'middle'; + delete e.verticalAnchor; + delete e.visibleTicksCount; + delete e.tickFormatter; + const formatedValue = formatPercent(value); + return {formatedValue}; + }} + /> + { + const {active: isTooltipActive, payload, label} = e; + if (!isTooltipActive || !payload) { + return <>; + } + if (payload.length > 0) { + const [{value, payload: innerPayload}] = payload; + const {gain, loss} = innerPayload; + const diff = toBigInt(gain) - toBigInt(loss); + const normalizedDiff = formatToNormalizedValue(diff, vaultDecimals); - return ( -
-
-

{formatDate(label)}

-
-
-

{'APR'}

- - {formatPercent(Number(value))} - -
-
-

- {normalizedDiff > 0 ? 'Gain' : 'Loss'} -

- {`${formatAmount(normalizedDiff)} ${vaultTicker}`} -
-
- ); - } - return
; - }} - /> - - + return ( +
+
+

{formatDate(label)}

+
+
+

{'APR'}

+ + {formatPercent(Number(value))} + +
+
+

+ {normalizedDiff > 0 ? 'Gain' : 'Loss'} +

+ {`${formatAmount(normalizedDiff)} ${vaultTicker}`} +
+
+ ); + } + return
; + }} + /> + + +
+ ); }