2021-03-30 15:47:08 -07:00
import React , { useRef , useEffect , useState } from 'react'
import styled from '@emotion/styled'
2021-04-26 05:53:27 -07:00
import { css , keyframes } from '@emotion/react'
2021-03-30 15:47:08 -07:00
import useInterval from '../hooks/useInterval'
import usePrevious from '../hooks/usePrevious'
2021-09-02 22:32:27 -07:00
import { isEqual , getDecimalCount , usdFormatter } from '../utils/'
2021-04-26 05:53:27 -07:00
import {
ArrowUpIcon ,
ArrowDownIcon ,
SwitchHorizontalIcon ,
} from '@heroicons/react/solid'
2021-08-27 17:37:45 -07:00
import { CumulativeSizeIcon , StepSizeIcon } from './icons'
2021-04-02 11:26:21 -07:00
import useMarkPrice from '../hooks/useMarkPrice'
2021-04-05 13:48:24 -07:00
import { ElementTitle } from './styles'
2021-04-13 16:41:04 -07:00
import useMangoStore from '../stores/useMangoStore'
2021-04-26 05:53:27 -07:00
import Tooltip from './Tooltip'
2021-09-04 21:42:37 -07:00
import GroupSize from './GroupSize'
2021-04-26 05:53:27 -07:00
import FloatingElement from './FloatingElement'
2021-09-02 22:32:27 -07:00
import { useOpenOrders } from '../hooks/useOpenOrders'
2021-03-30 15:47:08 -07:00
const Line = styled . div < any > `
text - align : $ { ( props ) = > ( props . invert ? 'left' : 'right' ) } ;
height : 100 % ;
2021-04-26 05:53:27 -07:00
filter : opacity ( 40 % ) ;
2021-03-30 15:47:08 -07:00
$ { ( props ) = > props [ 'data-width' ] && ` width: ${ props [ 'data-width' ] } ; ` }
`
2021-04-26 05:53:27 -07:00
const fadeIn = keyframes `
from {
opacity : 0 ;
}
2021-03-30 15:47:08 -07:00
2021-04-26 05:53:27 -07:00
to {
opacity : 1 ;
2021-04-07 08:44:22 -07:00
}
2021-04-26 05:53:27 -07:00
`
const FlipCard = styled . div `
background - color : transparent ;
height : 100 % ;
perspective : 1000px ;
`
const FlipCardInner = styled . div < any > `
position : relative ;
width : 100 % ;
height : 100 % ;
text - align : center ;
transition : transform 0.8 s ease - out ;
transform - style : preserve - 3 d ;
transform : $ { ( { flip } ) = > ( flip ? 'rotateY(0deg)' : 'rotateY(180deg)' ) } ;
`
const FlipCardFront = styled . div `
position : absolute ;
width : 100 % ;
height : 100 % ;
`
const FlipCardBack = styled . div `
position : absolute ;
width : 100 % ;
height : 100 % ;
transform : rotateY ( 180 deg ) ;
`
const StyledFloatingElement = styled ( FloatingElement ) `
animation : $ { css `
$ { fadeIn } 1 s linear
` };
2021-08-29 21:24:10 -07:00
overflow : hidden ;
2021-04-26 05:53:27 -07:00
`
2021-04-07 08:44:22 -07:00
2021-09-04 20:36:10 -07:00
//ary=[0: {price: 50012.3, size: 0.6991, cumulativeSize: 0.6991, sizePercent: 5, maxSizePercent: 5}, 1: {price: 50012.3, size: 0.6991, cumulativeSize: 0.6991, sizePercent: 5, maxSizePercent: 5}]
//loop through orders, find price group floor, if unique add as key to groupFloors object, sum size within key, repeat until Object.keys(groupFloors).length = depth
2021-09-05 05:43:12 -07:00
const groupBy = ( ordersArray , grouping ) = > {
2021-09-04 21:42:37 -07:00
if ( ! grouping || grouping <= 0 ) {
2021-09-05 05:43:12 -07:00
return ordersArray
2021-09-04 20:36:10 -07:00
}
const groupFloors = { }
2021-09-05 05:43:12 -07:00
for ( let i = 0 ; i < ordersArray . length ; i ++ ) {
if ( typeof ordersArray [ i ] == 'undefined' ) {
2021-09-04 20:36:10 -07:00
break
}
2021-09-05 05:43:12 -07:00
const floor = Math . floor ( ordersArray [ i ] [ 0 ] / grouping ) * grouping
2021-09-04 20:36:10 -07:00
if ( typeof groupFloors [ floor ] == 'undefined' ) {
2021-09-05 05:43:12 -07:00
groupFloors [ floor ] = parseInt ( ordersArray [ i ] [ 1 ] )
2021-09-04 20:36:10 -07:00
} else {
groupFloors [ floor ] = (
2021-09-05 05:43:12 -07:00
parseInt ( ordersArray [ i ] [ 1 ] ) + groupFloors [ floor ]
)
2021-09-04 20:36:10 -07:00
}
}
2021-09-05 05:43:12 -07:00
const groupedOrdersArray = Object . entries ( groupFloors ) . sort ( function ( a , b ) {
2021-09-04 20:36:10 -07:00
if ( ! a || ! b ) {
return - 1
}
return parseInt ( a [ 0 ] ) - parseInt ( b [ 0 ] )
} )
2021-09-05 05:43:12 -07:00
groupedOrdersArray . forEach ( ( entry ) = > {
return [ parseInt ( entry [ 0 ] ) , entry [ 1 ] ]
} )
debugger
return groupedOrdersArray
2021-09-04 20:36:10 -07:00
}
2021-04-26 08:20:55 -07:00
const getCumulativeOrderbookSide = (
orders ,
totalSize ,
2021-08-27 17:37:45 -07:00
maxSize ,
2021-04-26 08:20:55 -07:00
depth ,
2021-09-05 05:43:12 -07:00
backwards = false
2021-04-26 08:20:55 -07:00
) = > {
2021-09-04 21:42:37 -07:00
let cumulative = orders
2021-04-26 08:20:55 -07:00
. slice ( 0 , depth )
. reduce ( ( cumulative , [ price , size ] , i ) = > {
const cumulativeSize = ( cumulative [ i - 1 ] ? . cumulativeSize || 0 ) + size
cumulative . push ( {
price ,
size ,
cumulativeSize ,
sizePercent : Math.round ( ( cumulativeSize / ( totalSize || 1 ) ) * 100 ) ,
2021-08-27 17:37:45 -07:00
maxSizePercent : Math.round ( ( size / ( maxSize || 1 ) ) * 100 ) ,
2021-04-26 08:20:55 -07:00
} )
return cumulative
} , [ ] )
if ( backwards ) {
cumulative = cumulative . reverse ( )
}
return cumulative
}
2021-04-26 05:53:27 -07:00
export default function Orderbook ( { depth = 8 } ) {
2021-06-18 15:38:09 -07:00
const groupConfig = useMangoStore ( ( s ) = > s . selectedMangoGroup . config )
const marketConfig = useMangoStore ( ( s ) = > s . selectedMarket . config )
2021-06-23 12:09:19 -07:00
const orderbook = useMangoStore ( ( s ) = > s . selectedMarket . orderBook )
2021-09-03 13:25:09 -07:00
const market = useMangoStore ( ( s ) = > s . selectedMarket . current )
2021-03-30 15:47:08 -07:00
const markPrice = useMarkPrice ( )
2021-09-02 22:32:27 -07:00
const openOrders = useOpenOrders ( )
2021-09-02 22:45:58 -07:00
const openOrderPrices = openOrders ? . length
2021-09-02 22:32:27 -07:00
? openOrders . map ( ( { order } ) = > order . price )
: [ ]
2021-03-30 15:47:08 -07:00
const currentOrderbookData = useRef ( null )
const lastOrderbookData = useRef ( null )
2021-09-02 15:29:03 -07:00
const previousDepth = usePrevious ( depth )
2021-03-30 15:47:08 -07:00
const [ orderbookData , setOrderbookData ] = useState ( null )
2021-04-26 05:53:27 -07:00
const [ defaultLayout , setDefaultLayout ] = useState ( true )
2021-08-27 17:37:45 -07:00
const [ displayCumulativeSize , setDisplayCumulativeSize ] = useState ( false )
2021-09-04 21:42:37 -07:00
const [ grouping , setGrouping ] = useState ( 1 )
useEffect ( ( ) = > {
if ( market ) {
setGrouping ( market . tickSize )
}
2021-09-05 05:43:12 -07:00
} , [ market ? . publicKey ] )
2021-09-04 21:42:37 -07:00
2021-03-30 15:47:08 -07:00
useInterval ( ( ) = > {
if (
! currentOrderbookData . current ||
JSON . stringify ( currentOrderbookData . current ) !==
2021-09-02 15:29:03 -07:00
JSON . stringify ( lastOrderbookData . current ) ||
previousDepth !== depth
2021-03-30 15:47:08 -07:00
) {
2021-09-04 21:42:37 -07:00
const bids = groupBy ( orderbook ? . bids , grouping ) || [ ]
const asks = groupBy ( orderbook ? . asks , grouping ) || [ ]
2021-03-30 15:47:08 -07:00
const sum = ( total , [ , size ] , index ) = >
index < depth ? total + size : total
const totalSize = bids . reduce ( sum , 0 ) + asks . reduce ( sum , 0 )
2021-08-27 17:37:45 -07:00
const maxSize =
Math . max (
. . . asks . map ( function ( a ) {
return a [ 1 ]
} )
) +
Math . max (
. . . bids . map ( function ( b ) {
return b [ 1 ]
} )
)
2021-09-05 05:43:12 -07:00
debugger
2021-08-27 17:37:45 -07:00
const bidsToDisplay = defaultLayout
2021-09-04 20:36:10 -07:00
? getCumulativeOrderbookSide (
bids ,
totalSize ,
maxSize ,
depth ,
2021-09-05 05:43:12 -07:00
false
2021-09-04 20:36:10 -07:00
)
: getCumulativeOrderbookSide (
bids ,
totalSize ,
maxSize ,
depth / 2 ,
2021-09-05 05:43:12 -07:00
false
2021-09-04 20:36:10 -07:00
)
2021-04-26 05:53:27 -07:00
const asksToDisplay = defaultLayout
2021-09-04 20:36:10 -07:00
? getCumulativeOrderbookSide (
asks ,
totalSize ,
maxSize ,
depth ,
2021-09-05 05:43:12 -07:00
false
2021-09-04 20:36:10 -07:00
)
2021-08-27 17:37:45 -07:00
: getCumulativeOrderbookSide (
asks ,
totalSize ,
maxSize ,
( depth + 1 ) / 2 ,
2021-09-05 05:43:12 -07:00
true
2021-08-27 17:37:45 -07:00
)
2021-03-30 15:47:08 -07:00
currentOrderbookData . current = {
bids : orderbook?.bids ,
asks : orderbook?.asks ,
}
2021-08-04 14:54:44 -07:00
if ( bidsToDisplay [ 0 ] || asksToDisplay [ 0 ] ) {
const bid = bidsToDisplay [ 0 ] ? . price
2021-04-26 05:53:27 -07:00
const ask = defaultLayout
2021-08-04 14:54:44 -07:00
? asksToDisplay [ 0 ] ? . price
: asksToDisplay [ asksToDisplay . length - 1 ] ? . price
let spread , spreadPercentage
if ( bid && ask ) {
spread = ask - bid
spreadPercentage = ( spread / ask ) * 100
}
2021-09-05 05:43:12 -07:00
debugger
2021-04-26 05:53:27 -07:00
setOrderbookData ( {
bids : bidsToDisplay ,
asks : asksToDisplay ,
2021-08-04 14:54:44 -07:00
spread ,
spreadPercentage ,
2021-04-26 05:53:27 -07:00
} )
2021-06-18 11:07:07 -07:00
} else {
2021-06-18 15:38:09 -07:00
setOrderbookData ( null )
2021-04-26 05:53:27 -07:00
}
2021-03-30 15:47:08 -07:00
}
} , 250 )
useEffect ( ( ) = > {
lastOrderbookData . current = {
bids : orderbook?.bids ,
asks : orderbook?.asks ,
}
} , [ orderbook ] )
2021-04-26 05:53:27 -07:00
const handleLayoutChange = ( ) = > {
setDefaultLayout ( ! defaultLayout )
2021-04-26 08:20:55 -07:00
setOrderbookData ( ( prevState ) = > ( {
. . . orderbookData ,
asks : prevState.asks.reverse ( ) ,
} ) )
2021-04-26 05:53:27 -07:00
}
2021-09-04 21:42:37 -07:00
const onGroupSizeChange = ( groupSize ) = > {
setGrouping ( groupSize )
}
2021-04-02 11:26:21 -07:00
return (
< >
2021-04-26 05:53:27 -07:00
< FlipCard >
< FlipCardInner flip = { defaultLayout } >
{ defaultLayout ? (
< FlipCardFront >
< StyledFloatingElement >
< div className = "flex items-center justify-between pb-2.5" >
2021-08-27 17:37:45 -07:00
< div className = "flex relative" >
< Tooltip
content = {
displayCumulativeSize
? 'Display Step Size'
: 'Display Cumulative Size'
}
className = "text-xs py-1"
>
< button
onClick = { ( ) = > {
setDisplayCumulativeSize ( ! displayCumulativeSize )
} }
className = "flex items-center justify-center rounded-full bg-th-bkg-3 w-8 h-8 hover:text-th-primary focus:outline-none"
>
{ displayCumulativeSize ? (
< StepSizeIcon className = "w-5 h-5" / >
) : (
< CumulativeSizeIcon className = "w-5 h-5" / >
) }
< / button >
< / Tooltip >
< / div >
2021-04-26 05:53:27 -07:00
< ElementTitle noMarignBottom > Orderbook < / ElementTitle >
2021-09-05 05:43:12 -07:00
< GroupSize
tickSize = { market ? . tickSize }
2021-09-04 21:42:37 -07:00
onChange = { onGroupSizeChange }
2021-09-04 20:36:10 -07:00
value = { grouping }
2021-09-04 21:42:37 -07:00
className = ""
2021-09-04 20:36:10 -07:00
/ >
2021-04-26 05:53:27 -07:00
< div className = "flex relative" >
< Tooltip content = { 'Switch Layout' } className = "text-xs py-1" >
< button
2021-04-26 08:20:55 -07:00
onClick = { handleLayoutChange }
2021-04-26 05:53:27 -07:00
className = "flex items-center justify-center rounded-full bg-th-bkg-3 w-8 h-8 hover:text-th-primary focus:outline-none"
>
< SwitchHorizontalIcon className = "w-5 h-5" / >
< / button >
< / Tooltip >
< / div >
< / div >
< MarkPriceComponent markPrice = { markPrice } / >
2021-04-26 08:20:55 -07:00
< div
className = { ` text-th-fgd-4 flex justify-between mb-2 text-xs ` }
>
2021-06-18 15:38:09 -07:00
< div className = { ` text-left ` } >
2021-08-27 17:37:45 -07:00
{ displayCumulativeSize ? 'Cumulative ' : '' } Size (
{ marketConfig . baseSymbol } )
2021-06-18 15:38:09 -07:00
< / div >
< div className = { ` text-center ` } >
2021-06-18 15:53:24 -07:00
Price ( { groupConfig . quoteSymbol } )
2021-06-18 15:38:09 -07:00
< / div >
< div className = { ` text-right ` } >
2021-08-27 17:37:45 -07:00
{ displayCumulativeSize ? 'Cumulative ' : '' } Size (
{ marketConfig . baseSymbol } )
2021-06-18 15:38:09 -07:00
< / div >
2021-04-26 08:20:55 -07:00
< / div >
< div className = "flex" >
< div className = "w-1/2" >
2021-08-27 17:37:45 -07:00
{ orderbookData ? . bids . map (
( {
price ,
size ,
cumulativeSize ,
sizePercent ,
maxSizePercent ,
} ) = > (
< OrderbookRow
2021-09-03 13:25:09 -07:00
market = { market }
2021-09-02 22:32:27 -07:00
hasOpenOrder = { openOrderPrices . includes ( price ) }
2021-08-27 17:37:45 -07:00
key = { price + '' }
price = { price }
size = { displayCumulativeSize ? cumulativeSize : size }
side = "buy"
sizePercent = {
displayCumulativeSize ? maxSizePercent : sizePercent
}
/ >
)
) }
2021-04-26 05:53:27 -07:00
< / div >
2021-04-26 08:20:55 -07:00
< div className = "w-1/2" >
2021-08-27 17:37:45 -07:00
{ orderbookData ? . asks . map (
( {
price ,
size ,
cumulativeSize ,
sizePercent ,
maxSizePercent ,
} ) = > (
< OrderbookRow
2021-09-03 13:25:09 -07:00
market = { market }
2021-09-02 22:32:27 -07:00
hasOpenOrder = { openOrderPrices . includes ( price ) }
2021-08-27 17:37:45 -07:00
invert
key = { price + '' }
price = { price }
size = { displayCumulativeSize ? cumulativeSize : size }
side = "sell"
sizePercent = {
displayCumulativeSize ? maxSizePercent : sizePercent
}
/ >
)
) }
2021-04-26 08:20:55 -07:00
< / div >
< / div >
< div className = "flex justify-between bg-th-bkg-1 p-2 mt-4 rounded-md text-xs" >
< div className = "text-th-fgd-3" > Spread < / div >
< div className = "text-th-fgd-1" >
2021-08-04 14:54:44 -07:00
{ orderbookData ? . spread ? . toFixed ( 2 ) }
2021-04-26 08:20:55 -07:00
< / div >
< div className = "text-th-fgd-1" >
2021-08-04 14:54:44 -07:00
{ orderbookData ? . spreadPercentage ? . toFixed ( 2 ) } %
2021-04-26 08:20:55 -07:00
< / div >
< / div >
2021-04-26 05:53:27 -07:00
< / StyledFloatingElement >
< / FlipCardFront >
) : (
< FlipCardBack >
< StyledFloatingElement >
< div className = "flex items-center justify-between pb-2.5" >
2021-08-27 17:37:45 -07:00
< div className = "flex relative" >
< Tooltip
content = {
displayCumulativeSize
? 'Display Step Size'
: 'Display Cumulative Size'
}
className = "text-xs py-1"
>
< button
onClick = { ( ) = > {
setDisplayCumulativeSize ( ! displayCumulativeSize )
} }
className = "flex items-center justify-center rounded-full bg-th-bkg-3 w-8 h-8 hover:text-th-primary focus:outline-none"
>
{ displayCumulativeSize ? (
< StepSizeIcon className = "w-5 h-5" / >
) : (
< CumulativeSizeIcon className = "w-5 h-5" / >
) }
< / button >
< / Tooltip >
< / div >
2021-04-26 05:53:27 -07:00
< ElementTitle noMarignBottom > Orderbook < / ElementTitle >
< div className = "flex relative" >
< Tooltip content = { 'Switch Layout' } className = "text-xs py-1" >
< button
2021-04-26 08:20:55 -07:00
onClick = { handleLayoutChange }
2021-04-26 05:53:27 -07:00
className = "flex items-center justify-center rounded-full bg-th-bkg-3 w-8 h-8 hover:text-th-primary focus:outline-none"
>
< SwitchHorizontalIcon className = "w-5 h-5" / >
< / button >
< / Tooltip >
< / div >
< / div >
< MarkPriceComponent markPrice = { markPrice } / >
2021-04-26 08:20:55 -07:00
< div className = { ` text-th-fgd-4 flex justify-between mb-2 ` } >
< div className = { ` text-left text-xs ` } >
2021-08-27 17:37:45 -07:00
{ displayCumulativeSize ? 'Cumulative ' : '' } Size (
{ marketConfig . baseSymbol } )
2021-04-26 05:53:27 -07:00
< / div >
2021-04-26 08:20:55 -07:00
< div className = { ` text-right text-xs ` } >
2021-06-18 16:23:09 -07:00
Price ( { groupConfig . quoteSymbol } )
2021-04-26 08:20:55 -07:00
< / div >
< / div >
2021-08-27 17:37:45 -07:00
{ orderbookData ? . asks . map (
( {
price ,
size ,
cumulativeSize ,
sizePercent ,
maxSizePercent ,
} ) = > (
< OrderbookRow
2021-09-03 13:25:09 -07:00
market = { market }
2021-09-02 22:32:27 -07:00
hasOpenOrder = { openOrderPrices . includes ( price ) }
2021-08-27 17:37:45 -07:00
key = { price + '' }
price = { price }
size = { displayCumulativeSize ? cumulativeSize : size }
side = "sell"
sizePercent = {
displayCumulativeSize ? maxSizePercent : sizePercent
}
/ >
)
) }
2021-04-26 08:20:55 -07:00
< div className = "flex justify-between bg-th-bkg-1 p-2 my-2 rounded-md text-xs" >
< div className = "text-th-fgd-3" > Spread < / div >
< div className = "text-th-fgd-1" >
{ orderbookData ? . spread . toFixed ( 2 ) }
< / div >
< div className = "text-th-fgd-1" >
{ orderbookData ? . spreadPercentage . toFixed ( 2 ) } %
< / div >
< / div >
2021-08-27 17:37:45 -07:00
{ orderbookData ? . bids . map (
( {
price ,
size ,
cumulativeSize ,
sizePercent ,
maxSizePercent ,
} ) = > (
< OrderbookRow
2021-09-03 13:25:09 -07:00
market = { market }
2021-09-02 22:32:27 -07:00
hasOpenOrder = { openOrderPrices . includes ( price ) }
2021-08-27 17:37:45 -07:00
key = { price + '' }
price = { price }
size = { displayCumulativeSize ? cumulativeSize : size }
side = "buy"
sizePercent = {
displayCumulativeSize ? maxSizePercent : sizePercent
}
/ >
)
) }
2021-04-26 05:53:27 -07:00
< / StyledFloatingElement >
< / FlipCardBack >
) }
< / FlipCardInner >
< / FlipCard >
2021-04-02 11:26:21 -07:00
< / >
)
2021-03-30 15:47:08 -07:00
}
2021-04-02 11:26:21 -07:00
const OrderbookRow = React . memo < any > (
2021-09-03 13:25:09 -07:00
( { side , price , size , sizePercent , invert , hasOpenOrder , market } ) = > {
2021-04-02 11:26:21 -07:00
const element = useRef ( null )
2021-04-26 08:20:55 -07:00
const setMangoStore = useMangoStore ( ( s ) = > s . set )
2021-03-30 15:47:08 -07:00
useEffect ( ( ) = > {
! element . current ? . classList . contains ( 'flash' ) &&
element . current ? . classList . add ( 'flash' )
const id = setTimeout (
( ) = >
element . current ? . classList . contains ( 'flash' ) &&
element . current ? . classList . remove ( 'flash' ) ,
250
)
return ( ) = > clearTimeout ( id )
} , [ price , size ] )
const formattedSize =
market ? . minOrderSize && ! isNaN ( size )
2021-08-21 21:03:43 -07:00
? Number ( size ) . toFixed ( getDecimalCount ( market . minOrderSize ) )
2021-03-30 15:47:08 -07:00
: size
const formattedPrice =
market ? . tickSize && ! isNaN ( price )
2021-08-21 21:03:43 -07:00
? Number ( price ) . toFixed ( getDecimalCount ( market . tickSize ) )
2021-03-30 15:47:08 -07:00
: price
2021-04-26 08:20:55 -07:00
const handlePriceClick = ( ) = > {
setMangoStore ( ( state ) = > {
state . tradeForm . price = price
} )
}
const handleSizeClick = ( ) = > {
setMangoStore ( ( state ) = > {
state . tradeForm . baseSize = size
} )
}
2021-09-02 22:32:27 -07:00
if ( ! market ) return null
2021-03-30 15:47:08 -07:00
return (
2021-04-16 04:50:56 -07:00
< div className = { ` flex text-sm leading-7 justify-between ` } ref = { element } >
2021-03-30 15:47:08 -07:00
{ invert ? (
< >
2021-04-26 05:53:27 -07:00
< div className = { ` text-left relative flex-1 ` } >
2021-04-12 09:49:02 -07:00
< Line
invert
data - width = { sizePercent + '%' }
side = { side }
2021-04-26 05:53:27 -07:00
className = { ` absolute inset-y-0 left-0 ${
side === 'buy' ? ` bg-th-green ` : ` bg-th-red `
} ` }
2021-04-12 09:49:02 -07:00
/ >
2021-04-26 05:53:27 -07:00
< div
2021-04-26 08:20:55 -07:00
onClick = { handlePriceClick }
2021-09-03 13:25:09 -07:00
className = { ` z-30 filter brightness-110 relative text-th-fgd-1 px-4 ${
2021-09-02 22:32:27 -07:00
side === 'buy' ? ` text-th-green ` : ` text-th-red `
} ` }
2021-04-26 05:53:27 -07:00
>
2021-09-02 22:32:27 -07:00
{ usdFormatter (
formattedPrice ,
getDecimalCount ( market . tickSize ) ,
false
) }
2021-04-26 05:53:27 -07:00
< / div >
2021-03-30 15:47:08 -07:00
< / div >
2021-09-02 22:32:27 -07:00
< div
2021-09-05 22:36:27 -07:00
className = { ` absolute right-3 ${
2021-09-02 22:32:27 -07:00
hasOpenOrder ? 'text-th-primary' : 'text-th-fgd-1'
} ` }
onClick = { handleSizeClick }
>
2021-04-15 14:36:55 -07:00
{ formattedSize }
< / div >
2021-03-30 15:47:08 -07:00
< / >
) : (
< >
2021-04-15 14:36:55 -07:00
< div
2021-09-05 22:36:27 -07:00
className = { ` absolute left-3 flex-1 ${
2021-09-02 22:32:27 -07:00
hasOpenOrder ? 'text-th-primary' : 'text-th-fgd-1'
} ` }
2021-04-26 08:20:55 -07:00
onClick = { handleSizeClick }
2021-04-15 14:36:55 -07:00
>
2021-04-12 09:49:02 -07:00
{ formattedSize }
< / div >
< div className = { ` text-right relative flex-1 ` } >
2021-03-30 15:47:08 -07:00
< Line
2021-04-12 09:49:02 -07:00
className = { ` absolute inset-y-0 right-0 ${
side === 'buy' ? ` bg-th-green ` : ` bg-th-red `
} ` }
2021-03-30 15:47:08 -07:00
data - width = { sizePercent + '%' }
2021-04-12 06:32:01 -07:00
side = { side }
2021-03-30 15:47:08 -07:00
/ >
2021-04-12 09:49:02 -07:00
< div
2021-09-03 13:25:09 -07:00
className = { ` z-30 filter brightness-110 relative px-4 ${
2021-09-02 22:32:27 -07:00
side === 'buy' ? ` text-th-green ` : ` text-th-red `
} ` }
2021-04-26 08:20:55 -07:00
onClick = { handlePriceClick }
2021-04-12 09:49:02 -07:00
>
2021-09-02 22:32:27 -07:00
{ usdFormatter (
formattedPrice ,
getDecimalCount ( market . tickSize ) ,
false
) }
2021-04-05 12:03:20 -07:00
< / div >
2021-04-02 11:26:21 -07:00
< / div >
2021-03-30 15:47:08 -07:00
< / >
) }
< / div >
)
} ,
( prevProps , nextProps ) = >
isEqual ( prevProps , nextProps , [ 'price' , 'size' , 'sizePercent' ] )
)
2021-04-02 11:26:21 -07:00
const MarkPriceComponent = React . memo < { markPrice : number } > (
2021-03-30 15:47:08 -07:00
( { markPrice } ) = > {
2021-04-02 11:26:21 -07:00
const previousMarkPrice : number = usePrevious ( markPrice )
2021-03-30 15:47:08 -07:00
return (
2021-04-02 11:26:21 -07:00
< div
2021-04-26 05:53:27 -07:00
className = { ` flex justify-center items-center font-bold text-lg pb-4 ${
2021-04-12 06:32:01 -07:00
markPrice > previousMarkPrice
2021-04-12 09:49:02 -07:00
? ` text-th-green `
2021-04-12 06:32:01 -07:00
: markPrice < previousMarkPrice
2021-04-12 09:49:02 -07:00
? ` text-th-red `
: ` text-th-fgd-1 `
} ` }
2021-04-02 11:26:21 -07:00
>
{ markPrice > previousMarkPrice && (
2021-04-26 05:53:27 -07:00
< ArrowUpIcon className = { ` h-5 w-5 mr-1 text-th-green ` } / >
2021-04-02 11:26:21 -07:00
) }
{ markPrice < previousMarkPrice && (
2021-04-26 05:53:27 -07:00
< ArrowDownIcon className = { ` h-5 w-5 mr-1 text-th-red ` } / >
2021-04-02 11:26:21 -07:00
) }
2021-08-21 20:56:48 -07:00
{ markPrice || '----' }
2021-04-02 11:26:21 -07:00
< / div >
2021-03-30 15:47:08 -07:00
)
} ,
( prevProps , nextProps ) = > isEqual ( prevProps , nextProps , [ 'markPrice' ] )
)