1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Check graph sync status (#745)

* fix balance check after network switch

* error location

* remove console

* fix messages

* fixed sync status

* remove comment
This commit is contained in:
mihaisc 2021-07-22 02:40:44 -07:00 committed by GitHub
parent 38a8358762
commit 22da62b231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 20 deletions

View File

@ -40,18 +40,11 @@ export default function App({
const { warning } = useSiteMetadata() const { warning } = useSiteMetadata()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { isInPurgatory, purgatoryData } = useAccountPurgatory(accountId) const { isInPurgatory, purgatoryData } = useAccountPurgatory(accountId)
const { isGraphSynced, blockHead, blockGraph } = useGraphSyncStatus() // const { isGraphSynced, blockHead, blockGraph } = useGraphSyncStatus()
return ( return (
<Styles> <Styles>
<div className={styles.app}> <div className={styles.app}>
{(props as PageProps).uri.includes('/asset') && !isGraphSynced && (
<AnnouncementBanner
text={`The data for this network has only synced to Ethereum block ${blockGraph} (out of ${blockHead}). Please check back soon.`}
state="error"
/>
)}
{(props as PageProps).uri === '/' && ( {(props as PageProps).uri === '/' && (
<AnnouncementBanner text={warning.main} /> <AnnouncementBanner text={warning.main} />
)} )}

View File

@ -1,8 +1,9 @@
import React, { ReactElement } from 'react' import React, { ReactElement, useEffect } from 'react'
import { useWeb3 } from '../../providers/Web3' import { useWeb3 } from '../../providers/Web3'
import Status from '../atoms/Status' import Status from '../atoms/Status'
import styles from './Web3Feedback.module.css' import styles from './Web3Feedback.module.css'
import WalletNetworkSwitcher from './WalletNetworkSwitcher' import WalletNetworkSwitcher from './WalletNetworkSwitcher'
import { useGraphSyncStatus } from '../../hooks/useGraphSyncStatus'
export declare type Web3Error = { export declare type Web3Error = {
status: 'error' | 'warning' | 'success' status: 'error' | 'warning' | 'success'
@ -18,17 +19,20 @@ export default function Web3Feedback({
isAssetNetwork?: boolean isAssetNetwork?: boolean
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { isGraphSynced, blockGraph, blockHead } = useGraphSyncStatus()
const showFeedback = const showFeedback =
!accountId || !accountId ||
// !ocean || // !ocean ||
isBalanceSufficient === false || isBalanceSufficient === false ||
isAssetNetwork === false isAssetNetwork === false ||
isGraphSynced === false
const state = !accountId const state =
? 'error' !accountId || !isGraphSynced
: accountId && isBalanceSufficient && isAssetNetwork ? 'error'
? 'success' : accountId && isBalanceSufficient && isAssetNetwork
: 'warning' ? 'success'
: 'warning'
const title = !accountId const title = !accountId
? 'No account connected' ? 'No account connected'
@ -36,6 +40,8 @@ export default function Web3Feedback({
// ? 'Error connecting to Ocean' // ? 'Error connecting to Ocean'
accountId && isAssetNetwork === false accountId && isAssetNetwork === false
? 'Not connected to asset network' ? 'Not connected to asset network'
: isGraphSynced === false
? `Data out of sync`
: accountId : accountId
? isBalanceSufficient === false ? isBalanceSufficient === false
? 'Insufficient balance' ? 'Insufficient balance'
@ -44,10 +50,10 @@ export default function Web3Feedback({
const message = !accountId const message = !accountId
? 'Please connect your Web3 wallet.' ? 'Please connect your Web3 wallet.'
: // : !ocean : isBalanceSufficient === false
// ? 'Please try again.'
isBalanceSufficient === false
? 'You do not have enough OCEAN in your wallet to purchase this asset.' ? 'You do not have enough OCEAN in your wallet to purchase this asset.'
: isGraphSynced === false
? `The data for this network has only synced to Ethereum block ${blockGraph} (out of ${blockHead}). Transactions may fail! Please check back soon`
: 'Something went wrong.' : 'Something went wrong.'
return showFeedback ? ( return showFeedback ? (

View File

@ -18,7 +18,7 @@ import axios from 'axios'
export default function AssetActions(): ReactElement { export default function AssetActions(): ReactElement {
const { accountId, balance } = useWeb3() const { accountId, balance } = useWeb3()
const { ocean, config, account } = useOcean() const { ocean, config, account } = useOcean()
const { price, ddo, metadata, type, isAssetNetwork } = useAsset() const { price, ddo, isAssetNetwork } = useAsset()
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>() const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>()
const [dtBalance, setDtBalance] = useState<string>() const [dtBalance, setDtBalance] = useState<string>()
@ -86,7 +86,7 @@ export default function AssetActions(): ReactElement {
} }
} }
init() init()
}, [ocean, accountId, ddo.dataToken]) }, [ocean, accountId, ddo.dataToken, isAssetNetwork])
// Check user balance against price // Check user balance against price
useEffect(() => { useEffect(() => {