From cde92c6c4609f6de467a26b931bdfae877acb994 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Tue, 10 Jan 2023 10:39:03 +0200 Subject: [PATCH] Fix compute basetoken issue (#1829) * fix lint * add dynamic provider fees * fixes * cleanup and more fixes * bump oceanlib to 2.6.0 --- content/pages/editMetadata.json | 76 ++++++++------- content/publish/form.json | 94 ++++++++++--------- package-lock.json | 32 +++---- package.json | 2 +- .../Compute/FormComputeDataset.tsx | 14 ++- .../AssetActions/Compute/PriceOutput.tsx | 4 +- .../Asset/AssetActions/Compute/index.tsx | 26 ++++- 7 files changed, 138 insertions(+), 110 deletions(-) diff --git a/content/pages/editMetadata.json b/content/pages/editMetadata.json index e071852e7..f58ada87c 100644 --- a/content/pages/editMetadata.json +++ b/content/pages/editMetadata.json @@ -30,44 +30,47 @@ { "name": "files", "label": "File", - "prominentHelp": false, + "prominentHelp": false, "type": "tabs", - "fields": [{ - "value": "ipfs", - "title": "IPFS", - "label": "CID", - "placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq", - "help": "This CID will be stored encrypted after publishing.", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": true - }, - { - "value": "arweave", - "title": "Arweave", - "label": "Transaction ID", - "placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd", - "help": "This Transaction ID will be stored encrypted after publishing.", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": true - }, - { - "value": "url", - "title": "URL", - "label": "File", - "placeholder": "e.g. https://file.com/file.json", - "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": true - }], + "fields": [ + { + "value": "ipfs", + "title": "IPFS", + "label": "CID", + "placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq", + "help": "This CID will be stored encrypted after publishing.", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": true + }, + { + "value": "arweave", + "title": "Arweave", + "label": "Transaction ID", + "placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd", + "help": "This Transaction ID will be stored encrypted after publishing.", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": true + }, + { + "value": "url", + "title": "URL", + "label": "File", + "placeholder": "e.g. https://file.com/file.json", + "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": true + } + ], "sortOptions": false, "required": true - },{ + }, + { "name": "links", "label": "Sample file", "prominentHelp": false, @@ -83,7 +86,8 @@ "prominentHelp": true, "type": "files", "required": false - }], + } + ], "required": false }, diff --git a/content/publish/form.json b/content/publish/form.json index afd1c0849..463ef8e16 100644 --- a/content/publish/form.json +++ b/content/publish/form.json @@ -104,60 +104,64 @@ { "name": "files", "label": "File", - "prominentHelp": false, + "prominentHelp": false, "type": "tabs", - "fields": [{ - "value": "ipfs", - "title": "IPFS", - "label": "CID", - "placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq", - "help": "This CID will be stored encrypted after publishing.", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": true - }, - { - "value": "arweave", - "title": "Arweave", - "label": "Transaction ID", - "placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd", - "help": "This Transaction ID will be stored encrypted after publishing.", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": true - }, - { - "value": "url", - "title": "URL", - "label": "File", - "placeholder": "e.g. https://file.com/file.json", - "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": true - }], + "fields": [ + { + "value": "ipfs", + "title": "IPFS", + "label": "CID", + "placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq", + "help": "This CID will be stored encrypted after publishing.", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": true + }, + { + "value": "arweave", + "title": "Arweave", + "label": "Transaction ID", + "placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd", + "help": "This Transaction ID will be stored encrypted after publishing.", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": true + }, + { + "value": "url", + "title": "URL", + "label": "File", + "placeholder": "e.g. https://file.com/file.json", + "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": true + } + ], "sortOptions": false, "required": true - },{ + }, + { "name": "links", "label": "Sample file", "prominentHelp": false, "type": "tabs", "fields": [ { - "value": "url", - "title": "URL", - "label": "File", - "placeholder": "e.g. https://file.com/file.json", - "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", - "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", - "prominentHelp": true, - "type": "files", - "required": false - }], + "value": "url", + "title": "URL", + "label": "File", + "placeholder": "e.g. https://file.com/file.json", + "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", + "computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ", + "prominentHelp": true, + "type": "files", + "required": false + } + ], "required": false }, { diff --git a/package-lock.json b/package-lock.json index 4a0d017bf..c68c4a145 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@coingecko/cryptoformat": "^0.5.4", "@loadable/component": "^5.15.2", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^2.5.2", + "@oceanprotocol/lib": "^2.6.0", "@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/use-dark-mode": "^2.4.3", "@tippyjs/react": "^4.2.6", @@ -4591,18 +4591,18 @@ "integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ==" }, "node_modules/@oceanprotocol/lib": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.5.2.tgz", - "integrity": "sha512-hLNTS6go1GhpSJt7un1VPb/6XNNYSwGpYPX/O1E5q2XCRWjaWYodzqwxBcgQKw2ihSQmaH9JsDsFLZiIKqKRLA==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.6.0.tgz", + "integrity": "sha512-UMWOdJksJO43wzsmyidOjTyGtARw9OKGde6xbunNuRJDLmeYui4OZ0KTwA5yWBSibsqWk4TVAJgXrxW096NJ5g==", "dependencies": { "@oceanprotocol/contracts": "^1.1.8", "bignumber.js": "^9.1.0", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", - "web3": "^1.8.0", - "web3-core": "^1.8.0", - "web3-eth-contract": "^1.8.0" + "web3": "^1.8.1", + "web3-core": "^1.8.1", + "web3-eth-contract": "^1.8.1" }, "peerDependencies": { "web3": "^1.8.0" @@ -50186,18 +50186,17 @@ "integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ==" }, "@oceanprotocol/lib": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.5.2.tgz", - "integrity": "sha512-hLNTS6go1GhpSJt7un1VPb/6XNNYSwGpYPX/O1E5q2XCRWjaWYodzqwxBcgQKw2ihSQmaH9JsDsFLZiIKqKRLA==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.6.0.tgz", + "integrity": "sha512-UMWOdJksJO43wzsmyidOjTyGtARw9OKGde6xbunNuRJDLmeYui4OZ0KTwA5yWBSibsqWk4TVAJgXrxW096NJ5g==", "requires": { "@oceanprotocol/contracts": "^1.1.8", "bignumber.js": "^9.1.0", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", - "web3": "^1.8.0", - "web3-core": "^1.8.0", - "web3-eth-contract": "^1.8.0" + "web3-core": "^1.8.1", + "web3-eth-contract": "^1.8.1" } }, "@oceanprotocol/typographies": { @@ -50256,7 +50255,6 @@ "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", @@ -61274,7 +61272,7 @@ "git-url-parse": "11.6.0", "glob": "8.0.1", "global-agent": "3.0.0", - "graphql": "15.8.0", + "graphql": "14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0", "graphql-tag": "2.12.6", "listr": "0.14.3", "lodash.identity": "3.0.0", @@ -61515,7 +61513,7 @@ "cosmiconfig": "^7.0.1", "dotenv": "^16.0.0", "glob": "^8.0.0", - "graphql": "15.8.0", + "graphql": "14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0", "graphql-tag": "^2.10.1", "lodash.debounce": "^4.0.8", "lodash.merge": "^4.6.1", @@ -74394,7 +74392,6 @@ "integrity": "sha512-uJx9y/1NIqoYTp6ZW1osJ7U5ZrXGAJbOQ/Qzl05BdGYvN1S7Qmbzid6xOirgK0EIT0pJKEEh1s8qbassYZe4cw==", "peer": true, "requires": { - "@babel/core": "^7.14.0", "@babel/plugin-proposal-async-generator-functions": "^7.0.0", "@babel/plugin-proposal-class-properties": "^7.0.0", "@babel/plugin-proposal-export-default-from": "^7.0.0", @@ -74449,7 +74446,6 @@ "integrity": "sha512-Ogst/M6ujYrl/+9mpEWqE3zF7l2mTuftDTy3L8wZYwX1pWUQWQpfU1aJBeWiLxt1XlIq+uriRjKzKoRoIK57EA==", "peer": true, "requires": { - "@babel/core": "^7.14.0", "babel-preset-fbjs": "^3.4.0", "hermes-parser": "0.8.0", "metro-babel-transformer": "0.72.3", diff --git a/package.json b/package.json index 2b48676ad..8d52e0ae6 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@coingecko/cryptoformat": "^0.5.4", "@loadable/component": "^5.15.2", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^2.5.2", + "@oceanprotocol/lib": "^2.6.0", "@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/use-dark-mode": "^2.4.3", "@tippyjs/react": "^4.2.6", diff --git a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx index b6dd83451..a84e7af13 100644 --- a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx +++ b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx @@ -33,6 +33,7 @@ export default function FormStartCompute({ hasDatatokenSelectedComputeAsset, datasetSymbol, algorithmSymbol, + providerFeesSymbol, dtSymbolSelectedComputeAsset, dtBalanceSelectedComputeAsset, selectedComputeAssetType, @@ -61,6 +62,7 @@ export default function FormStartCompute({ hasDatatokenSelectedComputeAsset?: boolean datasetSymbol?: string algorithmSymbol?: string + providerFeesSymbol?: string dtSymbolSelectedComputeAsset?: string dtBalanceSelectedComputeAsset?: string selectedComputeAssetType?: string @@ -145,7 +147,7 @@ export default function FormStartCompute({ ? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS) : new Decimal(0) - if (algorithmSymbol === 'OCEAN') { + if (algorithmSymbol === providerFeesSymbol) { let sum = providerFees.add(priceAlgo) totalPrices.push({ value: sum.toDecimalPlaces(MAX_DECIMALS).toString(), @@ -161,7 +163,7 @@ export default function FormStartCompute({ }) } } else { - if (datasetSymbol === 'OCEAN') { + if (datasetSymbol === providerFeesSymbol) { const sum = providerFees.add(priceDataset) totalPrices.push({ value: sum.toDecimalPlaces(MAX_DECIMALS).toString(), @@ -179,7 +181,7 @@ export default function FormStartCompute({ }) totalPrices.push({ value: providerFees.toDecimalPlaces(MAX_DECIMALS).toString(), - symbol: 'OCEAN' + symbol: providerFeesSymbol }) } else { totalPrices.push({ @@ -188,7 +190,7 @@ export default function FormStartCompute({ }) totalPrices.push({ value: providerFees.toDecimalPlaces(MAX_DECIMALS).toString(), - symbol: 'OCEAN' + symbol: providerFeesSymbol }) totalPrices.push({ value: priceAlgo.toDecimalPlaces(MAX_DECIMALS).toString(), @@ -211,7 +213,8 @@ export default function FormStartCompute({ datasetOrderPrice, algoOrderPrice, algorithmSymbol, - datasetSymbol + datasetSymbol, + providerFeesSymbol ]) useEffect(() => { @@ -263,6 +266,7 @@ export default function FormStartCompute({ datasetOrderPrice={datasetOrderPrice} algoOrderPrice={algoOrderPrice} providerFeeAmount={providerFeeAmount} + providerFeesSymbol={providerFeesSymbol} validUntil={validUntil} totalPrices={totalPrices} /> diff --git a/src/components/Asset/AssetActions/Compute/PriceOutput.tsx b/src/components/Asset/AssetActions/Compute/PriceOutput.tsx index 39df72837..52069e975 100644 --- a/src/components/Asset/AssetActions/Compute/PriceOutput.tsx +++ b/src/components/Asset/AssetActions/Compute/PriceOutput.tsx @@ -20,6 +20,7 @@ interface PriceOutputProps { datasetOrderPrice?: string algoOrderPrice?: string providerFeeAmount?: string + providerFeesSymbol?: string validUntil?: string totalPrices?: totalPriceMap[] } @@ -84,6 +85,7 @@ export default function PriceOutput({ datasetOrderPrice, algoOrderPrice, providerFeeAmount, + providerFeesSymbol, validUntil, totalPrices }: PriceOutputProps): ReactElement { @@ -134,7 +136,7 @@ export default function PriceOutput({ diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 2f3795197..2718bc221 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -12,7 +12,8 @@ import { ComputeAlgorithm, ComputeOutput, ProviderComputeInitializeResults, - unitsToAmount + unitsToAmount, + minAbi } from '@oceanprotocol/lib' import { toast } from 'react-toastify' import Price from '@shared/Price' @@ -61,7 +62,7 @@ export default function Compute({ fileIsLoading?: boolean consumableFeedback?: string }): ReactElement { - const { accountId, web3, isSupportedOceanNetwork } = useWeb3() + const { accountId, web3, isSupportedOceanNetwork, networkId } = useWeb3() const { chainIds } = useUserPreferences() const { isAssetNetwork } = useAsset() @@ -90,6 +91,7 @@ export default function Compute({ const [initializedProviderResponse, setInitializedProviderResponse] = useState() const [providerFeeAmount, setProviderFeeAmount] = useState('0') + const [providerFeesSymbol, setProviderFeesSymbol] = useState('OCEAN') const [computeValidUntil, setComputeValidUntil] = useState('0') const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] = useState() @@ -160,6 +162,18 @@ export default function Compute({ setProviderFeeAmount(feeAmount) + const datatoken = new Datatoken( + await getDummyWeb3(asset?.chainId), + null, + null, + minAbi + ) + setProviderFeesSymbol( + await datatoken.getSymbol( + initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken + ) + ) + const computeDuration = ( parseInt(initializedProvider?.datasets?.[0]?.providerFee?.validUntil) - Math.floor(Date.now() / 1000) @@ -466,11 +480,15 @@ export default function Compute({ assetTimeout={secondsToString(asset?.services[0].timeout)} hasPreviousOrderSelectedComputeAsset={!!validAlgorithmOrderTx} hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken} - datasetSymbol={asset?.accessDetails?.baseToken?.symbol || 'OCEAN'} + datasetSymbol={ + asset?.accessDetails?.baseToken?.symbol || + (asset?.chainId === 137 ? 'mOCEAN' : 'OCEAN') + } algorithmSymbol={ selectedAlgorithmAsset?.accessDetails?.baseToken?.symbol || - 'OCEAN' + (selectedAlgorithmAsset?.chainId === 137 ? 'mOCEAN' : 'OCEAN') } + providerFeesSymbol={providerFeesSymbol} dtSymbolSelectedComputeAsset={ selectedAlgorithmAsset?.datatokens[0]?.symbol }