Show Bob balances too

This commit is contained in:
Oskar Thoren 2021-01-26 12:14:03 +08:00
parent c29fcba493
commit 471beb9bfe
No known key found for this signature in database
GPG Key ID: BDB55C8C0EF29911
1 changed files with 33 additions and 8 deletions

View File

@ -132,28 +132,53 @@ App = {
$("#aliceAddress").html("Address: " + App.aliceAddress); $("#aliceAddress").html("Address: " + App.aliceAddress);
$("#bobAddress").html("Address: " + App.bobAddress); $("#bobAddress").html("Address: " + App.bobAddress);
// Get Alice Balance
web3.eth.getBalance( web3.eth.getBalance(
App.aliceAddress, App.aliceAddress,
function(err, res) { function(err, res) {
if (err == null) { if (err == null) {
aliceBalance = web3.fromWei(res.toNumber()) balance = web3.fromWei(res.toNumber())
$("#aliceETHBalance").html("ETH Balance: " + aliceBalance + " ETH"); $("#aliceETHBalance").html("ETH Balance: " + balance + " ETH");
} else { } else {
console.log("Err", App.aliceAddress, err) console.log("Err", App.aliceAddress, err)
} }
}) })
// Show ERC20 balance // Get Bob Balance
// XXX: Not quite sure why it says App.contracts.ERC20PresetMinterPauser is undefiend? Sometimes... web3.eth.getBalance(
var erc20 = await App.contracts.ERC20PresetMinterPauser.deployed() App.bobAddress,
var erc20balance = await erc20.balanceOf(App.aliceAddress) function(err, res) {
console.log("ERC20 Balance ", erc20balance.toNumber()) if (err == null) {
$("#aliceERC20Balance").html("ERC20 Balance: " + erc20balance.toNumber() + " TEST"); balance = web3.fromWei(res.toNumber())
$("#bobETHBalance").html("ETH Balance: " + balance + " ETH");
} else {
console.log("Err", App.bobAddress, err)
}
})
// XXX: Not quite sure why it says App.contracts.ERC20PresetMinterPauser is undefined? Sometimes...
var erc20 = await App.contracts.ERC20PresetMinterPauser.deployed()
// Get Alice ERC20 balance
var aliceERC20Balance = await erc20.balanceOf(App.aliceAddress)
console.log("ERC20 Balance ", aliceERC20Balance.toNumber())
$("#aliceERC20Balance").html("ERC20 Balance: " + aliceERC20Balance.toNumber() + " TEST");
// Get Bob ERC20 balance
var bobERC20Balance = await erc20.balanceOf(App.bobAddress)
console.log("ERC20 Balance ", bobERC20Balance.toNumber())
$("#bobERC20Balance").html("ERC20 Balance: " + bobERC20Balance.toNumber() + " TEST");
// TODO Show balance as well
// NOTE: Hadcoding swapAddress, assuming deployed // NOTE: Hadcoding swapAddress, assuming deployed
console.log("aliceSwapAddress", App.aliceSwapAddress) console.log("aliceSwapAddress", App.aliceSwapAddress)
$("#aliceSwapAddress").html("Swap Address: " + App.aliceSwapAddress); $("#aliceSwapAddress").html("Swap Address: " + App.aliceSwapAddress);
// TODO Not using this yet I believe, implement
// Might help with withdrawal too?
//console.log("aliceSwapAddress", App.aliceSwapAddress)
//$("#bobSwapAddress").html("Swap Address: " + App.bobSwapAddress);
// Load contract data // Load contract data
// TODO Replace me // TODO Replace me
App.contracts.ERC20PresetMinterPauser.deployed().then(function(erc20) { App.contracts.ERC20PresetMinterPauser.deployed().then(function(erc20) {