-
Notifications
You must be signed in to change notification settings - Fork 0
/
dappTreasury.js
59 lines (53 loc) · 2.56 KB
/
dappTreasury.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Using the 'load' event listener for Javascript to
// check if window.ethereum is available
// check who is the current owner
window.addEventListener('load', function() {
if (typeof window.ethereum !== 'undefined') {
//console.log('window.ethereum is enabled')
if (window.ethereum.isMetaMask === true && ethereum.selectedAddress !== null) {
// console.log('MetaMask is active')
// console.log('getting current owner')
// const showOwnerOnLoad = document.getElementById('whoIsOwner')
// showOwnerOnLoad.innerHTML = 'Current Contract Owner: ' + ethereum.selectedAddress
// do nothing
} else {
// console.log('MetaMask is not available')
window.location.assign("Onboard.html")
}
} else {
// console.log('window.ethereum - metamask - is not found')
window.location.assign("Onboard.html")
}
})
window.onload = async () => {
// const getTokenSupply = document.getElementById('checkTokenButton')
var valueName = await grantMgmt.methods.name().call()
var valueSymbol = await grantMgmt.methods.symbol().call()
var valueSupply = await grantMgmt.methods.totalSupply().call()
//console.log('Current Supply: ' + valueSupply)
//const tokenNameValue = document.getElementById('tokenName')
document.getElementById('tokenName').innerHTML = 'Token Name: ' + valueName
const tokenSymbol = document.getElementById('tokenSymbol')
tokenSymbol.innerHTML = 'Token Symbol: ' + valueSymbol
const totalSupplyValue = document.getElementById('totalSupply')
totalSupplyValue.innerHTML = 'Current Supply: ' + Math.round(valueSupply * .000000000000000001)
}
// Mint Tokens
if (document.getElementById('mintTokens')) {
const clickMintButton = document.getElementById('mintTokens')
clickMintButton.onclick = async () => {
const mintStatus = document.getElementById('mintingComplete')
mintStatus.innerHTML = ``
const addressValue = document.getElementById('_receiveAddr').value;
const numberTokens = document.getElementById('_numToMint').value;
await grantMgmt.methods.mint(addressValue, numberTokens).send({from: ethereum.selectedAddress}).then(result => {
mintStatus.innerHTML = `See Transaction Information by Clicking Here`
mintStatus.href = `https://ropsten.etherscan.io/tx/${result.transactionHash}`
})
var updatedSupplyValue = await grantMgmt.methods.totalSupply().call()
const setNewSupplyValue = document.getElementById('totalSupply')
setNewSupplyValue.innerHTML = 'Current Supply: ' + Math.round(updatedSupplyValue * .000000000000000001)
document.getElementById('_receiveAddr').value = ''
document.getElementById('_numToMint').value = ''
}
}