Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-signer
Commits
756e34b6
Commit
756e34b6
authored
Mar 31, 2017
by
Marek Kotewicz
Committed by
GitHub
Mar 31, 2017
Browse files
Merge pull request #44 from paritytech/units-fix
Fix parsing 0s in RLP.
parents
f70ae73e
55c77aa2
Changes
2
Show whitespace changes
Inline
Side-by-side
src/util/units.js
View file @
756e34b6
...
...
@@ -48,10 +48,10 @@ let unitMap = {
function
getValueOfUnit
(
unit
)
{
unit
=
unit
?
unit
.
toLowerCase
()
:
'
ether
'
var
unitValue
=
unitMap
[
unit
]
var
unitValue
=
unitMap
[
unit
]
||
0
return
new
BigNumber
(
unitValue
,
10
)
}
export
function
fromWei
(
number
,
unit
)
{
return
new
BigNumber
(
number
,
16
).
dividedBy
(
getValueOfUnit
(
unit
)).
toString
(
10
)
return
new
BigNumber
(
number
||
0
,
16
).
dividedBy
(
getValueOfUnit
(
unit
)).
toString
(
10
)
}
src/util/units.spec.js
View file @
756e34b6
...
...
@@ -24,4 +24,12 @@ describe('units', () => {
let
ether
=
fromWei
(
wei
)
expect
(
ether
).
toEqual
(
'
0.000000000000021
'
)
})
it
(
'
should return BigNumber for undefined values
'
,
()
=>
{
expect
(
fromWei
(
null
)).
toEqual
(
'
0
'
)
expect
(
fromWei
(
undefined
)).
toEqual
(
'
0
'
)
expect
(
fromWei
(
0
)).
toEqual
(
'
0
'
)
expect
(
fromWei
(
'
0
'
)).
toEqual
(
'
0
'
)
expect
(
fromWei
(
''
)).
toEqual
(
'
0
'
)
})
})
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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