diff --git a/demoapp/package.json b/demoapp/package.json index b83d721..440c4c0 100644 --- a/demoapp/package.json +++ b/demoapp/package.json @@ -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" diff --git a/demoapp/src/App.js b/demoapp/src/App.js index 4b068aa..d4fc6a2 100644 --- a/demoapp/src/App.js +++ b/demoapp/src/App.js @@ -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 { @@ -86,10 +89,10 @@ class App extends Component { connectedDisplay.push( @@ -281,7 +305,7 @@ class Dapparatus extends Component { Install Wallet - ) + )*/ } else if(this.state.status=="locked"){ dapparatus = (
@@ -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 = (
diff --git a/src/transactions.js b/src/transactions.js index 218c202..dda263e 100644 --- a/src/transactions.js +++ b/src/transactions.js @@ -18,6 +18,9 @@ defaultConfig.GASLIMITMULTIPLIER = 1.2; defaultConfig.EXPECTEDPROGRESSBARVSAVGBLOCKTIME = 2.1; defaultConfig.DEFAULTGASLIMIT = 120000; + +const METATXPOLL = 1777 + class Transactions extends Component { constructor(props) { super(props); @@ -31,6 +34,48 @@ class Transactions extends Component { config: config, callbacks: {} } + if(props.metatx){ + this.metaTxPoll() + setInterval(this.metaTxPoll.bind(this),METATXPOLL) + } + } + metaTxPoll(){ + let metatxUrl = this.props.metatx.endpoint+'txs/'+this.props.account + axios.get(metatxUrl, { + headers: { + 'Content-Type': 'application/json', + } + }).then((response)=>{ + if(response&&response.data){ + let currentTransactions = this.state.transactions + let callbacks = this.state.callbacks + let changed = false + for(let d in response.data){ + let thisTransaction = response.data[d] + let found = false + for(let t in currentTransactions){ + if(currentTransactions[t].hash == thisTransaction.hash){ + found = true + } + } + if(!found){ + console.log("INCOMING META TX:",response.data[d]) + changed=true + if(this.state.config.DEBUG) console.log("Adding tx to list...") + currentTransactions.push(thisTransaction) + callbacks[transactionHash] = ()=>{ + console.log("META TX FINISHED",transactionHash) + } + } + } + if(changed){ + this.setState({transactions:currentTransactions,callbacks:callbacks}) + } + } + }) + .catch((error)=>{ + console.log(error); + }); } componentDidMount(){ interval = setInterval(this.checkTxs.bind(this),this.state.config.CHECKONTXS) @@ -39,41 +84,44 @@ class Transactions extends Component { metatx: async (tx,maxGasLimit,txData,cb)=>{ if(this.state.config.DEBUG) console.log("YOU WANT TO SEND A META TX ",tx,this.props.gwei) let callback = cb - let minBlock = 0 let value = 0 - this.sendMetaTx(this.props.metatx.contract,this.props.metaAccount.address,tx._parent._address,value,tx.encodeABI(),minBlock) + this.sendMetaTx(this.props.metatx.contract,this.props.metaAccount.address,tx._parent._address,value,tx.encodeABI()) }, - tx: async (tx,maxGasLimit,txData,cb)=>{ + tx: async (tx,maxGasLimit,txData,value,cb)=>{ if(this.state.config.DEBUG) console.log("YOU WANT TO SEND TX ",tx,this.props.gwei) let callback = cb + console.log("==MM meta:",this.props.metaAccount) + if(this.props.metaAccount){ console.log("================&&&& metaAccount, send as metatx to relayer "+this.props.metatx.endpoint+" to contract :",this.props.metatx.contract) - let minBlock = 0 - let value = 0 - this.sendMetaTx(this.props.metatx.contract,this.props.metaAccount.address,tx._parent._address,value,tx.encodeABI(),minBlock) + let _value = 0 + this.sendMetaTx(this.props.metatx.contract,this.props.metaAccount.address,tx._parent._address,_value,tx.encodeABI()) }else{ let gasLimit - try{ - gasLimit = Math.round((await tx.estimateGas()) * this.state.config.GASLIMITMULTIPLIER) - }catch(e){ - if(typeof maxGasLimit != "function"){ - gasLimit = maxGasLimit - }else{ + if(typeof maxGasLimit != "function"){ + gasLimit = maxGasLimit + }else{ + try{ + gasLimit = Math.round((await tx.estimateGas()) * this.state.config.GASLIMITMULTIPLIER) + }catch(e){ gasLimit = this.state.DEFAULTGASLIMIT } } - if(typeof maxGasLimit == "function"){ callback = maxGasLimit } + if(!value) value=0 let paramsObject = { from: this.props.account, - gas:gasLimit, - gasPrice:Math.round(this.props.gwei * 1000000000) + value: value, + gas: gasLimit, + gasPrice: Math.round(this.props.gwei * 1000000000) } + console.log("TX",paramsObject) + if(typeof txData == "function"){ callback = txData }else if(txData){ @@ -169,10 +217,9 @@ class Transactions extends Component { componentWillUnmount(){ clearInterval(interval) } - async sendMetaTx(proxyAddress,fromAddress,toAddress,value,txData,minBlock){ - if(!minBlock) minBlock=0 + async sendMetaTx(proxyAddress,fromAddress,toAddress,value,txData){ let {metaContract,account,web3} = this.props - const nonce = await metaContract.nonce(fromAddress,minBlock).call() + const nonce = await metaContract.nonce(fromAddress).call() console.log("Current nonce for "+fromAddress+" is ",nonce) let rewardAddress = "0x0000000000000000000000000000000000000000" let rewardAmount = 0 @@ -189,6 +236,8 @@ class Transactions extends Component { }*/ console.log("Reward: "+rewardAmount+" tokens at address "+rewardAddress) + + const parts = [ proxyAddress, fromAddress, @@ -197,7 +246,6 @@ class Transactions extends Component { txData, rewardAddress, web3.utils.toTwosComplement(rewardAmount), - web3.utils.toTwosComplement(minBlock), web3.utils.toTwosComplement(nonce), ] console.log("PARTS",parts)