mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Web3Feedback UI messages fix (#812)
* show isBalanceSufficient warning only on Use tab * show warning icon when both isAssetNetwork and isGraphSynced are false * refactor display messages code fix order and icon issues * moved isBalanceSufficient message handle from Web3Feedback to ButtonBuy * more refactoring, improve feedback message change * fix isBalanceSufficient for buying a compute job * fix lint error
This commit is contained in:
parent
c6f4220f37
commit
1f332c4148
@ -21,6 +21,7 @@ interface ButtonBuyProps {
|
|||||||
dtBalanceSelectedComputeAsset?: string
|
dtBalanceSelectedComputeAsset?: string
|
||||||
selectedComputeAssetLowPoolLiquidity?: boolean
|
selectedComputeAssetLowPoolLiquidity?: boolean
|
||||||
selectedComputeAssetType?: string
|
selectedComputeAssetType?: string
|
||||||
|
isBalanceSufficient: boolean
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
onClick?: (e: FormEvent<HTMLButtonElement>) => void
|
onClick?: (e: FormEvent<HTMLButtonElement>) => void
|
||||||
stepText?: string
|
stepText?: string
|
||||||
@ -38,6 +39,7 @@ function getConsumeHelpText(
|
|||||||
lowPoolLiquidity: boolean,
|
lowPoolLiquidity: boolean,
|
||||||
assetType: string,
|
assetType: string,
|
||||||
isConsumable: boolean,
|
isConsumable: boolean,
|
||||||
|
isBalanceSufficient: boolean,
|
||||||
consumableFeedback: string
|
consumableFeedback: string
|
||||||
) {
|
) {
|
||||||
const text =
|
const text =
|
||||||
@ -49,6 +51,8 @@ function getConsumeHelpText(
|
|||||||
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
|
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
|
||||||
: lowPoolLiquidity
|
: lowPoolLiquidity
|
||||||
? `There are not enought ${dtSymbol} available in the pool for the transaction to take place`
|
? `There are not enought ${dtSymbol} available in the pool for the transaction to take place`
|
||||||
|
: isBalanceSufficient === false
|
||||||
|
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
||||||
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
|
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
@ -62,6 +66,7 @@ function getComputeAssetHelpText(
|
|||||||
assetType: string,
|
assetType: string,
|
||||||
isConsumable: boolean,
|
isConsumable: boolean,
|
||||||
consumableFeedback: string,
|
consumableFeedback: string,
|
||||||
|
isBalanceSufficient: boolean,
|
||||||
hasPreviousOrderSelectedComputeAsset?: boolean,
|
hasPreviousOrderSelectedComputeAsset?: boolean,
|
||||||
hasDatatokenSelectedComputeAsset?: boolean,
|
hasDatatokenSelectedComputeAsset?: boolean,
|
||||||
dtSymbolSelectedComputeAsset?: string,
|
dtSymbolSelectedComputeAsset?: string,
|
||||||
@ -78,6 +83,7 @@ function getComputeAssetHelpText(
|
|||||||
lowPoolLiquidity,
|
lowPoolLiquidity,
|
||||||
assetType,
|
assetType,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
|
isBalanceSufficient,
|
||||||
consumableFeedback
|
consumableFeedback
|
||||||
)
|
)
|
||||||
const computeAlgoHelpText =
|
const computeAlgoHelpText =
|
||||||
@ -96,6 +102,8 @@ function getComputeAssetHelpText(
|
|||||||
? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.`
|
? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.`
|
||||||
: selectedComputeAssettLowPoolLiquidity
|
: selectedComputeAssettLowPoolLiquidity
|
||||||
? `There are not enought ${dtSymbolSelectedComputeAsset} available in the pool for the transaction to take place`
|
? `There are not enought ${dtSymbolSelectedComputeAsset} available in the pool for the transaction to take place`
|
||||||
|
: isBalanceSufficient === false
|
||||||
|
? ''
|
||||||
: `Additionally, you will buy 1 ${dtSymbolSelectedComputeAsset} for the ${selectedComputeAssetType} and spend it back to its publisher and pool.`
|
: `Additionally, you will buy 1 ${dtSymbolSelectedComputeAsset} for the ${selectedComputeAssetType} and spend it back to its publisher and pool.`
|
||||||
const computeHelpText = selectedComputeAssettLowPoolLiquidity
|
const computeHelpText = selectedComputeAssettLowPoolLiquidity
|
||||||
? computeAlgoHelpText
|
? computeAlgoHelpText
|
||||||
@ -117,6 +125,7 @@ export default function ButtonBuy({
|
|||||||
assetTimeout,
|
assetTimeout,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
consumableFeedback,
|
consumableFeedback,
|
||||||
|
isBalanceSufficient,
|
||||||
hasPreviousOrderSelectedComputeAsset,
|
hasPreviousOrderSelectedComputeAsset,
|
||||||
hasDatatokenSelectedComputeAsset,
|
hasDatatokenSelectedComputeAsset,
|
||||||
dtSymbolSelectedComputeAsset,
|
dtSymbolSelectedComputeAsset,
|
||||||
@ -168,6 +177,7 @@ export default function ButtonBuy({
|
|||||||
datasetLowPoolLiquidity,
|
datasetLowPoolLiquidity,
|
||||||
assetType,
|
assetType,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
|
isBalanceSufficient,
|
||||||
consumableFeedback
|
consumableFeedback
|
||||||
)
|
)
|
||||||
: getComputeAssetHelpText(
|
: getComputeAssetHelpText(
|
||||||
@ -179,6 +189,7 @@ export default function ButtonBuy({
|
|||||||
assetType,
|
assetType,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
consumableFeedback,
|
consumableFeedback,
|
||||||
|
isBalanceSufficient,
|
||||||
hasPreviousOrderSelectedComputeAsset,
|
hasPreviousOrderSelectedComputeAsset,
|
||||||
hasDatatokenSelectedComputeAsset,
|
hasDatatokenSelectedComputeAsset,
|
||||||
dtSymbolSelectedComputeAsset,
|
dtSymbolSelectedComputeAsset,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useEffect, useState } 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'
|
||||||
@ -12,46 +12,42 @@ export declare type Web3Error = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Web3Feedback({
|
export default function Web3Feedback({
|
||||||
isBalanceSufficient,
|
|
||||||
isAssetNetwork
|
isAssetNetwork
|
||||||
}: {
|
}: {
|
||||||
isBalanceSufficient?: boolean
|
|
||||||
isAssetNetwork?: boolean
|
isAssetNetwork?: boolean
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { isGraphSynced, blockGraph, blockHead } = useGraphSyncStatus()
|
const { isGraphSynced, blockGraph, blockHead } = useGraphSyncStatus()
|
||||||
const showFeedback =
|
const [state, setState] = useState<string>()
|
||||||
!accountId ||
|
const [title, setTitle] = useState<string>()
|
||||||
isBalanceSufficient === false ||
|
const [message, setMessage] = useState<string>()
|
||||||
isAssetNetwork === false ||
|
const [showFeedback, setShowFeedback] = useState<boolean>(false)
|
||||||
isGraphSynced === false
|
|
||||||
|
|
||||||
const state =
|
useEffect(() => {
|
||||||
!accountId || !isGraphSynced
|
setShowFeedback(
|
||||||
? 'error'
|
!accountId || isAssetNetwork === false || isGraphSynced === false
|
||||||
: accountId && isBalanceSufficient && isAssetNetwork
|
)
|
||||||
? 'success'
|
if (accountId && isAssetNetwork && isGraphSynced) return
|
||||||
: 'warning'
|
if (!accountId) {
|
||||||
|
setState('error')
|
||||||
const title = !accountId
|
setTitle('No account connected')
|
||||||
? 'No account connected'
|
setMessage('Please connect your Web3 wallet.')
|
||||||
: accountId && isAssetNetwork === false
|
} else if (isAssetNetwork === false) {
|
||||||
? 'Not connected to asset network'
|
setState('error')
|
||||||
: isGraphSynced === false
|
setTitle('Not connected to asset network')
|
||||||
? `Data out of sync`
|
setMessage('Please connect your Web3 wallet.')
|
||||||
: accountId
|
} else if (isGraphSynced === false) {
|
||||||
? isBalanceSufficient === false
|
setState('warning')
|
||||||
? 'Insufficient balance'
|
setTitle('Data out of sync')
|
||||||
: 'Connected to Ocean'
|
setMessage(
|
||||||
: 'Something went wrong'
|
`The data for this network has only synced to Ethereum block ${blockGraph} (out of ${blockHead}). Transactions may fail! Please check back soon.`
|
||||||
|
)
|
||||||
const message = !accountId
|
} else {
|
||||||
? 'Please connect your Web3 wallet.'
|
setState('warning')
|
||||||
: isBalanceSufficient === false
|
setTitle('Something went wrong.')
|
||||||
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
setMessage('Something went wrong.')
|
||||||
: isGraphSynced === false
|
}
|
||||||
? `The data for this network has only synced to Ethereum block ${blockGraph} (out of ${blockHead}). Transactions may fail! Please check back soon`
|
}, [accountId, isGraphSynced, isAssetNetwork])
|
||||||
: 'Something went wrong.'
|
|
||||||
|
|
||||||
return showFeedback ? (
|
return showFeedback ? (
|
||||||
<section className={styles.feedback}>
|
<section className={styles.feedback}>
|
||||||
|
@ -6,6 +6,7 @@ import { FormFieldProps } from '../../../../@types/Form'
|
|||||||
import { useStaticQuery, graphql } from 'gatsby'
|
import { useStaticQuery, graphql } from 'gatsby'
|
||||||
import { DDO, BestPrice } from '@oceanprotocol/lib'
|
import { DDO, BestPrice } from '@oceanprotocol/lib'
|
||||||
import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelection'
|
import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelection'
|
||||||
|
import compareAsBN from '../../../../utils/compareAsBN'
|
||||||
import ButtonBuy from '../../../atoms/ButtonBuy'
|
import ButtonBuy from '../../../atoms/ButtonBuy'
|
||||||
import PriceOutput from './PriceOutput'
|
import PriceOutput from './PriceOutput'
|
||||||
import { useAsset } from '../../../../providers/Asset'
|
import { useAsset } from '../../../../providers/Asset'
|
||||||
@ -96,7 +97,8 @@ export default function FormStartCompute({
|
|||||||
useFormikContext()
|
useFormikContext()
|
||||||
const { price, ddo, isAssetNetwork } = useAsset()
|
const { price, ddo, isAssetNetwork } = useAsset()
|
||||||
const [totalPrice, setTotalPrice] = useState(price?.value)
|
const [totalPrice, setTotalPrice] = useState(price?.value)
|
||||||
const { accountId } = useWeb3()
|
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
|
||||||
|
const { accountId, balance } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
const { ocean } = useOcean()
|
||||||
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
|
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
|
||||||
useState<number>()
|
useState<number>()
|
||||||
@ -148,6 +150,13 @@ export default function FormStartCompute({
|
|||||||
hasDatatokenSelectedComputeAsset
|
hasDatatokenSelectedComputeAsset
|
||||||
])
|
])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!totalPrice) return
|
||||||
|
setIsBalanceSufficient(
|
||||||
|
compareAsBN(balance.ocean, `${totalPrice}`) || Number(dtBalance) >= 1
|
||||||
|
)
|
||||||
|
}, [totalPrice])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form className={styles.form}>
|
<Form className={styles.form}>
|
||||||
{content.form.data.map((field: FormFieldProps) => (
|
{content.form.data.map((field: FormFieldProps) => (
|
||||||
@ -177,6 +186,7 @@ export default function FormStartCompute({
|
|||||||
disabled={
|
disabled={
|
||||||
isComputeButtonDisabled ||
|
isComputeButtonDisabled ||
|
||||||
!isValid ||
|
!isValid ||
|
||||||
|
!isBalanceSufficient ||
|
||||||
!isAssetNetwork ||
|
!isAssetNetwork ||
|
||||||
algorithmConsumableStatus > 0
|
algorithmConsumableStatus > 0
|
||||||
}
|
}
|
||||||
@ -202,6 +212,7 @@ export default function FormStartCompute({
|
|||||||
type="submit"
|
type="submit"
|
||||||
priceType={price?.type}
|
priceType={price?.type}
|
||||||
algorithmPriceType={algorithmPrice?.type}
|
algorithmPriceType={algorithmPrice?.type}
|
||||||
|
isBalanceSufficient={isBalanceSufficient}
|
||||||
isConsumable={isConsumable}
|
isConsumable={isConsumable}
|
||||||
consumableFeedback={consumableFeedback}
|
consumableFeedback={consumableFeedback}
|
||||||
algorithmConsumableStatus={algorithmConsumableStatus}
|
algorithmConsumableStatus={algorithmConsumableStatus}
|
||||||
|
@ -12,9 +12,5 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Default = (): ReactElement => (
|
export const Default = (): ReactElement => (
|
||||||
<Compute
|
<Compute dtBalance="1" file={ddo.service[0].attributes.main.files[0]} />
|
||||||
dtBalance="1"
|
|
||||||
isBalanceSufficient
|
|
||||||
file={ddo.service[0].attributes.main.files[0]}
|
|
||||||
/>
|
|
||||||
)
|
)
|
||||||
|
@ -48,14 +48,12 @@ const SuccessAction = () => (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export default function Compute({
|
export default function Compute({
|
||||||
isBalanceSufficient,
|
|
||||||
dtBalance,
|
dtBalance,
|
||||||
file,
|
file,
|
||||||
fileIsLoading,
|
fileIsLoading,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
consumableFeedback
|
consumableFeedback
|
||||||
}: {
|
}: {
|
||||||
isBalanceSufficient: boolean
|
|
||||||
dtBalance: string
|
dtBalance: string
|
||||||
file: FileMetadata
|
file: FileMetadata
|
||||||
fileIsLoading?: boolean
|
fileIsLoading?: boolean
|
||||||
@ -65,7 +63,7 @@ export default function Compute({
|
|||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { ocean, account } = useOcean()
|
const { ocean, account } = useOcean()
|
||||||
const { price, type, ddo, isAssetNetwork } = useAsset()
|
const { price, type, ddo } = useAsset()
|
||||||
const { buyDT, pricingError, pricingStepText } = usePricing()
|
const { buyDT, pricingError, pricingStepText } = usePricing()
|
||||||
const [isJobStarting, setIsJobStarting] = useState(false)
|
const [isJobStarting, setIsJobStarting] = useState(false)
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
@ -94,7 +92,6 @@ export default function Compute({
|
|||||||
isJobStarting === true ||
|
isJobStarting === true ||
|
||||||
file === null ||
|
file === null ||
|
||||||
!ocean ||
|
!ocean ||
|
||||||
!isBalanceSufficient ||
|
|
||||||
(!hasPreviousDatasetOrder && !hasDatatoken && !(datasetMaxDT >= 1)) ||
|
(!hasPreviousDatasetOrder && !hasDatatoken && !(datasetMaxDT >= 1)) ||
|
||||||
(!hasPreviousAlgorithmOrder && !hasAlgoAssetDatatoken && !(algoMaxDT >= 1))
|
(!hasPreviousAlgorithmOrder && !hasAlgoAssetDatatoken && !(algoMaxDT >= 1))
|
||||||
|
|
||||||
|
@ -183,6 +183,7 @@ export default function Consume({
|
|||||||
isLoading={pricingIsLoading || isLoading}
|
isLoading={pricingIsLoading || isLoading}
|
||||||
priceType={price?.type}
|
priceType={price?.type}
|
||||||
isConsumable={isConsumable}
|
isConsumable={isConsumable}
|
||||||
|
isBalanceSufficient={isBalanceSufficient}
|
||||||
consumableFeedback={consumableFeedback}
|
consumableFeedback={consumableFeedback}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
@ -111,7 +111,6 @@ export default function AssetActions(): ReactElement {
|
|||||||
const UseContent = isCompute ? (
|
const UseContent = isCompute ? (
|
||||||
<Compute
|
<Compute
|
||||||
dtBalance={dtBalance}
|
dtBalance={dtBalance}
|
||||||
isBalanceSufficient={isBalanceSufficient}
|
|
||||||
file={fileMetadata}
|
file={fileMetadata}
|
||||||
fileIsLoading={fileIsLoading}
|
fileIsLoading={fileIsLoading}
|
||||||
isConsumable={isConsumable}
|
isConsumable={isConsumable}
|
||||||
@ -153,10 +152,7 @@ export default function AssetActions(): ReactElement {
|
|||||||
<Permission eventType="consume">
|
<Permission eventType="consume">
|
||||||
<Tabs items={tabs} className={styles.actions} />
|
<Tabs items={tabs} className={styles.actions} />
|
||||||
</Permission>
|
</Permission>
|
||||||
<Web3Feedback
|
<Web3Feedback isAssetNetwork={isAssetNetwork} />
|
||||||
isBalanceSufficient={isBalanceSufficient}
|
|
||||||
isAssetNetwork={isAssetNetwork}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user