Skip to content

Commit 107ea7e

Browse files
committed
chore: cleanup
1 parent 872b666 commit 107ea7e

File tree

15 files changed

+33
-92
lines changed

15 files changed

+33
-92
lines changed

apps/main/src/lend/components/MarketInformationComp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SubTitle } from '@/lend/components/DetailsMarket/styles'
66
import { useBandsData } from '@/lend/hooks/useBandsData'
77
import networks from '@/lend/networks'
88
import { PageContentProps } from '@/lend/types/lend.types'
9-
import { BandsChart } from '@/llamalend/widgets/bands-chart/BandsChart'
9+
import { BandsChart } from '@/llamalend/features/bands-chart/BandsChart'
1010
import { Stack, useTheme } from '@mui/material'
1111
import { useUserProfileStore } from '@ui-kit/features/user-profile'
1212
import { useReleaseChannel } from '@ui-kit/hooks/useLocalStorage'

apps/main/src/lend/hooks/useBandsData.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { PageContentProps } from '@/lend/types/lend.types'
2-
import { useProcessedBandsData } from '@/llamalend/hooks/useBandsData'
2+
import { useMarketBands } from '@/llamalend/features/bands-chart/queries/market-bands.query'
3+
import { useMarketOraclePrices } from '@/llamalend/features/bands-chart/queries/market-oracle-prices.query'
4+
import { useUserBands } from '@/llamalend/features/bands-chart/queries/user-bands.query'
5+
import { useProcessedBandsData } from '@/llamalend/features/bands-chart/useBandsData'
36
import { useLoanExists } from '@/llamalend/queries/loan-exists'
4-
import { useMarketBands } from '@/llamalend/widgets/bands-chart/queries/market-bands.query'
5-
import { useMarketOraclePrices } from '@/llamalend/widgets/bands-chart/queries/market-oracle-prices.query'
6-
import { useUserBands } from '@/llamalend/widgets/bands-chart/queries/user-bands.query'
77

