mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
update hooks, refactor
Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
parent
f085ecd2ef
commit
95c65b7461
6
package-lock.json
generated
6
package-lock.json
generated
@ -4479,9 +4479,9 @@
|
||||
}
|
||||
},
|
||||
"@oceanprotocol/react": {
|
||||
"version": "0.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.3.5.tgz",
|
||||
"integrity": "sha512-k51Mltb8bhd/n7cpcwV3knURpUXiwlryQgi6/vyd2kMNMQX6OorwHT1LcmP593FW5pIHpUEC3x/zLthYY42EiA==",
|
||||
"version": "0.3.6",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.3.6.tgz",
|
||||
"integrity": "sha512-fUnbim8d0sNta5NXpwJDixS76kCmOkyaEpTYYHZOoCHyZuesDjdBEwglbxYQl2Dtz/2lnsK2y+aYSBNYsPGiVw==",
|
||||
"requires": {
|
||||
"@oceanprotocol/lib": "^0.7.3",
|
||||
"axios": "^0.20.0",
|
||||
|
@ -23,7 +23,7 @@
|
||||
"@loadable/component": "5.13.1",
|
||||
"@oceanprotocol/art": "^3.0.0",
|
||||
"@oceanprotocol/lib": "^0.7.5",
|
||||
"@oceanprotocol/react": "^0.3.5",
|
||||
"@oceanprotocol/react": "^0.3.6",
|
||||
"@oceanprotocol/typographies": "^0.1.0",
|
||||
"@sindresorhus/slugify": "^1.0.0",
|
||||
"@tippyjs/react": "^4.2.0",
|
||||
|
@ -17,6 +17,7 @@ import Button from '../../atoms/Button'
|
||||
import Input from '../../atoms/Input'
|
||||
import Alert from '../../atoms/Alert'
|
||||
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||
import checkPreviousOrder from '../../../utils/checkPreviousOrder'
|
||||
|
||||
export default function Compute({
|
||||
ddo,
|
||||
@ -46,7 +47,7 @@ export default function Compute({
|
||||
const [isPublished, setIsPublished] = useState(false)
|
||||
const [file, setFile] = useState(null)
|
||||
const [hasPreviousOrder, setHasPreviousOrder] = useState(false)
|
||||
|
||||
const [previousOrderId, setPreviousOrderId] = useState<string>()
|
||||
const isComputeButtonDisabled =
|
||||
isJobStarting === true ||
|
||||
file === null ||
|
||||
@ -57,16 +58,9 @@ export default function Compute({
|
||||
|
||||
useEffect(() => {
|
||||
async function checkPreviousOrders() {
|
||||
const service = ddo.findServiceByType('access')
|
||||
const previousOrder = await ocean.datatokens.getPreviousValidOrders(
|
||||
ddo.dataToken,
|
||||
service.attributes.main.cost,
|
||||
service.index,
|
||||
service.attributes.main.timeout,
|
||||
accountId
|
||||
)
|
||||
console.log('prev ord', previousOrder, !!previousOrder)
|
||||
setHasPreviousOrder(!!previousOrder)
|
||||
const orderId = await checkPreviousOrder(ocean, accountId, ddo)
|
||||
setPreviousOrderId(orderId)
|
||||
setHasPreviousOrder(!!orderId)
|
||||
}
|
||||
checkPreviousOrders()
|
||||
}, [ddo, accountId])
|
||||
@ -102,7 +96,8 @@ export default function Compute({
|
||||
ddo.dataToken,
|
||||
algorithmRawCode,
|
||||
computeContainer,
|
||||
marketFeeAddress
|
||||
marketFeeAddress,
|
||||
previousOrderId
|
||||
)
|
||||
|
||||
setHasPreviousOrder(true)
|
||||
|
@ -9,6 +9,7 @@ import styles from './Consume.module.css'
|
||||
import Loader from '../../atoms/Loader'
|
||||
import { useOcean, useConsume, usePricing } from '@oceanprotocol/react'
|
||||
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||
import checkPreviousOrder from '../../../utils/checkPreviousOrder'
|
||||
|
||||
export default function Consume({
|
||||
ddo,
|
||||
@ -24,6 +25,8 @@ export default function Consume({
|
||||
const { ocean, accountId } = useOcean()
|
||||
const { marketFeeAddress } = useSiteMetadata()
|
||||
const [hasPreviousOrder, setHasPreviousOrder] = useState(false)
|
||||
const [previousOrderId, setPreviousOrderId] = useState<string>()
|
||||
|
||||
const {
|
||||
dtSymbol,
|
||||
buyDT,
|
||||
@ -40,24 +43,23 @@ export default function Consume({
|
||||
const hasDatatoken = Number(dtBalance) >= 1
|
||||
|
||||
useEffect(() => {
|
||||
async function checkPreviousOrders() {
|
||||
const service = ddo.findServiceByType('access')
|
||||
const previousOrder = await ocean.datatokens.getPreviousValidOrders(
|
||||
ddo.dataToken,
|
||||
service.attributes.main.cost,
|
||||
service.index,
|
||||
service.attributes.main.timeout,
|
||||
accountId
|
||||
)
|
||||
console.log('prev ord', previousOrder, !!previousOrder)
|
||||
setHasPreviousOrder(!!previousOrder)
|
||||
async function checkOrders() {
|
||||
const orderId = await checkPreviousOrder(ocean, accountId, ddo)
|
||||
setPreviousOrderId(orderId)
|
||||
setHasPreviousOrder(!!orderId)
|
||||
}
|
||||
checkPreviousOrders()
|
||||
checkOrders()
|
||||
}, [ddo, accountId])
|
||||
|
||||
async function handleConsume() {
|
||||
!hasPreviousOrder && !hasDatatoken && (await buyDT('1'))
|
||||
await consume(ddo.id, ddo.dataToken, 'access', marketFeeAddress)
|
||||
await consume(
|
||||
ddo.id,
|
||||
ddo.dataToken,
|
||||
'access',
|
||||
marketFeeAddress,
|
||||
previousOrderId
|
||||
)
|
||||
setHasPreviousOrder(true)
|
||||
}
|
||||
|
||||
|
17
src/utils/checkPreviousOrder.ts
Normal file
17
src/utils/checkPreviousOrder.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { DDO, Ocean } from '@oceanprotocol/lib'
|
||||
|
||||
export default async function checkPreviousOrder(
|
||||
ocean: Ocean,
|
||||
accountId: string,
|
||||
ddo: DDO
|
||||
) {
|
||||
const service = ddo.findServiceByType('access')
|
||||
const previousOrder = await ocean.datatokens.getPreviousValidOrders(
|
||||
ddo.dataToken,
|
||||
service.attributes.main.cost,
|
||||
service.index,
|
||||
service.attributes.main.timeout,
|
||||
accountId
|
||||
)
|
||||
return previousOrder
|
||||
}
|
Loading…
Reference in New Issue
Block a user