diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx
index c8c9f4246..3a8622072 100644
--- a/src/components/organisms/AssetActions/Consume.tsx
+++ b/src/components/organisms/AssetActions/Consume.tsx
@@ -1,5 +1,6 @@
import React, { ReactElement } from 'react'
import { fromWei } from 'web3-utils'
+import { toast } from 'react-toastify'
import compareAsBN, { Comparisson } from '../../../utils/compareAsBN'
import Button from '../../atoms/Button'
import File from '../../atoms/File'
@@ -7,7 +8,7 @@ import Price from '../../atoms/Price'
import Web3Feedback from '../../molecules/Wallet/Feedback'
import styles from './Consume.module.css'
import Loader from '../../atoms/Loader'
-import { useOcean, useConsume } from '@oceanprotocol/react'
+import { useOcean, useConsume, useMetadata } from '@oceanprotocol/react'
import { MetadataMarket } from '../../../@types/Metadata'
export default function Consume({
@@ -17,32 +18,34 @@ export default function Consume({
did: string
metadata: MetadataMarket
}): ReactElement {
- const { ocean, balanceInOcean } = useOcean()
- const { consume, consumeStepText, isLoading } = useConsume()
- const { price } = metadata.main
+ const { ddo } = useMetadata(did)
const file = metadata.main.files[0]
- const isFree = price === '0'
- const isBalanceSufficient =
- isFree || compareAsBN(balanceInOcean, fromWei(price), Comparisson.gte)
- const isDisabled = !ocean || !isBalanceSufficient || isLoading
+ const { cost } = ddo.findServiceByType('access').attributes.main
- const PurchaseButton = () => {
- if (typeof window === 'undefined') {
- return null
- }
+ const { ocean } = useOcean()
+ const { consumeStepText, consume, consumeError } = useConsume()
- return isLoading ? (
+ const isFree = cost === '0'
+ // const isBalanceSufficient =
+ // isFree || compareAsBN(balanceInOcean, fromWei(cost), Comparisson.gte)
+ const isDisabled = !ocean
+
+ if (consumeError) {
+ toast.error(consumeError)
+ }
+
+ const PurchaseButton = () =>
+ consumeStepText ? (
) : (
)
- }
return (
)