Last active
November 21, 2017 07:34
-
-
Save devonwesley/948dd48f13b105141ed632e966a45dec to your computer and use it in GitHub Desktop.
Code that is being used for a blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderContractList() { | |
const contractListContainer = document.getElementById('contract-list') | |
const { contracts } = compiledContract | |
Object.keys(contracts).forEach((contract, index) => { | |
const label = `contract-id-${index}` | |
const gas = contracts[contract].gasEstimates.creation | |
createContractInfo(gas, contract, label, function(el){ | |
contractListContainer.appendChild(el) | |
const btnContainer = document.getElementById(label) | |
btnContainer.appendChild( | |
buttonFactory('primary', contract, contracts[contract], 'details') | |
) | |
}) | |
}) | |
} | |
function createContractInfo(gas, contractName, label, callback) { | |
const el = document.createElement('DIV') | |
el.innerHTML = ` | |
<div class="mui-panel"> | |
<div id="${label}" class="mui-row"> | |
<div class="mui-col-md-3"> | |
Contract Name: <strong>${contractName.substring(1, contractName.length)}</strong> | |
</div> | |
<div class="mui-col-md-3"> | |
Gas Estimate: <strong style="color: green;"> | |
${sumArrayOfInts(gas)} | |
</strong> | |
</div> | |
</div> | |
</div> | |
` | |
callback(el) | |
} | |
function sumArrayOfInts(array) { | |
return array.reduce((acc, el) => (acc += el), 0) | |
} | |
function buttonFactory(color, contractName, contract, type) { | |
const btn = document.createElement('BUTTON') | |
const btnContainer = document.createElement('DIV') | |
btn.className = `mui-btn mui-btn--small mui-btn--${color} mui-btn--raised"` | |
btn.innerText = type | |
btn.addEventListener('click', () => type === 'details' | |
? 'DETAILS BUTTON' | |
: 'DEPLOY BUTTON' | |
) | |
btnContainer.className = 'mui-col-md-3' | |
btnContainer.appendChild(btn) | |
return btnContainer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment