From f20a6a5a48d99fa52386a94d39615d9d94c35de2 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 20 Jun 2022 15:46:13 +0100 Subject: [PATCH 01/11] Opening blog post link in new tab (#1526) * Opening link in new tab * Adding styling to link * Updating button font size --- content/site.json | 2 +- .../@shared/AnnouncementBanner/index.module.css | 11 +++++++---- .../@shared/AnnouncementBanner/index.tsx | 7 ++++++- src/components/App/index.tsx | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/content/site.json b/content/site.json index 78ee99ef2..db26be565 100644 --- a/content/site.json +++ b/content/site.json @@ -14,7 +14,7 @@ "link": "/profile" } ], - "announcement": "Data NFTs, One-Sided Staking and more. [Explore OceanONDA V4](https://blog.oceanprotocol.com/oceanonda-v4-production-has-arrived-cb4fe8faaf39).", + "announcement": "Data NFTs, One-Sided Staking and more.", "warning": { "ctd": "Compute-to-Data is still in a testing phase, please use it only on test networks." } diff --git a/src/components/@shared/AnnouncementBanner/index.module.css b/src/components/@shared/AnnouncementBanner/index.module.css index 987a45de0..751ee3fcc 100644 --- a/src/components/@shared/AnnouncementBanner/index.module.css +++ b/src/components/@shared/AnnouncementBanner/index.module.css @@ -24,10 +24,6 @@ display: inline-block; } -.banner button { - font-size: calc(var(--font-size-small) / 1.1); -} - .text { font-size: var(--font-size-small); font-weight: var(--font-weight-bold); @@ -41,6 +37,13 @@ text-decoration: underline; } +.link { + color: inherit; + text-decoration: underline; + text-transform: inherit; + font-size: var(--font-size-small); +} + .text p:last-child { margin-bottom: 0; } diff --git a/src/components/@shared/AnnouncementBanner/index.tsx b/src/components/@shared/AnnouncementBanner/index.tsx index 2e1e532b9..ae28231c8 100644 --- a/src/components/@shared/AnnouncementBanner/index.tsx +++ b/src/components/@shared/AnnouncementBanner/index.tsx @@ -35,7 +35,12 @@ export default function AnnouncementBanner({
{text && } {action && ( - )} diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index e9eb4580a..dff602cab 100644 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -19,11 +19,26 @@ export default function App({ const { siteContent, appConfig } = useMarketMetadata() const { accountId } = useWeb3() const { isInPurgatory, purgatoryData } = useAccountPurgatory(accountId) + function openInNewTab() { + window + .open( + 'https://blog.oceanprotocol.com/how-to-publish-a-data-nft-f58ad2a622a9', + '_blank' + ) + .focus() + } return (
{siteContent?.announcement !== '' && ( - + )}
From d884a9529df5d2e144c78011e07a9b1a70244702 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 21 Jun 2022 14:18:40 +0100 Subject: [PATCH 02/11] remove Portis (#1529) * remove Portis * cleanup --- .env.example | 6 -- .github/workflows/deploy.yml | 1 - app.config.js | 3 - package-lock.json | 115 ----------------------- package.json | 1 - src/@context/MarketMetadata/_types.ts | 1 - src/@context/Web3.tsx | 8 +- src/components/Header/Wallet/Details.tsx | 34 +------ 8 files changed, 2 insertions(+), 167 deletions(-) diff --git a/.env.example b/.env.example index 60a85927b..9fca81994 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ - #NEXT_PUBLIC_INFURA_PROJECT_ID="xxx" #NEXT_PUBLIC_MARKET_FEE_ADDRESS="0xxx" #NEXT_PUBLIC_PUBLISHER_MARKET_ORDER_FEE="1" @@ -8,11 +7,6 @@ #NEXT_PUBLIC_CONSUME_MARKET_POOL_SWAP_FEE="1" #NEXT_PUBLIC_CONSUME_MARKET_FIXED_SWAP_FEE="1" - - -#NEXT_PUBLIC_PORTIS_ID="xxx" - - # # ADVANCED SETTINGS # diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fda9b1700..65a7f324e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,7 +17,6 @@ jobs: - run: npm run build env: NEXT_PUBLIC_INFURA_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_INFURA_PROJECT_ID }} - NEXT_PUBLIC_PORTIS_ID: ${{ secrets.NEXT_PUBLIC_PORTIS_ID }} - run: npm run deploy:s3 env: diff --git a/app.config.js b/app.config.js index 284628695..a8b439129 100644 --- a/app.config.js +++ b/app.config.js @@ -75,9 +75,6 @@ module.exports = { storageKey: 'oceanDarkMode' }, - // Wallets - portisId: process.env.NEXT_PUBLIC_PORTIS_ID || 'xxx', - // Used to show or hide the fixed, dynamic or free price options // tab to publishers during the price creation. allowFixedPricing: process.env.NEXT_PUBLIC_ALLOW_FIXED_PRICING || 'true', diff --git a/package-lock.json b/package-lock.json index 3643a118a..91107224f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "@oceanprotocol/art": "^3.2.0", "@oceanprotocol/lib": "^1.1.2", "@oceanprotocol/typographies": "^0.1.0", - "@portis/web3": "^4.0.7", "@tippyjs/react": "^4.2.6", "@urql/exchange-refocus": "^0.2.5", "@walletconnect/web3-provider": "^1.7.8", @@ -5239,17 +5238,6 @@ "url": "https://opencollective.com/popperjs" } }, - "node_modules/@portis/web3": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@portis/web3/-/web3-4.1.0.tgz", - "integrity": "sha512-efGssWqrwpYPzQyOupYPpWmjPU/WwcFGoPXzjLbjQ3Z4Z7Q4qqqwkMeE1mwMbxWudFKlHz/VxdpJrDA42Ufqrg==", - "dependencies": { - "ethereumjs-util": "5.2.0", - "penpal": "3.0.7", - "pocket-js-core": "0.0.3", - "web3-provider-engine": "16.0.1" - } - }, "node_modules/@react-spring/animated": { "version": "9.4.5", "resolved": "https://registry.npmjs.org/@react-spring/animated/-/animated-9.4.5.tgz", @@ -33516,11 +33504,6 @@ "node": ">=0.12" } }, - "node_modules/penpal": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/penpal/-/penpal-3.0.7.tgz", - "integrity": "sha512-WSXiq5HnEvzvY05SHhaXcsviUmCvh4Ze8AiIZzvmdzaaYAAx4rx8c6Xq6+MaVDG/Nfve3VmGD8HyRP3CkPvPbQ==" - }, "node_modules/performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -33616,48 +33599,6 @@ "node": ">=6" } }, - "node_modules/pocket-js-core": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/pocket-js-core/-/pocket-js-core-0.0.3.tgz", - "integrity": "sha512-OUTEvEVutdjLT6YyldvAlSebpBueUUWg2XKxGNt5u3QqrmLpBOOBmdDnGMNJ+lEwXtko+JqgwFq+HTi4g1QDVg==", - "dependencies": { - "axios": "^0.18.0" - } - }, - "node_modules/pocket-js-core/node_modules/axios": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz", - "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==", - "deprecated": "Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410", - "dependencies": { - "follow-redirects": "1.5.10", - "is-buffer": "^2.0.2" - } - }, - "node_modules/pocket-js-core/node_modules/debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/pocket-js-core/node_modules/follow-redirects": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", - "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", - "dependencies": { - "debug": "=3.1.0" - }, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/pocket-js-core/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, "node_modules/polished": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/polished/-/polished-4.2.2.tgz", @@ -45465,17 +45406,6 @@ "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz", "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==" }, - "@portis/web3": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@portis/web3/-/web3-4.1.0.tgz", - "integrity": "sha512-efGssWqrwpYPzQyOupYPpWmjPU/WwcFGoPXzjLbjQ3Z4Z7Q4qqqwkMeE1mwMbxWudFKlHz/VxdpJrDA42Ufqrg==", - "requires": { - "ethereumjs-util": "5.2.0", - "penpal": "3.0.7", - "pocket-js-core": "0.0.3", - "web3-provider-engine": "16.0.1" - } - }, "@react-spring/animated": { "version": "9.4.5", "resolved": "https://registry.npmjs.org/@react-spring/animated/-/animated-9.4.5.tgz", @@ -67519,11 +67449,6 @@ "sha.js": "^2.4.8" } }, - "penpal": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/penpal/-/penpal-3.0.7.tgz", - "integrity": "sha512-WSXiq5HnEvzvY05SHhaXcsviUmCvh4Ze8AiIZzvmdzaaYAAx4rx8c6Xq6+MaVDG/Nfve3VmGD8HyRP3CkPvPbQ==" - }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -67592,46 +67517,6 @@ "ts-pnp": "^1.1.6" } }, - "pocket-js-core": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/pocket-js-core/-/pocket-js-core-0.0.3.tgz", - "integrity": "sha512-OUTEvEVutdjLT6YyldvAlSebpBueUUWg2XKxGNt5u3QqrmLpBOOBmdDnGMNJ+lEwXtko+JqgwFq+HTi4g1QDVg==", - "requires": { - "axios": "^0.18.0" - }, - "dependencies": { - "axios": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz", - "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==", - "requires": { - "follow-redirects": "1.5.10", - "is-buffer": "^2.0.2" - } - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - }, - "follow-redirects": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", - "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", - "requires": { - "debug": "=3.1.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - } - } - }, "polished": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/polished/-/polished-4.2.2.tgz", diff --git a/package.json b/package.json index 6d4e438ed..ae0d5dde8 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "@oceanprotocol/art": "^3.2.0", "@oceanprotocol/lib": "^1.1.2", "@oceanprotocol/typographies": "^0.1.0", - "@portis/web3": "^4.0.7", "@tippyjs/react": "^4.2.6", "@urql/exchange-refocus": "^0.2.5", "@walletconnect/web3-provider": "^1.7.8", diff --git a/src/@context/MarketMetadata/_types.ts b/src/@context/MarketMetadata/_types.ts index c51218edc..1be2cb03f 100644 --- a/src/@context/MarketMetadata/_types.ts +++ b/src/@context/MarketMetadata/_types.ts @@ -18,7 +18,6 @@ export interface AppConfig { consumeMarketPoolSwapFee: string consumeMarketFixedSwapFee: string currencies: string[] - portisId: string allowFixedPricing: string allowDynamicPricing: string allowFreePricing: string diff --git a/src/@context/Web3.tsx b/src/@context/Web3.tsx index a97df6812..c7a7732a5 100644 --- a/src/@context/Web3.tsx +++ b/src/@context/Web3.tsx @@ -9,7 +9,7 @@ import React, { } from 'react' import Web3 from 'web3' import Web3Modal, { getProviderInfo, IProviderInfo } from 'web3modal' -import { infuraProjectId as infuraId, portisId } from '../../app.config' +import { infuraProjectId as infuraId } from '../../app.config' import WalletConnectProvider from '@walletconnect/web3-provider' import { LoggerInstance } from '@oceanprotocol/lib' import { isBrowser } from '@utils/index' @@ -58,12 +58,6 @@ const providerOptions = isBrowser walletconnect: { package: WalletConnectProvider, options: { infuraId } - }, - portis: { - package: require('@portis/web3'), - options: { - id: portisId - } } // torus: { // package: require('@toruslabs/torus-embed') diff --git a/src/components/Header/Wallet/Details.tsx b/src/components/Header/Wallet/Details.tsx index a786570ae..bd042f946 100644 --- a/src/components/Header/Wallet/Details.tsx +++ b/src/components/Header/Wallet/Details.tsx @@ -1,4 +1,4 @@ -import React, { ChangeEvent, ReactElement, useEffect, useState } from 'react' +import React, { ReactElement, useEffect, useState } from 'react' import { formatCurrency } from '@coingecko/cryptoformat' import { useUserPreferences } from '@context/UserPreferences' import Button from '@shared/atoms/Button' @@ -7,11 +7,9 @@ import Conversion from '@shared/Price/Conversion' import { useWeb3 } from '@context/Web3' import { getOceanConfig } from '@utils/ocean' import styles from './Details.module.css' -import InputElement from '@shared/FormInput/InputElement' export default function Details(): ReactElement { const { - web3Provider, web3ProviderInfo, web3Modal, connect, @@ -27,7 +25,6 @@ export default function Details(): ReactElement { address: string symbol: string }>() - const [portisNetwork, setPortisNetwork] = useState() useEffect(() => { if (!networkId) return @@ -45,16 +42,6 @@ export default function Details(): ReactElement { }) }, [networkData, networkId]) - // Handle network change for Portis - async function handlePortisNetworkChange(e: ChangeEvent) { - setPortisNetwork(e.target.value) - const portisNetworkName = e.target.value.toLowerCase() - await web3Provider._portis.changeNetwork(portisNetworkName) - // TODO: using our connect initializes a new Portis instance, - // which then defaults back to initial network (Mainnet). - // await connect() - } - return (
    @@ -76,16 +63,6 @@ export default function Details(): ReactElement { {web3ProviderInfo?.name} - {web3ProviderInfo?.name === 'Portis' && ( - - )} {web3ProviderInfo?.name === 'MetaMask' && (

    - {web3ProviderInfo?.name === 'Portis' && ( - - )}

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 ? ( <> From b09dc6b953d5c499dc9426f50d1c59fb9a8ae8cd Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 11:46:42 +0100 Subject: [PATCH 05/11] more typos --- src/@utils/compute.ts | 1 + .../Asset/AssetActions/Compute/index.tsx | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index f0506b50a..a47caf898 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -92,6 +92,7 @@ export async function isOrderable( ): Promise { const datasetService: Service = getServiceById(asset, serviceId) if (!datasetService) return false + if (datasetService.type === 'compute') { if (algorithm.meta) { // check if raw algo is allowed diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index b6fadd7b1..19507d4e4 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -63,9 +63,11 @@ export default function Compute({ consumableFeedback?: string }): ReactElement { const { accountId, web3 } = useWeb3() + const { getOpcFeeForToken } = useMarketMetadata() + const newAbortController = useAbortController() + const [isJobStarting, setIsJobStarting] = useState(false) const [error, setError] = useState() - const newAbortController = useAbortController() const [algorithmList, setAlgorithmList] = useState() const [ddoAlgorithmList, setDdoAlgorithmList] = useState() @@ -78,8 +80,6 @@ export default function Compute({ const [validOrderTx, setValidOrderTx] = useState('') const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('') - const hasDatatoken = Number(dtBalance) >= 1 - const { getOpcFeeForToken } = useMarketMetadata() const { poolData } = usePool() const newCancelToken = useCancelToken() const [isConsumablePrice, setIsConsumablePrice] = useState(true) @@ -95,7 +95,9 @@ export default function Compute({ useState() const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] = useState(false) - const [refetchJobs, setRefatchJobs] = useState(false) + const [refetchJobs, setRefetchJobs] = useState(false) + + const hasDatatoken = Number(dtBalance) >= 1 const isComputeButtonDisabled = isJobStarting === true || file === null || @@ -157,8 +159,8 @@ export default function Compute({ ) { setComputeStatusText( getComputeFeedback( - asset.accessDetails.baseToken?.symbol, - asset.accessDetails.datatoken?.symbol, + asset.accessDetails?.baseToken?.symbol, + asset.accessDetails?.datatoken?.symbol, asset.metadata.type )[0] ) @@ -208,7 +210,7 @@ export default function Compute({ if (selectedAlgorithmAsset?.accessDetails?.type === 'dynamic') { const response = await getPoolData( selectedAlgorithmAsset.chainId, - selectedAlgorithmAsset.accessDetails.addressOrId, + selectedAlgorithmAsset.accessDetails?.addressOrId, selectedAlgorithmAsset?.nft.owner, accountId || '' ) @@ -401,7 +403,7 @@ export default function Compute({ } LoggerInstance.log('[compute] Starting compute job response: ', response) setIsPublished(true) - setRefatchJobs(!refetchJobs) + setRefetchJobs(!refetchJobs) initPriceAndFees() } catch (error) { setError('Failed to start job!') From c8ab4b18c52c73bd3d74a1ffa7a2ce4d8a15c3c3 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 12:05:35 +0100 Subject: [PATCH 06/11] shorten getAccessDetailsFromTokenPrice() a bit --- src/@utils/accessDetailsAndPricing.ts | 25 ++++++++----------- .../Asset/AssetActions/Compute/index.tsx | 2 -- .../Asset/AssetActions/Download.tsx | 1 - 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index a47399bf5..612c77978 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -173,22 +173,21 @@ function getAccessDetailsFromTokenPrice( ): AccessDetails { const accessDetails = {} as AccessDetails - if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) { + if (tokenPrice?.orders?.length > 0) { const order = tokenPrice.orders[0] - const reusedOrder = - order && order.reuses && order.reuses.length > 0 ? order.reuses[0] : null + const reusedOrder = order?.reuses?.length > 0 ? order.reuses[0] : null // asset is owned if there is an order and asset has timeout 0 (forever) or if the condition is valid accessDetails.isOwned = - timeout === 0 || Date.now() / 1000 - order.createdTimestamp < timeout + timeout === 0 || Date.now() / 1000 - order?.createdTimestamp < timeout // the last valid order should be the last reuse order tx id if there is one - accessDetails.validOrderTx = reusedOrder ? reusedOrder.tx : order.tx + accessDetails.validOrderTx = reusedOrder?.tx || order?.tx } // TODO: fetch order fee from sub query - accessDetails.publisherMarketOrderFee = tokenPrice.publishMarketFeeAmount + accessDetails.publisherMarketOrderFee = tokenPrice?.publishMarketFeeAmount // free is always the best price - if (tokenPrice.dispensers && tokenPrice.dispensers.length > 0) { + if (tokenPrice?.dispensers?.length > 0) { const dispenser = tokenPrice.dispensers[0] accessDetails.type = 'free' accessDetails.addressOrId = dispenser.token.id @@ -203,10 +202,7 @@ function getAccessDetailsFromTokenPrice( } // checking for fixed price - if ( - tokenPrice.fixedRateExchanges && - tokenPrice.fixedRateExchanges.length > 0 - ) { + if (tokenPrice?.fixedRateExchanges?.length > 0) { const fixed = tokenPrice.fixedRateExchanges[0] accessDetails.type = 'fixed' accessDetails.addressOrId = fixed.exchangeId @@ -227,7 +223,7 @@ function getAccessDetailsFromTokenPrice( } // checking for pools - if (tokenPrice.pools && tokenPrice.pools.length > 0) { + if (tokenPrice?.pools?.length > 0) { const pool = tokenPrice.pools[0] accessDetails.type = 'dynamic' accessDetails.addressOrId = pool.id @@ -256,7 +252,6 @@ function getAccessDetailsFromTokenPrice( * @return {Promise} */ export async function getOrderPriceAndFees( - web3: Web3, asset: AssetExtended, accountId?: string, paramsForPool?: CalcInGivenOutParams, @@ -283,10 +278,10 @@ export async function getOrderPriceAndFees( !providerFees && (await ProviderInstance.initialize( asset?.id, - asset.services[0].id, + asset?.services[0].id, 0, accountId, - asset.services[0].serviceEndpoint + asset?.services[0].serviceEndpoint )) orderPriceAndFee.providerFee = providerFees || initializeData.providerFee diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 19507d4e4..18ca88dac 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -181,7 +181,6 @@ export default function Compute({ } : null const datasetPriceAndFees = await getOrderPriceAndFees( - web3, asset, ZERO_ADDRESS, poolParams, @@ -229,7 +228,6 @@ export default function Compute({ } } const algorithmOrderPriceAndFees = await getOrderPriceAndFees( - web3, selectedAlgorithmAsset, ZERO_ADDRESS, algoPoolParams, diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index beb35935d..fe536b94f 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -83,7 +83,6 @@ export default function Download({ consumeMarketSwapFee: '0' } const _orderPriceAndFees = await getOrderPriceAndFees( - web3, asset, ZERO_ADDRESS, paramsForPool From 36bc097c0b47d0cc756b17d51e4265f8fea948ae Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 12:46:27 +0100 Subject: [PATCH 07/11] state & hooks access reordering --- src/components/@shared/ButtonBuy/index.module.css | 2 +- src/components/Asset/AssetActions/Compute/index.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/@shared/ButtonBuy/index.module.css b/src/components/@shared/ButtonBuy/index.module.css index b89ee14f8..99516295e 100644 --- a/src/components/@shared/ButtonBuy/index.module.css +++ b/src/components/@shared/ButtonBuy/index.module.css @@ -4,7 +4,7 @@ } .actionsCenter { - margin: auto !important; + margin: auto; display: block; } diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 18ca88dac..6176e1b4c 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -64,7 +64,9 @@ export default function Compute({ }): ReactElement { const { accountId, web3 } = useWeb3() const { getOpcFeeForToken } = useMarketMetadata() + const { poolData } = usePool() const newAbortController = useAbortController() + const newCancelToken = useCancelToken() const [isJobStarting, setIsJobStarting] = useState(false) const [error, setError] = useState() @@ -80,8 +82,6 @@ export default function Compute({ const [validOrderTx, setValidOrderTx] = useState('') const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('') - const { poolData } = usePool() - const newCancelToken = useCancelToken() const [isConsumablePrice, setIsConsumablePrice] = useState(true) const [computeStatusText, setComputeStatusText] = useState('') const [computeEnv, setComputeEnv] = useState() From 3e4b79fc42e06074d925c22ec10ceba19d2c2a19 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Wed, 22 Jun 2022 15:13:33 +0300 Subject: [PATCH 08/11] Update src/@utils/ddo.ts remove metadata from service type Co-authored-by: Matthias Kretschmann --- src/@utils/ddo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/@utils/ddo.ts b/src/@utils/ddo.ts index 749a6143e..0bc817e4f 100644 --- a/src/@utils/ddo.ts +++ b/src/@utils/ddo.ts @@ -2,7 +2,7 @@ import { Asset, DDO, Service } from '@oceanprotocol/lib' export function getServiceByName( ddo: Asset | DDO, - name: 'access' | 'compute' | 'metadata' + name: 'access' | 'compute' ): Service { if (!ddo) return From 40f9170eb4abc8c73f4ea879c71c54db73b24196 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 13:40:22 +0100 Subject: [PATCH 09/11] effect dependency fixes --- .../AssetActions/Compute/FormComputeDataset.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx index 33147f37f..a0f17b43a 100644 --- a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx +++ b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx @@ -76,9 +76,11 @@ export default function FormStartCompute({ validUntil?: string }): ReactElement { const { siteContent } = useMarketMetadata() + const { accountId, balance } = useWeb3() const { isValid, values }: FormikContextType<{ algorithm: string }> = useFormikContext() const { asset, isAssetNetwork } = useAsset() + const [totalPrice, setTotalPrice] = useState('0') const [datasetOrderPrice, setDatasetOrderPrice] = useState( asset?.accessDetails?.price @@ -87,7 +89,6 @@ export default function FormStartCompute({ selectedAlgorithmAsset?.accessDetails?.price ) const [isBalanceSufficient, setIsBalanceSufficient] = useState(false) - const { accountId, balance } = useWeb3() function getAlgorithmAsset(algorithmId: string): Asset { let assetDdo = null @@ -99,6 +100,7 @@ export default function FormStartCompute({ useEffect(() => { if (!values.algorithm || !accountId || !isConsumable) return + async function fetchAlgorithmAssetExtended() { const algorithmAsset = getAlgorithmAsset(values.algorithm) const accessDetails = await getAccessDetails( @@ -159,15 +161,17 @@ export default function FormStartCompute({ hasPreviousOrderSelectedComputeAsset, hasDatatokenSelectedComputeAsset, datasetOrderPriceAndFees, - algoOrderPriceAndFees + algoOrderPriceAndFees, + providerFeeAmount ]) useEffect(() => { - if (!totalPrice) return + if (!totalPrice || !balance?.ocean || !dtBalance) return + setIsBalanceSufficient( compareAsBN(balance.ocean, `${totalPrice}`) || Number(dtBalance) >= 1 ) - }, [totalPrice]) + }, [totalPrice, balance?.ocean, dtBalance]) return (
From e3b751ea8bb91555d33f539b2f0c61c88d97e8eb Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 13:40:35 +0100 Subject: [PATCH 10/11] state renaming --- .../Asset/AssetActions/Compute/index.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 6176e1b4c..13a41bce2 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -68,7 +68,8 @@ export default function Compute({ const newAbortController = useAbortController() const newCancelToken = useCancelToken() - const [isJobStarting, setIsJobStarting] = useState(false) + const [isOrdering, setIsOrdering] = useState(false) + const [isOrdered, setIsOrdered] = useState(false) const [error, setError] = useState() const [algorithmList, setAlgorithmList] = useState() @@ -76,7 +77,6 @@ export default function Compute({ const [selectedAlgorithmAsset, setSelectedAlgorithmAsset] = useState() const [hasAlgoAssetDatatoken, setHasAlgoAssetDatatoken] = useState() - const [isPublished, setIsPublished] = useState(false) const [algorithmDTBalance, setAlgorithmDTBalance] = useState() const [validOrderTx, setValidOrderTx] = useState('') @@ -99,7 +99,7 @@ export default function Compute({ const hasDatatoken = Number(dtBalance) >= 1 const isComputeButtonDisabled = - isJobStarting === true || + isOrdering === true || file === null || (!validOrderTx && !hasDatatoken && !isConsumablePrice) || (!validAlgorithmOrderTx && !hasAlgoAssetDatatoken) @@ -291,8 +291,8 @@ export default function Compute({ async function startJob(): Promise { try { - setIsJobStarting(true) - setIsPublished(false) // would be nice to rename this + setIsOrdering(true) + setIsOrdered(false) // would be nice to rename this setError(undefined) const computeService = getServiceByName(asset, 'compute') const computeAlgorithm: ComputeAlgorithm = { @@ -400,14 +400,14 @@ export default function Compute({ return } LoggerInstance.log('[compute] Starting compute job response: ', response) - setIsPublished(true) + setIsOrdered(true) setRefetchJobs(!refetchJobs) initPriceAndFees() } catch (error) { setError('Failed to start job!') LoggerInstance.error('[compute] Failed to start job: ', error.message) } finally { - setIsJobStarting(false) + setIsOrdering(false) } } @@ -444,7 +444,7 @@ export default function Compute({ ddoListAlgorithms={ddoAlgorithmList} selectedAlgorithmAsset={selectedAlgorithmAsset} setSelectedAlgorithm={setSelectedAlgorithmAsset} - isLoading={isJobStarting || isRequestingAlgoOrderPrice} + isLoading={isOrdering || isRequestingAlgoOrderPrice} isComputeButtonDisabled={isComputeButtonDisabled} hasPreviousOrder={validOrderTx !== undefined} hasDatatoken={hasDatatoken} @@ -482,7 +482,7 @@ export default function Compute({ )}
- {isPublished && ( + {isOrdered && ( )}
From 923569e61a77c706ee9b79c8aec09c7b3b6d077c Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 22 Jun 2022 14:02:32 +0100 Subject: [PATCH 11/11] effect dependency fixes --- .../Asset/AssetActions/Compute/index.tsx | 2 +- .../Profile/History/ComputeJobs/index.tsx | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 13a41bce2..2f92e358b 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -490,7 +490,7 @@ export default function Compute({ diff --git a/src/components/Profile/History/ComputeJobs/index.tsx b/src/components/Profile/History/ComputeJobs/index.tsx index 84d4aba53..d104c9f3e 100644 --- a/src/components/Profile/History/ComputeJobs/index.tsx +++ b/src/components/Profile/History/ComputeJobs/index.tsx @@ -71,20 +71,21 @@ const columns = [ export default function ComputeJobs({ minimal, - assetChainId, + assetChainIds, refetchJobs }: { minimal?: boolean - assetChainId?: number[] + assetChainIds?: number[] refetchJobs?: boolean }): ReactElement { const { accountId } = useWeb3() const { asset } = useAsset() const { chainIds } = useUserPreferences() - const [isLoading, setIsLoading] = useState(false) - const [jobs, setJobs] = useState([]) const isMounted = useIsMounted() const newCancelToken = useCancelToken() + + const [isLoading, setIsLoading] = useState(false) + const [jobs, setJobs] = useState([]) const [columnsMinimal] = useState([columns[4], columns[5], columns[3]]) const fetchJobs = useCallback(async () => { @@ -96,7 +97,7 @@ export default function ComputeJobs({ try { setIsLoading(true) const jobs = await getComputeJobs( - assetChainId || chainIds, + assetChainIds || chainIds, accountId, asset, newCancelToken() @@ -106,15 +107,11 @@ export default function ComputeJobs({ } catch (error) { LoggerInstance.error(error.message) } - }, [chainIds, accountId, asset, isMounted]) + }, [chainIds, accountId, asset, isMounted, assetChainIds, newCancelToken]) useEffect(() => { fetchJobs() - }, [fetchJobs]) - - useEffect(() => { - fetchJobs() - }, [refetchJobs]) + }, [fetchJobs, refetchJobs]) return accountId ? ( <>