Skip to content
This repository was archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Fix space between td, change amount precision
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypalacios committed Oct 20, 2021
1 parent 5d3120b commit 18a51b8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
11 changes: 9 additions & 2 deletions src/apps/explorer/components/common/TextWithTooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React from 'react'
import { Placement } from '@popperjs/core'
import styled from 'styled-components'

import { Tooltip } from 'components/Tooltip'
import { usePopperDefault } from 'hooks/usePopper'

const Wrapper = styled.span`
> p {
margin: 0;
}
`

interface TextTooltipProps {
children: React.ReactNode
textInTooltip: string
Expand All @@ -17,9 +24,9 @@ export const TextWithTooltip: React.FC<TextTooltipProps> = ({
}): JSX.Element => {
const { tooltipProps, targetProps } = usePopperDefault<HTMLInputElement>(tooltipPlacement)
return (
<span className="wrap-text-tooltip">
<Wrapper>
<Tooltip {...tooltipProps}>{textInTooltip}</Tooltip>
<p {...targetProps}>{children}</p>
</span>
</Wrapper>
)
}
2 changes: 1 addition & 1 deletion src/apps/explorer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const DISPLAY_TEXT_COPIED_CHECK = 1000 // in ms

// formatSmart related constants
export const LOW_PRECISION_DECIMALS = 2 // display stuff with up to 2 digits: 123.432452 => 123.43
export const DEFAULT_PRECISION_DECIMALS = 4 // display stuff with up to 4 digits: 0.8319079051029 => 0.8319
export const MIDDLE_PRECISION_DECIMALS = 4 // display stuff with up to 4 digits: 0.8319079051029 => 0.8319
export const HIGH_PRECISION_DECIMALS = 8 // display stuff with up to 8 digits: 0.8319079051029 => 0.83190790
export const HIGH_PRECISION_SMALL_LIMIT = '0.00000001' // what is considered too small. See https://github.com/gnosis/dex-js/blob/master/src/utils/format.ts#L78-L80
export const PERCENTAGE_PRECISION = -2 // assumes 100% === 1; 1/10^-2 => 100
Expand Down
17 changes: 5 additions & 12 deletions src/components/orders/OrdersUserDetailsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,18 @@ const RowOrder: React.FC<RowProps> = ({ order, isPriceInverted }) => {
<HeaderTitle>Sell Amount</HeaderTitle>
<HeaderValue>
<TextWithTooltip
textInTooltip={`${formattedAmount(
sellToken,
sellAmount.plus(order.feeAmount),
FormatAmountPrecision.highPrecision,
)} ${sellToken?.symbol}`}
textInTooltip={`${formattedAmount(sellToken, sellAmount.plus(order.feeAmount))} ${sellToken?.symbol}`}
>
{formattedAmount(sellToken, sellAmount.plus(order.feeAmount))} {sellToken?.symbol}
{formattedAmount(sellToken, sellAmount.plus(order.feeAmount), FormatAmountPrecision.highPrecision)}{' '}
{sellToken?.symbol}
</TextWithTooltip>
</HeaderValue>
</td>
<td>
<HeaderTitle>Buy amount</HeaderTitle>
<HeaderValue>
<TextWithTooltip
textInTooltip={`${formattedAmount(buyToken, buyAmount, FormatAmountPrecision.highPrecision)} ${
buyToken?.symbol
}`}
>
{formattedAmount(buyToken, buyAmount)} {buyToken?.symbol}
<TextWithTooltip textInTooltip={`${formattedAmount(buyToken, buyAmount)} ${buyToken?.symbol}`}>
{formattedAmount(buyToken, buyAmount, FormatAmountPrecision.highPrecision)} {buyToken?.symbol}
</TextWithTooltip>
</HeaderValue>
</td>
Expand Down
18 changes: 13 additions & 5 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
MINIMUM_ATOM_VALUE,
} from 'const'
import {
DEFAULT_PRECISION_DECIMALS,
MIDDLE_PRECISION_DECIMALS,
HIGH_PRECISION_DECIMALS,
HIGH_PRECISION_SMALL_LIMIT,
NO_ADJUSTMENT_NEEDED_PRECISION,
} from 'apps/explorer/const'
import { batchIdToDate } from './time'
import { FormatAmountPrecision, batchIdToDate } from 'utils'

export {
formatSmart,
Expand Down Expand Up @@ -306,11 +306,19 @@ export function formatExecutedPriceToDisplay(
* @param amount BigNumber integer amount
* @param token Erc20 token
*/
export function defaultAmountFormatPrecision(amount: BigNumber, token: TokenErc20 | null): string {
export function formattingAmountPrecision(
amount: BigNumber,
token: TokenErc20 | null,
typePrecision: FormatAmountPrecision,
): string {
const typeFormatPrecision = {
[FormatAmountPrecision.highPrecision]: HIGH_PRECISION_DECIMALS,
[FormatAmountPrecision.middlePrecision]: MIDDLE_PRECISION_DECIMALS,
}
return formatSmart({
amount: amount.toString(10),
precision: token?.decimals || 0,
decimals: DEFAULT_PRECISION_DECIMALS,
smallLimit: getMinimumRepresentableValue(DEFAULT_PRECISION_DECIMALS),
decimals: typeFormatPrecision[typePrecision],
smallLimit: getMinimumRepresentableValue(typeFormatPrecision[typePrecision]),
})
}
11 changes: 6 additions & 5 deletions src/utils/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FILLED_ORDER_EPSILON, ONE_BIG_NUMBER, ZERO_BIG_NUMBER } from 'const'

import { Order, OrderStatus, RawOrder, RawTrade, Trade } from 'api/operator/types'

import { defaultAmountFormatPrecision, formatSmartMaxPrecision } from './format'
import { formattingAmountPrecision, formatSmartMaxPrecision } from 'utils'

function isOrderFilled(order: RawOrder): boolean {
let amount, executedAmount
Expand Down Expand Up @@ -242,22 +242,23 @@ export function isTokenErc20(token: TokenErc20 | null | undefined): token is Tok
}

export enum FormatAmountPrecision {
defaultPrecision,
middlePrecision,
highPrecision,
maxPrecision,
}

export function formattedAmount(
erc20: TokenErc20 | null | undefined,
amount: BigNumber,
typePrecision: FormatAmountPrecision = FormatAmountPrecision.defaultPrecision,
typePrecision: FormatAmountPrecision = FormatAmountPrecision.maxPrecision,
): string {
if (!isTokenErc20(erc20)) return '-'

if (!erc20.decimals) return amount.toString(10)

return typePrecision === FormatAmountPrecision.highPrecision
return typePrecision === FormatAmountPrecision.maxPrecision
? formatSmartMaxPrecision(amount, erc20)
: defaultAmountFormatPrecision(amount, erc20)
: formattingAmountPrecision(amount, erc20, typePrecision)
}

function getReceiverAddress({ owner, receiver }: RawOrder): string {
Expand Down

0 comments on commit 18a51b8

Please sign in to comment.