Skip to content

Commit

Permalink
update context imports and general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benwolski committed Nov 9, 2024
1 parent 3027dd8 commit be277de
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 200 deletions.
4 changes: 2 additions & 2 deletions src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default function App() {
currentLocation !== '/privacy' &&
currentLocation !== '/faq' &&
!currentLocation.includes('/chat') &&
isChatEnabled && !isFullScreen && <ChatPanel isFullScreen={false} />}
isChatEnabled &&
!isFullScreen && <ChatPanel isFullScreen={false} />}
</div>
);

Expand Down Expand Up @@ -147,7 +148,6 @@ export default function App() {
showMobileVersion && <FooterNav />
);


return (
<>
{location.pathname == '/' && platformName !== 'futa' && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ interface propsIF {
customBR?: string;
}
import { motion } from 'framer-motion';
import {
AppStateContext,
AppStateContextIF,
} from '../../../../contexts/AppStateContext';
import { AppStateContext } from '../../../../contexts/AppStateContext';
import { useBottomSheet } from '../../../../contexts/BottomSheetContext';

interface NetworkIF {
Expand All @@ -53,11 +50,10 @@ export default function NetworkSelector(props: propsIF) {
const {
chooseNetwork,
activeNetwork: { chainId },
} = useContext<AppStateContextIF>(AppStateContext);
} = useContext(AppStateContext);
const { networks, platformName, includeCanto } =
useContext<BrandContextIF>(BrandContext);
const { closeBottomSheet } =
useBottomSheet();
const { closeBottomSheet } = useBottomSheet();
const { switchNetwork } = useSwitchNetwork();
const smallScreen: boolean = useMediaQuery('(max-width: 600px)');

Expand Down Expand Up @@ -217,9 +213,8 @@ export default function NetworkSelector(props: propsIF) {
} else {
handleClick(chainMap.get(network.chainId));
}
closeBottomSheet()
closeBottomSheet();
}}

key={network.id}
custom={network.custom}
variants={ItemEnterAnimation}
Expand Down
4 changes: 0 additions & 4 deletions src/App/hooks/useAppChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,13 @@ export const useAppChain = (): {
activeNetwork.chainId !=
incomingChainFromWallet
) {
// !IMPORTANT: not this one
// alert('wow!');
// console.log('wow');
window.location.reload();
}
} else {
linkGenCurrent.navigate();
}
}
if (activeNetwork.chainId != incomingChainFromWallet) {
// !IMPORTANT: not this one
window.location.reload();
} else {
setIgnoreFirst(false);
Expand Down
26 changes: 12 additions & 14 deletions src/contexts/ChainDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@ import {
} from '../ambient-utils/constants';
import { isJsonString } from '../ambient-utils/dataLayer';
import { SinglePoolDataIF, TokenIF } from '../ambient-utils/types';
import { CachedDataContext, CachedDataContextIF } from './CachedDataContext';
import { CrocEnvContext, CrocEnvContextIF } from './CrocEnvContext';
import { TokenContext, TokenContextIF } from './TokenContext';
import { CachedDataContext } from './CachedDataContext';
import { CrocEnvContext } from './CrocEnvContext';
import { TokenContext } from './TokenContext';
import {
BlastUserXpDataIF,
UserDataContext,
UserDataContextIF,
UserXpDataIF,
} from './UserDataContext';
import {
NftDataIF,
NftListByChain,
TokenBalanceContext,
TokenBalanceContextIF,
} from './TokenBalanceContext';
import {
expandTokenBalances,
Expand All @@ -45,10 +43,10 @@ import {
IDexTokenBalances,
} from '../ambient-utils/api';
import { BLAST_RPC_URL } from '../ambient-utils/constants/networks/blastNetwork';
import { AppStateContext, AppStateContextIF } from './AppStateContext';
import { AppStateContext } from './AppStateContext';
import moment from 'moment';
import { fetchNFT } from '../ambient-utils/api/fetchNft';
import { ReceiptContext, ReceiptContextIF } from './ReceiptContext';
import { ReceiptContext } from './ReceiptContext';

export interface ChainDataContextIF {
gasPriceInGwei: number | undefined;
Expand Down Expand Up @@ -79,32 +77,32 @@ export const ChainDataContextProvider = (props: { children: ReactNode }) => {
graphCacheUrl,
},
isUserIdle,
} = useContext<AppStateContextIF>(AppStateContext);
} = useContext(AppStateContext);
const {
setTokenBalances,
setNFTData,
NFTFetchSettings,
setNFTFetchSettings,
} = useContext<TokenBalanceContextIF>(TokenBalanceContext);
const { sessionReceipts } = useContext<ReceiptContextIF>(ReceiptContext);
const { crocEnv, provider } = useContext<CrocEnvContextIF>(CrocEnvContext);
} = useContext(TokenBalanceContext);
const { sessionReceipts } = useContext(ReceiptContext);
const { crocEnv, provider } = useContext(CrocEnvContext);
const {
cachedFetchAmbientListWalletBalances,
cachedFetchDexBalances,
cachedFetchTokenPrice,
cachedTokenDetails,
cachedFetchNFT,
cachedAllPoolStatsFetch,
} = useContext<CachedDataContextIF>(CachedDataContext);
const { tokens } = useContext<TokenContextIF>(TokenContext);
} = useContext(CachedDataContext);
const { tokens } = useContext(TokenContext);
const {
userAddress,
isUserConnected,
setIsfetchNftTriggered,
isfetchNftTriggered,
nftTestWalletAddress,
setNftTestWalletAddress,
} = useContext<UserDataContextIF>(UserDataContext);
} = useContext(UserDataContext);

