From aa37155a16567dca6f561735cec94d7eb11b317d Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 23 Jun 2022 08:06:09 -0700 Subject: [PATCH] Correctly display trusted algorithms in compute asset (#1541) * fix allowed algo * fix trusted algo filter --- src/@utils/compute.ts | 28 ++++++++++++------- .../Asset/AssetActions/Compute/index.tsx | 1 - 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index a4967a014..7f7cfd350 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -151,19 +151,20 @@ export async function getComputeEnviroment( export function getQueryString( trustedAlgorithmList: PublisherTrustedAlgorithm[], + trustedPublishersList: string[], chainId?: number ): SearchQuery { - const algorithmDidList = trustedAlgorithmList.map((x) => x.did) + const algorithmDidList = trustedAlgorithmList?.map((x) => x.did) const baseParams = { chainIds: [chainId], sort: { sortBy: SortTermOptions.Created }, - filters: [ - getFilterTerm('metadata.type', 'algorithm'), - algorithmDidList.length > 0 && getFilterTerm('_id', algorithmDidList) - ] + filters: [getFilterTerm('metadata.type', 'algorithm')] } as BaseQueryParams - + algorithmDidList?.length > 0 && + baseParams.filters.push(getFilterTerm('_id', algorithmDidList)) + trustedPublishersList?.length > 0 && + baseParams.filters.push(getFilterTerm('nft.owner', trustedPublishersList)) const query = generateBaseQuery(baseParams) return query @@ -174,17 +175,24 @@ export async function getAlgorithmsForAsset( token: CancelToken ): Promise { const computeService: Service = getServiceByName(asset, 'compute') - const publisherTrustedAlgorithms = - computeService.compute.publisherTrustedAlgorithms || [] - if (!computeService.compute || publisherTrustedAlgorithms.length === 0) { + if ( + !computeService.compute || + (computeService.compute.publisherTrustedAlgorithms?.length === 0 && + computeService.compute.publisherTrustedAlgorithmPublishers?.length === 0) + ) { return [] } const gueryResults = await queryMetadata( - getQueryString(publisherTrustedAlgorithms, asset.chainId), + getQueryString( + computeService.compute.publisherTrustedAlgorithms, + computeService.compute.publisherTrustedAlgorithmPublishers, + asset.chainId + ), token ) + const algorithms: Asset[] = gueryResults?.results return algorithms } diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 617e88135..d70294c30 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -277,7 +277,6 @@ export default function Compute({ useEffect(() => { if (!asset) return - getAlgorithmsForAsset(asset, newCancelToken()).then((algorithmsAssets) => { setDdoAlgorithmList(algorithmsAssets) getAlgorithmAssetSelectionList(asset, algorithmsAssets).then(