From fe1978f67422b0f22634a26ee7b910a6d886ba0c Mon Sep 17 00:00:00 2001 From: dappbeast Date: Mon, 14 Nov 2022 10:45:24 +1100 Subject: [PATCH] feat: tidy up quote, fix quote errors --- .../common/OptionStatsGrid/index.tsx | 40 ++++----- .../position/PositionStatsCard/index.tsx | 11 ++- .../trade/TradeBoardNoticeSection/index.tsx | 70 +++++++++++++++ .../TradeBoardListMobile.tsx | 20 +++-- .../TradeBoardPriceButton.tsx | 14 +-- .../TradeBoardTableDesktop.tsx | 50 +++++------ .../trade/TradeBoardTableOrList/index.tsx | 12 ++- .../TradeChainPriceButton.tsx | 0 .../{TradeChain => TradeChainTable}/index.tsx | 86 +++++++++---------- app/constants/contracts.ts | 17 ++++ app/constants/ignore.ts | 14 +++ app/constants/layout.ts | 2 +- app/constants/links.ts | 3 +- .../common/ShortYieldValue/index.tsx | 4 +- .../trade/TradeAdvancedBoardCard/index.tsx | 24 ++++-- .../TradeSimpleBoardTable.tsx | 74 ++++++++-------- .../trade/TradeSimpleBoardCard/index.tsx | 1 - app/hooks/market/useBoardQuotesSync.ts | 42 +++++++++ app/hooks/market/useOptionQuotesSync.ts | 7 ++ app/hooks/market/useQuoteBoard.ts | 22 ----- app/hooks/market/useQuoteBoards.ts | 31 ------- app/hooks/market/useSelectedBoard.ts | 7 +- app/page_helpers/PositionPageHelper/index.tsx | 2 +- app/utils/getIsQuoteHidden.ts | 12 +++ sdk/src/board/index.ts | 52 +++++++++-- sdk/src/lyra.ts | 42 +++++++-- sdk/src/market/index.ts | 33 +++++-- sdk/src/option/index.ts | 30 ++++++- sdk/src/quote/getQuoteBoard.ts | 19 ---- sdk/src/quote/index.ts | 36 +++++++- sdk/src/strike/index.ts | 38 +++++++- sdk/src/trade/index.ts | 4 +- ui/components/Alert/index.tsx | 44 +++++++++- ui/theme/index.ts | 4 +- 34 files changed, 580 insertions(+), 287 deletions(-) create mode 100644 app/components/trade/TradeBoardNoticeSection/index.tsx rename app/components/trade/{TradeChain => TradeChainTable}/TradeChainPriceButton.tsx (100%) rename app/components/trade/{TradeChain => TradeChainTable}/index.tsx (81%) create mode 100644 app/constants/ignore.ts create mode 100644 app/hooks/market/useBoardQuotesSync.ts create mode 100644 app/hooks/market/useOptionQuotesSync.ts delete mode 100644 app/hooks/market/useQuoteBoard.ts delete mode 100644 app/hooks/market/useQuoteBoards.ts create mode 100644 app/utils/getIsQuoteHidden.ts delete mode 100644 sdk/src/quote/getQuoteBoard.ts diff --git a/app/components/common/OptionStatsGrid/index.tsx b/app/components/common/OptionStatsGrid/index.tsx index 9ab76f7d..1929c749 100644 --- a/app/components/common/OptionStatsGrid/index.tsx +++ b/app/components/common/OptionStatsGrid/index.tsx @@ -1,53 +1,49 @@ -import Box from '@lyra/ui/components/Box' import Grid from '@lyra/ui/components/Grid' -import useIsMobile from '@lyra/ui/hooks/useIsMobile' import formatNumber from '@lyra/ui/utils/formatNumber' import formatPercentage from '@lyra/ui/utils/formatPercentage' import formatTruncatedUSD from '@lyra/ui/utils/formatTruncatedUSD' import formatUSD from '@lyra/ui/utils/formatUSD' -import { Option } from '@lyrafinance/lyra-js' +import { Option, Quote } from '@lyrafinance/lyra-js' import React from 'react' import { UNIT } from '@/app/constants/bn' import { MAX_IV } from '@/app/constants/contracts' import fromBigNumber from '@/app/utils/fromBigNumber' -import getDefaultQuoteSize from '@/app/utils/getDefaultQuoteSize' import LabelItem from '../LabelItem' type Props = { option: Option - isBuy: boolean + bid: Quote | null + ask: Quote | null } -const OptionStatsGrid = ({ option, isBuy }: Props) => { - const size = getDefaultQuoteSize(option.market().name) - const bid = option.quoteSync(true, size) - const ask = option.quoteSync(false, size) - const quote = isBuy ? bid : ask +const OptionStatsGrid = ({ option, bid, ask }: Props) => { const openInterest = option.longOpenInterest.add(option.shortOpenInterest).mul(option.market().spotPrice).div(UNIT) - const isMobile = useIsMobile() return ( - + + - {!isMobile ? : null} - - - - - + + + + + ) } diff --git a/app/components/position/PositionStatsCard/index.tsx b/app/components/position/PositionStatsCard/index.tsx index f1b09061..26534fad 100644 --- a/app/components/position/PositionStatsCard/index.tsx +++ b/app/components/position/PositionStatsCard/index.tsx @@ -1,24 +1,27 @@ import Card from '@lyra/ui/components/Card' import CardSection from '@lyra/ui/components/Card/CardSection' import Text from '@lyra/ui/components/Text' -import { Option, Position } from '@lyrafinance/lyra-js' +import { Option } from '@lyrafinance/lyra-js' import React from 'react' +import useOptionQuotesSync from '@/app/hooks/market/useOptionQuotesSync' +import getDefaultQuoteSize from '@/app/utils/getDefaultQuoteSize' + import OptionStatsGrid from '../../common/OptionStatsGrid' type Props = { - position: Position option: Option } -const PositionStatsCard = ({ option, position }: Props): JSX.Element | null => { +const PositionStatsCard = ({ option }: Props): JSX.Element | null => { + const { bid, ask } = useOptionQuotesSync(option, getDefaultQuoteSize(option.market().name)) return ( Stats - + ) diff --git a/app/components/trade/TradeBoardNoticeSection/index.tsx b/app/components/trade/TradeBoardNoticeSection/index.tsx new file mode 100644 index 00000000..8ce2e2f9 --- /dev/null +++ b/app/components/trade/TradeBoardNoticeSection/index.tsx @@ -0,0 +1,70 @@ +import Alert from '@lyra/ui/components/Alert' +import { IconType } from '@lyra/ui/components/Icon' +import { MarginProps } from '@lyra/ui/types' +import formatTruncatedDuration from '@lyra/ui/utils/formatTruncatedDuration' +import { Board } from '@lyrafinance/lyra-js' +import React from 'react' + +import { MAX_UTILIZATION, OptionQuotesNullable, StrikeQuotesNullable } from '@/app/constants/contracts' +import { TRADING_CUTOFF_DOC_URL } from '@/app/constants/links' + +type Props = { + board: Board + isGlobalPaused: boolean + quotes: (StrikeQuotesNullable | OptionQuotesNullable)[] +} & MarginProps + +export default function TradeBoardNoticeSection({ board, isGlobalPaused, quotes, ...marginProps }: Props) { + const market = board.market() + if (board.isTradingCutoff || board.isExpired) { + return ( + + ) + } else if (isGlobalPaused || board.isPaused) { + return ( + + ) + } else if (market.liquidity.utilization >= MAX_UTILIZATION) { + return ( + + ) + } else if (!quotes.length) { + return ( + + ) + } else { + return null + } +} diff --git a/app/components/trade/TradeBoardTableOrList/TradeBoardListMobile.tsx b/app/components/trade/TradeBoardTableOrList/TradeBoardListMobile.tsx index 5596236e..a1c278e5 100644 --- a/app/components/trade/TradeBoardTableOrList/TradeBoardListMobile.tsx +++ b/app/components/trade/TradeBoardTableOrList/TradeBoardListMobile.tsx @@ -19,21 +19,25 @@ import { TradeBoardTableOrListProps } from '.' import TradeBoardPriceButton from './TradeBoardPriceButton' const TradeBoardListMobile = ({ - isCall, isBuy, quotes, selectedOption, onSelectOption, - ...styleProps }: TradeBoardTableOrListProps): ListElement => { - const [expandedQuote, setExpandedQuote] = useState<{ bid: Quote; ask: Quote; option: Option } | null>(null) + const [expandedQuote, setExpandedQuote] = useState<{ bid: Quote | null; ask: Quote | null; option: Option } | null>( + null + ) const strikeId = selectedOption?.strike().id return ( - + {quotes.map(({ option, bid, ask }) => { - const quote = isBuy ? bid : ask + const quote = isBuy ? ask : bid + const strike = option.strike() + if (!quote) { + return null + } return ( - + { setExpandedQuote({ option, bid, ask }) @@ -78,7 +82,7 @@ const TradeBoardListMobile = ({ expandedQuote ? ( {expandedQuote.option.market().name} ${fromBigNumber(expandedQuote.option.strike().strikePrice)}{' '} - {isCall ? 'Call' : 'Put'} + {expandedQuote.option.isCall ? 'Call' : 'Put'}  ยท Exp. {formatDate(expandedQuote.option.board().expiryTimestamp, true)} @@ -90,7 +94,7 @@ const TradeBoardListMobile = ({ > {expandedQuote ? ( - + ) : null} diff --git a/app/components/trade/TradeBoardTableOrList/TradeBoardPriceButton.tsx b/app/components/trade/TradeBoardTableOrList/TradeBoardPriceButton.tsx index 5406dfdc..991a372e 100644 --- a/app/components/trade/TradeBoardTableOrList/TradeBoardPriceButton.tsx +++ b/app/components/trade/TradeBoardTableOrList/TradeBoardPriceButton.tsx @@ -6,6 +6,7 @@ import { Quote, QuoteDisabledReason } from '@lyrafinance/lyra-js' import React from 'react' import emptyFunction from '@/app/utils/emptyFunction' +import getIsQuoteHidden from '@/app/utils/getIsQuoteHidden' type Props = { quote: Quote @@ -33,15 +34,6 @@ const getDisabledMessage = (disabledReason: QuoteDisabledReason): string => { } } -const getIsButtonDisabled = (disabledReason: QuoteDisabledReason): boolean => { - switch (disabledReason) { - case QuoteDisabledReason.InsufficientLiquidity: - return false - default: - return true - } -} - const getButtonWidthForMarket = (marketName: string) => { switch (marketName.toLowerCase()) { case 'btc': @@ -57,8 +49,8 @@ export default function TradeBoardPriceButton({ onSelected = emptyFunction, ...styleProps }: Props): ButtonElement { - const { isCall, isBuy, disabledReason } = quote - const isDisabled = disabledReason ? getIsButtonDisabled(disabledReason) : false + const { isBuy, disabledReason } = quote + const isDisabled = disabledReason ? getIsQuoteHidden(disabledReason) : false return (