From 5c02da859764d0aa60d0a38317aa647f1785d12d Mon Sep 17 00:00:00 2001 From: mihaisc Date: Wed, 26 Oct 2022 11:45:20 +0300 Subject: [PATCH] ignore assets with state 5 (#1749) * ignore assets with state 5 * hide in profile for other users * fix display on own account Co-authored-by: Matthias Kretschmann --- src/@context/Asset.tsx | 5 ++-- src/@context/Profile/index.tsx | 22 ++++++++++++---- src/@types/aquarius/BaseQueryParams.d.ts | 1 + src/@utils/aquarius.ts | 26 ++++++++++++++++--- .../Profile/History/PublishedList.tsx | 6 +++-- src/pages/profile/index.tsx | 11 ++++++-- 6 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index 92ebfc14b..12c533aa4 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -76,8 +76,9 @@ function AssetProvider({ LoggerInstance.error(`[asset] Failed getting asset for ${did}`, asset) return } - if (asset.nft.state !== 0 && asset.nft.state !== 4) { - // handle nft states as documented in https://docs.oceanprotocol.com/concepts/did-ddo/#state + + if ([1, 2, 3].includes(asset.nft.state)) { + // handle nft states as documented in https://docs.oceanprotocol.com/core-concepts/did-ddo/#state let state switch (asset.nft.state) { case 1: diff --git a/src/@context/Profile/index.tsx b/src/@context/Profile/index.tsx index ab6b46f28..64cf4be12 100644 --- a/src/@context/Profile/index.tsx +++ b/src/@context/Profile/index.tsx @@ -29,6 +29,7 @@ interface ProfileProviderValue { downloadsTotal: number isDownloadsLoading: boolean sales: number + ownAccount: boolean } const ProfileContext = createContext({} as ProfileProviderValue) @@ -46,17 +47,18 @@ const clearedProfile: Profile = { function ProfileProvider({ accountId, accountEns, + ownAccount, children }: { accountId: string accountEns: string + ownAccount: boolean children: ReactNode }): ReactElement { const { chainIds } = useUserPreferences() const { appConfig } = useMarketMetadata() const [isEthAddress, setIsEthAddress] = useState() - // // Do nothing in all following effects // when accountId is no ETH address @@ -111,7 +113,8 @@ function ProfileProvider({ const result = await getPublishedAssets( accountId, chainIds, - cancelTokenSource.token + cancelTokenSource.token, + ownAccount ) setAssets(result.results) setAssetsTotal(result.totalResults) @@ -134,7 +137,13 @@ function ProfileProvider({ return () => { cancelTokenSource.cancel() } - }, [accountId, appConfig.metadataCacheUri, chainIds, isEthAddress]) + }, [ + accountId, + appConfig.metadataCacheUri, + chainIds, + isEthAddress, + ownAccount + ]) // // DOWNLOADS @@ -154,11 +163,13 @@ function ProfileProvider({ for (let i = 0; i < tokenOrders?.length; i++) { dtList.push(tokenOrders[i].datatoken.address) } + const downloads = await getDownloadAssets( dtList, tokenOrders, chainIds, - cancelToken + cancelToken, + ownAccount ) setDownloads(downloads) setDownloadsTotal(downloads.length) @@ -167,7 +178,7 @@ function ProfileProvider({ downloads ) }, - [accountId, chainIds] + [accountId, chainIds, ownAccount] ) useEffect(() => { @@ -230,6 +241,7 @@ function ProfileProvider({ downloads, downloadsTotal, isDownloadsLoading, + ownAccount, sales }} > diff --git a/src/@types/aquarius/BaseQueryParams.d.ts b/src/@types/aquarius/BaseQueryParams.d.ts index 7517480f0..55b8b231e 100644 --- a/src/@types/aquarius/BaseQueryParams.d.ts +++ b/src/@types/aquarius/BaseQueryParams.d.ts @@ -12,4 +12,5 @@ interface BaseQueryParams { aggs?: any filters?: FilterTerm[] ignorePurgatory?: boolean + ignoreState?: boolean } diff --git a/src/@utils/aquarius.ts b/src/@utils/aquarius.ts index 2e0ed6c60..5d77982b2 100644 --- a/src/@utils/aquarius.ts +++ b/src/@utils/aquarius.ts @@ -59,7 +59,22 @@ export function generateBaseQuery( getFilterTerm('_index', 'aquarius'), ...(baseQueryParams.ignorePurgatory ? [] - : [getFilterTerm('purgatory.state', false)]) + : [getFilterTerm('purgatory.state', false)]), + ...(baseQueryParams.ignoreState + ? [] + : [ + { + bool: { + must_not: [ + { + term: { + 'nft.state': 5 + } + } + ] + } + } + ]) ] } } @@ -304,6 +319,7 @@ export async function getPublishedAssets( accountId: string, chainIds: number[], cancelToken: CancelToken, + ignoreState = false, page?: number, type?: string, accesType?: string @@ -332,6 +348,7 @@ export async function getPublishedAssets( } }, ignorePurgatory: true, + ignoreState, esPaginationOptions: { from: (Number(page) - 1 || 0) * 9, size: 9 @@ -445,14 +462,17 @@ export async function getDownloadAssets( dtList: string[], tokenOrders: OrdersData[], chainIds: number[], - cancelToken: CancelToken + cancelToken: CancelToken, + ignoreState = false ): Promise { const baseQueryparams = { chainIds, filters: [ getFilterTerm('services.datatokenAddress', dtList), getFilterTerm('services.type', 'access') - ] + ], + ignorePurgatory: true, + ignoreState } as BaseQueryParams const query = generateBaseQuery(baseQueryparams) try { diff --git a/src/components/Profile/History/PublishedList.tsx b/src/components/Profile/History/PublishedList.tsx index 3602cef62..5ce3251d5 100644 --- a/src/components/Profile/History/PublishedList.tsx +++ b/src/components/Profile/History/PublishedList.tsx @@ -8,6 +8,7 @@ import { useCancelToken } from '@hooks/useCancelToken' import Filters from '../../Search/Filters' import { useMarketMetadata } from '@context/MarketMetadata' import { CancelToken } from 'axios' +import { useProfile } from '@context/Profile' export default function PublishedList({ accountId @@ -16,7 +17,7 @@ export default function PublishedList({ }): ReactElement { const { appConfig } = useMarketMetadata() const { chainIds } = useUserPreferences() - + const { ownAccount } = useProfile() const [queryResult, setQueryResult] = useState() const [isLoading, setIsLoading] = useState(false) const [page, setPage] = useState(1) @@ -39,6 +40,7 @@ export default function PublishedList({ accountId.toLowerCase(), chainIds, cancelToken, + ownAccount, page, service, access @@ -50,7 +52,7 @@ export default function PublishedList({ setIsLoading(false) } }, - [] + [ownAccount] ) useEffect(() => { diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index d14b24f94..86955e436 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -13,7 +13,7 @@ export default function PageProfile(): ReactElement { const { accountId, accountEns } = useWeb3() const [finalAccountId, setFinalAccountId] = useState() const [finalAccountEns, setFinalAccountEns] = useState() - + const [ownAccount, setOwnAccount] = useState(false) // Have accountId in path take over, if not present fall back to web3 useEffect(() => { async function init() { @@ -23,6 +23,7 @@ export default function PageProfile(): ReactElement { if (router.asPath === '/profile') { setFinalAccountEns(accountEns) setFinalAccountId(accountId) + setOwnAccount(true) return } @@ -30,6 +31,7 @@ export default function PageProfile(): ReactElement { // Path has ETH address if (web3.utils.isAddress(pathAccount)) { + setOwnAccount(pathAccount === accountId) const finalAccountId = pathAccount || accountId setFinalAccountId(finalAccountId) @@ -45,6 +47,7 @@ export default function PageProfile(): ReactElement { resolvedAccountId === '0x0000000000000000000000000000000000000000' ) return + setOwnAccount(resolvedAccountId === accountId) setFinalAccountId(resolvedAccountId) } } @@ -66,7 +69,11 @@ export default function PageProfile(): ReactElement { title={accountTruncate(finalAccountId)} noPageHeader > - +