vega-frontend-monorepo/apps/trading/components/app-loader/index.tsx
Dexter Edwards dccc750154
fix(1758): data node being down (#1871)
* fix: timeout data node requests for node switcher

* chore: generate apollo client library

* chore: migrate console lite to use new apollo client package

* chore: migrate explorer across

* chore: remove completely unused file

* chore: migrate stats

* chore: migrate trading

* chore: migrate multisigner app

* chore: migrate token over

* chore: final migrations

* test: adjust tests for new behaviour

* fix: build script

* Update libs/apollo-client/src/lib/apollo-client.ts

* chore: fix conflicts

* fix: cache

* test: setup mocks before each test

* style: lint

* style: lint

* chore: resolve conflicts

* test: fix tests
2022-11-10 13:08:12 +00:00

71 lines
1.7 KiB
TypeScript

import type { ReactNode } from 'react';
import { useMemo } from 'react';
import { useEagerConnect } from '@vegaprotocol/wallet';
import { NetworkLoader } from '@vegaprotocol/environment';
import { Connectors } from '../../lib/vega-connectors';
import type { InMemoryCacheConfig } from '@apollo/client';
interface AppLoaderProps {
children: ReactNode;
}
/**
* Component to handle any app initialization, startup queries and other things
* that must happen for it can be used
*/
export function AppLoader({ children }: AppLoaderProps) {
// Get keys from vega wallet immediately
useEagerConnect(Connectors);
const cache: InMemoryCacheConfig = useMemo(
() => ({
typePolicies: {
Account: {
keyFields: false,
fields: {
balanceFormatted: {},
},
},
Instrument: {
keyFields: false,
},
TradableInstrument: {
keyFields: ['instrument'],
},
Product: {
keyFields: ['settlementAsset', ['id']],
},
MarketData: {
keyFields: ['market', ['id']],
},
Node: {
keyFields: false,
},
Withdrawal: {
fields: {
pendingOnForeignChain: {
read: (isPending = false) => isPending,
},
},
},
ERC20: {
keyFields: ['contractAddress'],
},
PositionUpdate: {
keyFields: false,
},
AccountUpdate: {
keyFields: false,
},
Party: {
keyFields: false,
},
Fees: {
keyFields: false,
},
},
}),
[]
);
return <NetworkLoader cache={cache}>{children}</NetworkLoader>;
}