Disable trading for markets where oracle was never active (#171)

This commit is contained in:
riordanp 2023-06-15 00:02:40 +01:00 committed by GitHub
parent a229d55ed6
commit b5f6bba803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 1 deletions

View File

@ -301,6 +301,27 @@ const AdvancedTradeForm = () => {
return [minOrderDecimals, minOrderSize]
}, [serumOrPerpMarket])
const isMarketEnabled = useMemo(() => {
const group = mangoStore.getState().group
if (!selectedMarket || !group) return false
if (selectedMarket instanceof PerpMarket) {
return selectedMarket.oracleLastUpdatedSlot !== 0
} else if (selectedMarket instanceof Serum3Market) {
const baseBank = group.getFirstBankByTokenIndex(
selectedMarket.baseTokenIndex
)
const quoteBank = group.getFirstBankByTokenIndex(
selectedMarket.quoteTokenIndex
)
return (
baseBank.oracleLastUpdatedSlot !== 0 &&
(quoteBank.name == 'USDC'
? true
: quoteBank.oracleLastUpdatedSlot !== 0)
)
}
}, [selectedMarket])
/*
* Updates the limit price on page load
*/
@ -459,7 +480,8 @@ const AdvancedTradeForm = () => {
const disabled =
(connected && (!tradeForm.baseSize || !tradeForm.price)) ||
!serumOrPerpMarket ||
parseFloat(tradeForm.baseSize) < serumOrPerpMarket.minOrderSize
parseFloat(tradeForm.baseSize) < serumOrPerpMarket.minOrderSize ||
!isMarketEnabled
return (
<div>