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:
parent
51b167fb14
commit
5c02da8597
@ -76,8 +76,9 @@ function AssetProvider({
|
|||||||
LoggerInstance.error(`[asset] Failed getting asset for ${did}`, asset)
|
LoggerInstance.error(`[asset] Failed getting asset for ${did}`, asset)
|
||||||
return
|
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
|
let state
|
||||||
switch (asset.nft.state) {
|
switch (asset.nft.state) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -29,6 +29,7 @@ interface ProfileProviderValue {
|
|||||||
downloadsTotal: number
|
downloadsTotal: number
|
||||||
isDownloadsLoading: boolean
|
isDownloadsLoading: boolean
|
||||||
sales: number
|
sales: number
|
||||||
|
ownAccount: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProfileContext = createContext({} as ProfileProviderValue)
|
const ProfileContext = createContext({} as ProfileProviderValue)
|
||||||
@ -46,17 +47,18 @@ const clearedProfile: Profile = {
|
|||||||
function ProfileProvider({
|
function ProfileProvider({
|
||||||
accountId,
|
accountId,
|
||||||
accountEns,
|
accountEns,
|
||||||
|
ownAccount,
|
||||||
children
|
children
|
||||||
}: {
|
}: {
|
||||||
accountId: string
|
accountId: string
|
||||||
accountEns: string
|
accountEns: string
|
||||||
|
ownAccount: boolean
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { chainIds } = useUserPreferences()
|
const { chainIds } = useUserPreferences()
|
||||||
const { appConfig } = useMarketMetadata()
|
const { appConfig } = useMarketMetadata()
|
||||||
|
|
||||||
const [isEthAddress, setIsEthAddress] = useState<boolean>()
|
const [isEthAddress, setIsEthAddress] = useState<boolean>()
|
||||||
|
|
||||||
//
|
//
|
||||||
// Do nothing in all following effects
|
// Do nothing in all following effects
|
||||||
// when accountId is no ETH address
|
// when accountId is no ETH address
|
||||||
@ -111,7 +113,8 @@ function ProfileProvider({
|
|||||||
const result = await getPublishedAssets(
|
const result = await getPublishedAssets(
|
||||||
accountId,
|
accountId,
|
||||||
chainIds,
|
chainIds,
|
||||||
cancelTokenSource.token
|
cancelTokenSource.token,
|
||||||
|
ownAccount
|
||||||
)
|
)
|
||||||
setAssets(result.results)
|
setAssets(result.results)
|
||||||
setAssetsTotal(result.totalResults)
|
setAssetsTotal(result.totalResults)
|
||||||
@ -134,7 +137,13 @@ function ProfileProvider({
|
|||||||
return () => {
|
return () => {
|
||||||
cancelTokenSource.cancel()
|
cancelTokenSource.cancel()
|
||||||
}
|
}
|
||||||
}, [accountId, appConfig.metadataCacheUri, chainIds, isEthAddress])
|
}, [
|
||||||
|
accountId,
|
||||||
|
appConfig.metadataCacheUri,
|
||||||
|
chainIds,
|
||||||
|
isEthAddress,
|
||||||
|
ownAccount
|
||||||
|
])
|
||||||
|
|
||||||
//
|
//
|
||||||
// DOWNLOADS
|
// DOWNLOADS
|
||||||
@ -154,11 +163,13 @@ function ProfileProvider({
|
|||||||
for (let i = 0; i < tokenOrders?.length; i++) {
|
for (let i = 0; i < tokenOrders?.length; i++) {
|
||||||
dtList.push(tokenOrders[i].datatoken.address)
|
dtList.push(tokenOrders[i].datatoken.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloads = await getDownloadAssets(
|
const downloads = await getDownloadAssets(
|
||||||
dtList,
|
dtList,
|
||||||
tokenOrders,
|
tokenOrders,
|
||||||
chainIds,
|
chainIds,
|
||||||
cancelToken
|
cancelToken,
|
||||||
|
ownAccount
|
||||||
)
|
)
|
||||||
setDownloads(downloads)
|
setDownloads(downloads)
|
||||||
setDownloadsTotal(downloads.length)
|
setDownloadsTotal(downloads.length)
|
||||||
@ -167,7 +178,7 @@ function ProfileProvider({
|
|||||||
downloads
|
downloads
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
[accountId, chainIds]
|
[accountId, chainIds, ownAccount]
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -230,6 +241,7 @@ function ProfileProvider({
|
|||||||
downloads,
|
downloads,
|
||||||
downloadsTotal,
|
downloadsTotal,
|
||||||
isDownloadsLoading,
|
isDownloadsLoading,
|
||||||
|
ownAccount,
|
||||||
sales
|
sales
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
1
src/@types/aquarius/BaseQueryParams.d.ts
vendored
1
src/@types/aquarius/BaseQueryParams.d.ts
vendored
@ -12,4 +12,5 @@ interface BaseQueryParams {
|
|||||||
aggs?: any
|
aggs?: any
|
||||||
filters?: FilterTerm[]
|
filters?: FilterTerm[]
|
||||||
ignorePurgatory?: boolean
|
ignorePurgatory?: boolean
|
||||||
|
ignoreState?: boolean
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,22 @@ export function generateBaseQuery(
|
|||||||
getFilterTerm('_index', 'aquarius'),
|
getFilterTerm('_index', 'aquarius'),
|
||||||
...(baseQueryParams.ignorePurgatory
|
...(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,
|
accountId: string,
|
||||||
chainIds: number[],
|
chainIds: number[],
|
||||||
cancelToken: CancelToken,
|
cancelToken: CancelToken,
|
||||||
|
ignoreState = false,
|
||||||
page?: number,
|
page?: number,
|
||||||
type?: string,
|
type?: string,
|
||||||
accesType?: string
|
accesType?: string
|
||||||
@ -332,6 +348,7 @@ export async function getPublishedAssets(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ignorePurgatory: true,
|
ignorePurgatory: true,
|
||||||
|
ignoreState,
|
||||||
esPaginationOptions: {
|
esPaginationOptions: {
|
||||||
from: (Number(page) - 1 || 0) * 9,
|
from: (Number(page) - 1 || 0) * 9,
|
||||||
size: 9
|
size: 9
|
||||||
@ -445,14 +462,17 @@ export async function getDownloadAssets(
|
|||||||
dtList: string[],
|
dtList: string[],
|
||||||
tokenOrders: OrdersData[],
|
tokenOrders: OrdersData[],
|
||||||
chainIds: number[],
|
chainIds: number[],
|
||||||
cancelToken: CancelToken
|
cancelToken: CancelToken,
|
||||||
|
ignoreState = false
|
||||||
): Promise<DownloadedAsset[]> {
|
): Promise<DownloadedAsset[]> {
|
||||||
const baseQueryparams = {
|
const baseQueryparams = {
|
||||||
chainIds,
|
chainIds,
|
||||||
filters: [
|
filters: [
|
||||||
getFilterTerm('services.datatokenAddress', dtList),
|
getFilterTerm('services.datatokenAddress', dtList),
|
||||||
getFilterTerm('services.type', 'access')
|
getFilterTerm('services.type', 'access')
|
||||||
]
|
],
|
||||||
|
ignorePurgatory: true,
|
||||||
|
ignoreState
|
||||||
} as BaseQueryParams
|
} as BaseQueryParams
|
||||||
const query = generateBaseQuery(baseQueryparams)
|
const query = generateBaseQuery(baseQueryparams)
|
||||||
try {
|
try {
|
||||||
|
@ -8,6 +8,7 @@ import { useCancelToken } from '@hooks/useCancelToken'
|
|||||||
import Filters from '../../Search/Filters'
|
import Filters from '../../Search/Filters'
|
||||||
import { useMarketMetadata } from '@context/MarketMetadata'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
import { CancelToken } from 'axios'
|
import { CancelToken } from 'axios'
|
||||||
|
import { useProfile } from '@context/Profile'
|
||||||
|
|
||||||
export default function PublishedList({
|
export default function PublishedList({
|
||||||
accountId
|
accountId
|
||||||
@ -16,7 +17,7 @@ export default function PublishedList({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { appConfig } = useMarketMetadata()
|
const { appConfig } = useMarketMetadata()
|
||||||
const { chainIds } = useUserPreferences()
|
const { chainIds } = useUserPreferences()
|
||||||
|
const { ownAccount } = useProfile()
|
||||||
const [queryResult, setQueryResult] = useState<PagedAssets>()
|
const [queryResult, setQueryResult] = useState<PagedAssets>()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [page, setPage] = useState<number>(1)
|
const [page, setPage] = useState<number>(1)
|
||||||
@ -39,6 +40,7 @@ export default function PublishedList({
|
|||||||
accountId.toLowerCase(),
|
accountId.toLowerCase(),
|
||||||
chainIds,
|
chainIds,
|
||||||
cancelToken,
|
cancelToken,
|
||||||
|
ownAccount,
|
||||||
page,
|
page,
|
||||||
service,
|
service,
|
||||||
access
|
access
|
||||||
@ -50,7 +52,7 @@ export default function PublishedList({
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[]
|
[ownAccount]
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -13,7 +13,7 @@ export default function PageProfile(): ReactElement {
|
|||||||
const { accountId, accountEns } = useWeb3()
|
const { accountId, accountEns } = useWeb3()
|
||||||
const [finalAccountId, setFinalAccountId] = useState<string>()
|
const [finalAccountId, setFinalAccountId] = useState<string>()
|
||||||
const [finalAccountEns, setFinalAccountEns] = 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
|
// Have accountId in path take over, if not present fall back to web3
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
@ -23,6 +23,7 @@ export default function PageProfile(): ReactElement {
|
|||||||
if (router.asPath === '/profile') {
|
if (router.asPath === '/profile') {
|
||||||
setFinalAccountEns(accountEns)
|
setFinalAccountEns(accountEns)
|
||||||
setFinalAccountId(accountId)
|
setFinalAccountId(accountId)
|
||||||
|
setOwnAccount(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ export default function PageProfile(): ReactElement {
|
|||||||
|
|
||||||
// Path has ETH address
|
// Path has ETH address
|
||||||
if (web3.utils.isAddress(pathAccount)) {
|
if (web3.utils.isAddress(pathAccount)) {
|
||||||
|
setOwnAccount(pathAccount === accountId)
|
||||||
const finalAccountId = pathAccount || accountId
|
const finalAccountId = pathAccount || accountId
|
||||||
setFinalAccountId(finalAccountId)
|
setFinalAccountId(finalAccountId)
|
||||||
|
|
||||||
@ -45,6 +47,7 @@ export default function PageProfile(): ReactElement {
|
|||||||
resolvedAccountId === '0x0000000000000000000000000000000000000000'
|
resolvedAccountId === '0x0000000000000000000000000000000000000000'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
setOwnAccount(resolvedAccountId === accountId)
|
||||||
setFinalAccountId(resolvedAccountId)
|
setFinalAccountId(resolvedAccountId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +69,11 @@ export default function PageProfile(): ReactElement {
|
|||||||
title={accountTruncate(finalAccountId)}
|
title={accountTruncate(finalAccountId)}
|
||||||
noPageHeader
|
noPageHeader
|
||||||
>
|
>
|
||||||
<ProfileProvider accountId={finalAccountId} accountEns={finalAccountEns}>
|
<ProfileProvider
|
||||||
|
accountId={finalAccountId}
|
||||||
|
accountEns={finalAccountEns}
|
||||||
|
ownAccount={ownAccount}
|
||||||
|
>
|
||||||
<ProfilePage accountId={finalAccountId} />
|
<ProfilePage accountId={finalAccountId} />
|
||||||
</ProfileProvider>
|
</ProfileProvider>
|
||||||
</Page>
|
</Page>
|
||||||
|
Loading…
Reference in New Issue
Block a user