Skip to content

Commit

Permalink
quick refactor of AssetList data flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Oct 27, 2021
1 parent b6cfe6d commit 032b3e1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/@types/aquarius/BaseQueryParams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface EsPaginationOptions {

interface BaseQueryParams {
chainIds: number[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nestedQuery?: any
esPaginationOptions?: EsPaginationOptions
sortOptions?: SortOptions
Expand Down
4 changes: 4 additions & 0 deletions src/@utils/aquarius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { PriceList, getAssetsPriceList } from './subgraph'
import axios, { CancelToken, AxiosResponse } from 'axios'
import { OrdersData_tokenOrders as OrdersData } from '../@types/apollo/OrdersData'
import { metadataCacheUri } from '../../app.config'
import {
SortDirectionOptions,
SortTermOptions
} from '../@types/aquarius/SearchQuery'

export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476

Expand Down
25 changes: 14 additions & 11 deletions src/components/@shared/AssetList/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ const AssetList: React.FC<AssetListProps> = ({
noPublisher
}) => {
const { chainIds } = useUserPreferences()
const [assetsWithPrices, setAssetWithPrices] = useState<AssetListPrices[]>()
const [loading, setLoading] = useState<boolean>(true)
const [assetsWithPrices, setAssetsWithPrices] = useState<AssetListPrices[]>()
const [loading, setLoading] = useState<boolean>(isLoading)
const isMounted = useIsMounted()

useEffect(() => {
if (!assets) return
isLoading && setLoading(true)

const initialAssets: AssetListPrices[] = assets.map((asset) => ({
ddo: asset,
price: null
}))
setAssetsWithPrices(initialAssets)
setLoading(false)

async function fetchPrices() {
const asset = await getAssetsBestPrices(assets)
const assetsWithPrices = await getAssetsBestPrices(assets)
if (!isMounted()) return
setAssetWithPrices(asset)
setLoading(false)
setAssetsWithPrices(assetsWithPrices)
}

fetchPrices()
}, [assets])
}, [assets, isMounted])

// // This changes the page field inside the query
function handlePageChange(selected: number) {
Expand All @@ -72,9 +77,7 @@ const AssetList: React.FC<AssetListProps> = ({
<div className={styleClasses}>
<div className={styles.empty}>No network selected</div>
</div>
) : assetsWithPrices &&
!loading &&
(isLoading === undefined || isLoading === false) ? (
) : assetsWithPrices && !loading ? (
<>
<div className={styleClasses}>
{assetsWithPrices.length > 0 ? (
Expand Down
1 change: 1 addition & 0 deletions src/components/Asset/AssetActions/Compute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import AssetActionHistoryTable from '../AssetActionHistoryTable'
import ComputeJobs from '../../../Profile/History/ComputeJobs'
import { useCancelToken } from '@hooks/useCancelToken'
import { useIsMounted } from '@hooks/useIsMounted'
import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery'

export default function Compute({
dtBalance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanpr
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import FormActions from './FormActions'
import { useCancelToken } from '@hooks/useCancelToken'
import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery'

export default function FormEditComputeDataset({
data,
Expand Down

0 comments on commit 032b3e1

Please sign in to comment.