From 21257bba138df53e8299a6172a521361190e064e Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Fri, 23 Oct 2020 00:55:54 -0700 Subject: [PATCH] check previousValidOrders --- src/components/organisms/AssetActions/Compute.tsx | 12 ++++++++++-- src/components/organisms/AssetActions/Consume.tsx | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/organisms/AssetActions/Compute.tsx b/src/components/organisms/AssetActions/Compute.tsx index d1202ec0a..efccd29cd 100644 --- a/src/components/organisms/AssetActions/Compute.tsx +++ b/src/components/organisms/AssetActions/Compute.tsx @@ -29,7 +29,7 @@ export default function Compute({ }): ReactElement { const { marketFeeAddress } = useSiteMetadata() - const { ocean } = useOcean() + const { ocean, account } = useOcean() const { compute, isLoading, computeStepText, computeError } = useCompute() const { buyDT, dtSymbol } = usePricing(ddo) @@ -54,6 +54,14 @@ export default function Compute({ !isBalanceSufficient const hasDatatoken = Number(dtBalance) >= 1 + const previousOrder = ocean.datatokens.getPreviousValidOrders( + ddo.dataToken, + computeService.attributes.main.cost, + computeService.index, + computeService.attributes.main.timeout, + account.getId() + ) + const hasPreviousOrder = !!previousOrder const onDrop = async (files: File[]) => { setFile(files[0]) const fileText = await readFileContent(files[0]) @@ -136,7 +144,7 @@ export default function Compute({ onClick={() => startJob()} disabled={isComputeButtonDisabled} > - {hasDatatoken ? 'Start job' : 'Buy'} + {hasDatatoken || hasPreviousOrder ? 'Start job' : 'Buy'} )} diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index 9947d0b9c..d573f78e8 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -21,7 +21,7 @@ export default function Consume({ isBalanceSufficient: boolean dtBalance: string }): ReactElement { - const { ocean } = useOcean() + const { ocean, account } = useOcean() const { marketFeeAddress } = useSiteMetadata() const { dtSymbol, @@ -39,6 +39,16 @@ export default function Consume({ pricingIsLoading const hasDatatoken = Number(dtBalance) >= 1 + const service = ddo.findServiceByType('access') + const previousOrder = ocean.datatokens.getPreviousValidOrders( + ddo.dataToken, + service.attributes.main.cost, + service.index, + service.attributes.main.timeout, + account.getId() + ) + const hasPreviousOrder = !!previousOrder + async function handleConsume() { !hasDatatoken && (await buyDT('1')) await consume(ddo.id, ddo.dataToken, 'access', marketFeeAddress) @@ -56,7 +66,7 @@ export default function Consume({ ) : ( )}