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 + ) : ( + + )} +