import React, { Children } from 'react'; import { breezeConstants } from '@ezerous/breeze'; import { useSelector } from 'react-redux'; import LoadingComponent from './LoadingComponent'; // CSS import '../assets/css/loading-component.css'; const LoadingContainer = ({ children }) => { const initializing = useSelector((state) => state.drizzleStatus.initializing); const failed = useSelector((state) => state.drizzleStatus.failed); const ipfsStatus = useSelector((state) => state.ipfs.status); const orbitStatus = useSelector((state) => state.orbit.status); const web3Status = useSelector((state) => state.web3.status); const web3NetworkId = useSelector((state) => state.web3.networkId); const web3NetworkFailed = useSelector((state) => state.web3.networkFailed); const web3AccountsFailed = useSelector((state) => state.web3.accountsFailed); const contractInitialized = useSelector((state) => state.contracts.Forum.initialized); const contractDeployed = useSelector((state) => state.contracts.Forum.deployed); const userFetched = useSelector((state) => state.user.address); if ((web3Status === 'initializing' || !web3NetworkId) && !web3NetworkFailed) { return ( ); } if (web3Status === 'failed' || web3NetworkFailed) { return ( ); } if (web3Status === 'initialized' && web3AccountsFailed) { return ( ); } if (initializing || (!failed && !contractInitialized && contractDeployed)) { return ( ); } if (!contractDeployed) { return ( ); } if (ipfsStatus === breezeConstants.STATUS_INITIALIZING) { return ( ); } if (ipfsStatus === breezeConstants.STATUS_FAILED) { return ( ); } if (orbitStatus === breezeConstants.STATUS_INITIALIZING) { const message = process.env.NODE_ENV === 'development' ? 'If needed, please sign the transaction in MetaMask to create the databases.' : 'Please sign the transaction in MetaMask to create the databases.'; return ( ); } if (orbitStatus === breezeConstants.STATUS_FAILED) { return ( ); } if (!userFetched) { return ( ); } return Children.only(children); }; export default LoadingContainer;