import React, { ReactElement, useEffect, useState } from 'react' import Status from '@shared/atoms/Status' import styles from './index.module.css' import WalletNetworkSwitcher from '../WalletNetworkSwitcher' import { useGraphSyncStatus } from '@hooks/useGraphSyncStatus' export declare type Web3Error = { status: 'error' | 'warning' | 'success' title: string message?: string } export default function Web3Feedback({ networkId, accountId, isAssetNetwork }: { networkId: number accountId: string isAssetNetwork?: boolean }): ReactElement { const { isGraphSynced, blockGraph, blockHead } = useGraphSyncStatus(networkId) const [state, setState] = useState() const [title, setTitle] = useState() const [message, setMessage] = useState() const [showFeedback, setShowFeedback] = useState(false) useEffect(() => { setShowFeedback( !accountId || isAssetNetwork === false || isGraphSynced === false ) if (accountId && isAssetNetwork && isGraphSynced) return if (!accountId) { setState('error') setTitle('No account connected') setMessage('Please connect your wallet.') } else if (isAssetNetwork === false) { setState('error') setTitle('Not connected to asset network') setMessage('Please connect your wallet.') } else if (isGraphSynced === false) { setState('warning') setTitle('Data out of sync') setMessage( `The data for this network has only synced to Ethereum block ${blockGraph} (out of ${blockHead}). Transactions may fail! Please check back soon.` ) } else { setState('warning') setTitle('Something went wrong.') setMessage('Something went wrong.') } }, [accountId, isGraphSynced, isAssetNetwork]) return showFeedback ? (

{title}

{isAssetNetwork === false ? ( ) : ( message &&

{message}

)}
) : null }