add getBalance + refactor

pull/1/head
yann300 8 years ago
parent 682f0709e8
commit c660fc8048
  1. 9
      src/app.js
  2. 7
      src/app/renderer.js
  3. 6
      src/lib/helper.js
  4. 4
      src/universal-dapp.js

@ -770,6 +770,15 @@ var run = function () {
},
getAccounts: (callback) => {
udapp.getAccounts(callback)
},
getBalance: (address, callback) => {
udapp.getBalance(address, (error, balance) => {
if (error) {
callback(error)
} else {
callback(null, executionContext.web3().fromWei(balance, 'ether'))
}
})
}
}
var renderer = new Renderer(rendererAPI, compiler.event)

@ -3,6 +3,7 @@
var $ = require('jquery')
var utils = require('./utils')
var helper = require('../lib/helper.js')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
@ -61,7 +62,7 @@ function Renderer (appAPI, compilerEvent) {
})
}
})
setInterval(() => { updateAccountBalances(appAPI) }, 1000)
setInterval(() => { updateAccountBalances(self, appAPI) }, 1000)
}
Renderer.prototype.clear = function () {
@ -345,13 +346,13 @@ Renderer.prototype.contracts = function (data, source) {
$('.' + css.col2 + ' input,textarea').click(function () { this.select() })
}
function updateAccountBalances (appAPI) {
function updateAccountBalances (self, appAPI) {
var accounts = $('#txorigin').children('option')
accounts.each(function (index, value) {
(function (acc) {
appAPI.getBalance(accounts[acc].value, function (err, res) {
if (!err) {
accounts[acc].innerText = accounts[acc].value.substring(0, 8) + '... (' + res.toString() + ' ether)'
accounts[acc].innerText = helper.shortenAddress(accounts[acc].value, res)
}
})
})(index)

@ -0,0 +1,6 @@
module.exports = {
shortenAddress: function (address, etherBalance) {
var len = address.length
return address.slice(0, 5) + '...' + address.slice(len - 5, len) + (etherBalance ? ' (' + etherBalance.toString() + ' ether)' : '')
}
}

@ -9,6 +9,7 @@ var EventManager = require('ethereum-remix').lib.EventManager
var crypto = require('crypto')
var async = require('async')
var TxRunner = require('./app/txRunner')
var helper = require('./lib/helper')
var yo = require('yo-yo')
// copy to copyToClipboard
@ -353,8 +354,7 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
var context = self.executionContext.isVM() ? 'memory' : 'blockchain'
address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex')
var len = address.length
var shortAddress = address.slice(0, 5) + '...' + address.slice(len - 5, len)
var shortAddress = helper.shortenAddress(address)
var title = yo`
<div class="${cssInstance.title}" onclick=${toggleClass}>
<div class="${cssInstance.titleText}"> ${contract.name} at ${shortAddress} (${context}) </div>

Loading…
Cancel
Save