From db23ed6ada378105fcfe320032db273f8fb6ef15 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 11:32:59 +0100 Subject: [PATCH] cleanup * remove commented out code * remove unused state * removed unused imports * typos in comments, variables, props --- package-lock.json | 2 ++ src/@utils/accessDetailsAndPricing.ts | 3 +-- src/@utils/aquarius.ts | 2 +- src/@utils/compute.ts | 5 ++-- src/@utils/ddo.ts | 5 ---- src/@utils/fixedRateExchange.ts | 1 - src/@utils/nft.ts | 11 -------- src/@utils/order.ts | 9 ++++--- src/@utils/provider.ts | 1 - src/@utils/subgraph.ts | 2 +- .../Compute/FormComputeDataset.tsx | 2 +- .../Compute/PriceOutput.module.css | 1 - .../Asset/AssetActions/Compute/index.tsx | 27 +++++-------------- src/components/Asset/Edit/index.tsx | 1 - .../Profile/History/ComputeJobs/Details.tsx | 6 ----- .../Profile/History/ComputeJobs/index.tsx | 6 ++--- 16 files changed, 22 insertions(+), 62 deletions(-) diff --git a/package-lock.json b/package-lock.json index e97da576a..91107224f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44925,6 +44925,7 @@ "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.3.1", + "web3": "^1.7.3", "web3-core": "^1.7.1", "web3-eth-contract": "^1.7.1" } @@ -44976,6 +44977,7 @@ "integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==", "dev": true, "requires": { + "@oclif/config": "^1.18.2", "@oclif/errors": "^1.3.5", "@oclif/help": "^1.0.1", "@oclif/parser": "^3.8.6", diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index 7cbf86a97..a47399bf5 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -12,8 +12,7 @@ import { Asset, LoggerInstance, ProviderFees, - ProviderInstance, - unitsToAmount + ProviderInstance } from '@oceanprotocol/lib' import { AssetExtended } from 'src/@types/AssetExtended' import { calcInGivenOut } from './pool' diff --git a/src/@utils/aquarius.ts b/src/@utils/aquarius.ts index 9eea10c6b..8eb6208c9 100644 --- a/src/@utils/aquarius.ts +++ b/src/@utils/aquarius.ts @@ -180,7 +180,7 @@ export async function getAssetsFromDidList( didList: string[], chainIds: number[], cancelToken: CancelToken -): Promise { +): Promise { try { if (!(didList.length > 0)) return diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index 9a7eaf9a2..f0506b50a 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -21,7 +21,6 @@ import { } from './aquarius' import { fetchDataForMultipleChains } from './subgraph' import { getServiceById, getServiceByName } from './ddo' -import { getOceanConfig } from './ocean' import { SortTermOptions } from 'src/@types/aquarius/SearchQuery' import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection' import { transformAssetToAssetSelection } from './assetConvertor' @@ -149,7 +148,7 @@ export async function getComputeEnviroment( } } -export function getQuerryString( +export function getQueryString( trustedAlgorithmList: PublisherTrustedAlgorithm[], chainId?: number ): SearchQuery { @@ -182,7 +181,7 @@ export async function getAlgorithmsForAsset( algorithms = [] } else { const gueryResults = await queryMetadata( - getQuerryString(publisherTrustedAlgorithms, asset.chainId), + getQueryString(publisherTrustedAlgorithms, asset.chainId), token ) algorithms = gueryResults?.results diff --git a/src/@utils/ddo.ts b/src/@utils/ddo.ts index 11a56e8a9..749a6143e 100644 --- a/src/@utils/ddo.ts +++ b/src/@utils/ddo.ts @@ -1,9 +1,4 @@ import { Asset, DDO, Service } from '@oceanprotocol/lib' -interface Consumable { - status: number - message: string - result: boolean -} export function getServiceByName( ddo: Asset | DDO, diff --git a/src/@utils/fixedRateExchange.ts b/src/@utils/fixedRateExchange.ts index 30abb2f2d..e8d1b1360 100644 --- a/src/@utils/fixedRateExchange.ts +++ b/src/@utils/fixedRateExchange.ts @@ -3,7 +3,6 @@ import { AccessDetails } from 'src/@types/Price' import Web3 from 'web3' import { getOceanConfig } from './ocean' import { consumeMarketPoolSwapFee } from '../../app.config' - import { getDummyWeb3 } from './web3' /** diff --git a/src/@utils/nft.ts b/src/@utils/nft.ts index 166a447e0..d75518d74 100644 --- a/src/@utils/nft.ts +++ b/src/@utils/nft.ts @@ -112,17 +112,6 @@ export async function setNftMetadata( // theoretically used by aquarius or provider, not implemented yet, will remain hardcoded const flags = '0x2' - const estGasSetMetadata = await nft.estGasSetMetadata( - asset.nftAddress, - accountId, - 0, - asset.services[0].serviceEndpoint, - '', - flags, - encryptedDdo, - '0x' + metadataHash, - [] - ) const setMetadataTx = await nft.setMetadata( asset.nftAddress, accountId, diff --git a/src/@utils/order.ts b/src/@utils/order.ts index cd2c456a3..665e39318 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -26,9 +26,9 @@ import { toast } from 'react-toastify' * For pool you need to buy the datatoken beforehand, this always assumes you want to order the first service * @param web3 * @param asset + * @param orderPriceAndFees * @param accountId - * @param computeEnv - * @param computeValidUntil + * @param providerFees * @param computeConsumerAddress * @returns {TransactionReceipt} receipt of the order */ @@ -162,9 +162,10 @@ export async function reuseOrder( * - no validOrder -> we need to call order, to pay 1 DT & providerFees * @param web3 * @param asset + * @param orderPriceAndFees * @param accountId - * @param computeEnv - * @param computeValidUntil + * @param hasDatatoken + * @param initializeData * @param computeConsumerAddress * @returns {Promise} tx id */ diff --git a/src/@utils/provider.ts b/src/@utils/provider.ts index 91ee9c2b9..358361bb4 100644 --- a/src/@utils/provider.ts +++ b/src/@utils/provider.ts @@ -8,7 +8,6 @@ import { ProviderComputeInitializeResults, ProviderInstance } from '@oceanprotocol/lib' -import { toast } from 'react-toastify' import { AssetExtended } from 'src/@types/AssetExtended' import Web3 from 'web3' import { getValidUntilTime } from './compute' diff --git a/src/@utils/subgraph.ts b/src/@utils/subgraph.ts index 2972980dd..7b32da86b 100644 --- a/src/@utils/subgraph.ts +++ b/src/@utils/subgraph.ts @@ -15,7 +15,7 @@ import { import { OrdersData_orders as OrdersData } from '../@types/subgraph/OrdersData' import { UserSalesQuery as UsersSalesList } from '../@types/subgraph/UserSalesQuery' import { OpcFeesQuery as OpcFeesData } from '../@types/subgraph/OpcFeesQuery' -import { calcSingleOutGivenPoolIn, getLiquidityByShares } from './pool' +import { calcSingleOutGivenPoolIn } from './pool' import Decimal from 'decimal.js' import { MAX_DECIMALS } from './constants' diff --git a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx index 67ad637b5..33147f37f 100644 --- a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx +++ b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx @@ -211,7 +211,7 @@ export default function FormStartCompute({ !isValid || !isBalanceSufficient || !isAssetNetwork || - !selectedAlgorithmAsset?.accessDetails.isPurchasable + !selectedAlgorithmAsset?.accessDetails?.isPurchasable } hasPreviousOrder={hasPreviousOrder} hasDatatoken={hasDatatoken} diff --git a/src/components/Asset/AssetActions/Compute/PriceOutput.module.css b/src/components/Asset/AssetActions/Compute/PriceOutput.module.css index d9e7780f9..413f2f859 100644 --- a/src/components/Asset/AssetActions/Compute/PriceOutput.module.css +++ b/src/components/Asset/AssetActions/Compute/PriceOutput.module.css @@ -39,7 +39,6 @@ display: grid; grid-template-columns: 5% 1fr auto; column-gap: calc(var(--spacer) / 10); - /* justify-content: space-between; */ } .priceRow:last-child { diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 891f0485b..b6fadd7b1 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, ReactElement, useEffect, useCallback } from 'react' +import React, { useState, ReactElement, useEffect } from 'react' import { Asset, DDO, @@ -36,7 +36,6 @@ import AlgorithmDatasetsListForCompute from './AlgorithmDatasetsListForCompute' import AssetActionHistoryTable from '../AssetActionHistoryTable' import ComputeJobs from '../../../Profile/History/ComputeJobs' import { useCancelToken } from '@hooks/useCancelToken' -// import { useIsMounted } from '@hooks/useIsMounted' import { Decimal } from 'decimal.js' import { useAbortController } from '@hooks/useAbortController' import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing' @@ -55,14 +54,12 @@ export default function Compute({ dtBalance, file, fileIsLoading, - isConsumable, consumableFeedback }: { asset: AssetExtended dtBalance: string file: FileInfo fileIsLoading?: boolean - isConsumable?: boolean consumableFeedback?: string }): ReactElement { const { accountId, web3 } = useWeb3() @@ -78,18 +75,14 @@ export default function Compute({ const [isPublished, setIsPublished] = useState(false) const [algorithmDTBalance, setAlgorithmDTBalance] = useState() - // const [isOwned, setIsOwned] = useState(false) const [validOrderTx, setValidOrderTx] = useState('') - // const [isAlgorithmOwned, setIsAlgorithmOwned] = useState(false) const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('') const hasDatatoken = Number(dtBalance) >= 1 - // const isMounted = useIsMounted() const { getOpcFeeForToken } = useMarketMetadata() const { poolData } = usePool() const newCancelToken = useCancelToken() const [isConsumablePrice, setIsConsumablePrice] = useState(true) - const [isAlgoConsumablePrice, setIsAlgoConsumablePrice] = useState(true) const [computeStatusText, setComputeStatusText] = useState('') const [computeEnv, setComputeEnv] = useState() const [initializedProviderResponse, setInitializedProviderResponse] = @@ -98,19 +91,16 @@ export default function Compute({ const [computeValidUntil, setComputeValidUntil] = useState('0') const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] = useState() - const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] = - useState(false) const [algoOrderPriceAndFees, setAlgoOrderPriceAndFees] = useState() const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] = useState(false) - const [refatchJobs, setRefatchJobs] = useState(false) - // const [isProviderFeeValid, setIsProviderFeeValid] = useState(false) + const [refetchJobs, setRefatchJobs] = useState(false) const isComputeButtonDisabled = isJobStarting === true || file === null || (!validOrderTx && !hasDatatoken && !isConsumablePrice) || - (!validAlgorithmOrderTx && !hasAlgoAssetDatatoken && !isAlgoConsumablePrice) + (!validAlgorithmOrderTx && !hasAlgoAssetDatatoken) async function checkAssetDTBalance(asset: DDO): Promise { if (!asset?.services[0].datatokenAddress) return @@ -411,7 +401,7 @@ export default function Compute({ } LoggerInstance.log('[compute] Starting compute job response: ', response) setIsPublished(true) - setRefatchJobs(!refatchJobs) + setRefatchJobs(!refetchJobs) initPriceAndFees() } catch (error) { setError('Failed to start job!') @@ -454,11 +444,7 @@ export default function Compute({ ddoListAlgorithms={ddoAlgorithmList} selectedAlgorithmAsset={selectedAlgorithmAsset} setSelectedAlgorithm={setSelectedAlgorithmAsset} - isLoading={ - isJobStarting || - isRequestingDataseOrderPrice || - isRequestingAlgoOrderPrice - } + isLoading={isJobStarting || isRequestingAlgoOrderPrice} isComputeButtonDisabled={isComputeButtonDisabled} hasPreviousOrder={validOrderTx !== undefined} hasDatatoken={hasDatatoken} @@ -479,7 +465,6 @@ export default function Compute({ selectedAlgorithmAsset?.datatokens[0]?.symbol } dtBalanceSelectedComputeAsset={algorithmDTBalance} - selectedComputeAssetLowPoolLiquidity={!isAlgoConsumablePrice} selectedComputeAssetType="algorithm" selectedComputeAssetTimeout={secondsToString( selectedAlgorithmAsset?.services[0]?.timeout @@ -506,7 +491,7 @@ export default function Compute({ )} diff --git a/src/components/Asset/Edit/index.tsx b/src/components/Asset/Edit/index.tsx index 59145bde6..40d144254 100644 --- a/src/components/Asset/Edit/index.tsx +++ b/src/components/Asset/Edit/index.tsx @@ -1,5 +1,4 @@ import React, { ReactElement, useState, useEffect } from 'react' -import { LoggerInstance } from '@oceanprotocol/lib' import { useAsset } from '@context/Asset' import styles from './index.module.css' import Tabs from '@shared/atoms/Tabs' diff --git a/src/components/Profile/History/ComputeJobs/Details.tsx b/src/components/Profile/History/ComputeJobs/Details.tsx index fe87131ce..62a681537 100644 --- a/src/components/Profile/History/ComputeJobs/Details.tsx +++ b/src/components/Profile/History/ComputeJobs/Details.tsx @@ -98,12 +98,6 @@ export default function Details({ /> )} {job.jobId}} /> - {/* {job.results[0]. && ( - {job.resultsDid}} - /> - )} */} diff --git a/src/components/Profile/History/ComputeJobs/index.tsx b/src/components/Profile/History/ComputeJobs/index.tsx index 3d33c65c7..84d4aba53 100644 --- a/src/components/Profile/History/ComputeJobs/index.tsx +++ b/src/components/Profile/History/ComputeJobs/index.tsx @@ -72,11 +72,11 @@ const columns = [ export default function ComputeJobs({ minimal, assetChainId, - refatchJobs + refetchJobs }: { minimal?: boolean assetChainId?: number[] - refatchJobs?: boolean + refetchJobs?: boolean }): ReactElement { const { accountId } = useWeb3() const { asset } = useAsset() @@ -114,7 +114,7 @@ export default function ComputeJobs({ useEffect(() => { fetchJobs() - }, [refatchJobs]) + }, [refetchJobs]) return accountId ? ( <>