Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
14f01905
Unverified
Commit
14f01905
authored
Oct 10, 2022
by
lynn
Committed by
GitHub
Oct 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: price formatting spot check fixes (#4850)
fix price formatting
parent
23eb31e6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
PriceChart.tsx
src/components/Tokens/TokenDetails/PriceChart.tsx
+2
-1
formatDollarAmt.test.ts
src/utils/formatDollarAmt.test.ts
+7
-1
formatDollarAmt.ts
src/utils/formatDollarAmt.ts
+3
-2
No files found.
src/components/Tokens/TokenDetails/PriceChart.tsx
View file @
14f01905
...
...
@@ -22,6 +22,7 @@ import {
monthYearDayFormatter
,
weekFormatter
,
}
from
'
utils/formatChartTimes
'
import
{
formatDollar
}
from
'
utils/formatDollarAmt
'
import
{
MEDIUM_MEDIA_BREAKPOINT
}
from
'
../constants
'
import
{
DISPLAYS
,
ORDERED_TIMES
}
from
'
../TokenTable/TimeSelector
'
...
...
@@ -270,7 +271,7 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
return
(
<>
<
ChartHeader
>
<
TokenPrice
>
$
{
displayPrice
.
value
<
0.000001
?
'
<0.000001
'
:
displayPrice
.
value
.
toFixed
(
6
)
}
</
TokenPrice
>
<
TokenPrice
>
{
formatDollar
(
displayPrice
.
value
,
true
)
}
</
TokenPrice
>
<
DeltaContainer
>
{
formattedDelta
}
<
ArrowCell
>
{
arrow
}
</
ArrowCell
>
...
...
src/utils/formatDollarAmt.test.ts
View file @
14f01905
...
...
@@ -39,8 +39,14 @@ describe('formatDollar for a price', () => {
it
(
'
num >= 0.1 && num < 1.05
'
,
()
=>
{
expect
(
formatDollar
(
0.812831
,
true
)).
toEqual
(
'
$0.813
'
)
})
it
(
'
number is greater than 1 million
'
,
()
=>
{
expect
(
formatDollar
(
11192312.408
,
true
)).
toEqual
(
'
$1.12e+7
'
)
})
it
(
'
number in the thousands
'
,
()
=>
{
expect
(
formatDollar
(
1234.408
,
true
)).
toEqual
(
'
$1,234.41
'
)
})
it
(
'
number is greater than 1.05
'
,
()
=>
{
expect
(
formatDollar
(
102312.408
,
true
)).
toEqual
(
'
$102312.41
'
)
expect
(
formatDollar
(
102312.408
,
true
)).
toEqual
(
'
$102
,
312.41
'
)
})
})
...
...
src/utils/formatDollarAmt.ts
View file @
14f01905
/* Copied from Uniswap/v-3: https://github.com/Uniswap/v3-info/blob/master/src/utils/numbers.ts */
import
{
Currency
,
CurrencyAmount
}
from
'
@uniswap/sdk-core
'
import
{
DEFAULT_LOCALE
}
from
'
constants/locales
'
import
numbro
from
'
numbro
'
// Convert [CurrencyAmount] to number with necessary precision for price formatting.
...
...
@@ -19,14 +20,14 @@ export const formatDollar = (num: number | undefined | null, isPrice = false, di
if
(
num
<
0.000001
)
{
return
`$
${
num
.
toExponential
(
2
)}
`
}
if
(
num
>=
0.000001
&&
num
<
0.1
)
{
if
(
(
num
>=
0.000001
&&
num
<
0.1
)
||
num
>
1000000
)
{
return
`$
${
Number
(
num
).
toPrecision
(
3
)}
`
}
if
(
num
>=
0.1
&&
num
<
1.05
)
{
return
`$
${
num
.
toFixed
(
3
)}
`
}
// if number is greater than 1.05:
return
`$
${
num
.
toFixed
(
2
)}
`
return
`$
${
Number
(
num
.
toFixed
(
2
)).
toLocaleString
(
DEFAULT_LOCALE
)}
`
}
// For volume dollar amounts, like market cap, total value locked, etc.
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment