import { Action , Dispatch , Middleware } from '@reduxjs/toolkit' ; import { addNewAccounts , createAsset , importState , setDemoMode , setProductAnalyticsAuthorisation } from '@store' ; import { trackEvent } from './saga' ; export const analyticsMiddleware = ( state ) => ( next ) => ( action ) => { switch ( action . type ) { case addNewAccounts . type : { action . payload . newAccounts . forEach ( ( ) => { state . dispatch ( trackEvent ( { action : 'Add Account' , customDimensions : [ { id : 1 , value : action . payload . accountType } , { id : 2 , value : action . payload . networkId } ] } ) ) ; } ) ; break ; } case createAsset . type : { state . dispatch ( trackEvent ( { action : 'Add Asset' , name : action . payload . ticker , customDimensions : action . payload . contractAddress ? [ { id : 3 , value : action . payload . contractAddress } ] : [ ] } ) ) ; break ; } case setDemoMode . type : { state . dispatch ( trackEvent ( { action : 'Set Demo Mode' } ) ) ; break ; } case setProductAnalyticsAuthorisation . type : { state . dispatch ( trackEvent ( { action : 'Deactivate analytics' } ) ) ; break ; } case importState . type : { state . dispatch ( trackEvent ( { action : 'Import AppState' } ) ) ; break ; } default : break ; } return next ( action ) ; } ;