78f5a9c520
Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com> Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: bwallacee <ben@vega.xyz>
35 lines
885 B
TypeScript
35 lines
885 B
TypeScript
import { useAssetsMapProvider } from '@vegaprotocol/assets';
|
|
import { useMarketsMapProvider } from '@vegaprotocol/markets';
|
|
import type { ReactNode } from 'react';
|
|
|
|
export const DataLoader = ({
|
|
children,
|
|
failure,
|
|
skeleton,
|
|
}: {
|
|
children: ReactNode;
|
|
failure: ReactNode;
|
|
skeleton: ReactNode;
|
|
}) => {
|
|
// Query all markets and assets to ensure they are cached
|
|
const { data: markets, error, loading } = useMarketsMapProvider();
|
|
const {
|
|
data: assets,
|
|
error: errorAssets,
|
|
loading: loadingAssets,
|
|
} = useAssetsMapProvider();
|
|
|
|
if (loading || loadingAssets) {
|
|
// eslint-disable-next-line
|
|
return <>{skeleton}</>;
|
|
}
|
|
|
|
if (error || errorAssets || !markets || !assets) {
|
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
return <>{failure}</>;
|
|
}
|
|
|
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
return <>{children}</>;
|
|
};
|