Show alice balance

This commit is contained in:
Oskar Thoren 2021-01-19 19:04:06 +08:00
parent 25c18b88ce
commit ee0d1445e6
No known key found for this signature in database
GPG Key ID: BDB55C8C0EF29911
1 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,7 @@
App = {
web3Provider: null,
contracts: {},
aliceAddress: '0x0',
account: '0x0',
init: function() {
@ -68,7 +69,8 @@ App = {
});
},
render: function() {
// NOTE: async, might want to pull some stuff out here
render: async function() {
var electionInstance;
var loader = $("#loader");
var content = $("#content");
@ -77,21 +79,22 @@ App = {
content.hide();
// Load account data
web3.eth.getCoinbase(function(err, account) {
console.log("getCoinbase", account, err);
if (err === null) {
App.account = account;
$("#accountAddress").html("Your Account: " + account);
}
});
aliceAddress = await web3.eth.accounts[0];
App.aliceAddress = aliceAddress;
$("#accountAddress").html("Your Account: " + aliceAddress);
console.log("aliceAddress", aliceAddress)
web3.eth.getCoinbase(function(err, account) {
console.log("getCoinbase", account, err);
if (err === null) {
App.account = account;
$("#accountAddress").html("Your Account: " + account);
}
});
web3.eth.getBalance(
App.aliceAddress,
function(err, res) {
if (err == null) {
console.log("Balance", res.toNumber())
aliceBalance = res.toNumber()
$("#aliceBalance").html("Alice Balance: " + aliceBalance);
} else {
console.log("Err", App.aliceAddress, err)
}
})
// Load contract data
// TODO Replace me