Skip to content

Commit

Permalink
megalodon-ontology
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Dec 20, 2024
1 parent 5cb0dbd commit e2f1279
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/abacus-ts/selectors/assets.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { createSelector } from 'reselect';

import { transformAssetsInfo } from '../calculators/assets';
import { selectRawAssetsData } from './base';
import { selectRawAssets, selectRawAssetsData } from './base';
import { selectCurrentMarketInfo } from './markets';

export const selectAllAssetsInfo = createSelector([selectRawAssetsData], (assets) =>
transformAssetsInfo(assets)
);

export const selectAllAssetsInfoLoading = createSelector(
[selectRawAssets],
(assets) => assets.status
);

export const selectCurrentMarketAssetInfo = createSelector(
[selectCurrentMarketInfo, selectAllAssetsInfo],
(currentMarketInfo, assets) => {
Expand Down
5 changes: 5 additions & 0 deletions src/abacus-ts/selectors/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const selectRawAccountState = (state: RootState) => state.raw.account;
export const selectRawMarkets = (state: RootState) => state.raw.markets.allMarkets;
export const selectRawMarketsData = (state: RootState) => state.raw.markets.allMarkets.data;
export const selectRawAssetsData = (state: RootState) => state.raw.markets.assets.data;
export const selectRawAssets = (state: RootState) => state.raw.markets.assets;

export const selectRawParentSubaccount = (state: RootState) => state.raw.account.parentSubaccount;
export const selectRawParentSubaccountData = (state: RootState) =>
Expand All @@ -31,6 +32,10 @@ export const selectRawIndexerHeightData = (state: RootState) =>
state.raw.heights.indexerHeight.data;
export const selectRawValidatorHeightData = (state: RootState) =>
state.raw.heights.validatorHeight.data;
export const selectRawIndexerHeightDataLoading = (state: RootState) =>
state.raw.heights.indexerHeight.status;
export const selectRawValidatorHeightDataLoading = (state: RootState) =>
state.raw.heights.validatorHeight.status;

export const selectRawFillsRest = (state: RootState) => state.raw.account.fills;
export const selectRawOrdersRest = (state: RootState) => state.raw.account.orders;
Expand Down
7 changes: 6 additions & 1 deletion src/abacus-ts/selectors/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { createAppSelector } from '@/state/appTypes';
import { getCurrentMarketId } from '@/state/perpetualsSelectors';

import { calculateAllMarkets } from '../calculators/markets';
import { selectRawMarketsData } from './base';
import { selectRawMarkets, selectRawMarketsData } from './base';

export const selectAllMarketsInfo = createAppSelector([selectRawMarketsData], (markets) =>
calculateAllMarkets(markets)
);

export const selectAllMarketsInfoLoading = createAppSelector(
[selectRawMarkets],
(markets) => markets.status
);

export const selectCurrentMarketInfo = createAppSelector(
[selectAllMarketsInfo, getCurrentMarketId],
(markets, currentMarketId) => (currentMarketId ? markets?.[currentMarketId] : undefined)
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSeen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef } from 'react';

import { selectRawIndexerHeightData } from '@/abacus-ts/selectors/base';
import { MegalodonCore } from '@/abacus-ts/ontology';
import { shallowEqual } from 'react-redux';

import { getUserWalletAddress } from '@/state/accountSelectors';
Expand All @@ -14,7 +14,7 @@ export function useViewPanel(
) {
const networkId = useAppSelector(getSelectedNetwork);
const walletId = useAppSelector(getUserWalletAddress);
const height = useAppSelector(selectRawIndexerHeightData);
const height = useAppSelector(MegalodonCore.network.indexerHeight.data);
const lastSetCore = useRef<any[]>([]);

const dispatch = useAppDispatch();
Expand Down
6 changes: 3 additions & 3 deletions src/state/accountSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selectRawIndexerHeightData } from '@/abacus-ts/selectors/base';
import { MegalodonCore } from '@/abacus-ts/ontology';
import { OrderSide } from '@dydxprotocol/v4-client-js';
import BigNumber from 'bignumber.js';
import { groupBy, sum } from 'lodash';
Expand Down Expand Up @@ -702,7 +702,7 @@ export const createGetUnseenOrdersCount = () =>
createAppSelector(
[
getCurrentAccountMemory,
selectRawIndexerHeightData,
MegalodonCore.network.indexerHeight.data,
getSubaccountOrders,
(state, market: string | undefined) => market,
],
Expand Down Expand Up @@ -734,7 +734,7 @@ export const createGetUnseenFillsCount = () =>
createAppSelector(
[
getCurrentAccountMemory,
selectRawIndexerHeightData,
MegalodonCore.network.indexerHeight.data,
getSubaccountFills,
(state, market: string | undefined) => market,
],
Expand Down
8 changes: 3 additions & 5 deletions src/views/MarketDetails/CurrentMarketDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { selectCurrentMarketAssetInfo } from '@/abacus-ts/selectors/assets';
import { selectCurrentMarketInfo } from '@/abacus-ts/selectors/markets';
import { MegalodonHelpers } from '@/abacus-ts/ontology';
import { IndexerPerpetualMarketType } from '@/types/indexer/indexerApiGen';
import BigNumber from 'bignumber.js';
import { shallowEqual } from 'react-redux';

import { STRING_KEYS } from '@/constants/localization';

Expand All @@ -22,8 +20,8 @@ import { MarketDetails } from './MarketDetails';

export const CurrentMarketDetails = () => {
const stringGetter = useStringGetter();
const currentMarketData = useAppSelector(selectCurrentMarketInfo, shallowEqual);
const asset = useAppSelector(selectCurrentMarketAssetInfo);
const currentMarketData = useAppSelector(MegalodonHelpers.currentMarket.marketInfo);
const asset = useAppSelector(MegalodonHelpers.currentMarket.assetInfo);

const {
displayableAsset,
Expand Down

0 comments on commit e2f1279

Please sign in to comment.