Last active
December 20, 2017 02:32
-
-
Save devonwesley/53412871b75f025cf3211698ef596a03 to your computer and use it in GitHub Desktop.
This function is going to create elements for our contract props.
This file contains hidden or 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 createContractElement(contractProp, container) { | |
return typeof contractProp[1] === 'function' | |
? createContractFunction(contractProp, container) | |
: createContractProp(contractProp, 'P') | |
} | |
function createContractFunction(contractFunc, container) { | |
const name = contractFunc[0] | |
const func = contractFunc[1] | |
const btn = document.createElement('BUTTON') | |
btn.className = 'mui-btn mui-btn--primary mui-col-md-2' | |
btn.innerText = name | |
const eventHandler = () => { | |
const div = document.createElement('DIV') | |
div.className = 'mui-col-md-3' | |
div.innerHTML = `<br /> "${func()}"` | |
container.appendChild(div) | |
} | |
btn.addEventListener('click', eventHandler) | |
return btn | |
} | |
function createContractProp(contractProp, element) { | |
const className = 'mui-col-md-2 mui-panel' | |
const name = contractProp[0] | |
const value = contractProp[1] | |
const hashesNames = { | |
'hash': 'hash', | |
'blockHash': 'blockHash', | |
'input': 'input', | |
'from': 'from', | |
} | |
return hashesNames[name] | |
? createContractHash(name, value, 'LI') | |
: createContractHash(name, value, 'P', className) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment