1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

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 <m@kretschmann.io>
This commit is contained in:
mihaisc 2022-10-26 11:45:20 +03:00 committed by GitHub
parent 51b167fb14
commit 5c02da8597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 14 deletions

View File

@ -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:

View File

@ -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<boolean>()
//
// 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
}}
>

View File

@ -12,4 +12,5 @@ interface BaseQueryParams {
aggs?: any
filters?: FilterTerm[]
ignorePurgatory?: boolean
ignoreState?: boolean
}

View File

@ -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<DownloadedAsset[]> {
const baseQueryparams = {
chainIds,
filters: [
getFilterTerm('services.datatokenAddress', dtList),
getFilterTerm('services.type', 'access')
]
],
ignorePurgatory: true,
ignoreState
} as BaseQueryParams
const query = generateBaseQuery(baseQueryparams)
try {

View File

@ -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<PagedAssets>()
const [isLoading, setIsLoading] = useState(false)
const [page, setPage] = useState<number>(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(() => {

View File

@ -13,7 +13,7 @@ export default function PageProfile(): ReactElement {
const { accountId, accountEns } = useWeb3()
const [finalAccountId, setFinalAccountId] = useState<string>()
const [finalAccountEns, setFinalAccountEns] = useState<string>()
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
>
<ProfileProvider accountId={finalAccountId} accountEns={finalAccountEns}>
<ProfileProvider
accountId={finalAccountId}
accountEns={finalAccountEns}
ownAccount={ownAccount}
>
<ProfilePage accountId={finalAccountId} />
</ProfileProvider>
</Page>