Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
swap-v2-sdk
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
swap-v2-sdk
Commits
518ff797
Unverified
Commit
518ff797
authored
Feb 14, 2020
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add toExact to TokenAmount
parent
1653d121
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
tokenAmount.ts
src/entities/fractions/tokenAmount.ts
+9
-0
entities.test.ts
test/entities.test.ts
+6
-0
No files found.
src/entities/fractions/tokenAmount.ts
View file @
518ff797
import
invariant
from
'
tiny-invariant
'
import
JSBI
from
'
jsbi
'
import
_Big
from
'
big.js
'
import
toFormat
from
'
toformat
'
import
{
BigintIsh
,
Rounding
}
from
'
../../types
'
import
{
TEN
,
SolidityType
}
from
'
../../constants
'
...
...
@@ -7,6 +9,8 @@ import { parseBigintIsh, validateSolidityTypeInstance } from '../../utils'
import
{
Token
}
from
'
../token
'
import
{
Fraction
}
from
'
./fraction
'
const
Big
=
toFormat
(
_Big
)
export
class
TokenAmount
extends
Fraction
{
public
readonly
token
:
Token
...
...
@@ -49,4 +53,9 @@ export class TokenAmount extends Fraction {
invariant
(
decimalPlaces
<=
this
.
token
.
decimals
,
'
DECIMALS
'
)
return
super
.
toFixed
(
decimalPlaces
,
format
,
rounding
)
}
public
toExact
(
format
:
object
=
{
groupSeparator
:
''
}):
string
{
Big
.
DP
=
this
.
token
.
decimals
return
new
Big
(
this
.
numerator
.
toString
()).
div
(
this
.
denominator
.
toString
()).
toFormat
(
format
)
}
}
test/entities.test.ts
View file @
518ff797
...
...
@@ -173,6 +173,12 @@ describe('entities', () => {
}
})
})
it
(
'
TokenAmount
'
,
()
=>
{
const
amount
=
new
TokenAmount
(
WETH
,
'
1234567000000000000000
'
)
expect
(
amount
.
toExact
()).
toEqual
(
'
1234.567
'
)
expect
(
amount
.
toExact
({
groupSeparator
:
'
,
'
})).
toEqual
(
'
1,234.567
'
)
})
})
})
})
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