Skip to content

Instantly share code, notes, and snippets.

View devonwesley's full-sized avatar
Probably at coffee shop in Oakland, CA.

Devon Wesley devonwesley

Probably at coffee shop in Oakland, CA.
  • Oakland, CA
View GitHub Profile
@devonwesley
devonwesley / CreateContractHash.js
Last active December 20, 2017 18:07
This creates an element from the contract props pass to it.
function createContractHash(name, hash, tag, className) {
const el = document.createElement(tag)
const value = name === 'input'
? `<br/><textarea style="width: 100%;">${hash}</textarea>`
: hash
el.className = className
el.innerHTML = `<br/><strong>${name}</strong>: ${value}`
return el
@devonwesley
devonwesley / CreateContractElement.js
Last active December 20, 2017 02:32
This function is going to create elements for our contract props.
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')
@devonwesley
devonwesley / FilterProps.js
Last active December 20, 2017 02:29
This is the information about the contract and transaction that we don't want.
function filterProps(prop) {
const excludes = {
'_eth': '_eth',
'abi': 'abi',
'allEvents': 'allEvents',
'to': 'to',
'value': 'value',
'blockNumber': 'blockNumber',
'address': 'address',
'transactionHash': 'transactionHash',
@devonwesley
devonwesley / CategorizeContractProps.js
Last active December 20, 2017 02:30
This function helps us pick which containers a prop is for.
function categorizeContractProps(params) {
const hashNames = {
'hash': 'hash',
'blockHash': 'blockHash',
'input': 'input',
'from': 'from',
}
if (hashNames[params.key]) {
return params.hashList
@devonwesley
devonwesley / CreatePropsContainers.js
Last active December 20, 2017 02:28
These our the 3 panel containers for our contract props.
function createPropsContainers(panel, callback) {
document.getElementById('contractFunction').appendChild(panel)
const propsList = createPanelContainer('props')
const hashList = createPanelContainer('hashes')
const functionList = createPanelContainer()
const banner = '<H3><strong>Contract Functions: </strong></H3>'
functionList.innerHTML = banner
panel.append(propsList)
panel.append(hashList)
@devonwesley
devonwesley / CreateContract.js
Last active December 20, 2017 02:27
This is how we create contracts, and display them in the view.
function createContract(contract, panel) {
const propHandler = lists => props => {
if(!filterProps(props[0])) {
const container = categorizeContractProps({
key: props[0],
value: props[1],
...lists
})
container.append(createContractElement(props, container))
@devonwesley
devonwesley / CreateContractPanel.js
Last active December 20, 2017 02:26
Creates a Container for smart contract info inside of the UI.
function createContractPanel(contract, callback) {
const div = document.createElement('DIV')
div.className = 'mui-panel'
div.innerHTML = `
<h3>
<strong>Contract: </strong>
${contract.contractName}
</h3>
<p>
<strong>Block Number: </strong>
@devonwesley
devonwesley / currentNetwork.js
Last active December 20, 2017 02:24
A code snippet that checks which ethereum network your on.
function currentNetwork() {
const network = web3.eth.getBlock(0).hash
const main = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
const test = '0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d'
switch (network) {
case main:
return 'Main Net'
case test:
return 'Ropsten Network'
@devonwesley
devonwesley / newContractCallback.js
Last active December 20, 2017 02:25
Code snippet of a callback for a contract being deployed.
function newContractCallback(name) {
return (err, contract) => {
getAccounts()
if (!err) {
!contract.address
? status(`Deploying contract..`)
: renderContract(contract, name)
}
}
}
function renderContract(contract, contractName) {
status(`Contract Deployed...`)
const { transactionHash, address } = contract
web3.eth.getTransaction(transactionHash, (err, transaction) => {
if (!err) {
const props = { ...transaction, ...contract, }
const details = {
blockNumber: transaction.blockNumber,
contractName,