2022-06-21 23:20:53 +00:00
|
|
|
import type { ReactNode } from 'react';
|
2022-11-10 13:08:12 +00:00
|
|
|
import { useMemo } from 'react';
|
2022-04-20 19:37:44 +00:00
|
|
|
import { useEagerConnect } from '@vegaprotocol/wallet';
|
2022-06-21 23:20:53 +00:00
|
|
|
import { NetworkLoader } from '@vegaprotocol/environment';
|
2022-04-20 19:37:44 +00:00
|
|
|
import { Connectors } from '../../lib/vega-connectors';
|
2022-11-10 13:08:12 +00:00
|
|
|
import type { InMemoryCacheConfig } from '@apollo/client';
|
2022-03-11 00:28:48 +00:00
|
|
|
|
|
|
|
interface AppLoaderProps {
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-23 12:21:54 +00:00
|
|
|
* Component to handle any app initialization, startup queries and other things
|
2022-03-11 00:28:48 +00:00
|
|
|
* that must happen for it can be used
|
|
|
|
*/
|
|
|
|
export function AppLoader({ children }: AppLoaderProps) {
|
|
|
|
// Get keys from vega wallet immediately
|
2022-04-20 19:37:44 +00:00
|
|
|
useEagerConnect(Connectors);
|
2022-11-10 13:08:12 +00:00
|
|
|
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>;
|
2022-03-11 00:28:48 +00:00
|
|
|
}
|