import type { InMemoryCacheConfig } from '@apollo/client'; import { AppLoader, NetworkLoader, useEnvironment, useNodeSwitcherStore, } from '@vegaprotocol/environment'; import { useEffect, type ReactNode, useState } from 'react'; import { Web3Provider } from './web3-provider'; import { useT } from '../../lib/use-t'; import { DataLoader } from './data-loader'; import { WalletProvider } from '@vegaprotocol/wallet-react'; import { useVegaWalletConfig } from '../../lib/hooks/use-vega-wallet-config'; import { Trans } from 'react-i18next'; import { Button, Loader, Splash, VLogo } from '@vegaprotocol/ui-toolkit'; const Failure = ({ reason }: { reason?: ReactNode }) => { const t = useT(); const setNodeSwitcher = useNodeSwitcherStore((store) => store.setDialogOpen); return ( {t('Failed to initialize the app')} {reason} setNodeSwitcher(true)}> {t('Change node')} ); }; const Loading = () => { const [showSlowNotification, setShowSlowNotification] = useState(false); const t = useT(); const setNodeSwitcher = useNodeSwitcherStore((store) => store.setDialogOpen); useEffect(() => { const to = setTimeout(() => { if (!showSlowNotification) setShowSlowNotification(true); }, 5000); return () => { clearTimeout(to); }; }, [showSlowNotification]); return ( {showSlowNotification && ( <> {t( "It looks like you're connection is slow, try switching to another node." )} setNodeSwitcher(true)} > {t('Change node')} > )} ); }; export const Bootstrapper = ({ children }: { children: ReactNode }) => { const t = useT(); const { error, VEGA_URL } = useEnvironment((state) => ({ error: state.error, VEGA_URL: state.VEGA_URL, })); const config = useVegaWalletConfig(); if (!config) { return ; } const ERR_DATA_LOADER = ( {VEGA_URL} , ]} values={{ VEGA_URL, }} /> ); return ( } failure={} > } failure={} > } failure={} > {children} ); }; const cacheConfig: InMemoryCacheConfig = { typePolicies: { Statistics: { merge: true, }, Account: { keyFields: false, fields: { balanceFormatted: {}, }, }, Instrument: { keyFields: false, }, TradableInstrument: { keyFields: false, }, Product: { keyFields: ['settlementAsset', ['id']], }, Market: { fields: { /** * Intercept cache field for tickSize because mainnet specific queries have been * set up, marking this field as client only. The following can be removed when mainnet * supports ticksize: * * 1. The typePolicy for tickSize below * 2. The MarketInfoMainnet query in libs/markets/src/lib/components/market-info/MarketInfo.graphql * 3. The ternary to switch queries in libs/markets/src/lib/components/market-info/market-info-data-provider.ts * 4. The MarketsMainnet query in libs/markets/src/lib/markets.graphql * 5. The ternary to switch queries in libs/markets/src/lib/markets-provider.ts */ tickSize: { read(value) { // value is not present, we have probably marked tickSize as a client only field if (!value) return '1'; // Use fetch response value return value; }, }, }, }, MarketData: { keyFields: ['market', ['id']], }, Node: { keyFields: false, }, Withdrawal: { fields: { pendingOnForeignChain: { read: (isPending = false) => isPending, }, }, }, ERC20: { keyFields: ['contractAddress'], }, Party: { keyFields: false, }, Position: { keyFields: ['market', ['id'], 'party', ['id']], }, Fees: { keyFields: false, }, PartyProfile: { keyFields: ['partyId'], }, // The folling types are cached by the data provider and not by apollo PositionUpdate: { keyFields: false, }, TradeUpdate: { keyFields: false, }, AccountUpdate: { keyFields: false, }, OrderUpdate: { keyFields: false, }, Game: { keyFields: false, }, }, };
{reason}
{t( "It looks like you're connection is slow, try switching to another node." )}