Skip to content

Commit

Permalink
add eth-events, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kangarang committed Aug 11, 2018
1 parent 1d4c1dd commit 4560984
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 275 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ if Bob has SUN, FOAM, and CVL, he can participate in the Sunset, FOAM, and Civil

## Requirements

* Node >= 8.0.0
* Yarn >= 1.7.0\*

- Node >= 8.0.0
- Yarn >= 1.7.0\*
<sub>*npm is not supported for package management. tcr-ui uses yarn.lock to ensure sub-dependency versions are pinned. yarn is required to install node_modules</sub>

## Getting started
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "react-scripts test --env=jsdom",
"update:tokens": "babel-node scripts/update-tokens",
"update:abis": "babel-node scripts/addABIs",
"getLogs": "babel-node scripts/getLogs",
"eth-events": "babel-node scripts/eth-events",
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public"
},
Expand All @@ -31,6 +31,7 @@
"bn.js": "4.11.8",
"date-fns": "1.29.0",
"dayjs": "1.6.4",
"eth-events": "0.1.1",
"ethereum-ens": "0.7.4",
"ethereumjs-util": "5.2.0",
"ethers": "3.0.26",
Expand Down
38 changes: 38 additions & 0 deletions scripts/eth-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ethjs from 'ethjs'
import EthEvents from 'eth-events'

import {
buildContract,
printCommitVote,
printTokenTransfer,
printClaimReward,
} from './utils'

const provider = new Ethjs.HttpProvider(`https://mainnet.infura.io`)
const ethjs = new Ethjs(provider)

const contract = buildContract('adChain', 'registry')
const ethEvents = new EthEvents(ethjs, contract)

const fromBlock = '6000000'
const toBlock = 'latest'

const eventNames = ['_RewardClaimed']
const indexedFilterValues = {
// _to: '0xb4b26709ffed2cd165b9b49eea1ac38d133d7975',
}

ethEvents.getLogs(fromBlock, toBlock, eventNames, indexedFilterValues).then(logs => {
console.log(`${logs.length} logs`)

logs.forEach(({ logData, txData }) => {
// console.log('logData:', logData)
// console.log('txData:', txData)

printClaimReward(logData, txData)

// find matching log
// const match = find({ 'logData': { 'challengeID': logData.challengeID } }, logsC)
// console.log('match:', match)
})
})
84 changes: 0 additions & 84 deletions scripts/getLogs.js

This file was deleted.

54 changes: 54 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Token from './abis/EIP20.json'
import PLCRVoting from './abis/PLCRVoting.json'
import Registry from './abis/Registry.json'

import { baseToConvertedUnit } from 'libs/units'

export const contracts = {
abis: {
token: Token.abi,
voting: PLCRVoting.abi,
registry: Registry.abi,
},
addresses: {
adChain: {
token: '0xd0d6d6c5fe4a677d343cc433536bb717bae167dd',
voting: '0xb4b26709ffed2cd165b9b49eea1ac38d133d7975',
registry: '0x5e2eb68a31229b469e34999c467b017222677183',
},
},
}

export function buildContract(tcr = 'adChain', contract) {
return {
abi: contracts.abis[contract],
address: contracts.addresses[tcr][contract],
}
}

export function printTokenTransfer(logData, txData) {
console.log('from:', logData._from)
console.log('value:', baseToConvertedUnit(logData._value, '9'))
console.log('txHash:', txData.txHash)
console.log('blockNumber:', txData.blockNumber)
console.log('date:', txData.date)
console.log('')
}

export function printCommitVote(logData, txData) {
console.log('pollID:', logData.pollID.toString())
console.log('numTokens:', logData.numTokens.toString())
console.log('voter:', logData.voter)
console.log('txHash:', txData.txHash)
console.log('blockNumber:', txData.blockNumber)
console.log('date:', txData.date)
console.log('')
}

export function printClaimReward(logData) {
console.log('pollID:', logData.challengeID.toString())
console.log('voter:', logData.voter)
console.log('reward:', baseToConvertedUnit(logData.reward, '9'))
console.log('reward:', logData.reward.toString())
console.log('')
}
6 changes: 3 additions & 3 deletions src/Root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { Component } from 'react'
import { Provider } from 'react-redux'
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'

import Home from './containers/Home/Loadable'
import Registry from './containers/Registry/Loadable'
import Home from 'containers/Home/Loadable'
import Registry from 'containers/Registry/Loadable'

