-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: market loading using the wrong data source (#1565)
- Loading branch information
Showing
4 changed files
with
39 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { useMetadataService } from './useMetadataService'; | ||
import { usePerpetualMarkets } from './userPerpetualMarkets'; | ||
import { mergeLoadableStatusState } from '@/bonsai/lib/mapLoadable'; | ||
import { BonsaiCore } from '@/bonsai/ontology'; | ||
|
||
import { useAppSelector } from '@/state/appTypes'; | ||
|
||
import { getMarketIdFromAsset } from '@/lib/assetUtils'; | ||
import { orEmptyRecord } from '@/lib/typeUtils'; | ||
|
||
export const useLaunchableMarkets = () => { | ||
const perpetualMarketsFetch = usePerpetualMarkets(); | ||
const metadataServiceData = useMetadataService(); | ||
const perpsRaw = orEmptyRecord(useAppSelector(BonsaiCore.markets.markets.data)); | ||
const assetsRaw = orEmptyRecord(useAppSelector(BonsaiCore.markets.assets.data)); | ||
const loadingStateMarkets = useAppSelector(BonsaiCore.markets.markets.loading); | ||
const loadingStateAssets = useAppSelector(BonsaiCore.markets.assets.loading); | ||
const loadingState = mergeLoadableStatusState(loadingStateMarkets, loadingStateAssets); | ||
|
||
const filteredPotentialMarkets: { id: string; asset: string }[] = useMemo(() => { | ||
const assets = Object.keys(metadataServiceData.data).map((asset) => { | ||
const assets = Object.values(assetsRaw).map((asset) => { | ||
return { | ||
id: `${asset}-USD`, | ||
asset, | ||
id: getMarketIdFromAsset(asset.assetId), | ||
asset: asset.assetId, | ||
}; | ||
}); | ||
|
||
return assets.filter(({ id }) => { | ||
return !perpetualMarketsFetch.data?.[id]; | ||
return perpsRaw[id] == null; | ||
}); | ||
}, [perpetualMarketsFetch.data, metadataServiceData.data]); | ||
}, [assetsRaw, perpsRaw]); | ||
|
||
return { | ||
...metadataServiceData, | ||
data: filteredPotentialMarkets, | ||
isLoading: | ||
(Object.keys(perpsRaw).length === 0 || Object.keys(assetsRaw).length === 0) && | ||
(loadingState === 'idle' || loadingState === 'pending'), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters