mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix precision to account for small wei increase.
This commit is contained in:
parent
833d73da56
commit
e6a618b82d
@ -31,7 +31,7 @@ BnAsDecimalInput.prototype.render = function () {
|
|||||||
const suffix = props.suffix
|
const suffix = props.suffix
|
||||||
const style = props.style
|
const style = props.style
|
||||||
const valueString = value.toString(10)
|
const valueString = value.toString(10)
|
||||||
const newValue = this.downsize(valueString, scale, precision)
|
const newValue = this.downsize(valueString, scale)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('.flex-column', [
|
h('.flex-column', [
|
||||||
@ -145,14 +145,17 @@ BnAsDecimalInput.prototype.constructWarning = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BnAsDecimalInput.prototype.downsize = function (number, scale, precision) {
|
BnAsDecimalInput.prototype.downsize = function (number, scale) {
|
||||||
// if there is no scaling, simply return the number
|
// if there is no scaling, simply return the number
|
||||||
if (scale === 0) {
|
if (scale === 0) {
|
||||||
return Number(number)
|
return Number(number)
|
||||||
} else {
|
} else {
|
||||||
// if the scale is the same as the precision, account for this edge case.
|
// if the scale is the same as the precision, account for this edge case.
|
||||||
var decimals = (scale === precision) ? -1 : scale - precision
|
var adjustedNumber = number
|
||||||
return Number(number.slice(0, -scale) + '.' + number.slice(-scale, decimals))
|
while (adjustedNumber.length < scale) {
|
||||||
|
adjustedNumber = '0' + adjustedNumber
|
||||||
|
}
|
||||||
|
return Number(adjustedNumber.slice(0, -scale) + '.' + adjustedNumber.slice(-scale))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user