class RootClass extends Component {
render() {
const { store } = this.props

// :[variables] are accessible via `props.match.params`
const routes = (
<Switch>
{/* :[variables] are accessible via `props.match.params` */}
<Route exact path="/:filter?" component={Home} />
<Route path="/:registryAddress/:filter?" component={Registry} />
{/* <Route path="/registry/:registryAddress" component={Registry} /> */}
Expand Down
6 changes: 4 additions & 2 deletions src/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ import { createStructuredSelector } from 'reselect'
import { selectBalances, selectTCR, selectStats } from 'modules/home/selectors'
import * as actions from 'modules/home/actions'

import Registry from 'containers/Registry'
import Wrapper from 'containers/Wrapper'
import Banner from 'components/Banner'
import Stats from 'components/Stats'
import toJS from 'components/toJS'
import Wrapper from '../Wrapper'

class Home extends Component {
componentDidMount() {
this.props.onSetupEthereum()
}

render() {
const { stats, balances, tcr } = this.props
const { stats, balances, tcr, match, history } = this.props

return (
<Wrapper>
<Banner tcr={tcr} />
<Stats balances={balances} stats={stats} tcr={tcr} />
<Registry match={match} history={history} />
</Wrapper>
)
}
Expand Down
86 changes: 46 additions & 40 deletions src/containers/Registry/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { compose } from 'redux'
import { createStructuredSelector } from 'reselect'
import { connect } from 'react-redux'
import styled from 'styled-components'
import { createStructuredSelector } from 'reselect'

import Tabs from '@material-ui/core/Tabs'
import Tab from '@material-ui/core/Tab'
import Tabs from '@material-ui/core/Tabs'
import { withStyles } from '@material-ui/core/styles'

import { colors, theme, muiTheme } from 'global-styles'
import { makeSelectVisibleListings } from 'modules/listings/selectors'
import { selectStats, selectTCR } from 'modules/home/selectors'
import { makeSelectVisibleListings } from 'modules/listings/selectors'

import toJS from 'components/toJS'
import Listings from 'containers/Listings/Loadable'
import Wrapper from '../Wrapper'
// import Wrapper from '../Wrapper'

const Table = styled.div`
flex-grow: 1;
Expand Down Expand Up @@ -72,60 +72,66 @@ class Registry extends Component {
}
handleChange = (event, value) => {
this.setState({ value })
this.props.history.push(`/${this.props.tcr.registryAddress.slice(0, 8)}/${value}`)
// this.props.history.push(`/${this.props.tcr.registryAddress.slice(0, 8)}/${value}`)
this.props.history.push(`/${value}`)
}
handleChangePage = (event, page) => {
this.setState({ page })
}

render() {
const { value } = this.state
const { classes, stats, visibleListings } = this.props
const {
stats,
classes: { tabRoot, tabSelected, tabsIndicator, tabsRoot },
visibleListings,
} = this.props

return (
<Wrapper>
<Table>
<TabsContainer>
<Tabs
centered={false}
value={value}
onChange={this.handleChange}
classes={{ root: classes.tabsRoot, indicator: classes.tabsIndicator }}
>
{/* router navlinks change the value of props.filter
<Table>
{/* <Wrapper> */}
<TabsContainer>
<Tabs
centered={false}
value={value}
onChange={this.handleChange}
classes={{ root: tabsRoot, indicator: tabsIndicator }}
>
{/* router navlinks change the value of props.filter
what matters in practice is that there is only 1 single source of truth for any independent piece of data
redux: listings, react-router: anything that can be computed by the URL (visibility filter) */}
<Tab
disableRipple
value="whitelist"
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label={`IN REGISTRY (${stats.sizes.whitelist})`}
/>
<Tab
disableRipple
value="applications"
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label={`NEW APPLICATIONS (${stats.sizes.applications})`}
/>
<Tab
disableRipple
value="faceoffs"
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label={`VOTE (${stats.sizes.faceoffs})`}
/>
</Tabs>
</TabsContainer>
<Tab
disableRipple
value="whitelist"
classes={{ root: tabRoot, selected: tabSelected }}
label={`IN REGISTRY (${stats.sizes.whitelist})`}
/>
<Tab
disableRipple
value="applications"
classes={{ root: tabRoot, selected: tabSelected }}
label={`NEW APPLICATIONS (${stats.sizes.applications})`}
/>
<Tab
disableRipple
value="faceoffs"
classes={{ root: tabRoot, selected: tabSelected }}
label={`VOTE (${stats.sizes.faceoffs})`}
/>
</Tabs>
</TabsContainer>

<Listings listingType={value} visibleListings={visibleListings} />
</Table>
</Wrapper>
<Listings listingType={value} visibleListings={visibleListings} />
{/* </Wrapper> */}
</Table>
)
}
}

const mapStateToProps = createStructuredSelector({
stats: selectStats,
tcr: selectTCR,

// send route-based props to selector
visibleListings: makeSelectVisibleListings(),
})
Expand Down
Loading

0 comments on commit 4560984

Please sign in to comment.