Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
WIP : config events with zustand (aave#22)
Browse files Browse the repository at this point in the history
* feat: config events with zustand

* feat: types

* chore: remove prev impl

* chore: remove var from re render

* chore: remove

* feat: update types
  • Loading branch information
foodaka authored Mar 23, 2023
1 parent 396e247 commit d4b9323
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 93 deletions.
78 changes: 42 additions & 36 deletions pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '/public/fonts/inter/inter.css';
import { CacheProvider, EmotionCache } from '@emotion/react';
import { Web3ReactProvider } from '@web3-react/core';
import { providers } from 'ethers';
import mixpanel from 'mixpanel-browser';
import { NextPage } from 'next';
import { AppProps } from 'next/app';
import Head from 'next/head';
Expand All @@ -25,7 +26,6 @@ import { BackgroundDataProvider } from 'src/hooks/app-data-provider/BackgroundDa
import { AppDataProvider } from 'src/hooks/app-data-provider/useAppDataProvider';
import { ModalContextProvider } from 'src/hooks/useModal';
import { PermissionProvider } from 'src/hooks/usePermissions';
import MixpanelProvider from 'src/libs/Mixpanel/MixpanelProvider';
import { Web3ContextProvider } from 'src/libs/web3-data-provider/Web3Provider';

import createEmotionCache from '../src/createEmotionCache';
Expand Down Expand Up @@ -53,7 +53,15 @@ interface MyAppProps extends AppProps {
export default function MyApp(props: MyAppProps) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
const getLayout = Component.getLayout ?? ((page: React.ReactNode) => page);
const MIXPANEL_TOKEN = process.env.NEXT_PUBLIC_MIXPANEL;
const MIXPANEL_TOKEN = process.env.NEXT_PUBLIC_MIXPANEL || '';

React.useEffect(() => {
if (MIXPANEL_TOKEN) {
mixpanel.init(MIXPANEL_TOKEN);
} else {
console.warn('Mixpanel token not provided. Mixpanel will not be initialized.');
}
}, []);

return (
<CacheProvider value={emotionCache}>
Expand All @@ -67,40 +75,38 @@ export default function MyApp(props: MyAppProps) {
}
imageUrl="https://app.aave.com/aaveMetaLogo-min.jpg"
/>
<MixpanelProvider mixpanelToken={MIXPANEL_TOKEN}>
<LanguageProvider>
<Web3ReactProvider getLibrary={getWeb3Library}>
<Web3ContextProvider>
<AppGlobalStyles>
<AddressBlocked>
<PermissionProvider>
<ModalContextProvider>
<BackgroundDataProvider>
<AppDataProvider>
<GasStationProvider>
{getLayout(<Component {...pageProps} />)}
<SupplyModal />
<WithdrawModal />
<BorrowModal />
<RepayModal />
<CollateralChangeModal />
<RateSwitchModal />
<ClaimRewardsModal />
<EmodeModal />
<SwapModal />
<FaucetModal />
<MigrateV3Modal />
</GasStationProvider>
</AppDataProvider>
</BackgroundDataProvider>
</ModalContextProvider>
</PermissionProvider>
</AddressBlocked>
</AppGlobalStyles>
</Web3ContextProvider>
</Web3ReactProvider>
</LanguageProvider>
</MixpanelProvider>
<LanguageProvider>
<Web3ReactProvider getLibrary={getWeb3Library}>
<Web3ContextProvider>
<AppGlobalStyles>
<AddressBlocked>
<PermissionProvider>
<ModalContextProvider>
<BackgroundDataProvider>
<AppDataProvider>
<GasStationProvider>
{getLayout(<Component {...pageProps} />)}
<SupplyModal />
<WithdrawModal />
<BorrowModal />
<RepayModal />
<CollateralChangeModal />
<RateSwitchModal />
<ClaimRewardsModal />
<EmodeModal />
<SwapModal />
<FaucetModal />
<MigrateV3Modal />
</GasStationProvider>
</AppDataProvider>
</BackgroundDataProvider>
</ModalContextProvider>
</PermissionProvider>
</AddressBlocked>
</AppGlobalStyles>
</Web3ContextProvider>
</Web3ReactProvider>
</LanguageProvider>
</CacheProvider>
);
}
4 changes: 2 additions & 2 deletions src/components/MarketSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
useTheme,
} from '@mui/material';
import React, { useState } from 'react';
import { useRootStore } from 'src/store/root';
import { BaseNetworkConfig } from 'src/ui-config/networksConfig';
import useMixpanelTrack from 'src/utils/mixPanel';
import { DASHBOARD } from 'src/utils/mixPanelEvents';

import { useProtocolDataContext } from '../hooks/useProtocolDataContext';
Expand Down Expand Up @@ -114,7 +114,7 @@ export const MarketSwitcher = () => {
const theme = useTheme();
const upToLG = useMediaQuery(theme.breakpoints.up('lg'));
const downToXSM = useMediaQuery(theme.breakpoints.down('xsm'));
const trackEvent = useMixpanelTrack();
const trackEvent = useRootStore((store) => store.trackEvent);

const isV3MarketsAvailable = availableMarkets
.map((marketId: CustomMarket) => {
Expand Down
6 changes: 0 additions & 6 deletions src/libs/Mixpanel/MixpanelContext.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/libs/Mixpanel/MixpanelProvider.tsx

This file was deleted.

25 changes: 25 additions & 0 deletions src/store/analyticsSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import mixpanel from 'mixpanel-browser';
import { StateCreator } from 'zustand';

import { RootStore } from './root';

export type AnalyticsSlice = {
trackEvent: (eventName: string, properties?: { [key: string]: string }) => void;
};

export const createAnalyticsSlice: StateCreator<
RootStore,
[['zustand/subscribeWithSelector', never], ['zustand/devtools', never]],
[],
AnalyticsSlice
> = (set, get) => {
return {
trackEvent: (eventName: string, properties?: { [key: string]: string }) => {
const eventProperties = {
...properties,
walletAddress: get().account,
};
mixpanel.track(eventName, eventProperties);
},
};
};
5 changes: 4 additions & 1 deletion src/store/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ENABLE_TESTNET, STAGING_ENV } from 'src/utils/marketsAndNetworksConfig'
import create from 'zustand';
import { devtools, subscribeWithSelector } from 'zustand/middleware';

import { AnalyticsSlice, createAnalyticsSlice } from './analyticsSlice';
import { createGovernanceSlice, GovernanceSlice } from './governanceSlice';
import { createIncentiveSlice, IncentiveSlice } from './incentiveSlice';
import { createPoolSlice, PoolSlice } from './poolSlice';
Expand All @@ -25,7 +26,8 @@ export type RootStore = StakeSlice &
IncentiveSlice &
GovernanceSlice &
V3MigrationSlice &
WalletDomainsSlice;
WalletDomainsSlice &
AnalyticsSlice;

export const useRootStore = create<RootStore>()(
subscribeWithSelector(
Expand All @@ -39,6 +41,7 @@ export const useRootStore = create<RootStore>()(
...createGovernanceSlice(...args),
...createV3MigrationSlice(...args),
...createWalletDomainsSlice(...args),
...createAnalyticsSlice(...args),
};
})
)
Expand Down
22 changes: 0 additions & 22 deletions src/utils/mixPanel.ts

This file was deleted.

0 comments on commit d4b9323

Please sign in to comment.