mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Add full precision to send tx value field.
This commit is contained in:
parent
22a77b8041
commit
60270de53d
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
## Current Master
|
## Current Master
|
||||||
|
|
||||||
- UI Overhaul per Vlad Todirut's designs
|
- UI Overhaul per Vlad Todirut's designs.
|
||||||
- Replaced identicons with jazzicons
|
- Replaced identicons with jazzicons.
|
||||||
- Fixed glitchy transitions
|
- Fixed glitchy transitions.
|
||||||
- Added support for capitalization-based address checksums
|
- Added support for capitalization-based address checksums.
|
||||||
|
- Send value is no longer limited by javascript number precision, and is always in ETH.
|
||||||
|
|
||||||
## 1.8.4 2016-05-13
|
## 1.8.4 2016-05-13
|
||||||
|
|
||||||
|
@ -159,6 +159,20 @@ describe('util', function() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('normalizeEthStringToWei', function() {
|
||||||
|
it('should convert decimal eth to pure wei BN', function() {
|
||||||
|
var input = '1.23456789'
|
||||||
|
var output = util.normalizeEthStringToWei(input)
|
||||||
|
assert.equal(output.toString(10), '1234567890000000000')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should convert 1 to expected wei', function() {
|
||||||
|
var input = '1'
|
||||||
|
var output = util.normalizeEthStringToWei(input)
|
||||||
|
assert.equal(output.toString(10), ethInWei)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('#normalizeNumberToWei', function() {
|
describe('#normalizeNumberToWei', function() {
|
||||||
|
|
||||||
it('should handle a simple use case', function() {
|
it('should handle a simple use case', function() {
|
||||||
|
@ -209,8 +209,8 @@ SendTransactionScreen.prototype.back = function() {
|
|||||||
SendTransactionScreen.prototype.onSubmit = function() {
|
SendTransactionScreen.prototype.onSubmit = function() {
|
||||||
|
|
||||||
const recipient = document.querySelector('input[name="address"]').value
|
const recipient = document.querySelector('input[name="address"]').value
|
||||||
const inputAmount = parseFloat(document.querySelector('input[name="amount"]').value)
|
const input = document.querySelector('input[name="amount"]').value
|
||||||
const value = util.normalizeNumberToWei(inputAmount, 'ether')
|
const value = util.normalizeEthStringToWei(input)
|
||||||
const txData = document.querySelector('input[name="txData"]').value
|
const txData = document.querySelector('input[name="txData"]').value
|
||||||
const balance = this.props.balance
|
const balance = this.props.balance
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ module.exports = {
|
|||||||
ethToWei: ethToWei,
|
ethToWei: ethToWei,
|
||||||
weiToEth: weiToEth,
|
weiToEth: weiToEth,
|
||||||
normalizeToWei: normalizeToWei,
|
normalizeToWei: normalizeToWei,
|
||||||
|
normalizeEthStringToWei: normalizeEthStringToWei,
|
||||||
normalizeNumberToWei: normalizeNumberToWei,
|
normalizeNumberToWei: normalizeNumberToWei,
|
||||||
valueTable: valueTable,
|
valueTable: valueTable,
|
||||||
bnTable: bnTable,
|
bnTable: bnTable,
|
||||||
@ -120,6 +121,20 @@ function normalizeToWei(amount, currency) {
|
|||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeEthStringToWei(str) {
|
||||||
|
const parts = str.split('.')
|
||||||
|
let eth = new ethUtil.BN(parts[0], 10).mul(bnTable.wei)
|
||||||
|
if (parts[1]) {
|
||||||
|
var decimal = parts[1]
|
||||||
|
while(decimal.length < 18) {
|
||||||
|
decimal += '0'
|
||||||
|
}
|
||||||
|
const decimalBN = new ethUtil.BN(decimal, 10)
|
||||||
|
eth = eth.add(decimalBN)
|
||||||
|
}
|
||||||
|
return eth
|
||||||
|
}
|
||||||
|
|
||||||
var multiple = new ethUtil.BN('10000', 10)
|
var multiple = new ethUtil.BN('10000', 10)
|
||||||
function normalizeNumberToWei(n, currency) {
|
function normalizeNumberToWei(n, currency) {
|
||||||
var enlarged = n * 10000
|
var enlarged = n * 10000
|
||||||
|
Loading…
Reference in New Issue
Block a user