-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate Market Details page (#1381)
- Loading branch information
Showing
9 changed files
with
142 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { mapValues } from 'lodash'; | ||
import { weakMapMemoize } from 'reselect'; | ||
|
||
import { MetadataServiceAssetInfo, MetadataServiceInfoResponse } from '@/constants/assetMetadata'; | ||
|
||
export const parseAssetInfo = weakMapMemoize( | ||
(assetInfo: MetadataServiceAssetInfo, assetId: string) => ({ | ||
assetId, | ||
name: assetInfo.name, | ||
logo: assetInfo.logo, | ||
urls: { | ||
website: assetInfo.urls.website, | ||
technicalDoc: assetInfo.urls.technical_doc, | ||
cmc: assetInfo.urls.cmc, | ||
}, | ||
}) | ||
); | ||
|
||
export const transformAssetsInfo = (assetsInfo: MetadataServiceInfoResponse | undefined) => { | ||
if (assetsInfo == null) { | ||
return assetsInfo; | ||
} | ||
|
||
// Add id field to each assetInfo | ||
return mapValues(assetsInfo, (assetInfo, key) => parseAssetInfo(assetInfo, key)); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
import { transformAssetsInfo } from '../calculators/assets'; | ||
import { selectRawAssetsData } from './base'; | ||
import { selectCurrentMarketInfo } from './markets'; | ||
|
||
export const selectAllAssetsInfo = createSelector([selectRawAssetsData], (assets) => | ||
transformAssetsInfo(assets) | ||
); | ||
|
||
export const selectCurrentMarketAssetInfo = createSelector( | ||
[selectCurrentMarketInfo, selectAllAssetsInfo], | ||
(currentMarketInfo, assets) => { | ||
if (currentMarketInfo == null || assets == null) { | ||
return undefined; | ||
} | ||
|
||
return assets[currentMarketInfo.assetId]; | ||
} | ||
); |
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,8 +1,14 @@ | ||
import { createAppSelector } from '@/state/appTypes'; | ||
import { getCurrentMarketId } from '@/state/perpetualsSelectors'; | ||
|
||
import { calculateAllMarkets } from '../calculators/markets'; | ||
import { selectRawMarketsData } from './base'; | ||
|
||
export const selectAllMarketsInfo = createAppSelector([selectRawMarketsData], (markets) => | ||
calculateAllMarkets(markets) | ||
); | ||
|
||
export const selectCurrentMarketInfo = createAppSelector( | ||
[selectAllMarketsInfo, getCurrentMarketId], | ||
(markets, currentMarketId) => (currentMarketId ? markets?.[currentMarketId] : undefined) | ||
); |
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
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