From 70d074e8252b8e6014a945566844401f30efffc6 Mon Sep 17 00:00:00 2001 From: jaredvu Date: Fri, 20 Dec 2024 13:53:20 -0800 Subject: [PATCH] fix: raw asset structure --- src/abacus-ts/calculators/assets.ts | 34 +++++++++++++++++------------ src/abacus-ts/rawTypes.ts | 2 +- src/abacus-ts/rest/assets.ts | 15 ++++++++++++- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/abacus-ts/calculators/assets.ts b/src/abacus-ts/calculators/assets.ts index d0ecad118..a74350bc8 100644 --- a/src/abacus-ts/calculators/assets.ts +++ b/src/abacus-ts/calculators/assets.ts @@ -1,22 +1,28 @@ import { mapValues } from 'lodash'; import { weakMapMemoize } from 'reselect'; -import { MetadataServiceAssetInfo, MetadataServiceInfoResponse } from '@/constants/assetMetadata'; +import { getTickSizeDecimalsFromPrice } from '@/lib/numbers'; -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, - }, - }) -); +import { AssetInfo, AssetInfos } from '../rawTypes'; -export const transformAssetsInfo = (assetsInfo: MetadataServiceInfoResponse | undefined) => { +export const parseAssetInfo = weakMapMemoize((assetInfo: AssetInfo, assetId: string) => ({ + assetId, + name: assetInfo.name, + logo: assetInfo.logo, + price: assetInfo.price, + marketCap: assetInfo.market_cap, + volume24h: assetInfo.volume_24h, + percentChange24h: assetInfo.percent_change_24h, + reportedMarketCap: assetInfo.self_reported_market_cap, + tickSizeDecimals: getTickSizeDecimalsFromPrice(assetInfo.price), + urls: { + website: assetInfo.urls.website, + technicalDoc: assetInfo.urls.technical_doc, + cmc: assetInfo.urls.cmc, + }, +})); + +export const transformAssetsInfo = (assetsInfo: AssetInfos | undefined) => { if (assetsInfo == null) { return assetsInfo; } diff --git a/src/abacus-ts/rawTypes.ts b/src/abacus-ts/rawTypes.ts index fe6ea7f72..aa08f9bf5 100644 --- a/src/abacus-ts/rawTypes.ts +++ b/src/abacus-ts/rawTypes.ts @@ -46,5 +46,5 @@ export interface ChildSubaccountData { assetPositions: { [symbol: string]: IndexerAssetPositionResponseObject }; } -export type AssetInfo = MetadataServiceAssetInfo & { id: string; priceData?: MetadataServicePrice }; +export type AssetInfo = MetadataServiceAssetInfo & MetadataServicePrice & { id: string }; export type AssetInfos = Record; diff --git a/src/abacus-ts/rest/assets.ts b/src/abacus-ts/rest/assets.ts index 19237dd6b..c3c7ea07d 100644 --- a/src/abacus-ts/rest/assets.ts +++ b/src/abacus-ts/rest/assets.ts @@ -1,6 +1,7 @@ import { QueryObserver } from '@tanstack/react-query'; import { mapValues } from 'lodash'; +import { MetadataServicePrice } from '@/constants/assetMetadata'; import { timeUnits } from '@/constants/time'; import { type RootStore } from '@/state/_store'; @@ -28,7 +29,19 @@ export function setUpAssetsQuery(store: RootStore) { setAllAssetsRaw( mapLoadableData(queryResultToLoadable(result), (map) => { const [info, prices] = map; - return mapValues(info, (v, id) => ({ ...v, id, priceData: prices[id] })); + return mapValues(info, (assetInfo, id) => { + const priceData = + prices[id] ?? + ({ + price: null, + percent_change_24h: null, + volume_24h: null, + market_cap: null, + self_reported_market_cap: null, + } satisfies MetadataServicePrice); + + return { ...assetInfo, ...priceData, id }; + }); }) ) );