mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 09:23:21 +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
|
||||
|
||||
- UI Overhaul per Vlad Todirut's designs
|
||||
- Replaced identicons with jazzicons
|
||||
- Fixed glitchy transitions
|
||||
- Added support for capitalization-based address checksums
|
||||
- UI Overhaul per Vlad Todirut's designs.
|
||||
- Replaced identicons with jazzicons.
|
||||
- Fixed glitchy transitions.
|
||||
- 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
|
||||
|
||||
|
@ -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() {
|
||||
|
||||
it('should handle a simple use case', function() {
|
||||
|
@ -209,8 +209,8 @@ SendTransactionScreen.prototype.back = function() {
|
||||
SendTransactionScreen.prototype.onSubmit = function() {
|
||||
|
||||
const recipient = document.querySelector('input[name="address"]').value
|
||||
const inputAmount = parseFloat(document.querySelector('input[name="amount"]').value)
|
||||
const value = util.normalizeNumberToWei(inputAmount, 'ether')
|
||||
const input = document.querySelector('input[name="amount"]').value
|
||||
const value = util.normalizeEthStringToWei(input)
|
||||
const txData = document.querySelector('input[name="txData"]').value
|
||||
const balance = this.props.balance
|
||||
|
||||
|
@ -31,6 +31,7 @@ module.exports = {
|
||||
ethToWei: ethToWei,
|
||||
weiToEth: weiToEth,
|
||||
normalizeToWei: normalizeToWei,
|
||||
normalizeEthStringToWei: normalizeEthStringToWei,
|
||||
normalizeNumberToWei: normalizeNumberToWei,
|
||||
valueTable: valueTable,
|
||||
bnTable: bnTable,
|
||||
@ -120,6 +121,20 @@ function normalizeToWei(amount, currency) {
|
||||
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)
|
||||
function normalizeNumberToWei(n, currency) {
|
||||
var enlarged = n * 10000
|
||||
|
Loading…
Reference in New Issue
Block a user