File tree 2 files changed +37
-4
lines changed
2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -20,13 +20,15 @@ export const useStats = (query: {
20
20
fetchCoinStats ?: boolean
21
21
transactionResponseType ?: string | undefined
22
22
validatorResponseType ?: string | undefined
23
+ refreshEnabled ?: boolean
23
24
} ) : StatsResult => {
24
25
const {
25
26
validatorStatsCount,
26
27
transactionStatsCount,
27
28
fetchCoinStats,
28
29
transactionResponseType,
29
30
validatorResponseType,
31
+ refreshEnabled,
30
32
} = query
31
33
32
34
// set query paths to `null` if we shouldn't fetch them
@@ -38,13 +40,28 @@ export const useStats = (query: {
38
40
: null
39
41
const coinStatsQuery = fetchCoinStats ? `${ PATHS . STATS_COIN } ` : null
40
42
43
+ const swrOptions = {
44
+ refreshInterval : ! refreshEnabled ? 0 : undefined ,
45
+ revalidateOnFocus : refreshEnabled ,
46
+ revalidateOnReconnect : refreshEnabled ,
47
+ }
48
+
41
49
// get responses
42
- const validatorStatsResponse = useSWR < { validatorStats : ValidatorStats [ ] } > ( validatorStatsQuery , fetcher )
50
+ const validatorStatsResponse = useSWR < { validatorStats : ValidatorStats [ ] } > (
51
+ validatorStatsQuery ,
52
+ fetcher ,
53
+ swrOptions
54
+ )
43
55
const transactionStatsResponse = useSWR < { transactionStats : TransactionStats [ ] } > (
44
56
transactionStatsQuery ,
45
- fetcher
57
+ fetcher ,
58
+ swrOptions
59
+ )
60
+ const coinStatsResponse = useSWR < { totalSupply : number ; totalStaked : number } > (
61
+ coinStatsQuery ,
62
+ fetcher ,
63
+ swrOptions
46
64
)
47
- const coinStatsResponse = useSWR < { totalSupply : number ; totalStaked : number } > ( coinStatsQuery , fetcher )
48
65
49
66
// get values
50
67
const validatorStats =
Original file line number Diff line number Diff line change 1
- import React from 'react'
1
+ import React , { useState } from 'react'
2
2
3
3
import { ContentLayout , StackedLineStockChart } from '../components'
4
4
@@ -7,15 +7,31 @@ import { useStats } from '../api'
7
7
import { convertValidatorStatsToSeriesData } from '../utils/transformChartData'
8
8
9
9
export const ValidatorLineChart : React . FC = ( ) => {
10
+ const [ refreshEnabled , setRefreshDisabled ] = useState ( true )
10
11
const height = 600
11
12
12
13
const { validatorStats, loading } = useStats ( {
13
14
validatorStatsCount : 10000000 ,
15
+ refreshEnabled,
14
16
} )
15
17
18
+ const toggleNoRefresh = ( ) : void => setRefreshDisabled ( ( prev ) => ! prev )
19
+
16
20
return (
17
21
< div className = { styles . ValidatorLineChart } >
18
22
< ContentLayout title = "Active Validators per Cycle Chart" >
23
+ < div style = { { marginBottom : '1rem' } } >
24
+ < label >
25
+ < input
26
+ type = "checkbox"
27
+ checked = { refreshEnabled }
28
+ onChange = { toggleNoRefresh }
29
+ style = { { appearance : 'auto' } }
30
+ />
31
+ < span > Auto Refresh</ span >
32
+ </ label >
33
+ </ div >
34
+
19
35
{ loading ? (
20
36
< div > Loading...</ div >
21
37
) : (
You can’t perform that action at this time.
0 commit comments