From 5388035d336aa93a24a75aade7cb147bfd08511c Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 9 Feb 2023 11:31:53 +1100 Subject: [PATCH 1/2] handle swap reduce only --- components/swap/SwapForm.tsx | 28 +++++++++++++++--- components/swap/SwapFormTokenList.tsx | 25 +++++++++++++---- components/swap/useTokenMax.tsx | 39 ++++++++++++++++---------- components/trade/AdvancedTradeForm.tsx | 2 +- public/locales/en/swap.json | 2 ++ public/locales/en/trade.json | 1 + public/locales/es/swap.json | 2 ++ public/locales/es/trade.json | 1 + public/locales/ru/swap.json | 2 ++ public/locales/ru/trade.json | 1 + public/locales/zh/swap.json | 2 ++ public/locales/zh_tw/swap.json | 2 ++ 12 files changed, 82 insertions(+), 25 deletions(-) diff --git a/components/swap/SwapForm.tsx b/components/swap/SwapForm.tsx index 8470972f..9900fdad 100644 --- a/components/swap/SwapForm.tsx +++ b/components/swap/SwapForm.tsx @@ -63,7 +63,7 @@ const SwapForm = () => { //initial state is undefined null is returned on error const [selectedRoute, setSelectedRoute] = useState() const [animateSwitchArrow, setAnimateSwitchArrow] = useState(0) - const [showTokenSelect, setShowTokenSelect] = useState('') + const [showTokenSelect, setShowTokenSelect] = useState(undefined) const [showSettings, setShowSettings] = useState(false) const [showConfirm, setShowConfirm] = useState(false) const { group } = useMangoGroup() @@ -193,7 +193,7 @@ const SwapForm = () => { s.swap.inputBank = bank }) } - setShowTokenSelect('') + setShowTokenSelect(undefined) }, []) const handleTokenOutSelect = useCallback((mintAddress: string) => { @@ -204,7 +204,7 @@ const SwapForm = () => { s.swap.outputBank = bank }) } - setShowTokenSelect('') + setShowTokenSelect(undefined) }, []) const handleSwitchTokens = useCallback(() => { @@ -299,7 +299,7 @@ const SwapForm = () => { show={!!showTokenSelect} > setShowTokenSelect('')} + onClose={() => setShowTokenSelect(undefined)} onTokenSelect={ showTokenSelect === 'input' ? handleTokenInSelect @@ -451,6 +451,26 @@ const SwapForm = () => { {group && inputBank ? ( ) : null} + {inputBank && inputBank.reduceOnly ? ( +
+ +
+ ) : null} + {outputBank && outputBank.reduceOnly ? ( +
+ +
+ ) : null}
diff --git a/components/swap/SwapFormTokenList.tsx b/components/swap/SwapFormTokenList.tsx index 94383112..5a672ee8 100644 --- a/components/swap/SwapFormTokenList.tsx +++ b/components/swap/SwapFormTokenList.tsx @@ -47,10 +47,17 @@ const TokenItem = ({ token: Token onSubmit: (x: string) => void useMargin: boolean - type: string + type: 'input' | 'output' | undefined }) => { + const { t } = useTranslation('trade') const { address, symbol, logoURI, name } = token + const bank = useMemo(() => { + const group = mangoStore.getState().group + if (!group) return + return group.getFirstBankByMint(new PublicKey(address)) + }, [address]) + return (
{type === 'input' && @@ -103,7 +118,7 @@ const SwapFormTokenList = ({ }: { onClose: () => void onTokenSelect: (x: string) => void - type: string + type: 'input' | 'output' | undefined useMargin: boolean }) => { const { t } = useTranslation(['common', 'swap']) diff --git a/components/swap/useTokenMax.tsx b/components/swap/useTokenMax.tsx index 5b676433..5aed2e09 100644 --- a/components/swap/useTokenMax.tsx +++ b/components/swap/useTokenMax.tsx @@ -49,19 +49,29 @@ export const getTokenInMax = ( mangoAccount.getTokenBalanceUi(inputBank) ) - const maxAmountWithoutMargin = inputTokenBalance.gt(0) - ? inputTokenBalance - : new Decimal(0) - - const maxUiAmountWithBorrow = floorToDecimal( - mangoAccount.getMaxSourceUiForTokenSwap( - group, - inputBank.mint, - outputBank.mint - ), - inputBank.mintDecimals + const outputTokenBalance = new Decimal( + mangoAccount.getTokenBalanceUi(outputBank) ) + const maxAmountWithoutMargin = + (inputTokenBalance.gt(0) && !outputBank.reduceOnly) || + (outputBank.reduceOnly && outputTokenBalance.lt(0)) + ? inputTokenBalance + : new Decimal(0) + + const maxUiAmountWithBorrow = + outputBank.reduceOnly && + (outputTokenBalance.gt(0) || outputTokenBalance.eq(0)) + ? new Decimal(0) + : floorToDecimal( + mangoAccount.getMaxSourceUiForTokenSwap( + group, + inputBank.mint, + outputBank.mint + ), + inputBank.mintDecimals + ) + const inputBankVaultBalance = floorToDecimal( group .getTokenVaultBalanceByMintUi(inputBank.mint) @@ -81,10 +91,9 @@ export const getTokenInMax = ( maxUiAmountWithBorrow ) - const maxAmountWithBorrow = Decimal.min( - maxUiAmountWithBorrow, - inputBankVaultBalance - ) + const maxAmountWithBorrow = inputBank.reduceOnly + ? Decimal.min(maxAmountWithoutMargin, inputBankVaultBalance) + : Decimal.min(maxUiAmountWithBorrow, inputBankVaultBalance) return { amount: maxAmount, diff --git a/components/trade/AdvancedTradeForm.tsx b/components/trade/AdvancedTradeForm.tsx index 2aee0a38..c8670819 100644 --- a/components/trade/AdvancedTradeForm.tsx +++ b/components/trade/AdvancedTradeForm.tsx @@ -561,7 +561,7 @@ const AdvancedTradeForm = () => { checked={tradeForm.reduceOnly} onChange={(e) => handleReduceOnlyChange(e.target.checked)} > - Reduce Only + {t('trade:reduce-only')}
diff --git a/public/locales/en/swap.json b/public/locales/en/swap.json index a918f3e2..4cf427ff 100644 --- a/public/locales/en/swap.json +++ b/public/locales/en/swap.json @@ -5,12 +5,14 @@ "fees-paid-to": "Fees Paid to {{route}}", "health-impact": "Health Impact", "hide-fees": "Hide Fees", + "input-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap your balance to another token", "insufficient-balance": "Insufficient {{symbol}} Balance", "insufficient-collateral": "Insufficient Collateral", "max-slippage": "Max Slippage", "maximum-cost": "Maximum Cost", "minimum-received": "Minimum Received", "no-history": "No swap history", + "output-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap to close borrows only", "paid": "Paid", "pay": "You Pay", "preset": "Preset", diff --git a/public/locales/en/trade.json b/public/locales/en/trade.json index 6a1e53a6..08162e4b 100644 --- a/public/locales/en/trade.json +++ b/public/locales/en/trade.json @@ -38,6 +38,7 @@ "post": "Post", "price-expect": "The price you receive may be worse than you expect and full execution is not guaranteed. Max slippage is 2.5% for your safety. The part of your position with slippage beyond 2.5% will not be closed.", "quote": "Quote", + "reduce-only": "Reduce Only", "sells": "Sells", "settle-funds": "Settle Funds", "settle-funds-error": "Failed to settle funds", diff --git a/public/locales/es/swap.json b/public/locales/es/swap.json index a918f3e2..4cf427ff 100644 --- a/public/locales/es/swap.json +++ b/public/locales/es/swap.json @@ -5,12 +5,14 @@ "fees-paid-to": "Fees Paid to {{route}}", "health-impact": "Health Impact", "hide-fees": "Hide Fees", + "input-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap your balance to another token", "insufficient-balance": "Insufficient {{symbol}} Balance", "insufficient-collateral": "Insufficient Collateral", "max-slippage": "Max Slippage", "maximum-cost": "Maximum Cost", "minimum-received": "Minimum Received", "no-history": "No swap history", + "output-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap to close borrows only", "paid": "Paid", "pay": "You Pay", "preset": "Preset", diff --git a/public/locales/es/trade.json b/public/locales/es/trade.json index 6a1e53a6..08162e4b 100644 --- a/public/locales/es/trade.json +++ b/public/locales/es/trade.json @@ -38,6 +38,7 @@ "post": "Post", "price-expect": "The price you receive may be worse than you expect and full execution is not guaranteed. Max slippage is 2.5% for your safety. The part of your position with slippage beyond 2.5% will not be closed.", "quote": "Quote", + "reduce-only": "Reduce Only", "sells": "Sells", "settle-funds": "Settle Funds", "settle-funds-error": "Failed to settle funds", diff --git a/public/locales/ru/swap.json b/public/locales/ru/swap.json index a918f3e2..4cf427ff 100644 --- a/public/locales/ru/swap.json +++ b/public/locales/ru/swap.json @@ -5,12 +5,14 @@ "fees-paid-to": "Fees Paid to {{route}}", "health-impact": "Health Impact", "hide-fees": "Hide Fees", + "input-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap your balance to another token", "insufficient-balance": "Insufficient {{symbol}} Balance", "insufficient-collateral": "Insufficient Collateral", "max-slippage": "Max Slippage", "maximum-cost": "Maximum Cost", "minimum-received": "Minimum Received", "no-history": "No swap history", + "output-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap to close borrows only", "paid": "Paid", "pay": "You Pay", "preset": "Preset", diff --git a/public/locales/ru/trade.json b/public/locales/ru/trade.json index 6a1e53a6..08162e4b 100644 --- a/public/locales/ru/trade.json +++ b/public/locales/ru/trade.json @@ -38,6 +38,7 @@ "post": "Post", "price-expect": "The price you receive may be worse than you expect and full execution is not guaranteed. Max slippage is 2.5% for your safety. The part of your position with slippage beyond 2.5% will not be closed.", "quote": "Quote", + "reduce-only": "Reduce Only", "sells": "Sells", "settle-funds": "Settle Funds", "settle-funds-error": "Failed to settle funds", diff --git a/public/locales/zh/swap.json b/public/locales/zh/swap.json index a918f3e2..4cf427ff 100644 --- a/public/locales/zh/swap.json +++ b/public/locales/zh/swap.json @@ -5,12 +5,14 @@ "fees-paid-to": "Fees Paid to {{route}}", "health-impact": "Health Impact", "hide-fees": "Hide Fees", + "input-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap your balance to another token", "insufficient-balance": "Insufficient {{symbol}} Balance", "insufficient-collateral": "Insufficient Collateral", "max-slippage": "Max Slippage", "maximum-cost": "Maximum Cost", "minimum-received": "Minimum Received", "no-history": "No swap history", + "output-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap to close borrows only", "paid": "Paid", "pay": "You Pay", "preset": "Preset", diff --git a/public/locales/zh_tw/swap.json b/public/locales/zh_tw/swap.json index a918f3e2..4cf427ff 100644 --- a/public/locales/zh_tw/swap.json +++ b/public/locales/zh_tw/swap.json @@ -5,12 +5,14 @@ "fees-paid-to": "Fees Paid to {{route}}", "health-impact": "Health Impact", "hide-fees": "Hide Fees", + "input-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap your balance to another token", "insufficient-balance": "Insufficient {{symbol}} Balance", "insufficient-collateral": "Insufficient Collateral", "max-slippage": "Max Slippage", "maximum-cost": "Maximum Cost", "minimum-received": "Minimum Received", "no-history": "No swap history", + "output-reduce-only-warning": "{{symbol}} is in reduce only mode. You can swap to close borrows only", "paid": "Paid", "pay": "You Pay", "preset": "Preset", From 180d7bf79ce2ff1bf51fce8b076bc87596793c0c Mon Sep 17 00:00:00 2001 From: saml33 Date: Fri, 10 Feb 2023 23:55:06 +1100 Subject: [PATCH 2/2] improve detailed charts --- components/shared/Change.tsx | 4 +- components/shared/DetailedAreaChart.tsx | 75 ++++++++--- components/stats/MangoPerpStatsCharts.tsx | 38 +----- components/stats/PerpMarketDetails.tsx | 116 ++++++++++++------ components/stats/PerpMarketsTable.tsx | 51 +++++--- components/stats/PerpStats.tsx | 2 +- components/stats/TotalDepositBorrowCharts.tsx | 34 +---- components/token/ChartTabs.tsx | 36 +++--- 8 files changed, 191 insertions(+), 165 deletions(-) diff --git a/components/shared/Change.tsx b/components/shared/Change.tsx index e877a9bb..3bb5d95f 100644 --- a/components/shared/Change.tsx +++ b/components/shared/Change.tsx @@ -4,11 +4,13 @@ import FormatNumericValue from './FormatNumericValue' const Change = ({ change, + decimals, prefix, size, suffix, }: { change: number | typeof NaN + decimals?: number prefix?: string size?: 'small' suffix?: string @@ -44,7 +46,7 @@ const Change = ({ {prefix ? prefix : ''} {suffix ? suffix : ''}

diff --git a/components/shared/DetailedAreaChart.tsx b/components/shared/DetailedAreaChart.tsx index d38aae06..ed0277dd 100644 --- a/components/shared/DetailedAreaChart.tsx +++ b/components/shared/DetailedAreaChart.tsx @@ -45,6 +45,7 @@ interface DetailedAreaChartProps { tickFormat?: (x: number) => string title?: string xKey: string + yDecimals?: number yKey: string } @@ -72,6 +73,7 @@ const DetailedAreaChart: FunctionComponent = ({ tickFormat, title, xKey, + yDecimals, yKey, }) => { const { t } = useTranslation('common') @@ -92,22 +94,43 @@ const DetailedAreaChart: FunctionComponent = ({ setMouseData(null) } - const calculateChartChange = () => { - if (data.length) { - if (mouseData) { - const index = data.findIndex((d: any) => d[xKey] === mouseData[xKey]) - const change = index >= 0 ? data[index][yKey] - data[0][yKey] : 0 - return isNaN(change) ? 0 : change - } else return data[data.length - 1][yKey] - data[0][yKey] - } - return 0 - } - const flipGradientCoords = useMemo(() => { if (!data.length) return return data[0][yKey] <= 0 && data[data.length - 1][yKey] <= 0 }, [data]) + const filteredData = useMemo(() => { + if (!data.length) return [] + if (daysToShow !== '30') { + const seconds = Number(daysToShow) * 86400 + const filtered = data.filter((d: any) => { + const dataTime = new Date(d[xKey]).getTime() / 1000 + const now = new Date().getTime() / 1000 + const limit = now - seconds + return dataTime >= limit + }) + return filtered + } + return data + }, [data, daysToShow]) + + const calculateChartChange = () => { + if (filteredData.length) { + if (mouseData) { + const index = filteredData.findIndex( + (d: any) => d[xKey] === mouseData[xKey] + ) + const change = + index >= 0 ? filteredData[index][yKey] - filteredData[0][yKey] : 0 + return isNaN(change) ? 0 : change + } else + return ( + filteredData[filteredData.length - 1][yKey] - filteredData[0][yKey] + ) + } + return 0 + } + return ( @@ -119,7 +142,7 @@ const DetailedAreaChart: FunctionComponent = ({ } w-full rounded-lg bg-th-bkg-2`} /> - ) : data.length ? ( + ) : filteredData.length ? (
@@ -157,7 +180,8 @@ const DetailedAreaChart: FunctionComponent = ({ numbers={`${ mouseData[yKey] < 0 ? '-' : '' }${prefix}${formatNumericValue( - Math.abs(mouseData[yKey]) + Math.abs(mouseData[yKey]), + yDecimals )}${suffix}`} /> ) : ( @@ -166,6 +190,7 @@ const DetailedAreaChart: FunctionComponent = ({ {prefix} {suffix} @@ -174,6 +199,7 @@ const DetailedAreaChart: FunctionComponent = ({ @@ -203,17 +229,25 @@ const DetailedAreaChart: FunctionComponent = ({ width={small ? 17 : 30} play numbers={`${ - data[data.length - 1][yKey] < 0 ? '-' : '' + filteredData[filteredData.length - 1][yKey] < 0 + ? '-' + : '' }${prefix}${formatNumericValue( - Math.abs(data[data.length - 1][yKey]) + Math.abs( + filteredData[filteredData.length - 1][yKey] + ), + yDecimals )}${suffix}`} /> ) : ( - {data[data.length - 1][yKey] < 0 ? '-' : ''} + {filteredData[filteredData.length - 1][yKey] < 0 + ? '-' + : ''} {prefix} {suffix} @@ -222,6 +256,7 @@ const DetailedAreaChart: FunctionComponent = ({ @@ -233,9 +268,9 @@ const DetailedAreaChart: FunctionComponent = ({ small ? 'text-xs' : 'text-sm' } text-th-fgd-4`} > - {dayjs(data[data.length - 1][xKey]).format( - 'DD MMM YY, h:mma' - )} + {dayjs( + filteredData[filteredData.length - 1][xKey] + ).format('DD MMM YY, h:mma')}

)} @@ -258,7 +293,7 @@ const DetailedAreaChart: FunctionComponent = ({
diff --git a/components/stats/MangoPerpStatsCharts.tsx b/components/stats/MangoPerpStatsCharts.tsx index b12f0b1a..779b73e8 100644 --- a/components/stats/MangoPerpStatsCharts.tsx +++ b/components/stats/MangoPerpStatsCharts.tsx @@ -68,42 +68,12 @@ const MangoPerpStatsCharts = () => { return values.reverse() }, [perpStats]) - const filteredOiValues = useMemo(() => { - if (!totalOpenInterestValues.length) return [] - if (oiDaysToShow !== '30') { - const seconds = Number(oiDaysToShow) * 86400 - const data = totalOpenInterestValues.filter((d: OiValueItem) => { - const dataTime = new Date(d.date).getTime() / 1000 - const now = new Date().getTime() / 1000 - const limit = now - seconds - return dataTime >= limit - }) - return data - } - return totalOpenInterestValues - }, [totalOpenInterestValues, oiDaysToShow]) - - const filteredFeesValues = useMemo(() => { - if (!totalFeeValues.length) return [] - if (feesDaysToShow !== '30') { - const seconds = Number(feesDaysToShow) * 86400 - const data = totalFeeValues.filter((d: FeeValueItem) => { - const dataTime = new Date(d.date).getTime() / 1000 - const now = new Date().getTime() / 1000 - const limit = now - seconds - return dataTime >= limit - }) - return data - } - return totalFeeValues - }, [totalFeeValues, feesDaysToShow]) - return ( <> - {totalFeeValues.length ? ( + {totalOpenInterestValues.length ? (
{ />
) : null} - {totalOpenInterestValues.length ? ( + {totalFeeValues.length ? (
import('@components/shared/DetailedAreaChart'), { ssr: false } ) const PerpMarketDetails = ({ - perpMarket, + perpMarketName, setShowPerpDetails, }: { - perpMarket: string + perpMarketName: string setShowPerpDetails: (x: string) => void }) => { const { t } = useTranslation(['common', 'trade']) + const perpMarkets = mangoStore((s) => s.perpMarkets) const perpStats = mangoStore((s) => s.perpStats.data) const loadingPerpStats = mangoStore((s) => s.perpStats.loading) + const [priceDaysToShow, setPriceDaysToShow] = useState('30') + const [oiDaysToShow, setOiDaysToShow] = useState('30') + const [hourlyFundingeDaysToShow, setHourlyFundingDaysToShow] = useState('30') + const [instantFundingDaysToShow, setInstantFundingDaysToShow] = useState('30') + const rate = usePerpFundingRate() - const marketStats = useMemo(() => { - if (!perpStats) return [] - return perpStats.filter((stat) => stat.perp_market === perpMarket).reverse() + const perpMarket = useMemo(() => { + return perpMarkets.find((m) => (m.name = perpMarketName)) + }, [perpMarkets, perpMarketName]) + + const [marketStats, lastStat] = useMemo(() => { + if (!perpStats) return [[], undefined] + const stats = perpStats + .filter((stat) => stat.perp_market === perpMarketName) + .reverse() + return [stats, stats[stats.length - 1]] }, [perpStats]) + const fundingRate = useMemo(() => { + if (!lastStat) return 0 + if (rate?.isSuccess) { + const marketRate = rate?.data?.find( + (r) => r.market_index === perpMarket?.perpMarketIndex + ) + return marketRate?.funding_rate_hourly + } + return lastStat.instantaneous_funding_rate + }, [rate, lastStat]) + return (
@@ -38,38 +63,24 @@ const PerpMarketDetails = ({ > -

{`${perpMarket} ${t('stats')}`}

+

{`${perpMarketName} ${t('stats')}`}

- {loadingPerpStats ? ( - <> -
- -
- -
-
- -
- -
-
- -
- -
-
- -
- -
- - ) : marketStats.length ? ( + {marketStats.length && lastStat ? ( <>
formatYAxis(x)} title={t('price')} @@ -79,10 +90,21 @@ const PerpMarketDetails = ({
Math.floor(x).toString()} + loading={loadingPerpStats} + loaderHeightClass="h-[350px]" + tickFormat={(x) => formatYAxis(x)} title={t('trade:open-interest')} xKey="date_hour" yKey={'open_interest'} @@ -91,25 +113,39 @@ const PerpMarketDetails = ({
formatNumericValue(x, 4)} title={t('trade:hourly-funding')} xKey="date_hour" yKey={'funding_rate_hourly'} + yDecimals={5} />
formatNumericValue(x, 4)} title={t('trade:instantaneous-funding')} xKey="date_hour" yKey={'instantaneous_funding_rate'} + yDecimals={5} />
diff --git a/components/stats/PerpMarketsTable.tsx b/components/stats/PerpMarketsTable.tsx index f5692c8c..f67565b6 100644 --- a/components/stats/PerpMarketsTable.tsx +++ b/components/stats/PerpMarketsTable.tsx @@ -87,7 +87,7 @@ const PerpMarketsTable = ({ : 0 let fundingRate - if (rate.isSuccess && market instanceof PerpMarket) { + if (rate.isSuccess) { const marketRate = rate?.data?.find( (r) => r.market_index === market.perpMarketIndex ) @@ -198,6 +198,7 @@ const PerpMarketsTable = ({ ) })} @@ -209,7 +210,13 @@ const PerpMarketsTable = ({ export default PerpMarketsTable -const MobilePerpMarketItem = ({ market }: { market: PerpMarket }) => { +const MobilePerpMarketItem = ({ + market, + setShowPerpDetails, +}: { + market: PerpMarket + setShowPerpDetails: (x: string) => void +}) => { const { t } = useTranslation('common') const loadingPerpStats = mangoStore((s) => s.perpStats.loading) const perpStats = mangoStore((s) => s.perpStats.data) @@ -252,24 +259,30 @@ const MobilePerpMarketItem = ({ market }: { market: PerpMarket }) => {
+ {!loadingPerpStats ? ( + marketStats.length ? ( +
+ = 0 ? COLORS.UP[theme] : COLORS.DOWN[theme]} + data={marketStats} + name={market.name} + xKey="date_hour" + yKey="price" + /> +
+ ) : symbol === 'USDC' || symbol === 'USDT' ? null : ( +

{t('unavailable')}

+ ) + ) : ( +
+ )}
- {!loadingPerpStats ? ( - marketStats.length ? ( -
- = 0 ? COLORS.UP[theme] : COLORS.DOWN[theme]} - data={marketStats} - name={market.name} - xKey="date_hour" - yKey="price" - /> -
- ) : symbol === 'USDC' || symbol === 'USDT' ? null : ( -

{t('unavailable')}

- ) - ) : ( -
- )} + setShowPerpDetails(market.name)} + size="medium" + > + +
) diff --git a/components/stats/PerpStats.tsx b/components/stats/PerpStats.tsx index f09eb8ab..74e29597 100644 --- a/components/stats/PerpStats.tsx +++ b/components/stats/PerpStats.tsx @@ -8,7 +8,7 @@ const PerpStats = () => { ) : ( ) diff --git a/components/stats/TotalDepositBorrowCharts.tsx b/components/stats/TotalDepositBorrowCharts.tsx index af9a9c56..cd392c5a 100644 --- a/components/stats/TotalDepositBorrowCharts.tsx +++ b/components/stats/TotalDepositBorrowCharts.tsx @@ -48,36 +48,6 @@ const TotalDepositBorrowCharts = () => { return values.reverse() }, [tokenStats]) - const filteredBorrowValues = useMemo(() => { - if (!totalDepositBorrowValues) return [] - if (borrowDaysToShow !== '30') { - const seconds = Number(borrowDaysToShow) * 86400 - const data = totalDepositBorrowValues.filter((d) => { - const dataTime = new Date(d.date).getTime() / 1000 - const now = new Date().getTime() / 1000 - const limit = now - seconds - return dataTime >= limit - }) - return data - } - return totalDepositBorrowValues - }, [totalDepositBorrowValues, borrowDaysToShow]) - - const filteredDepositValues = useMemo(() => { - if (!totalDepositBorrowValues) return [] - if (depositDaysToShow !== '30') { - const seconds = Number(depositDaysToShow) * 86400 - const data = totalDepositBorrowValues.filter((d) => { - const dataTime = new Date(d.date).getTime() / 1000 - const now = new Date().getTime() / 1000 - const limit = now - seconds - return dataTime >= limit - }) - return data - } - return totalDepositBorrowValues - }, [totalDepositBorrowValues, depositDaysToShow]) - const [currentTotalDepositValue, currentTotalBorrowValue] = useMemo(() => { if (banks.length) { return [ @@ -92,7 +62,7 @@ const TotalDepositBorrowCharts = () => { <>
{
{ }, []) }, [tokenStats]) - const filterStats = (daysToShow: string) => { - if (!statsHistory.length) return [] - if (daysToShow !== '30') { - const seconds = Number(daysToShow) * 86400 - const data = statsHistory.filter((d) => { - const dataTime = new Date(d.date_hour).getTime() / 1000 - const now = new Date().getTime() / 1000 - const limit = now - seconds - return dataTime >= limit - }) - return data - } - return statsHistory - } + // const filterStats = (daysToShow: string) => { + // if (!statsHistory.length) return [] + // if (daysToShow !== '30') { + // const seconds = Number(daysToShow) * 86400 + // const data = statsHistory.filter((d) => { + // const dataTime = new Date(d.date_hour).getTime() / 1000 + // const now = new Date().getTime() / 1000 + // const limit = now - seconds + // return dataTime >= limit + // }) + // return data + // } + // return statsHistory + // } return (
@@ -77,7 +77,7 @@ const ChartTabs = ({ token }: { token: string }) => {
{activeDepositsTab === 'token:deposits' ? ( { /> ) : ( {
{activeBorrowsTab === 'token:borrows' ? ( { /> ) : (