Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin committed Oct 3, 2018
2 parents 13e1bca + d2029d9 commit b55f697
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 50 deletions.
2 changes: 1 addition & 1 deletion demoapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"s3": "^4.4.0"
},
"scripts": {
"start": "react-scripts start",
"start": "PORT=8000 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
Expand Down
17 changes: 10 additions & 7 deletions demoapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import Web3 from 'web3';

//requires some stuff to be installed:
// bouncer-proxy -> clevis test full
// mkdir ~/dapparatus/demoapp/src/contracts
// cp ~/bouncer-proxy/src/contracts/* ~/dapparatus/demoapp/src/contracts/
// cp ~/bouncer-proxy/Example/Example.address ~/dapparatus/demoapp/Example/
// clevis test publish
// mkdir ~/dapparatus/demoapp/Example
// cp ~/bouncer-proxy/Example/* ~/dapparatus/demoapp/Example/
// in demoapp: clevis test publish

const METATX = {
endpoint:"http://0.0.0.0:10001/",
contract:"0xf5bf6541843D2ba2865e9aeC153F28aaD96F6fbc"
contract:"0xf5bf6541843D2ba2865e9aeC153F28aaD96F6fbc",
//accountGenerator: "//account.metatx.io",
}

class App extends Component {
Expand Down Expand Up @@ -86,10 +89,10 @@ class App extends Component {
connectedDisplay.push(
<Transactions
key="Transactions"
config={{DEBUG:true}}
config={{DEBUG:false}}
metaAccount={this.state.metaAccount}
metaContract={this.state.metaContract}
metatx={this.state.metatx}
metatx={METATX}
account={account}
gwei={gwei}
web3={web3}
Expand All @@ -115,7 +118,7 @@ class App extends Component {
{this.state.count}
</div>
<Button size="2" onClick={()=>{
tx(contracts.Example.addAmount(3),(receipt)=>{
tx(contracts.Example.addAmount(3),50000,(receipt)=>{
console.log("addAmount RESULT:",receipt)
})
}}>
Expand All @@ -130,7 +133,7 @@ class App extends Component {
<div className="App">
<Dapparatus
config={{
DEBUG:true,
DEBUG:false,
requiredNetwork:['Unknown','Rinkeby'],
}}
metatx={METATX}
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class Address extends Component {
load() {
window.web3.eth.getBalance(this.props.address,(err,balance,e)=>{
if(balance){
balance=balance.toNumber()/1000000000000000000
if(typeof balance == "string"){
balance = parseFloat(balance)/1000000000000000000
}else{
balance=balance.toNumber()/1000000000000000000
}
this.setState({balance:balance})
}
})
Expand Down
72 changes: 50 additions & 22 deletions src/dapparatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import Blockies from 'react-blockies'
import ENS from 'ethereum-ens'
import Web3 from 'web3';
import Button from "./button.js"
const queryString = require('query-string');

let interval
let defaultConfig = {}
defaultConfig.DEBUG = false;
defaultConfig.POLLINTERVAL = 777
defaultConfig.showBalance = true

//metatx
defaultConfig.metatxAccountGenerator = "//account.metatx.io"


defaultConfig.hideNetworks = [
"Mainnet"
]
Expand Down Expand Up @@ -57,24 +63,33 @@ defaultConfig.requiredNetwork = [
"Mainnet",
"Unknown"//allow local RPC for testing
]

class Dapparatus extends Component {
constructor(props) {
super(props);
let config = defaultConfig

if(props.config) {
config = deepmerge(config, props.config)
if(props.config.requiredNetwork){ config.requiredNetwork = props.config.requiredNetwork}
}
const { cookies } = props;
let metaAccountCookie = cookie.load('metaAccount')
let queryParams = queryString.parse(window.location.search)
let metaPrivateKey = cookie.load('metaPrivateKey')
let metaAccount
let account = 0
if(metaAccountCookie){
if(metaPrivateKey){
let tempweb3 = new Web3()
metaAccount = tempweb3.eth.accounts.privateKeyToAccount(metaAccountCookie.privateKey);
metaAccount = tempweb3.eth.accounts.privateKeyToAccount(metaPrivateKey);
account = metaAccount.address
}else if(queryParams.privateKey){
const expires = new Date()
expires.setDate(expires.getDate() + 365)
cookie.save('metaPrivateKey', queryParams.privateKey, { path: '/',expires})
window.location = window.location.href.split("?")[0];
}

console.log("!!!!~~~~~ ",config)

this.state = {
status:"loading",
network:0,
Expand All @@ -84,7 +99,7 @@ class Dapparatus extends Component {
avgBlockTime: 15000,
lastBlockTime: 0,
metaAccount: metaAccount,
metatx: this.props.metatx
web3Fellback: false,
}
}
componentDidMount(){
Expand All @@ -99,6 +114,7 @@ class Dapparatus extends Component {
if (typeof window.web3 == 'undefined') {
console.log("Connecting to infura...")
window.web3 = new Web3(this.props.fallbackWeb3Provider) //CORS ISSUES!//
this.setState({web3Fellback:true})
//window.web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws'))
}

Expand All @@ -113,19 +129,16 @@ class Dapparatus extends Component {
}
} else {
if(this.state.config.DEBUG) console.log("DAPPARATUS - yes web 3",window.web3)

if(typeof window.web3.version.getNetwork != "function"){
window.window.web3.eth.net.getId((err,network)=>{
console.log("NETWORK GETID",err,network)
//console.log("NETWORK GETID",err,network)
this.inspectNetwork(network)
})
}else{
window.web3.version.getNetwork((err,network)=>{
this.inspectNetwork(network)
})
}


}
}
inspectNetwork(network){
Expand All @@ -134,22 +147,24 @@ class Dapparatus extends Component {
if(this.state.config.DEBUG) console.log("DAPPARATUS - translated network",network)
let accounts
try{
if(this.state.config.DEBUG) console.log("DAPPARATUS - getting accounts...")
window.web3.eth.getAccounts((err,_accounts)=>{

if(!_accounts||_accounts.length<=0||network=="Unknown"||network=="Private"){
//console.log("ACCOUNTS",err,_accounts)
if(!_accounts||_accounts.length<=0||this.state.web3Fellback){
if(this.state.config.DEBUG) console.log("DAPPARATUS - no inject accounts - generate? ")
if(!this.state.metaAccount||!this.state.metaAccount.address){
this.setState({status:"noaccount"},()=>{this.props.onUpdate(this.state)})
}else{
let currentAccounts = []
console.log("generated account",this.state.metaAccount)
//console.log("generated account",this.state.metaAccount)
currentAccounts.push(this.state.metaAccount.address)
console.log("currentAccounts",currentAccounts)
//console.log("currentAccounts",currentAccounts)
this.inspectAccounts(currentAccounts,network)
}
}else{
if(this.state.config.DEBUG) console.log("DAPPARATUS - injected account: ",_accounts)
this.inspectAccounts(_accounts,network)
this.setState({metaAccount:false})
}
})
}catch(e){
Expand Down Expand Up @@ -181,7 +196,7 @@ class Dapparatus extends Component {
window.web3.eth.getBalance(""+account,(err,balance,e)=>{
if(typeof balance == "string"){
balance = parseFloat(balance)/1000000000000000000
}else{
}else if(balance){
balance=balance.toNumber()/1000000000000000000
}

Expand Down Expand Up @@ -263,15 +278,24 @@ class Dapparatus extends Component {
let mmClick = ()=>{
window.open('https://metamask.io', '_blank');
}
if(this.state.config.metatxAccountGenerator){
dapparatus = "Connecting to "+this.state.config.metatxAccountGenerator+"..."
window.location = this.state.config.metatxAccountGenerator
}else{
dapparatus = "Generating Account..."
let result = window.web3.eth.accounts.create();
//console.log("GENERATE",result)
const expires = new Date()
expires.setDate(expires.getDate() + 365)
cookie.save('metaPrivateKey', result.privateKey, { path: '/',expires})
this.setState({metaAccount:result,account:result.address})
}

/*
dapparatus = (
<div style={this.state.config.boxStyleBefore}>
<Button color={"blue"} onClick={()=>{
let result = window.web3.eth.accounts.create();
console.log("GENERATE",result)
const expires = new Date()
expires.setDate(expires.getDate() + 365)
cookie.save('metaAccount', result, { path: '/',expires})
this.setState({metaAccount:result,account:result.address})
}}>
Generate Account
</Button>
Expand All @@ -281,7 +305,7 @@ class Dapparatus extends Component {
Install Wallet
</Button>
</div>
)
)*/
} else if(this.state.status=="locked"){
dapparatus = (
<div style={this.state.config.boxStyleBefore}>
Expand Down Expand Up @@ -333,7 +357,11 @@ class Dapparatus extends Component {
}

let displayName = this.state.account.substr(0,this.state.config.accountCutoff)
if(this.state.ens) displayName = this.state.ens
if(this.props.replaceName){
displayName = this.props.replaceName
}else if(this.state.ens){
displayName = this.state.ens
}

dapparatus = (
<div style={this.state.config.boxStyle}>
Expand Down
Loading

0 comments on commit b55f697

Please sign in to comment.