import { currentTimestamp } from './../../utils/index' ; import { updateProtocolData , updateChartData , updateTransactions } from './actions' ; import { createReducer } from '@reduxjs/toolkit' ; import { ChartDayData , Transaction } from 'types' ; import { SupportedNetwork } from 'constants/networks' ; export interface ProtocolData { volumeUSD : number ; volumeUSDChange : number ; tvlUSD : number ; tvlUSDChange : number ; feesUSD : number ; feeChange : number ; txCount : number ; txCountChange : number ; } export interface ProtocolState { [ networkId ] : { readonly lastUpdated : number | undefined ; readonly data : ProtocolData | undefined ; readonly chartData : ChartDayData [ ] | undefined ; readonly transactions : Transaction [ ] | undefined ; } ; } export const initialState = { [ SupportedNetwork . ETHEREUM ] : { data : undefined , chartData : undefined , transactions : undefined , lastUpdated : undefined , } , [ SupportedNetwork . ARBITRUM ] : { data : undefined , chartData : undefined , transactions : undefined , lastUpdated : undefined , } , [ SupportedNetwork . OPTIMISM ] : { data : undefined , chartData : undefined , transactions : undefined , lastUpdated : undefined , } , [ SupportedNetwork . POLYGON ] : { data : undefined , chartData : undefined , transactions : undefined , lastUpdated : undefined , } , } ; export default createReducer ( initialState , ( builder ) => builder . addCase ( updateProtocolData , ( state , { payload : { protocolData , networkId } } ) => { state [ networkId ] . data = protocolData ; state [ networkId ] . lastUpdated = currentTimestamp ( ) ; } ) . addCase ( updateChartData , ( state , { payload : { chartData , networkId } } ) => { state [ networkId ] . chartData = chartData ; } ) . addCase ( updateTransactions , ( state , { payload : { transactions , networkId } } ) => { state [ networkId ] . transactions = transactions ; } ) ) ;