88
export const useBandsData = ({ rChainId, rOwmId, api }: Pick<PageContentProps, 'rChainId' | 'api' | 'rOwmId'>) => {
99
const { data: marketOraclePrices } = useMarketOraclePrices({ chainId: rChainId, marketId: rOwmId })

apps/main/src/llamalend/widgets/bands-chart/BandsChart.tsx renamed to apps/main/src/llamalend/features/bands-chart/BandsChart.tsx

Lines changed: 20 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { DataZoomComponentOption } from 'echarts'
21
import ReactECharts, { type EChartsOption } from 'echarts-for-react'
3-
import { useMemo, useRef, useEffect, useState, useCallback } from 'react'
2+
import { useMemo, useRef, useCallback, useState, useEffect } from 'react'
43
import { createRoot } from 'react-dom/client'
54
import Spinner, { SpinnerWrapper } from 'ui/src/Spinner'
5+
import { ChartDataPoint, BandsBalancesData, BandsChartPalette } from '@/llamalend/features/bands-chart/types'
66
import { Token } from '@/llamalend/features/borrow/types'
7-
import { ChartDataPoint, BandsBalancesData, BandsChartPalette } from '@/llamalend/widgets/bands-chart/types'
87
import { Box, Stack, useTheme, ThemeProvider } from '@mui/material'
98
import { DesignSystem } from '@ui-kit/themes/design'
109
import { getChartOptions } from './chartOptions'
@@ -23,12 +22,6 @@ type BandsChartProps = {
2322
height?: number
2423
}
2524

26-
type DataZoomEvent = {
27-
start?: number
28-
end?: number
29-
batch?: { start?: number; end?: number }[]
30-
}
31-
3225
export const BandsChart = ({
3326
collateralToken,
3427
borrowToken,
@@ -147,76 +140,17 @@ export const BandsChart = ({
147140
],
148141
)
149142

150-
// Persist dataZoom (start/end) across renders
151-
const [zoom, setZoom] = useState<{ start?: number; end?: number }>({})
152-
const initializedZoomRef = useRef(false)
153-
const lastZoomRef = useRef<{ start?: number; end?: number }>({})
154-
const chartRef = useRef<ReactECharts | null>(null)
143+
const [initialZoom, setInitialZoom] = useState<{ start?: number; end?: number }>({})
155144

156145
useEffect(() => {
157-
if (!initializedZoomRef.current && chartData.length > 0 && initialZoomIndices) {
146+
if (chartData.length > 0 && initialZoomIndices) {
158147
const start = (initialZoomIndices.startIndex / chartData.length) * 100
159148
const end = ((initialZoomIndices.endIndex + 1) / chartData.length) * 100
160-
setZoom({ start, end })
161-
lastZoomRef.current = { start, end }
162-
initializedZoomRef.current = true
149+
setInitialZoom({ start, end })
163150
}
164151
}, [chartData.length, initialZoomIndices])
165152

166-
useEffect(() => {
167-
if (chartData.length === 0 || !initialZoomIndices) return
168-
169-
const isFullRange =
170-
lastZoomRef.current.start !== undefined &&
171-
lastZoomRef.current.end !== undefined &&
172-
lastZoomRef.current.start <= 0.0001 &&
173-
lastZoomRef.current.end >= 99.999
174-
175-
if (Object.keys(lastZoomRef.current).length === 0 || isFullRange) {
176-
const start = (initialZoomIndices.startIndex / chartData.length) * 100
177-
const end = ((initialZoomIndices.endIndex + 1) / chartData.length) * 100
178-
179-
if (lastZoomRef.current.start !== start || lastZoomRef.current.end !== end) {
180-
setZoom({ start, end })
181-
lastZoomRef.current = { start, end }
182-
}
183-
}
184-
}, [chartData.length, userBandsBalances.length, oraclePrice, initialZoomIndices])
185-
186-
const onEvents = useMemo(
187-
() => ({
188-
dataZoom: (evt: DataZoomEvent) => {
189-
const payload = Array.isArray(evt?.batch) && evt.batch.length ? evt.batch[0] : evt
190-
const s = payload?.start
191-
const e = payload?.end
192-
if (typeof s === 'number' && typeof e === 'number') {
193-
const prev = lastZoomRef.current
194-
if (prev.start !== s || prev.end !== e) {
195-
lastZoomRef.current = { start: s, end: e }
196-
setZoom({ start: s, end: e })
197-
}
198-
}
199-
},
200-
}),
201-
[],
202-
)
203-
204-
const optionWithZoom: EChartsOption = useMemo(() => {
205-
if (option.dataZoom && Array.isArray(option.dataZoom) && zoom) {
206-
const dz = option.dataZoom.map((z: DataZoomComponentOption) => {
207-
if (z && 'type' in z && z.type === 'slider') {
208-
return {
209-
...z,
210-
...(zoom.start != null ? { start: zoom.start } : {}),
211-
...(zoom.end != null ? { end: zoom.end } : {}),
212-
}
213-
}
214-
return z
215-
})
216-
return { ...option, dataZoom: dz }
217-
}
218-
return option
219-
}, [option, zoom])
153+
const chartRef = useRef<ReactECharts | null>(null)
220154

221155
if (chartData.length === 0) {
222156
return (
@@ -244,10 +178,21 @@ export const BandsChart = ({
244178
<Box sx={{ width: '99%', fontVariantNumeric: 'tabular-nums', height }}>
245179
<ReactECharts
246180
ref={chartRef}
247-
option={optionWithZoom}
181+
option={{
182+
...option,
183+
dataZoom: option.dataZoom?.map((z: any) => {
184+
if (z && 'type' in z && z.type === 'slider') {
185+
return {
186+
...z,
187+
...(initialZoom.start != null ? { start: initialZoom.start } : {}),
188+
...(initialZoom.end != null ? { end: initialZoom.end } : {}),
189+
}
190+
}
191+
return z
192+
}),
193+
}}
248194
style={{ width: '100%', height: '100%' }}
249-
opts={{ renderer: 'svg' }}
250-
onEvents={onEvents}
195+
opts={{ renderer: 'canvas' }}
251196
lazyUpdate
252197
/>
253198
</Box>

apps/main/src/llamalend/widgets/bands-chart/TooltipContent.tsx renamed to apps/main/src/llamalend/features/bands-chart/TooltipContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Token } from '@/llamalend/features/borrow/types'
22
import { TooltipItem, TooltipItems, TooltipWrapper } from '@/llamalend/widgets/tooltips/TooltipComponents'
3-
import { Box, Stack, useTheme } from '@mui/material'
3+
import { Box, useTheme } from '@mui/material'
44
import Typography from '@mui/material/Typography'
55
import { formatNumber } from '@ui/utils'
66
import { t } from '@ui-kit/lib/i18n'

apps/main/src/llamalend/widgets/bands-chart/queries/user-bands.query.ts renamed to apps/main/src/llamalend/features/bands-chart/queries/user-bands.query.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import { userMarketValidationSuite } from '@ui-kit/lib/model/query/user-market-v
77
import { createValidationSuite } from '@ui-kit/lib/validation'
88
import { sortLendBands, sortMintBands, fetchLendChartBandBalancesData, fetchMintChartBandBalancesData } from './utils'
99

10-
// Extend UserMarketQuery locally to include loanExists
1110
type UserBandsQuery = UserMarketQuery & { loanExists: boolean | undefined | null }
1211
type UserBandsParams = UserMarketParams & { loanExists: boolean | undefined | null }
1312

14-
// Create custom validation suite that includes both user market validation and loan exists validation
1513
const userBandsValidationSuite = createValidationSuite((params: UserBandsParams) => {
1614
userMarketValidationSuite(params)
1715
loanExistsValidationGroup({ loanExists: params.loanExists })

apps/main/src/llamalend/widgets/bands-chart/types.ts renamed to apps/main/src/llamalend/features/bands-chart/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { LendMarketTemplate } from '@curvefi/llamalend-api/lib/lendMarkets'
2-
31
export type ChartDataPoint = {
42
n: number | string
53
pUpDownMedian: number

0 commit comments

Comments
 (0)