mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
refactor Compute for new hooks
This commit is contained in:
parent
b516743a59
commit
5ebbb479fe
@ -1,5 +1,5 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
import { File as FileMetadata } from '@oceanprotocol/lib'
|
||||||
import filesize from 'filesize'
|
import filesize from 'filesize'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
import cleanupContentType from '../../utils/cleanupContentType'
|
import cleanupContentType from '../../utils/cleanupContentType'
|
||||||
|
@ -9,26 +9,21 @@ import Price from '../../atoms/Price'
|
|||||||
import {
|
import {
|
||||||
computeOptions,
|
computeOptions,
|
||||||
useCompute,
|
useCompute,
|
||||||
readFileContent
|
readFileContent,
|
||||||
|
useMetadata,
|
||||||
|
useOcean
|
||||||
} from '@oceanprotocol/react'
|
} from '@oceanprotocol/react'
|
||||||
import styles from './Compute.module.css'
|
import styles from './Compute.module.css'
|
||||||
import Button from '../../atoms/Button'
|
import Button from '../../atoms/Button'
|
||||||
import Input from '../../atoms/Input'
|
import Input from '../../atoms/Input'
|
||||||
import { MetadataMarket } from '../../../@types/Metadata'
|
|
||||||
import Alert from '../../atoms/Alert'
|
import Alert from '../../atoms/Alert'
|
||||||
|
|
||||||
export default function Compute({
|
export default function Compute({ did }: { did: string }): ReactElement {
|
||||||
did,
|
const { ocean } = useOcean()
|
||||||
metadata,
|
const { ddo } = useMetadata(did)
|
||||||
balance,
|
|
||||||
ocean
|
|
||||||
}: {
|
|
||||||
did: string
|
|
||||||
metadata: MetadataMarket
|
|
||||||
balance: string | null
|
|
||||||
ocean: Ocean | null
|
|
||||||
}): ReactElement {
|
|
||||||
const { compute, isLoading, computeStepText, computeError } = useCompute()
|
const { compute, isLoading, computeStepText, computeError } = useCompute()
|
||||||
|
const computeService = ddo.findServiceByType('compute').attributes.main
|
||||||
|
|
||||||
const [isJobStarting, setIsJobStarting] = useState(false)
|
const [isJobStarting, setIsJobStarting] = useState(false)
|
||||||
const [, setError] = useState('')
|
const [, setError] = useState('')
|
||||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState(false)
|
const [isBalanceSufficient, setIsBalanceSufficient] = useState(false)
|
||||||
@ -41,11 +36,10 @@ export default function Compute({
|
|||||||
const [algorithmRawCode, setAlgorithmRawCode] = useState('')
|
const [algorithmRawCode, setAlgorithmRawCode] = useState('')
|
||||||
const [isPublished, setIsPublished] = useState(false)
|
const [isPublished, setIsPublished] = useState(false)
|
||||||
const [file, setFile] = useState(null)
|
const [file, setFile] = useState(null)
|
||||||
|
|
||||||
const { price } = metadata.main
|
|
||||||
const isFree = price === '0'
|
|
||||||
|
|
||||||
const [isTermsAgreed, setIsTermsAgreed] = useState(true)
|
const [isTermsAgreed, setIsTermsAgreed] = useState(true)
|
||||||
|
|
||||||
|
const isFree = computeService.cost === '0'
|
||||||
|
|
||||||
const isComputeButtonDisabled =
|
const isComputeButtonDisabled =
|
||||||
isJobStarting ||
|
isJobStarting ||
|
||||||
file === null ||
|
file === null ||
|
||||||
@ -54,13 +48,13 @@ export default function Compute({
|
|||||||
!isBalanceSufficient ||
|
!isBalanceSufficient ||
|
||||||
!isTermsAgreed
|
!isTermsAgreed
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
setIsBalanceSufficient(
|
// setIsBalanceSufficient(
|
||||||
isFree ||
|
// isFree ||
|
||||||
(balance !== null &&
|
// (balance !== null &&
|
||||||
compareAsBN(balance, fromWei(price), Comparisson.gte))
|
// compareAsBN(balance, fromWei(computeService.cost), Comparisson.gte))
|
||||||
)
|
// )
|
||||||
}, [balance])
|
// }, [balance])
|
||||||
|
|
||||||
const onDrop = async (files: any) => {
|
const onDrop = async (files: any) => {
|
||||||
setFile(files[0])
|
setFile(files[0])
|
||||||
@ -80,11 +74,18 @@ export default function Compute({
|
|||||||
const startJob = async () => {
|
const startJob = async () => {
|
||||||
try {
|
try {
|
||||||
if (!ocean) return
|
if (!ocean) return
|
||||||
|
|
||||||
setIsJobStarting(true)
|
setIsJobStarting(true)
|
||||||
setIsPublished(false)
|
setIsPublished(false)
|
||||||
setError('')
|
setError('')
|
||||||
|
|
||||||
await compute(did, algorithmRawCode, computeContainer)
|
await compute(
|
||||||
|
did,
|
||||||
|
computeService,
|
||||||
|
ddo.dataToken,
|
||||||
|
algorithmRawCode,
|
||||||
|
computeContainer
|
||||||
|
)
|
||||||
|
|
||||||
setIsPublished(true)
|
setIsPublished(true)
|
||||||
setFile(null)
|
setFile(null)
|
||||||
@ -97,7 +98,7 @@ export default function Compute({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.compute}>
|
<div className={styles.compute}>
|
||||||
<Price price={price} />
|
<Price price={computeService.cost} />
|
||||||
|
|
||||||
<div className={styles.info}>
|
<div className={styles.info}>
|
||||||
<div className={styles.selectType}>
|
<div className={styles.selectType}>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import { fromWei } from 'web3-utils'
|
import { fromWei } from 'web3-utils'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
|
import { File as FileMetadata } from '@oceanprotocol/lib'
|
||||||
import compareAsBN, { Comparisson } from '../../../utils/compareAsBN'
|
import compareAsBN, { Comparisson } from '../../../utils/compareAsBN'
|
||||||
import Button from '../../atoms/Button'
|
import Button from '../../atoms/Button'
|
||||||
import File from '../../atoms/File'
|
import File from '../../atoms/File'
|
||||||
@ -9,17 +10,15 @@ import Web3Feedback from '../../molecules/Wallet/Feedback'
|
|||||||
import styles from './Consume.module.css'
|
import styles from './Consume.module.css'
|
||||||
import Loader from '../../atoms/Loader'
|
import Loader from '../../atoms/Loader'
|
||||||
import { useOcean, useConsume, useMetadata } from '@oceanprotocol/react'
|
import { useOcean, useConsume, useMetadata } from '@oceanprotocol/react'
|
||||||
import { MetadataMarket } from '../../../@types/Metadata'
|
|
||||||
|
|
||||||
export default function Consume({
|
export default function Consume({
|
||||||
did,
|
did,
|
||||||
metadata
|
file
|
||||||
}: {
|
}: {
|
||||||
did: string
|
did: string
|
||||||
metadata: MetadataMarket
|
file: FileMetadata
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ddo } = useMetadata(did)
|
const { ddo } = useMetadata(did)
|
||||||
const file = metadata.main.files[0]
|
|
||||||
const { cost } = ddo.findServiceByType('access').attributes.main
|
const { cost } = ddo.findServiceByType('access').attributes.main
|
||||||
|
|
||||||
const { ocean } = useOcean()
|
const { ocean } = useOcean()
|
||||||
|
@ -3,7 +3,6 @@ import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'
|
|||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import Compute from './Compute'
|
import Compute from './Compute'
|
||||||
import Consume from './Consume'
|
import Consume from './Consume'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
|
||||||
import { MetadataMarket } from '../../../@types/Metadata'
|
import { MetadataMarket } from '../../../@types/Metadata'
|
||||||
|
|
||||||
export default function AssetActions({
|
export default function AssetActions({
|
||||||
@ -13,7 +12,6 @@ export default function AssetActions({
|
|||||||
metadata: MetadataMarket
|
metadata: MetadataMarket
|
||||||
did: string
|
did: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
// const { ocean, balanceInOcean } = useOcean()
|
|
||||||
const { access } = metadata.additionalInformation
|
const { access } = metadata.additionalInformation
|
||||||
const isCompute = access && access === 'Compute'
|
const isCompute = access && access === 'Compute'
|
||||||
|
|
||||||
@ -26,15 +24,9 @@ export default function AssetActions({
|
|||||||
<div className={styles.tabContent}>
|
<div className={styles.tabContent}>
|
||||||
<TabPanel>
|
<TabPanel>
|
||||||
{isCompute ? (
|
{isCompute ? (
|
||||||
// <Compute
|
<Compute did={did} />
|
||||||
// did={did}
|
|
||||||
// metadata={metadata}
|
|
||||||
// ocean={ocean}
|
|
||||||
// balance={balanceInOcean}
|
|
||||||
// />
|
|
||||||
'Compute Me'
|
|
||||||
) : (
|
) : (
|
||||||
<Consume did={did} metadata={metadata} />
|
<Consume did={did} file={metadata.main.files[0]} />
|
||||||
)}
|
)}
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel>Trade Me</TabPanel>
|
<TabPanel>Trade Me</TabPanel>
|
||||||
|
Loading…
Reference in New Issue
Block a user