Skip to content

Commit

Permalink
refactor: remove useInitApp
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteMinds committed Nov 3, 2023
1 parent 14e339d commit 4c6133b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
2 changes: 0 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { DefaultTheme, ThemeProvider } from 'styled-components'
import Routers from './routes'
import Toast from './components/Toast'
import useInitApp from './contexts/providers/hook'
import { isMainnet } from './utils/chain'
import { DASQueryContextProvider } from './contexts/providers/dasQuery'
import { getPrimaryColor, getSecondaryColor } from './constants/common'
Expand All @@ -17,7 +16,6 @@ const appStyle = {
const queryClient = new QueryClient()

const App = () => {
useInitApp()
const theme = useMemo<DefaultTheme>(
() => ({
primary: getPrimaryColor(),
Expand Down
19 changes: 0 additions & 19 deletions src/contexts/providers/hook.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/service/app/charts/cache.ts

This file was deleted.

24 changes: 21 additions & 3 deletions src/services/ExplorerService/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { BehaviorSubject, Subscription, map, switchMap, timer } from 'rxjs'
import { BLOCKCHAIN_ALERT_POLLING_TIME, BLOCK_POLLING_TIME } from '../../constants/common'
import {
BLOCKCHAIN_ALERT_POLLING_TIME,
BLOCK_POLLING_TIME,
FLUSH_CHART_CACHE_POLLING_TIME,
} from '../../constants/common'
import { APIReturn, apiFetcher } from './fetcher'
import { networkErrMsgs$ } from './requester'
import { CacheService, cacheService } from '../CacheService'

const initStatistics: APIReturn<'fetchStatistics'> = {
tipBlockNumber: '0',
Expand Down Expand Up @@ -39,7 +44,7 @@ class ExplorerService {

private callbacksAtStop?: Subscription

constructor() {
constructor(private cacheService: CacheService) {
this.start()
}

Expand Down Expand Up @@ -68,14 +73,27 @@ class ExplorerService {
)
.subscribe(this.blockchainAlerts$),
)

this.callbacksAtStop.add(
timer(0, FLUSH_CHART_CACHE_POLLING_TIME)
.pipe(
switchMap(this.api.fetchFlushChartCache),
map(({ flushCacheInfo }) => {
if (flushCacheInfo.length === 0) return

this.cacheService.clear()
}),
)
.subscribe(),
)
}

stop() {
this.callbacksAtStop?.unsubscribe()
}
}

export const explorerService = new ExplorerService()
export const explorerService = new ExplorerService(cacheService)

export * from './hooks'
export * from './types'
Expand Down

0 comments on commit 4c6133b

Please sign in to comment.