From a27bc6718af529714761286f496a64e0b0cd4e9c Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Mon, 12 Apr 2021 17:09:41 +0300 Subject: [PATCH] update get prev order method & small typo --- .../organisms/AssetActions/Compute/index.tsx | 12 ++++++------ src/components/organisms/AssetActions/Consume.tsx | 1 - src/utils/subgraph.ts | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/components/organisms/AssetActions/Compute/index.tsx b/src/components/organisms/AssetActions/Compute/index.tsx index 15c193f2a..5302412ac 100644 --- a/src/components/organisms/AssetActions/Compute/index.tsx +++ b/src/components/organisms/AssetActions/Compute/index.tsx @@ -122,14 +122,14 @@ export default function Compute({ isJobStarting === true || file === null || !ocean || !isBalanceSufficient const hasDatatoken = Number(dtBalance) >= 1 - async function checkPreviousOrders(ddo: DDO, serviceType: ServiceType) { + async function checkPreviousOrders(ddo: DDO) { const { timeout } = ( ddo.findServiceByType('access') || ddo.findServiceByType('compute') ).attributes.main const orderId = await getPreviousOrders( ddo.dataToken?.toLowerCase(), accountId?.toLowerCase(), - secondsToString(timeout) + timeout.toString() ) const assetType = ddo.findServiceByType('metadata').attributes.main.type if (assetType === 'algorithm') { @@ -253,23 +253,23 @@ export default function Compute({ useEffect(() => { if (!ocean || !accountId) return - checkPreviousOrders(ddo, 'compute') + checkPreviousOrders(ddo) }, [ocean, ddo, accountId]) useEffect(() => { if (!ocean || !accountId || !selectedAlgorithmAsset) return if (selectedAlgorithmAsset.findServiceByType('access')) { - checkPreviousOrders(selectedAlgorithmAsset, 'access').then(() => { + checkPreviousOrders(selectedAlgorithmAsset).then(() => { if ( !hasPreviousAlgorithmOrder && selectedAlgorithmAsset.findServiceByType('compute') ) { - checkPreviousOrders(selectedAlgorithmAsset, 'compute') + checkPreviousOrders(selectedAlgorithmAsset) } }) } else if (selectedAlgorithmAsset.findServiceByType('compute')) { - checkPreviousOrders(selectedAlgorithmAsset, 'compute') + checkPreviousOrders(selectedAlgorithmAsset) } checkAssetDTBalance(selectedAlgorithmAsset) initMetadata(selectedAlgorithmAsset) diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index d7c19cdcc..30ba32d08 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -69,7 +69,6 @@ export default function Consume({ }) useEffect(() => { - console.log('data', data) if (!data || !assetTimeout || data.tokenOrders.length === 0) return const lastOrder = data.tokenOrders[0] diff --git a/src/utils/subgraph.ts b/src/utils/subgraph.ts index 96a8a143b..90322e8e0 100644 --- a/src/utils/subgraph.ts +++ b/src/utils/subgraph.ts @@ -65,20 +65,20 @@ export async function getPreviousOrders( id: id, account: account } - const fatchedPreviousOrders: any = await fetchData( + const fetchedPreviousOrders: any = await fetchData( previousOrderQuery, variables ) - if (fatchedPreviousOrders.data?.tokenOrders?.length === 0) return null - if (assetTimeout === 'Forever') { - return fatchedPreviousOrders?.data?.tokenOrders[0]?.tx + if (fetchedPreviousOrders.data?.tokenOrders?.length === 0) return null + if (assetTimeout === '0') { + return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx } else { const expiry = new BigNumber( - fatchedPreviousOrders?.data?.tokenOrders[0]?.timestamp + fetchedPreviousOrders?.data?.tokenOrders[0]?.timestamp ).plus(assetTimeout) const unixTime = new BigNumber(Math.floor(Date.now() / 1000)) if (unixTime.isLessThan(expiry)) { - return fatchedPreviousOrders?.data?.tokenOrders[0]?.tx + return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx } else { return null }