From ed4645e13c6e97b3a6dbc90810e4583e9407ae68 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 9 Feb 2023 12:25:15 +0300 Subject: [PATCH] Fetching prices from Aquarius in AssetList component (#1774) * Fetching prices from Aquarius in AssetList component * Removing unused imports * Removing fetching logic from AssetList * Using Asset Price from Aquarius * removing unused code for loader * Updating ocean.js * Updating price format in tests * removing console logs * Fixing build issues * Updating condition for showing free price * Fixing tests * Removing logs * Showing No pricing schema available on asset teaser * Showing No pricing schema available on asset detail page * Adding additional tests * Removing console logs * Avoiding getInitialPaymentCollector failure (#1816) * early return is no web3 or ddo * Creating test for MetaFull * adding test: src/components/Asset/AssetContent/MetaSecondary.test.tsx * Adding test for bookmarks * Adding test for displaying payment collector * Removing comments * Renaming assetAquarius * Renaming assetWithAccessDetails * Ensuring that the payment collector is shown even without a wallet connected * Removing broken test * Using getDummyWeb3 for fetching the payment collector address * google validation (#1835) * Updating validation to exclude any google link * Updating Yup validation * Checking if domain includes google.com * Updating isGoogleUrl function * Moving isGoogleUrl into @utils/url/index file * isGoogleUrl function * Updating tests * Adding additional tests for other google domains * Updating tests * Updating isGoogleUrl file path * Updating pricing message (#1842) * Bump @storybook/addon-essentials from 6.5.13 to 6.5.15 (#1841) Bumps [@storybook/addon-essentials](https://github.com/storybookjs/storybook/tree/HEAD/addons/essentials) from 6.5.13 to 6.5.15. - [Release notes](https://github.com/storybookjs/storybook/releases) - [Changelog](https://github.com/storybookjs/storybook/blob/v6.5.15/CHANGELOG.md) - [Commits](https://github.com/storybookjs/storybook/commits/v6.5.15/addons/essentials) --- updated-dependencies: - dependency-name: "@storybook/addon-essentials" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @types/jest from 29.2.3 to 29.2.5 (#1840) Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 29.2.3 to 29.2.5. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) --- updated-dependencies: - dependency-name: "@types/jest" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump prettier from 2.8.0 to 2.8.1 (#1837) Bumps [prettier](https://github.com/prettier/prettier) from 2.8.0 to 2.8.1. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.0...2.8.1) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump react-select from 5.6.1 to 5.7.0 (#1839) Bumps [react-select](https://github.com/JedWatson/react-select) from 5.6.1 to 5.7.0. - [Release notes](https://github.com/JedWatson/react-select/releases) - [Changelog](https://github.com/JedWatson/react-select/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/JedWatson/react-select/compare/react-select@5.6.1...react-select@5.7.0) --- updated-dependencies: - dependency-name: react-select dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump react-tabs from 5.1.0 to 6.0.0 (#1838) Bumps [react-tabs](https://github.com/reactjs/react-tabs) from 5.1.0 to 6.0.0. - [Release notes](https://github.com/reactjs/react-tabs/releases) - [Commits](https://github.com/reactjs/react-tabs/compare/v5.1.0...v6.0.0) --- updated-dependencies: - dependency-name: react-tabs dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix asset route (#1836) * updating the buy button message for free assets * Updating pricing text for compute and algorithms * Updating tests * Adding a seperate sentence about paying gas fees for network charges with free assets * Fixing tests Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mihaisc * Showing hosting type in File Info (#1846) * Bump @storybook/addon-essentials from 6.5.13 to 6.5.15 (#1841) Bumps [@storybook/addon-essentials](https://github.com/storybookjs/storybook/tree/HEAD/addons/essentials) from 6.5.13 to 6.5.15. - [Release notes](https://github.com/storybookjs/storybook/releases) - [Changelog](https://github.com/storybookjs/storybook/blob/v6.5.15/CHANGELOG.md) - [Commits](https://github.com/storybookjs/storybook/commits/v6.5.15/addons/essentials) --- updated-dependencies: - dependency-name: "@storybook/addon-essentials" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @types/jest from 29.2.3 to 29.2.5 (#1840) Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 29.2.3 to 29.2.5. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) --- updated-dependencies: - dependency-name: "@types/jest" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump prettier from 2.8.0 to 2.8.1 (#1837) Bumps [prettier](https://github.com/prettier/prettier) from 2.8.0 to 2.8.1. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.0...2.8.1) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump react-select from 5.6.1 to 5.7.0 (#1839) Bumps [react-select](https://github.com/JedWatson/react-select) from 5.6.1 to 5.7.0. - [Release notes](https://github.com/JedWatson/react-select/releases) - [Changelog](https://github.com/JedWatson/react-select/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/JedWatson/react-select/compare/react-select@5.6.1...react-select@5.7.0) --- updated-dependencies: - dependency-name: react-select dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump react-tabs from 5.1.0 to 6.0.0 (#1838) Bumps [react-tabs](https://github.com/reactjs/react-tabs) from 5.1.0 to 6.0.0. - [Release notes](https://github.com/reactjs/react-tabs/releases) - [Commits](https://github.com/reactjs/react-tabs/compare/v5.1.0...v6.0.0) --- updated-dependencies: - dependency-name: react-tabs dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix asset route (#1836) * Adding hosting type to the file info component * Writting smart contract hosting type across two lines Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mihaisc * add initial price value for not supported price assets (#1851) * Updating test * Updating accessDetailsAndPricing * Adding orderPriceAndFees back in to show the price with fees on the asset detail page * Using price with fees for compute assets * Fixing conversions by ensuring that the symbol is always sent through * Removing unwanted changes in package-lock.json * Updating use of isUnsupportedPricing variable * Getting rid of getAccessDetailsForAssets completely * Removing unused imports and query * Fixing test * Removing unused import --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mihaisc Co-authored-by: Bogdan Fazakas --- .../@utils/accessDetailsAndPricing.ts | 3 - src/@utils/accessDetailsAndPricing.ts | 120 +----------------- src/@utils/assetConvertor.ts | 10 +- src/components/@shared/AssetList/index.tsx | 51 +------- .../@shared/AssetTeaser/index.test.tsx | 15 +++ src/components/@shared/AssetTeaser/index.tsx | 26 ++-- .../AssetSelection/index.test.tsx | 6 +- .../InputElement/AssetSelection/index.tsx | 5 +- .../@shared/FormInput/index.test.tsx | 4 +- src/components/@shared/Price/PriceUnit.tsx | 8 +- src/components/@shared/Price/index.test.tsx | 24 +--- src/components/@shared/Price/index.tsx | 20 ++- .../Asset/AssetActions/Compute/index.tsx | 2 +- .../Asset/AssetActions/Download.tsx | 10 +- src/components/Home/Bookmarks.tsx | 9 +- src/components/Profile/Header/Stats.tsx | 9 +- 16 files changed, 77 insertions(+), 245 deletions(-) delete mode 100644 .jest/__mocks__/@utils/accessDetailsAndPricing.ts diff --git a/.jest/__mocks__/@utils/accessDetailsAndPricing.ts b/.jest/__mocks__/@utils/accessDetailsAndPricing.ts deleted file mode 100644 index 7a162fc69..000000000 --- a/.jest/__mocks__/@utils/accessDetailsAndPricing.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { assets } from '../../__fixtures__/datasetsWithAccessDetails' - -export const getAccessDetailsForAssets = jest.fn().mockResolvedValue(assets) diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index 2d053684c..7d0b07741 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -5,11 +5,6 @@ import { TokenPriceQuery_token as TokenPrice } from '../@types/subgraph/TokenPriceQuery' import { - TokensPriceQuery, - TokensPriceQuery_tokens as TokensPrice -} from '../@types/subgraph/TokensPriceQuery' -import { - Asset, LoggerInstance, ProviderFees, ProviderInstance @@ -21,64 +16,6 @@ import { publisherMarketOrderFee } from '../../app.config' -const tokensPriceQuery = gql` - query TokensPriceQuery($datatokenIds: [ID!], $account: String) { - tokens(first: 1000, where: { id_in: $datatokenIds }) { - id - symbol - name - publishMarketFeeAddress - publishMarketFeeToken - publishMarketFeeAmount - templateId - orders( - where: { payer: $account } - orderBy: createdTimestamp - orderDirection: desc - ) { - tx - serviceIndex - createdTimestamp - reuses(orderBy: createdTimestamp, orderDirection: desc) { - id - caller - createdTimestamp - tx - block - } - } - dispensers { - id - active - isMinter - maxBalance - token { - id - name - symbol - } - } - fixedRateExchanges { - id - exchangeId - price - publishMarketSwapFee - baseToken { - symbol - name - address - decimals - } - datatoken { - symbol - name - address - } - active - } - } - } -` const tokenPriceQuery = gql` query TokenPriceQuery($datatokenId: ID!, $account: String) { token(id: $datatokenId) { @@ -139,7 +76,7 @@ const tokenPriceQuery = gql` ` function getAccessDetailsFromTokenPrice( - tokenPrice: TokenPrice | TokensPrice, + tokenPrice: TokenPrice, timeout?: number ): AccessDetails { const accessDetails = {} as AccessDetails @@ -216,7 +153,7 @@ export async function getOrderPriceAndFees( providerFees?: ProviderFees ): Promise { const orderPriceAndFee = { - price: '0', + price: String(asset?.stats?.price?.value || '0'), publisherMarketOrderFee: publisherMarketOrderFee || '0', publisherMarketFixedSwapFee: '0', consumeMarketOrderFee: consumeMarketOrderFee || '0', @@ -291,56 +228,3 @@ export async function getAccessDetails( LoggerInstance.error('Error getting access details: ', error.message) } } - -export async function getAccessDetailsForAssets( - assets: Asset[], - account = '' -): Promise { - const assetsExtended: AssetExtended[] = assets - const chainAssetLists: { [key: number]: string[] } = {} - - try { - for (const asset of assets) { - if (chainAssetLists[asset.chainId]) { - chainAssetLists[asset.chainId].push( - asset.services[0].datatokenAddress.toLowerCase() - ) - } else { - chainAssetLists[asset.chainId] = [] - chainAssetLists[asset.chainId].push( - asset.services[0].datatokenAddress.toLowerCase() - ) - } - } - - for (const chainKey in chainAssetLists) { - const queryContext = getQueryContext(Number(chainKey)) - const tokenQueryResult: OperationResult< - TokensPriceQuery, - { datatokenIds: [string]; account: string } - > = await fetchData( - tokensPriceQuery, - { - datatokenIds: chainAssetLists[chainKey], - account: account?.toLowerCase() - }, - queryContext - ) - tokenQueryResult?.data?.tokens?.forEach((token) => { - const currentAsset = assetsExtended.find( - (asset) => - asset.services[0].datatokenAddress.toLowerCase() === token.id - ) - const accessDetails = getAccessDetailsFromTokenPrice( - token, - currentAsset?.services[0]?.timeout - ) - - currentAsset.accessDetails = accessDetails - }) - } - return assetsExtended - } catch (error) { - LoggerInstance.error('Error getting access details: ', error.message) - } -} diff --git a/src/@utils/assetConvertor.ts b/src/@utils/assetConvertor.ts index 2b143b591..c8f89e953 100644 --- a/src/@utils/assetConvertor.ts +++ b/src/@utils/assetConvertor.ts @@ -1,4 +1,3 @@ -import { getAccessDetailsForAssets } from './accessDetailsAndPricing' import { PublisherTrustedAlgorithm, Asset } from '@oceanprotocol/lib' import { AssetSelectionAsset } from '@shared/FormInput/InputElement/AssetSelection' import { getServiceByName } from './ddo' @@ -8,17 +7,14 @@ export async function transformAssetToAssetSelection( assets: Asset[], selectedAlgorithms?: PublisherTrustedAlgorithm[] ): Promise { - const extendedAssets: AssetExtended[] = await getAccessDetailsForAssets( - assets - ) const algorithmList: AssetSelectionAsset[] = [] - for (const asset of extendedAssets) { + for (const asset of assets) { const algoService = getServiceByName(asset, 'compute') || getServiceByName(asset, 'access') if ( - asset?.accessDetails?.price && + asset?.stats?.price?.value && algoService?.serviceEndpoint === datasetProviderEndpoint ) { let selected = false @@ -30,7 +26,7 @@ export async function transformAssetToAssetSelection( const algorithmAsset: AssetSelectionAsset = { did: asset.id, name: asset.metadata.name, - price: asset.accessDetails.price, + price: asset.stats.price.value, checked: selected, symbol: asset.datatokens[0].symbol } diff --git a/src/components/@shared/AssetList/index.tsx b/src/components/@shared/AssetList/index.tsx index 7624a61aa..35fd67da3 100644 --- a/src/components/@shared/AssetList/index.tsx +++ b/src/components/@shared/AssetList/index.tsx @@ -1,19 +1,7 @@ import AssetTeaser from '@shared/AssetTeaser' -import React, { ReactElement, useEffect, useState } from 'react' +import React, { ReactElement } from 'react' import Pagination from '@shared/Pagination' import styles from './index.module.css' -import Loader from '@shared/atoms/Loader' -import { useIsMounted } from '@hooks/useIsMounted' -import { getAccessDetailsForAssets } from '@utils/accessDetailsAndPricing' -import { useWeb3 } from '@context/Web3' - -function LoaderArea() { - return ( -
- -
- ) -} export declare type AssetListProps = { assets: AssetExtended[] @@ -33,52 +21,27 @@ export default function AssetList({ showPagination, page, totalPages, - isLoading, onPageChange, className, noPublisher, noDescription, noPrice }: AssetListProps): ReactElement { - const { accountId } = useWeb3() - const [assetsWithPrices, setAssetsWithPrices] = - useState(assets) - const [loading, setLoading] = useState(isLoading) - const isMounted = useIsMounted() - - useEffect(() => { - if (!assets || !assets.length) return - - setAssetsWithPrices(assets as AssetExtended[]) - setLoading(false) - async function fetchPrices() { - const assetsWithPrices = await getAccessDetailsForAssets( - assets, - accountId || '' - ) - if (!isMounted() || !assetsWithPrices) return - setAssetsWithPrices([...assetsWithPrices]) - } - fetchPrices() - }, [assets, isMounted, accountId]) - - // // This changes the page field inside the query + // This changes the page field inside the query function handlePageChange(selected: number) { onPageChange(selected + 1) } const styleClasses = `${styles.assetList} ${className || ''}` - return loading ? ( - - ) : ( + return ( <>
- {assetsWithPrices?.length > 0 ? ( - assetsWithPrices?.map((assetWithPrice) => ( + {assets?.length > 0 ? ( + assets?.map((asset) => ( { testRender() + + it('renders no pricing schema available', () => { + asset.stats.price = null + render() + expect(screen.getByText('No pricing schema available')).toBeInTheDocument() + expect(screen.getByText('This is a test.')).toBeInTheDocument() + }) + it('renders asset teaser with no description', () => { + asset.metadata.description = null + render() + expect( + screen.queryByText('This is a test description') + ).not.toBeInTheDocument() + }) }) diff --git a/src/components/@shared/AssetTeaser/index.tsx b/src/components/@shared/AssetTeaser/index.tsx index 75e0b023b..ed76d7d3a 100644 --- a/src/components/@shared/AssetTeaser/index.tsx +++ b/src/components/@shared/AssetTeaser/index.tsx @@ -21,16 +21,18 @@ export declare type AssetTeaserProps = { export default function AssetTeaser({ asset, noPublisher, - noDescription, - noPrice + noDescription }: AssetTeaserProps): ReactElement { const { name, type, description } = asset.metadata const { datatokens } = asset const isCompute = Boolean(getServiceByName(asset, 'compute')) const accessType = isCompute ? 'compute' : 'access' const { owner } = asset.nft - const { orders, allocated } = asset.stats - const isUnsupportedPricing = asset?.accessDetails?.type === 'NOT_SUPPORTED' + const { orders, allocated, price } = asset.stats + const isUnsupportedPricing = + !asset.services.length || + asset?.stats?.price?.value === undefined || + asset?.accessDetails?.type === 'NOT_SUPPORTED' const { locale } = useUserPreferences() return ( @@ -60,15 +62,13 @@ export default function AssetTeaser({
)} - {!noPrice && ( -
- {isUnsupportedPricing || !asset.services.length ? ( - No pricing schema available - ) : ( - - )} -
- )} +
+ {isUnsupportedPricing ? ( + No pricing schema available + ) : ( + + )} +