Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- fixed: Connecting tokens to FIO addresses failing if there was a "." in the currency code
- fixed: (ETH) Improper Kiln staking balance shown.
- fixed: Informative insufficient funds error message for Velo staking
- fixed: Chart price data not updating when `assetId` changes

## 4.29.0 (2025-06-10)

Expand Down
31 changes: 23 additions & 8 deletions src/components/charts/SwipeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ const PULSE_CURSOR_RADIUS = 6

const BUTTON_MARGINS = [0, 0.5, 0, 0.5]

const DEFAULT_CHART_DATA: Array<[Timespan, ChartDataPoint[] | undefined]> = [
['hour', undefined],
['week', undefined],
['month', undefined],
['year', undefined]
]

// Gives the formatted timestamp per timespan, using locale-specific formatting,
// i.e. 'MM/DD' vs 'DD/MM'
const formatTimestamp = (date: Date, timespan: Timespan): { xTooltip: string; xRange: string } => {
Expand Down Expand Up @@ -130,16 +137,24 @@ const SwipeChartComponent = (params: Props) => {
const styles = getStyles(theme)
const { assetId } = params

// Clear chart data and cache when assetId changes.
React.useEffect(() => {
setChartData([])
setCachedChartData(new Map<Timespan, ChartDataPoint[] | undefined>(DEFAULT_CHART_DATA))
setIsFetching(false)

// Fetch the chart data for the new assetId
setFetchAssetId(assetId)
}, [assetId])

// #region Chart setup

// Maintain a separate fetchAssetId to ensure fetching can react to changes to
// assetId **after** the chart data and cache are cleared.
const [fetchAssetId, setFetchAssetId] = React.useState<string>(assetId)
const [chartData, setChartData] = React.useState<ChartDataPoint[]>([])
const [cachedTimespanChartData, setCachedChartData] = React.useState<Map<Timespan, ChartDataPoint[] | undefined>>(
new Map<Timespan, ChartDataPoint[] | undefined>([
['hour', undefined],
['week', undefined],
['month', undefined],
['year', undefined]
])
new Map<Timespan, ChartDataPoint[] | undefined>(DEFAULT_CHART_DATA)
)
const [selectedTimespan, setSelectedTimespan] = React.useState<Timespan>('month')
const [queryFromTimeOffset, setQueryFromTimeOffset] = React.useState(UNIX_SECONDS_MONTH_OFFSET)
Expand Down Expand Up @@ -207,7 +222,7 @@ const SwipeChartComponent = (params: Props) => {
} else {
const unixNow = Math.trunc(new Date().getTime() / 1000)
const fromParam = unixNow - queryFromTimeOffset
const fetchPath = sprintf(MARKET_CHART_ENDPOINT_4S, assetId, coingeckoFiat, fromParam, unixNow)
const fetchPath = sprintf(MARKET_CHART_ENDPOINT_4S, fetchAssetId, coingeckoFiat, fromParam, unixNow)
// Start with the free base URL
let fetchUrl = `${COINGECKO_URL}${fetchPath}`
do {
Expand Down Expand Up @@ -255,7 +270,7 @@ const SwipeChartComponent = (params: Props) => {
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[selectedTimespan, isConnected],
[selectedTimespan, isConnected, fetchAssetId],
'swipeChart'
)

Expand Down
Loading