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

effect dependency fixes

This commit is contained in:
Matthias Kretschmann 2022-06-22 13:40:22 +01:00
parent 3e4b79fc42
commit 40f9170eb4
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -76,9 +76,11 @@ export default function FormStartCompute({
validUntil?: string validUntil?: string
}): ReactElement { }): ReactElement {
const { siteContent } = useMarketMetadata() const { siteContent } = useMarketMetadata()
const { accountId, balance } = useWeb3()
const { isValid, values }: FormikContextType<{ algorithm: string }> = const { isValid, values }: FormikContextType<{ algorithm: string }> =
useFormikContext() useFormikContext()
const { asset, isAssetNetwork } = useAsset() const { asset, isAssetNetwork } = useAsset()
const [totalPrice, setTotalPrice] = useState('0') const [totalPrice, setTotalPrice] = useState('0')
const [datasetOrderPrice, setDatasetOrderPrice] = useState( const [datasetOrderPrice, setDatasetOrderPrice] = useState(
asset?.accessDetails?.price asset?.accessDetails?.price
@ -87,7 +89,6 @@ export default function FormStartCompute({
selectedAlgorithmAsset?.accessDetails?.price selectedAlgorithmAsset?.accessDetails?.price
) )
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false) const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
const { accountId, balance } = useWeb3()
function getAlgorithmAsset(algorithmId: string): Asset { function getAlgorithmAsset(algorithmId: string): Asset {
let assetDdo = null let assetDdo = null
@ -99,6 +100,7 @@ export default function FormStartCompute({
useEffect(() => { useEffect(() => {
if (!values.algorithm || !accountId || !isConsumable) return if (!values.algorithm || !accountId || !isConsumable) return
async function fetchAlgorithmAssetExtended() { async function fetchAlgorithmAssetExtended() {
const algorithmAsset = getAlgorithmAsset(values.algorithm) const algorithmAsset = getAlgorithmAsset(values.algorithm)
const accessDetails = await getAccessDetails( const accessDetails = await getAccessDetails(
@ -159,15 +161,17 @@ export default function FormStartCompute({
hasPreviousOrderSelectedComputeAsset, hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset, hasDatatokenSelectedComputeAsset,
datasetOrderPriceAndFees, datasetOrderPriceAndFees,
algoOrderPriceAndFees algoOrderPriceAndFees,
providerFeeAmount
]) ])
useEffect(() => { useEffect(() => {
if (!totalPrice) return if (!totalPrice || !balance?.ocean || !dtBalance) return
setIsBalanceSufficient( setIsBalanceSufficient(
compareAsBN(balance.ocean, `${totalPrice}`) || Number(dtBalance) >= 1 compareAsBN(balance.ocean, `${totalPrice}`) || Number(dtBalance) >= 1
) )
}, [totalPrice]) }, [totalPrice, balance?.ocean, dtBalance])
return ( return (
<Form className={styles.form}> <Form className={styles.form}>