2023-02-16 03:52:54 +00:00
|
|
|
import type { InMemoryCacheConfig } from '@apollo/client';
|
|
|
|
import {
|
2023-05-09 19:58:09 +00:00
|
|
|
AppFailure,
|
2023-10-13 14:02:33 +00:00
|
|
|
AppLoader,
|
2023-02-16 03:52:54 +00:00
|
|
|
NetworkLoader,
|
2023-10-16 14:49:23 +00:00
|
|
|
NodeFailure,
|
2023-02-16 03:52:54 +00:00
|
|
|
NodeGuard,
|
|
|
|
useEnvironment,
|
|
|
|
} from '@vegaprotocol/environment';
|
2024-03-01 14:25:56 +00:00
|
|
|
import { type ReactNode } from 'react';
|
2023-02-16 03:52:54 +00:00
|
|
|
import { Web3Provider } from './web3-provider';
|
2023-11-16 03:10:39 +00:00
|
|
|
import { useT } from '../../lib/use-t';
|
2024-01-05 11:16:59 +00:00
|
|
|
import { DataLoader } from './data-loader';
|
2024-03-01 14:25:56 +00:00
|
|
|
import { WalletProvider } from '@vegaprotocol/wallet-react';
|
|
|
|
import { useVegaWalletConfig } from '../../lib/hooks/use-vega-wallet-config';
|
2023-02-16 03:52:54 +00:00
|
|
|
|
2023-10-13 14:02:33 +00:00
|
|
|
export const Bootstrapper = ({ children }: { children: ReactNode }) => {
|
2023-11-16 03:10:39 +00:00
|
|
|
const t = useT();
|
2024-03-01 14:25:56 +00:00
|
|
|
const { error, VEGA_URL } = useEnvironment();
|
|
|
|
const config = useVegaWalletConfig();
|
2023-02-16 03:52:54 +00:00
|
|
|
|
2024-03-01 14:25:56 +00:00
|
|
|
if (!config) {
|
2023-10-16 14:49:23 +00:00
|
|
|
return <AppLoader />;
|
2023-08-31 02:40:04 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 03:52:54 +00:00
|
|
|
return (
|
2023-11-16 03:10:39 +00:00
|
|
|
<NetworkLoader
|
|
|
|
cache={cacheConfig}
|
|
|
|
skeleton={<AppLoader />}
|
|
|
|
failure={
|
|
|
|
<AppFailure title={t('Could not initialize app')} error={error} />
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<NodeGuard
|
2023-10-13 14:02:33 +00:00
|
|
|
skeleton={<AppLoader />}
|
2023-11-15 05:10:06 +00:00
|
|
|
failure={
|
2023-11-16 03:10:39 +00:00
|
|
|
<NodeFailure
|
|
|
|
title={t('Node: {{VEGA_URL}} is unsuitable', { VEGA_URL })}
|
|
|
|
/>
|
2023-11-15 05:10:06 +00:00
|
|
|
}
|
2023-02-16 03:52:54 +00:00
|
|
|
>
|
2024-01-05 11:16:59 +00:00
|
|
|
<DataLoader
|
2023-10-16 14:49:23 +00:00
|
|
|
skeleton={<AppLoader />}
|
2023-11-16 03:10:39 +00:00
|
|
|
failure={
|
2024-01-05 11:16:59 +00:00
|
|
|
<AppFailure
|
|
|
|
title={t('Could not load market data or asset data')}
|
|
|
|
error={error}
|
|
|
|
/>
|
2023-11-16 03:10:39 +00:00
|
|
|
}
|
2023-10-16 14:49:23 +00:00
|
|
|
>
|
2024-01-05 11:16:59 +00:00
|
|
|
<Web3Provider
|
|
|
|
skeleton={<AppLoader />}
|
|
|
|
failure={
|
|
|
|
<AppFailure title={t('Could not configure web3 provider')} />
|
|
|
|
}
|
2023-08-31 02:40:04 +00:00
|
|
|
>
|
2024-03-01 14:25:56 +00:00
|
|
|
<WalletProvider config={config}>{children}</WalletProvider>
|
2024-01-05 11:16:59 +00:00
|
|
|
</Web3Provider>
|
|
|
|
</DataLoader>
|
2023-11-16 03:10:39 +00:00
|
|
|
</NodeGuard>
|
|
|
|
</NetworkLoader>
|
2023-02-16 03:52:54 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const cacheConfig: InMemoryCacheConfig = {
|
|
|
|
typePolicies: {
|
2023-06-16 08:50:22 +00:00
|
|
|
Statistics: {
|
|
|
|
merge: true,
|
|
|
|
},
|
2023-02-16 03:52:54 +00:00
|
|
|
Account: {
|
|
|
|
keyFields: false,
|
|
|
|
fields: {
|
|
|
|
balanceFormatted: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Instrument: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
|
|
|
TradableInstrument: {
|
2023-05-31 15:38:49 +00:00
|
|
|
keyFields: false,
|
2023-02-16 03:52:54 +00:00
|
|
|
},
|
|
|
|
Product: {
|
|
|
|
keyFields: ['settlementAsset', ['id']],
|
|
|
|
},
|
|
|
|
MarketData: {
|
|
|
|
keyFields: ['market', ['id']],
|
|
|
|
},
|
|
|
|
Node: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
|
|
|
Withdrawal: {
|
|
|
|
fields: {
|
|
|
|
pendingOnForeignChain: {
|
|
|
|
read: (isPending = false) => isPending,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ERC20: {
|
|
|
|
keyFields: ['contractAddress'],
|
|
|
|
},
|
|
|
|
Party: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
2023-05-25 10:59:08 +00:00
|
|
|
Position: {
|
|
|
|
keyFields: ['market', ['id'], 'party', ['id']],
|
|
|
|
},
|
2023-02-16 03:52:54 +00:00
|
|
|
Fees: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
2023-06-16 08:50:22 +00:00
|
|
|
// The folling types are cached by the data provider and not by apollo
|
|
|
|
PositionUpdate: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
|
|
|
TradeUpdate: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
|
|
|
AccountUpdate: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
2023-05-31 15:38:49 +00:00
|
|
|
OrderUpdate: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
2024-02-12 14:03:21 +00:00
|
|
|
Game: {
|
|
|
|
keyFields: false,
|
|
|
|
},
|
2023-02-16 03:52:54 +00:00
|
|
|
},
|
|
|
|
};
|