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

quick refactor of AssetList data flow

This commit is contained in:
Matthias Kretschmann 2021-10-21 12:31:19 +01:00
parent b6cfe6de34
commit 032b3e1496
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 21 additions and 11 deletions

View File

@ -5,6 +5,7 @@ interface EsPaginationOptions {
interface BaseQueryParams { interface BaseQueryParams {
chainIds: number[] chainIds: number[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nestedQuery?: any nestedQuery?: any
esPaginationOptions?: EsPaginationOptions esPaginationOptions?: EsPaginationOptions
sortOptions?: SortOptions sortOptions?: SortOptions

View File

@ -9,6 +9,10 @@ import { PriceList, getAssetsPriceList } from './subgraph'
import axios, { CancelToken, AxiosResponse } from 'axios' import axios, { CancelToken, AxiosResponse } from 'axios'
import { OrdersData_tokenOrders as OrdersData } from '../@types/apollo/OrdersData' import { OrdersData_tokenOrders as OrdersData } from '../@types/apollo/OrdersData'
import { metadataCacheUri } from '../../app.config' import { metadataCacheUri } from '../../app.config'
import {
SortDirectionOptions,
SortTermOptions
} from '../@types/aquarius/SearchQuery'
export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476 export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476

View File

@ -41,22 +41,27 @@ const AssetList: React.FC<AssetListProps> = ({
noPublisher noPublisher
}) => { }) => {
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()
const [assetsWithPrices, setAssetWithPrices] = useState<AssetListPrices[]>() const [assetsWithPrices, setAssetsWithPrices] = useState<AssetListPrices[]>()
const [loading, setLoading] = useState<boolean>(true) const [loading, setLoading] = useState<boolean>(isLoading)
const isMounted = useIsMounted() const isMounted = useIsMounted()
useEffect(() => { useEffect(() => {
if (!assets) return if (!assets) return
isLoading && setLoading(true)
const initialAssets: AssetListPrices[] = assets.map((asset) => ({
ddo: asset,
price: null
}))
setAssetsWithPrices(initialAssets)
setLoading(false)
async function fetchPrices() { async function fetchPrices() {
const asset = await getAssetsBestPrices(assets) const assetsWithPrices = await getAssetsBestPrices(assets)
if (!isMounted()) return if (!isMounted()) return
setAssetWithPrices(asset) setAssetsWithPrices(assetsWithPrices)
setLoading(false)
} }
fetchPrices() fetchPrices()
}, [assets]) }, [assets, isMounted])
// // This changes the page field inside the query // // This changes the page field inside the query
function handlePageChange(selected: number) { function handlePageChange(selected: number) {
@ -72,9 +77,7 @@ const AssetList: React.FC<AssetListProps> = ({
<div className={styleClasses}> <div className={styleClasses}>
<div className={styles.empty}>No network selected</div> <div className={styles.empty}>No network selected</div>
</div> </div>
) : assetsWithPrices && ) : assetsWithPrices && !loading ? (
!loading &&
(isLoading === undefined || isLoading === false) ? (
<> <>
<div className={styleClasses}> <div className={styleClasses}>
{assetsWithPrices.length > 0 ? ( {assetsWithPrices.length > 0 ? (

View File

@ -38,6 +38,7 @@ import AssetActionHistoryTable from '../AssetActionHistoryTable'
import ComputeJobs from '../../../Profile/History/ComputeJobs' import ComputeJobs from '../../../Profile/History/ComputeJobs'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { useIsMounted } from '@hooks/useIsMounted' import { useIsMounted } from '@hooks/useIsMounted'
import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery'
export default function Compute({ export default function Compute({
dtBalance, dtBalance,

View File

@ -15,6 +15,7 @@ import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanpr
import { useSiteMetadata } from '@hooks/useSiteMetadata' import { useSiteMetadata } from '@hooks/useSiteMetadata'
import FormActions from './FormActions' import FormActions from './FormActions'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery'
export default function FormEditComputeDataset({ export default function FormEditComputeDataset({
data, data,