From ec28ef546c58b45804f0f5516ff834b48afc6ac2 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 23 Oct 2020 18:33:39 +0300 Subject: [PATCH] fix compute previous order Signed-off-by: mihaisc --- src/components/organisms/AssetActions/Compute.tsx | 2 +- src/components/organisms/AssetActions/Consume.tsx | 2 +- src/utils/checkPreviousOrder.ts | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/organisms/AssetActions/Compute.tsx b/src/components/organisms/AssetActions/Compute.tsx index e10841ac0..0394c62f4 100644 --- a/src/components/organisms/AssetActions/Compute.tsx +++ b/src/components/organisms/AssetActions/Compute.tsx @@ -58,7 +58,7 @@ export default function Compute({ useEffect(() => { async function checkPreviousOrders() { - const orderId = await checkPreviousOrder(ocean, accountId, ddo) + const orderId = await checkPreviousOrder(ocean, accountId, ddo, 'compute') setPreviousOrderId(orderId) setHasPreviousOrder(!!orderId) } diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index 420a46b65..60cf2a225 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -44,7 +44,7 @@ export default function Consume({ useEffect(() => { async function checkOrders() { - const orderId = await checkPreviousOrder(ocean, accountId, ddo) + const orderId = await checkPreviousOrder(ocean, accountId, ddo, 'access') setPreviousOrderId(orderId) setHasPreviousOrder(!!orderId) } diff --git a/src/utils/checkPreviousOrder.ts b/src/utils/checkPreviousOrder.ts index af27d7a97..a0e09314c 100644 --- a/src/utils/checkPreviousOrder.ts +++ b/src/utils/checkPreviousOrder.ts @@ -1,11 +1,12 @@ -import { DDO, Ocean } from '@oceanprotocol/lib' +import { DDO, Ocean, ServiceType } from '@oceanprotocol/lib' export default async function checkPreviousOrder( ocean: Ocean, accountId: string, - ddo: DDO + ddo: DDO, + serviceType: ServiceType ) { - const service = ddo.findServiceByType('access') + const service = ddo.findServiceByType(serviceType) const previousOrder = await ocean.datatokens.getPreviousValidOrders( ddo.dataToken, service.attributes.main.cost,