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
61d6556a
Unverified
Commit
61d6556a
authored
Sep 17, 2019
by
Noah Zinsmeister
Committed by
GitHub
Sep 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix rounding issue (#445)
parent
ecd71753
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
2 deletions
+1
-2
index.js
src/utils/index.js
+1
-2
No files found.
src/utils/index.js
View file @
61d6556a
...
@@ -221,6 +221,7 @@ export async function getTokenAllowance(address, tokenAddress, spenderAddress, l
...
@@ -221,6 +221,7 @@ export async function getTokenAllowance(address, tokenAddress, spenderAddress, l
return
getContract
(
tokenAddress
,
ERC20_ABI
,
library
).
allowance
(
address
,
spenderAddress
)
return
getContract
(
tokenAddress
,
ERC20_ABI
,
library
).
allowance
(
address
,
spenderAddress
)
}
}
//
// amount must be a BigNumber, {base,display}Decimals must be Numbers
// amount must be a BigNumber, {base,display}Decimals must be Numbers
export
function
amountFormatter
(
amount
,
baseDecimals
=
18
,
displayDecimals
=
3
,
useLessThan
=
true
)
{
export
function
amountFormatter
(
amount
,
baseDecimals
=
18
,
displayDecimals
=
3
,
useLessThan
=
true
)
{
if
(
baseDecimals
>
18
||
displayDecimals
>
18
||
displayDecimals
>
baseDecimals
)
{
if
(
baseDecimals
>
18
||
displayDecimals
>
18
||
displayDecimals
>
baseDecimals
)
{
...
@@ -261,10 +262,8 @@ export function amountFormatter(amount, baseDecimals = 18, displayDecimals = 3,
...
@@ -261,10 +262,8 @@ export function amountFormatter(amount, baseDecimals = 18, displayDecimals = 3,
// if there is a decimal portion
// if there is a decimal portion
else
{
else
{
const
[
wholeComponent
,
decimalComponent
]
=
stringAmount
.
split
(
'
.
'
)
const
[
wholeComponent
,
decimalComponent
]
=
stringAmount
.
split
(
'
.
'
)
const
roundUpAmount
=
minimumDisplayAmount
.
div
(
ethers
.
constants
.
Two
)
const
roundedDecimalComponent
=
ethers
.
utils
const
roundedDecimalComponent
=
ethers
.
utils
.
bigNumberify
(
decimalComponent
.
padEnd
(
baseDecimals
,
'
0
'
))
.
bigNumberify
(
decimalComponent
.
padEnd
(
baseDecimals
,
'
0
'
))
.
add
(
roundUpAmount
)
.
toString
()
.
toString
()
.
padStart
(
baseDecimals
,
'
0
'
)
.
padStart
(
baseDecimals
,
'
0
'
)
.
substring
(
0
,
displayDecimals
)
.
substring
(
0
,
displayDecimals
)
...
...
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