const [lastBlockNumber, setLastBlockNumber] = useState<number>(0);

Expand Down
4 changes: 2 additions & 2 deletions src/contexts/CrocEnvContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import { UserDataContext } from './UserDataContext';
import { translateTokenSymbol } from '../ambient-utils/dataLayer';
import { TokenContext } from './TokenContext';
import { AppStateContext, AppStateContextIF } from './AppStateContext';
import { AppStateContext } from './AppStateContext';

interface UrlRoutesTemplateIF {
swap: string;
Expand Down Expand Up @@ -75,7 +75,7 @@ export const CrocEnvContextProvider = (props: { children: ReactNode }) => {
const { cachedFetchTokenPrice } = useContext(CachedDataContext);
const {
activeNetwork: { chainId, evmRpcUrl },
} = useContext<AppStateContextIF>(AppStateContext);
} = useContext(AppStateContext);

const { userAddress } = useContext(UserDataContext);
const { walletProvider } = useWeb3ModalProvider();
Expand Down
21 changes: 10 additions & 11 deletions src/contexts/ExploreContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useEffect,
useState,
} from 'react';
import { CachedDataContext, CachedDataContextIF } from './CachedDataContext';
import { CachedDataContext } from './CachedDataContext';
import { CrocEnv, toDisplayPrice } from '@crocswap-libs/sdk';
import { PoolIF, SinglePoolDataIF } from '../ambient-utils/types';
import {
Expand All @@ -16,15 +16,15 @@ import {
expandPoolStats,
} from '../ambient-utils/dataLayer';
import { lookupChain } from '@crocswap-libs/sdk/dist/context';
import { CrocEnvContext, CrocEnvContextIF } from './CrocEnvContext';
import { CrocEnvContext } from './CrocEnvContext';
import { PoolContext } from './PoolContext';
import {
useTokenStatsIF,
useTokenStats,
} from '../pages/platformAmbient/Explore/useTokenStats';
import { TokenContext, TokenContextIF } from './TokenContext';
import { ChainDataContext, ChainDataContextIF } from './ChainDataContext';
import { AppStateContext, AppStateContextIF } from './AppStateContext';
import { TokenContext } from './TokenContext';
import { ChainDataContext } from './ChainDataContext';
import { AppStateContext } from './AppStateContext';

export interface ExploreContextIF {
pools: {
Expand Down Expand Up @@ -61,13 +61,12 @@ export const ExploreContext = createContext<ExploreContextIF>(
);

export const ExploreContextProvider = (props: { children: ReactNode }) => {
const { activeNetwork } = useContext<AppStateContextIF>(AppStateContext);
const { activeNetwork } = useContext(AppStateContext);
const { cachedQuerySpotPrice, cachedFetchTokenPrice, cachedTokenDetails } =
useContext<CachedDataContextIF>(CachedDataContext);
const { crocEnv, provider } = useContext<CrocEnvContextIF>(CrocEnvContext);
const { tokens } = useContext<TokenContextIF>(TokenContext);
const { allPoolStats } = useContext<ChainDataContextIF>(ChainDataContext);
// metadata only
useContext(CachedDataContext);
const { crocEnv, provider } = useContext(CrocEnvContext);
const { tokens } = useContext(TokenContext);
const { allPoolStats } = useContext(ChainDataContext);
const { poolList } = useContext(PoolContext);

const [allPools, setAllPools] = useState<Array<PoolDataIF>>([]);
Expand Down
38 changes: 16 additions & 22 deletions src/contexts/GraphDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ import {
LiquidityDataIF,
RecordType,
} from '../ambient-utils/types';
import { AppStateContext, AppStateContextIF } from './AppStateContext';
import { CachedDataContext, CachedDataContextIF } from './CachedDataContext';
import { CrocEnvContext, CrocEnvContextIF } from './CrocEnvContext';
import { TokenContext, TokenContextIF } from './TokenContext';
import { UserDataContext, UserDataContextIF } from './UserDataContext';
import { DataLoadingContext, DataLoadingContextIF } from './DataLoadingContext';
import {
PositionUpdateIF,
ReceiptContext,
ReceiptContextIF,
} from './ReceiptContext';
import { AppStateContext } from './AppStateContext';
import { CachedDataContext } from './CachedDataContext';
import { CrocEnvContext } from './CrocEnvContext';
import { TokenContext } from './TokenContext';
import { UserDataContext } from './UserDataContext';
import { DataLoadingContext } from './DataLoadingContext';
import { PositionUpdateIF, ReceiptContext } from './ReceiptContext';
import { getPositionHash } from '../ambient-utils/dataLayer/functions/getPositionHash';
import { TradeDataContext, TradeDataContextIF } from './TradeDataContext';
import { TradeDataContext } from './TradeDataContext';

export interface Changes {
dataReceived: boolean;
Expand Down Expand Up @@ -111,23 +107,21 @@ export const GraphDataContextProvider = (props: { children: ReactNode }) => {
activeNetwork: { graphCacheUrl, chainId },
server: { isEnabled: isServerEnabled },
isUserIdle,
} = useContext<AppStateContextIF>(AppStateContext);
const { baseToken, quoteToken } =
useContext<TradeDataContextIF>(TradeDataContext);
} = useContext(AppStateContext);
const { baseToken, quoteToken } = useContext(TradeDataContext);
const { pendingTransactions, allReceipts, sessionPositionUpdates } =
useContext<ReceiptContextIF>(ReceiptContext);
const { setDataLoadingStatus } =
useContext<DataLoadingContextIF>(DataLoadingContext);
useContext(ReceiptContext);
const { setDataLoadingStatus } = useContext(DataLoadingContext);
const {
cachedQuerySpotPrice,
cachedFetchTokenPrice,
cachedTokenDetails,
cachedEnsResolve,
} = useContext<CachedDataContextIF>(CachedDataContext);
const { crocEnv, provider } = useContext<CrocEnvContextIF>(CrocEnvContext);
const { tokens } = useContext<TokenContextIF>(TokenContext);
} = useContext(CachedDataContext);
const { crocEnv, provider } = useContext(CrocEnvContext);
const { tokens } = useContext(TokenContext);
const { userAddress: userDefaultAddress, isUserConnected } =
useContext<UserDataContextIF>(UserDataContext);
useContext(UserDataContext);

const [positionsByUser, setPositionsByUser] = useState<PositionsByUser>({
dataReceived: false,
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/SidebarContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { sidebarMethodsIF, useSidebar } from '../App/hooks/useSidebar';
import { IS_LOCAL_ENV } from '../ambient-utils/constants';
import { diffHashSig, isJsonString } from '../ambient-utils/dataLayer';
import { AppStateContext, AppStateContextIF } from './AppStateContext';
import { AppStateContext } from './AppStateContext';
import { ReceiptContext } from './ReceiptContext';
import { TransactionReceipt } from 'ethers';
import useMediaQuery from '../utils/hooks/useMediaQuery';
Expand All @@ -36,7 +36,7 @@ export const SidebarContextProvider = (props: { children: ReactNode }) => {
const {
activeNetwork: { chainId },
snackbar: { open: openSnackbar },
} = useContext<AppStateContextIF>(AppStateContext);
} = useContext(AppStateContext);

// all receipts stored in the current user session (array of stringified JSONs)
const { allReceipts } = useContext(ReceiptContext);
Expand Down
12 changes: 4 additions & 8 deletions src/contexts/TokenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import {
import { tokenMethodsIF, useTokens } from '../App/hooks/useTokens';
import { useTokenSearch } from '../App/hooks/useTokenSearch';
import { TokenIF } from '../ambient-utils/types';
import {
TokenBalanceContext,
TokenBalanceContextIF,
} from './TokenBalanceContext';
import { AppStateContext, AppStateContextIF } from './AppStateContext';
import { TokenBalanceContext } from './TokenBalanceContext';
import { AppStateContext } from './AppStateContext';

export interface TokenContextIF {
tokens: tokenMethodsIF;
Expand All @@ -29,9 +26,8 @@ export const TokenContext = createContext<TokenContextIF>({} as TokenContextIF);
export const TokenContextProvider = (props: { children: React.ReactNode }) => {
const {
activeNetwork: { chainId },
} = useContext<AppStateContextIF>(AppStateContext);
const { tokenBalances } =
useContext<TokenBalanceContextIF>(TokenBalanceContext);
} = useContext(AppStateContext);
const { tokenBalances } = useContext(TokenBalanceContext);
const tokens: tokenMethodsIF = useTokens(chainId, tokenBalances);
const { addRecentToken, getRecentTokens } = useRecentTokens(chainId);

Expand Down
8 changes: 4 additions & 4 deletions src/contexts/TradeDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
isStablePair,
translateTokenSymbol,
} from '../ambient-utils/dataLayer';
import { TokenContext, TokenContextIF } from './TokenContext';
import { AppStateContextIF, AppStateContext } from './AppStateContext';
import { TokenContext } from './TokenContext';
import { AppStateContext } from './AppStateContext';

export interface TradeDataContextIF {
tokenA: TokenIF;
Expand Down Expand Up @@ -71,8 +71,8 @@ export const TradeDataContext = createContext<TradeDataContextIF>(
export const TradeDataContextProvider = (props: { children: ReactNode }) => {
const {
activeNetwork: { chainId },
} = useContext<AppStateContextIF>(AppStateContext);
const { tokens } = useContext<TokenContextIF>(TokenContext);
} = useContext(AppStateContext);
const { tokens } = useContext(TokenContext);

const savedTokenASymbol = localStorage.getItem('tokenA');
const savedTokenBSymbol = localStorage.getItem('tokenB');
Expand Down
Loading

0 comments on commit be277de

Please sign in to comment.