Merge branch 'master' into AddTravisCI

feature/default_network_editable
Dan Finlay 9 years ago
commit 08c126e88e
  1. 1
      CHANGELOG.md
  2. 77
      app/scripts/inpage.js
  3. 9
      ui/app/util.js
  4. 16
      ui/test/unit/util_test.js

@ -4,6 +4,7 @@
- Corrected text above account list. Selected account is visible to all sites, not just the current domain. - Corrected text above account list. Selected account is visible to all sites, not just the current domain.
- Merged the UI codebase into the main plugin codebase for simpler maintenance. - Merged the UI codebase into the main plugin codebase for simpler maintenance.
- Fix Ether display rounding error. Now rendering to four decimal points.
## 1.5.0 2016-04-13 ## 1.5.0 2016-04-13

@ -1,6 +1,4 @@
const XHR = window.XMLHttpRequest const XHR = window.XMLHttpRequest
// const fauxJax = require('faux-jax')
// fauxJax.install()
// bring in web3 but rename on window // bring in web3 but rename on window
const Web3 = require('web3') const Web3 = require('web3')
@ -34,7 +32,9 @@ remoteProvider.on('error', console.error.bind(console))
// //
// handle accounts cache // handle accounts cache
var accountsCache = [] var accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]')
web3.eth.defaultAccount = accounts[0]
setInterval(populateAccountsCache, 4000) setInterval(populateAccountsCache, 4000)
function populateAccountsCache(){ function populateAccountsCache(){
remoteProvider.sendAsync(createPayload({ remoteProvider.sendAsync(createPayload({
@ -46,6 +46,7 @@ function populateAccountsCache(){
// update localStorage // update localStorage
var accounts = response.result var accounts = response.result
if (accounts.toString() !== accountsCache.toString()) { if (accounts.toString() !== accountsCache.toString()) {
web3.eth.defaultAccount = accounts[0]
accountsCache = accounts accountsCache = accounts
localStorage['MetaMask-Accounts'] = JSON.stringify(accounts) localStorage['MetaMask-Accounts'] = JSON.stringify(accounts)
} }
@ -60,13 +61,11 @@ remoteProvider.send = function(payload){
case 'eth_accounts': case 'eth_accounts':
// read from localStorage // read from localStorage
accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]')
result = accountsCache result = accountsCache
break break
case 'eth_coinbase': case 'eth_coinbase':
// read from localStorage // read from localStorage
accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]')
result = accountsCache[0] || '0x0000000000000000000000000000000000000000' result = accountsCache[0] || '0x0000000000000000000000000000000000000000'
break break
@ -94,71 +93,3 @@ web3.setProvider = function(){
console.log('MetaMask - overrode web3.setProvider') console.log('MetaMask - overrode web3.setProvider')
} }
console.log('MetaMask - injected web3') console.log('MetaMask - injected web3')
//
// intercept local node requests
//
// console.log('MetaMask - intercepting localhost:8545 requests')
// fauxJax.on('request', function(req){
// // check if local node request
// if (req.requestURL.indexOf('localhost:8545') !== -1) {
// var rpcReq = JSON.parse(req.requestBody)
// if (req.async) {
// remoteProvider.sendAsync(rpcReq, function(err, result){
// // console.log('intercepted request (async):', rpcReq, result)
// handleResult(result)
// })
// } else {
// var result = remoteProvider.send(rpcReq)
// // console.log('intercepted request (sync):', rpcReq, result)
// handleResult(result)
// }
// } else {
// // console.log('request continuing normally:', req.requestURL)
// continueRequestNormally(req)
// }
// function handleResult(result){
// var serializedResult = JSON.stringify(result)
// req.respond(200, {
// 'content-type': 'application/json',
// }, serializedResult)
// }
// })
// function continueRequestNormally(req){
// var xhr = new XHR()
// // set target url and method
// xhr.open(req.requestMethod, req.requestURL, req.async)
// // set headers
// Object.keys(req.requestHeaders || {}).forEach(function(headerKey){
// xhr.setRequestHeader(headerKey, req.requestHeaders[headerKey])
// })
// // send and call completion handler
// if (req.async) {
// xhr.onload = copyResult
// xhr.send(req.requestBody)
// } else {
// xhr.send(req.requestBody)
// copyResult()
// }
// function copyResult() {
// var headers = extractResponseHeaders(xhr.getAllResponseHeaders())
// req.respond(xhr.status, headers, xhr.response)
// }
// }
// function extractResponseHeaders(rawHeaders){
// var headers = {}
// var headerKeyValues = rawHeaders.split('\r\n').filter(Boolean)
// headerKeyValues.forEach(function(keyValue){
// var data = keyValue.split(': ')
// headers[data[0]] = data[1]
// })
// return headers
// }

@ -64,11 +64,16 @@ function weiToEth(bn) {
return eth return eth
} }
var decimalsToKeep = 4
function formatBalance(balance) { function formatBalance(balance) {
if (!balance) return 'None' if (!balance) return 'None'
var wei = numericBalance(balance) var wei = numericBalance(balance)
var eth = weiToEth(wei) var padded = wei.toString(10)
return eth.toString(10) + ' ETH' var len = padded.length
var nonZeroIndex = padded.match(/[^0]/).index
var beforeDecimal = padded.substr(nonZeroIndex ? nonZeroIndex : 0, len - 18)
var afterDecimal = padded.substr(len - 18, decimalsToKeep)
return `${beforeDecimal}.${afterDecimal} ETH`
} }
function dataSize(data) { function dataSize(data) {

@ -63,9 +63,21 @@ describe('util', function() {
}) })
it('should return eth as string followed by ETH', function() { it('should return eth as string followed by ETH', function() {
var input = new ethUtil.BN(ethInWei).toJSON() var input = new ethUtil.BN(ethInWei, 10).toJSON()
var result = util.formatBalance(input) var result = util.formatBalance(input)
assert.equal(result, '1 ETH') assert.equal(result, '1.0000 ETH')
})
it('should return eth as string followed by ETH', function() {
var input = new ethUtil.BN(ethInWei, 10).div(new ethUtil.BN('2', 10)).toJSON()
var result = util.formatBalance(input)
assert.equal(result, '.5000 ETH')
})
it('should display four decimal points', function() {
var input = "0x128dfa6a90b28000"
var result = util.formatBalance(input)
assert.equal(result, '1.3370 ETH')
}) })
}) })

Loading…
Cancel
Save