Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: limit display delta between price and market #8412

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
MenuOptionGroup,
Skeleton,
Stack,
Text as CText,
} from '@chakra-ui/react'
import type { Asset } from '@shapeshiftoss/types'
import { bnOrZero } from '@shapeshiftoss/utils'
Expand All @@ -21,6 +22,7 @@ import { SwapIcon } from 'components/Icons/SwapIcon'
import { Text } from 'components/Text'
import { useActions } from 'hooks/useActions'
import { useLocaleFormatter } from 'hooks/useLocaleFormatter/useLocaleFormatter'
import { bn } from 'lib/bignumber/bignumber'
import { assertUnreachable } from 'lib/utils'
import {
ExpiryOption,
Expand All @@ -30,6 +32,7 @@ import {
import { limitOrderInput } from 'state/slices/limitOrderInputSlice/limitOrderInputSlice'
import {
selectExpiry,
selectLimitPrice,
selectLimitPriceDirection,
selectLimitPriceForSelectedPriceDirection,
selectLimitPriceMode,
Expand Down Expand Up @@ -90,6 +93,7 @@ export const LimitOrderConfig = ({
const limitPriceForSelectedPriceDirection = useAppSelector(
selectLimitPriceForSelectedPriceDirection,
)
const limitPrice = useAppSelector(selectLimitPrice)
const priceDirection = useAppSelector(selectLimitPriceDirection)
const expiry = useAppSelector(selectExpiry)
const limitPriceMode = useAppSelector(selectLimitPriceMode)
Expand Down Expand Up @@ -194,10 +198,29 @@ export const LimitOrderConfig = ({
[setExpiry],
)

const renderDelta = useMemo(() => {
const delta = bn(limitPrice.buyAssetDenomination).div(marketPriceBuyAsset).minus(1).times(100)
const prefix = delta.gt(0) ? '+' : ''
NeOMakinG marked this conversation as resolved.
Show resolved Hide resolved

if (limitPrice.buyAssetDenomination === '') return null
if (isLoading) return null
if (delta.isZero()) return null

return (
<CText color={delta.gt(0) ? 'text.success' : 'text.error'}>
({prefix}
{delta.toFixed(2)}%)
</CText>
)
}, [isLoading, limitPrice.buyAssetDenomination, marketPriceBuyAsset])

return (
<Stack spacing={4} px={6} py={4}>
<Flex justifyContent='space-between' alignItems='center'>
<Text translation='limitOrder.whenPriceReaches' />
<HStack>
<Text translation='limitOrder.whenPriceReaches' />
{renderDelta}
</HStack>
<Flex justifyContent='space-between' alignItems='center'>
<Text translation='limitOrder.expiry' mr={4} />
<Menu isLazy>
Expand Down