Skip to content

Commit

Permalink
fix: null oracle price for new markets (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Nov 16, 2024
1 parent 18a6677 commit 0e87b69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/hooks/useMarketsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ export const useMarketsData = ({
const markets = useMemo(() => {
const listOfMarkets = Object.values(allPerpetualMarkets)
.filter(isTruthy)
// temporarily filter out markets with empty/0 oracle price
.filter((m) => isTruthy(m.oraclePrice))
// temporary filterout TRUMPWIN until the backend is working
.filter(
(m) => m.assetId !== 'TRUMPWIN' || featureFlags[StatsigFlags.ffShowPredictionMarketsUi]
Expand Down
19 changes: 18 additions & 1 deletion src/views/forms/TradeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ import {
getTradeFormInputs,
useTradeFormData,
} from '@/state/inputsSelectors';
import { getCurrentMarketConfig } from '@/state/perpetualsSelectors';
import {
getCurrentMarketConfig,
getCurrentMarketId,
getCurrentMarketOraclePrice,
} from '@/state/perpetualsSelectors';

import abacusStateManager from '@/lib/abacus';
import { isTruthy } from '@/lib/isTruthy';
import { getSelectedOrderSide, getTradeInputAlert } from '@/lib/tradeData';

import { CanvasOrderbook } from '../CanvasOrderbook/CanvasOrderbook';
Expand Down Expand Up @@ -92,6 +97,9 @@ export const TradeForm = ({
const { tickSizeDecimals, stepSizeDecimals } =
useAppSelector(getCurrentMarketConfig, shallowEqual) ?? {};

const oraclePrice = useAppSelector(getCurrentMarketOraclePrice);
const currentMarketId = useAppSelector(getCurrentMarketId);

const tradeFormInputValues = useAppSelector(getTradeFormInputs, shallowEqual);

const currentTradeData = useAppSelector(getInputTradeData, shallowEqual);
Expand Down Expand Up @@ -323,6 +331,15 @@ export const TradeForm = ({
/>
);

// prevent real trading if null/zero oracle price or we are out of sync with abacus somehow
if (!isTruthy(oraclePrice) || currentMarketId !== marketId) {
return (
<div tw="flex h-full w-full items-center p-1 text-center">
{stringGetter({ key: STRING_KEYS.SOMETHING_WENT_WRONG })}
</div>
);
}

return (
<$TradeForm onSubmit={onSubmit} className={className}>
{currentStep && currentStep !== MobilePlaceOrderSteps.EditOrder ? (
Expand Down

0 comments on commit 0e87b69

Please sign in to comment.