From 4d44cdf723b281006da6ad5fb6db14b3d5e5ea6f Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 10:10:06 -0700 Subject: [PATCH 01/10] get yo text right --- src/App.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index ca1882d5..161b8437 100644 --- a/src/App.js +++ b/src/App.js @@ -142,7 +142,8 @@ if(ERC20TOKEN=="BuffiDai"){ let innerStyle = { maxWidth:740, - margin:'0 auto' + margin:'0 auto', + textAlign:'left', } let buttonStyle = { From a470c096928cf47401275cc1200339655c38ce78 Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 11:35:50 -0700 Subject: [PATCH 02/10] debugging on stage sorry for the master pushes :) --- src/App.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 161b8437..e1530b4f 100644 --- a/src/App.js +++ b/src/App.js @@ -439,14 +439,14 @@ class App extends Component { address _destination, uint256 _gasReward */ - tx(contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account,0), 220000, false, 0, (result) => { + tx(contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account,0), 550000, false, 0, (result) => { if (result) { console.log("CLAIMED!!!", result) this.setState({claimed: true}) setTimeout(() => { this.setState({sending: false}, () => { //alert("DONE") - window.location = "/" + //window.location = "/" }) }, 2000) } From 3bdcb91896d57a04cbc0b83065185ea86811e87d Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 12:15:37 -0700 Subject: [PATCH 03/10] pull out relayer reward --- contracts/Links/Links.sol | 160 ++++++++++++++++---------------------- src/App.js | 38 ++++----- 2 files changed, 80 insertions(+), 118 deletions(-) diff --git a/contracts/Links/Links.sol b/contracts/Links/Links.sol index f9b95173..67f4f845 100644 --- a/contracts/Links/Links.sol +++ b/contracts/Links/Links.sol @@ -21,10 +21,10 @@ contract Links { ); event Claimed( bytes32 indexed id, - address sender, - uint256 value, - address indexed receiver, - uint256 indexed nonce, + address sender, + uint256 value, + address indexed receiver, + uint256 indexed nonce, bool claimed ); @@ -32,11 +32,11 @@ contract Links { /// @param _id Fund lookup key value. /// @param _signature Sender signature. function send( - bytes32 _id, + bytes32 _id, bytes memory _signature - ) - public - payable + ) + public + payable returns (bool) { require(msg.value >= 1500000000000000,"Links::send, needs to be at least 0.0015 xDai to pay relay reward"); @@ -68,33 +68,30 @@ contract Links { /// @param _signature Sender signature. /// @param _destination Destination address. function claim( - bytes32 _id, - bytes memory _signature, - bytes32 _claimHash, - address _destination, - uint256 _gasReward - ) - public + bytes32 _id, + bytes memory _signature, + bytes32 _claimHash, + address _destination + ) + public returns (bool) { require(isFundValid(_id),"Links::claim, invalid fund"); - require(_gasReward <= 1500000000000000, "Links::claim, cannot reward more than 0.0015 xDai"); - require(_gasReward <= funds[_id].value,"Links::claim, gas reward is greater than the fund value"); - return executeClaim(_id,_signature,_claimHash,_destination,_gasReward); + return executeClaim(_id,_signature,_claimHash,_destination); } - + /// @dev Off chain relayer can validate the claim before submitting. /// @param _id Claim lookup key value. /// @param _signature Sender signature. /// @param _destination Destination address. function isClaimValid( - bytes32 _id, + bytes32 _id, bytes memory _signature, - bytes32 _claimHash, + bytes32 _claimHash, address _destination - ) - public - view + ) + public + view returns (bool) { // address(0) destination is valid @@ -108,7 +105,7 @@ contract Links { signer = recoverSigner(claimHash1,_signature); } else{ return false; - } + } if(signer != address(0)){ return(funds[_id].signer == signer); } else{ @@ -119,13 +116,13 @@ contract Links { } } - /// @dev Validate fund status. + /// @dev Validate fund status. /// @param _id Lookup key id. function isFundValid( bytes32 _id - ) - public - view + ) + public + view returns (bool) { address sender = funds[_id].sender; @@ -134,16 +131,16 @@ contract Links { uint256 nonce = funds[_id].nonce; /* solium-disable-next-line security/no-inline-assembly */ assembly { - // Cannot assume empty initial values without initializating them. + // Cannot assume empty initial values without initializating them. sender := and(sender, 0xffffffff) signer := and(signer, 0xffffffff) value := and(value, 0xffffffff) nonce := and(nonce, 0xffffffff) } return ( - sender != address(0) && - signer != address(0) && - value > uint256(0) && + sender != address(0) && + signer != address(0) && + value > uint256(0) && nonce > uint256(0) && nonce < contractNonce ); @@ -153,13 +150,12 @@ contract Links { /// @param _id Claim lookup key value. /// @param _destination Destination address. function executeClaim( - bytes32 _id, - bytes memory _signature, - bytes32 _claimHash, - address _destination, - uint256 _gasReward - ) - private + bytes32 _id, + bytes memory _signature, + bytes32 _claimHash, + address _destination + ) + private returns (bool) { //makes sure signature is correct and fund is valid. @@ -169,45 +165,19 @@ contract Links { bool claimed = funds[_id].claimed; uint256 value = funds[_id].value; uint256 nonce = funds[_id].nonce; - + assert(nonce < contractNonce); if(claimed == false){ - // gasReward > 0, relayer is paying to claim and taking its reward - if(_gasReward > 0){ - // !isContract - Preventive measure against deployed contracts. - require(!isContract(msg.sender),"Links::executeClaim, relay sender should not be a contract"); - // temporary fund invalidation - funds[_id].claimed = true; - residual = safeSub(value, _gasReward); - // address.send() restricts to 2300 gas units - /* solium-disable-next-line security/no-send */ - status = _destination.send(residual); - // update fund with correct status - funds[_id].claimed = status; - // update fund - if(status == true){ - // DESTROY object so it can't be claimed again and free storage space. - delete funds[_id]; - } else{ - funds[_id].value = residual; - } - /* solium-disable-next-line security/no-send */ - require(msg.sender.send(_gasReward),"Links::executeClaim, could not pay relayer"); - - // Gas Reward == 0, msg.sender is paying to claim - } else if(_gasReward == 0){ - // temporary fund invalidation - funds[_id].claimed = true; - /* solium-disable-next-line security/no-send */ - status = _destination.send(value); - // update fund with correct status - funds[_id].claimed = status; - if(status == true){ - // DESTROY object so it can't be claimed again and free storage space. - delete funds[_id]; - } + // temporary fund invalidation + funds[_id].claimed = true; + /* solium-disable-next-line security/no-send */ + status = _destination.send(value); + // update fund with correct status + funds[_id].claimed = status; + if(status == true){ + // DESTROY object so it can't be claimed again and free storage space. + delete funds[_id]; } - } else{ status = claimed; // DESTROY object so it can't be claimed again and free storage space. @@ -223,10 +193,10 @@ contract Links { ///@return whether the target address is a contract function isContract( address account - ) - private - view - returns (bool) + ) + private + view + returns (bool) { uint256 size; // TODO Check this again before the Serenity release, because all addresses will be contracts then. @@ -239,11 +209,11 @@ contract Links { /// @param _hash bytes32 data. /// @param _signature message signature (65 bytes). function recoverSigner( - bytes32 _hash, + bytes32 _hash, bytes memory _signature - ) - private - pure + ) + private + pure returns (address) { bytes32 r; @@ -279,12 +249,12 @@ contract Links { /// @dev Adds two numbers, throws on overflow. function safeAdd( - uint256 _a, + uint256 _a, uint256 _b - ) - private - pure - returns (uint256 c) + ) + private + pure + returns (uint256 c) { c = _a + _b; assert(c >= _a); @@ -293,14 +263,14 @@ contract Links { /// @dev Substracts two numbers, throws on underflow. function safeSub( - uint256 _a, + uint256 _a, uint256 _b - ) - private - pure - returns (uint256) + ) + private + pure + returns (uint256) { assert(_b <= _a); return _a - _b; } -} \ No newline at end of file +} diff --git a/src/App.js b/src/App.js index e1530b4f..dafd9d62 100644 --- a/src/App.js +++ b/src/App.js @@ -429,29 +429,20 @@ class App extends Component { console.log("this.state.claimKey", this.state.claimKey) let sig = this.state.web3.eth.accounts.sign(claimHash, this.state.claimKey); sig = sig.signature; - //contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account,0).estimateGas() - //.then((gasAmount) => { - console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account,0) - /* - bytes32 _id, - bytes memory _signature, - bytes32 _claimHash, - address _destination, - uint256 _gasReward - */ - tx(contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account,0), 550000, false, 0, (result) => { - if (result) { - console.log("CLAIMED!!!", result) - this.setState({claimed: true}) - setTimeout(() => { - this.setState({sending: false}, () => { - //alert("DONE") - //window.location = "/" - }) - }, 2000) - } - }) - //}) + + console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account) + tx(contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account), 240000, false, 0, (result) => { + if (result) { + console.log("CLAIMED!!!", result) + this.setState({claimed: true}) + setTimeout(() => { + this.setState({sending: false}, () => { + //alert("DONE") + window.location = "/" + }) + }, 2000) + } + }) .catch((error) => { console.log(error); //Estimate Gas promise }); @@ -1205,6 +1196,7 @@ render() {
+ {defaultBalanceDisplay} Date: Tue, 22 Jan 2019 20:03:59 +0000 Subject: [PATCH 04/10] catch the RN issues for non RN --- src/App.js | 25 ++++++++++++++----------- src/components/SendByScan.js | 6 +++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/App.js b/src/App.js index dafd9d62..2c61de0c 100644 --- a/src/App.js +++ b/src/App.js @@ -209,19 +209,22 @@ class App extends Component { }; this.alertTimeout = null; - RNMessageChannel.on('json', update => { - let safeUpdate = {} - if(update.title) safeUpdate.title = update.title - if(update.extraHeadroom) safeUpdate.extraHeadroom = update.extraHeadroom - if(update.possibleNewPrivateKey) safeUpdate.possibleNewPrivateKey = update.possibleNewPrivateKey - - this.setState(safeUpdate,()=>{ - if(this.state.possibleNewPrivateKey){ - this.dealWithPossibleNewPrivateKey() - } + try{ + RNMessageChannel.on('json', update => { + try{ + let safeUpdate = {} + if(update.title) safeUpdate.title = update.title + if(update.extraHeadroom) safeUpdate.extraHeadroom = update.extraHeadroom + if(update.possibleNewPrivateKey) safeUpdate.possibleNewPrivateKey = update.possibleNewPrivateKey + this.setState(safeUpdate,()=>{ + if(this.state.possibleNewPrivateKey){ + this.dealWithPossibleNewPrivateKey() + } + }) + }catch(e){console.log(e)} }) + }catch(e){console.log(e)} - }) } updateDimensions() { //force it to rerender when the window is resized to make sure qr fits etc diff --git a/src/components/SendByScan.js b/src/components/SendByScan.js index e9c802a2..f614e9a8 100644 --- a/src/components/SendByScan.js +++ b/src/components/SendByScan.js @@ -23,7 +23,11 @@ class SendByScan extends Component { }; this.handleScan = this.handleScan.bind(this) - RNMessageChannel.send("qr") + if(RNMessageChannel&&typeof RNMessageChannel.send == "function"){ + try{ + RNMessageChannel.send("qr") + }catch(e){} + } } stopRecording = () => this.setState({ delay: false }); onImageLoad = data => { From 35a6b4cc4b15f44b5f206b41dce89e4d2251128a Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 13:21:48 -0700 Subject: [PATCH 05/10] no reward in relay --- xdairelay.js | 55 ++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/xdairelay.js b/xdairelay.js index 5f8aa660..5a6e5884 100644 --- a/xdairelay.js +++ b/xdairelay.js @@ -92,39 +92,34 @@ app.post('/link', async (req, res) => { web3.eth.getGasPrice() .then((gasPrice) => { gasPrice = gasPrice < 500000000 ? 1000000000 : gasPrice; // Fix for xDai 0 Txs avg - //150000*gasPrice - contracts.Links.methods.claim(req.body.id,req.body.sig,req.body.claimHash,req.body.dest,0).estimateGas() - .then((gasAmount) => { - console.log("Relay gas estimation: ",gasAmount) - console.log("PARAMS",{from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}) - /// OLD CODE BUT REVERTING FOR NOW, (gasAmount+10000)*(gasPrice+500000000) - contracts.Links.methods.claim(req.body.id,req.body.sig,req.body.claimHash,req.body.dest,0) - .send({from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}, - (error, transactionHash)=>{ - console.log("TX CALLBACK",error,transactionHash) - res.set('Content-Type', 'application/json'); - res.end(JSON.stringify({transactionHash:transactionHash})); - } - ) - .on('error',(err,receiptMaybe)=>{ - console.log("TX ERROR",err,receiptMaybe) - }) - .on('transactionHash',(transactionHash)=>{ - console.log("TX HASH",transactionHash) - }) - .on('receipt',(receipt)=>{ - console.log("TX RECEIPT",receipt) - }) - .then((receipt)=>{ - console.log("TX THEN",receipt) - }) - .catch((error) => { - console.log(error); //Tx promise - }); + + console.log("Relay gas estimation: ",gasAmount) + console.log("PARAMS",{from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}) + /// OLD CODE BUT REVERTING FOR NOW, (gasAmount+10000)*(gasPrice+500000000) + contracts.Links.methods.claim(req.body.id,req.body.sig,req.body.claimHash,req.body.dest) + .send({from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}, + (error, transactionHash)=>{ + console.log("TX CALLBACK",error,transactionHash) + res.set('Content-Type', 'application/json'); + res.end(JSON.stringify({transactionHash:transactionHash})); + } + ) + .on('error',(err,receiptMaybe)=>{ + console.log("TX ERROR",err,receiptMaybe) + }) + .on('transactionHash',(transactionHash)=>{ + console.log("TX HASH",transactionHash) + }) + .on('receipt',(receipt)=>{ + console.log("TX RECEIPT",receipt) + }) + .then((receipt)=>{ + console.log("TX THEN",receipt) }) .catch((error) => { - console.log(error); //Estimate Gas promise + console.log(error); //Tx promise }); + }) .catch((error) => { console.log(error); //Get Gas price promise From 663aaa46e789997aa63be5b8a6404916e0dd993a Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 14:38:44 -0700 Subject: [PATCH 06/10] fix claiming for meta accounts --- src/App.js | 63 +++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/src/App.js b/src/App.js index 2c61de0c..5883f926 100644 --- a/src/App.js +++ b/src/App.js @@ -476,41 +476,36 @@ class App extends Component { /* getGasPrice() is not implemented on Metamask, leaving the code as reference. */ //this.state.web3.eth.getGasPrice() //.then((gasPrice) => { - let gasPrice = 1500000000 // Hardcoded to 1.5 Gwei. Real value is calculated on the relay. - this.state.contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account,0).estimateGas() - .then((gasAmount) => { - console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account, gasAmount, (gasAmount * gasPrice)) - - this.setState({sending: true}) - let postData = { - id: this.state.claimId, - sig: sig, - claimHash: claimHash, - dest: this.state.account, - reward: (gasAmount * gasPrice) + + console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account) + + this.setState({sending: true}) + let postData = { + id: this.state.claimId, + sig: sig, + claimHash: claimHash, + dest: this.state.account, + } + console.log("CLAIM_RELAY:", CLAIM_RELAY) + axios.post(CLAIM_RELAY + "/link", postData, { + headers: { + 'Content-Type': 'application/json', } - console.log("CLAIM_RELAY:", CLAIM_RELAY) - axios.post(CLAIM_RELAY + "/link", postData, { - headers: { - 'Content-Type': 'application/json', - } - }).then((response) => { - console.log("TX RESULT", response.data.transactionHash) - this.setState({claimed: true}) - setTimeout(() => { - this.setState({sending: false}, () => { - //alert("DONE") - window.location = "/" - }) - }, 2000) - }) - .catch((error) => { - console.log(error); //axios promise - }); + }).then((response) => { + console.log("TX RESULT", response.data.transactionHash) + this.setState({claimed: true}) + setTimeout(() => { + this.setState({sending: false}, () => { + //alert("DONE") + window.location = "/" + }) + }, 2000) }) - .catch((error) => { - console.log(error); //Estimate Gas promise - }); + .catch((error) => { + console.log(error); //axios promise + }); + + //}) //.catch((error) => { // console.log(error); //Get Gas price promise @@ -1620,7 +1615,7 @@ async function tokenSend(to,value,gasLimit,txData,cb){ to:this.state.contracts[ERC20TOKEN]._address, value: 0, gas: setGasLimit, - gasPrice: Math.round(this.state.gwei * 1000000000) + gasPrice: Math.round(this.state.gwei * 1010101010) } if(data){ From 0e419c3c5a348304f7abd17e8a0e5daf997eec8d Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 14:44:50 -0700 Subject: [PATCH 07/10] patching up relay --- xdairelay.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xdairelay.js b/xdairelay.js index 5a6e5884..0e12598d 100644 --- a/xdairelay.js +++ b/xdairelay.js @@ -89,15 +89,15 @@ app.post('/link', async (req, res) => { console.log("CLAIM IS VALID...") //console.log("dApp reward estimation: ",req.body.reward) - web3.eth.getGasPrice() - .then((gasPrice) => { - gasPrice = gasPrice < 500000000 ? 1000000000 : gasPrice; // Fix for xDai 0 Txs avg + //web3.eth.getGasPrice() + // .then((gasPrice) => { + // gasPrice = gasPrice < 500000000 ? 1000000000 : gasPrice; // Fix for xDai 0 Txs avg - console.log("Relay gas estimation: ",gasAmount) - console.log("PARAMS",{from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}) + // console.log("Relay gas estimation: ",gasAmount) + // console.log("PARAMS",{from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}) /// OLD CODE BUT REVERTING FOR NOW, (gasAmount+10000)*(gasPrice+500000000) contracts.Links.methods.claim(req.body.id,req.body.sig,req.body.claimHash,req.body.dest) - .send({from: accounts[DESKTOPMINERACCOUNT],gas: parseInt(gasAmount)+10000,gasPrice: parseInt(gasPrice)+500000000}, + .send({from: accounts[DESKTOPMINERACCOUNT],gas: 240000,gasPrice: 1010101010}, (error, transactionHash)=>{ console.log("TX CALLBACK",error,transactionHash) res.set('Content-Type', 'application/json'); @@ -120,10 +120,10 @@ app.post('/link', async (req, res) => { console.log(error); //Tx promise }); - }) + /*}) .catch((error) => { console.log(error); //Get Gas price promise - }); + });*/ } From 891f57309011508565b690cfe8ed013132fabfd1 Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 22 Jan 2019 15:23:44 -0700 Subject: [PATCH 08/10] testing out link claiming in prod --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 5883f926..7c0ebb6c 100644 --- a/src/App.js +++ b/src/App.js @@ -441,7 +441,7 @@ class App extends Component { setTimeout(() => { this.setState({sending: false}, () => { //alert("DONE") - window.location = "/" + //window.location = "/" }) }, 2000) } From 3eecc723bfcaaed48280d3821ea6a697d40fce4f Mon Sep 17 00:00:00 2001 From: Austin Griffith Date: Tue, 22 Jan 2019 22:51:07 +0000 Subject: [PATCH 09/10] fix lame callback issue with async await --- src/App.js | 74 ++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/App.js b/src/App.js index 7c0ebb6c..6476b3b6 100644 --- a/src/App.js +++ b/src/App.js @@ -413,47 +413,45 @@ class App extends Component { console.log("ensResolver:",ensResolver) return ensResolver.methods.addr(hash).call() } - chainClaim(tx, contracts) { + async chainClaim(tx, contracts) { console.log("DOING CLAIM ONCHAIN", this.state.claimId, this.state.claimKey, this.state.account); this.setState({sending: true}) - contracts.Links.funds(this.state.claimId).call().then((fund) => { - if (fund) { - this.setState({fund: fund}) - console.log("FUND: ", fund) - - let claimHash = this.state.web3.utils.soliditySha3( - {type: 'bytes32', value: this.state.claimId}, // fund id - {type: 'address', value: this.state.account}, // destination address - {type: 'uint256', value: fund[3]}, // nonce - {type: 'address', value: contracts.Links._address} // contract address - ) - console.log("claimHash", claimHash) - console.log("this.state.claimKey", this.state.claimKey) - let sig = this.state.web3.eth.accounts.sign(claimHash, this.state.claimKey); - sig = sig.signature; - - console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account) - tx(contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account), 240000, false, 0, (result) => { - if (result) { - console.log("CLAIMED!!!", result) - this.setState({claimed: true}) - setTimeout(() => { - this.setState({sending: false}, () => { - //alert("DONE") - //window.location = "/" - }) - }, 2000) - } - }) - .catch((error) => { - console.log(error); //Estimate Gas promise - }); - } - }) - .catch((error) => { - console.log(error); //FUNDS promise - }); + let fund = await contracts.Links.funds(this.state.claimId).call() + console.log("FUND FOR "+this.state.claimId+" IS: ", fund) + if (fund) { + this.setState({fund: fund}) + + + let claimHash = this.state.web3.utils.soliditySha3( + {type: 'bytes32', value: this.state.claimId}, // fund id + {type: 'address', value: this.state.account}, // destination address + {type: 'uint256', value: fund[3]}, // nonce + {type: 'address', value: contracts.Links._address} // contract address + ) + console.log("claimHash", claimHash) + console.log("this.state.claimKey", this.state.claimKey) + let sig = this.state.web3.eth.accounts.sign(claimHash, this.state.claimKey); + sig = sig.signature; + + console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account) + tx(contracts.Links.claim(this.state.claimId, sig, claimHash, this.state.account), 240000, false, 0, (result) => { + if (result) { + console.log("CLAIMED!!!", result) + this.setState({claimed: true}) + setTimeout(() => { + this.setState({sending: false}, () => { + //alert("DONE") + window.location = "/" + }) + }, 2000) + } + }) + .catch((error) => { + console.log(error); //Estimate Gas promise + }); + } + this.forceUpdate(); } relayClaim() { From e8a367492314319a3129f513d6e3cb2fc56f1db1 Mon Sep 17 00:00:00 2001 From: Austin Griffith Date: Tue, 22 Jan 2019 23:46:45 +0000 Subject: [PATCH 10/10] im over links for now --- src/App.js | 118 +++++++++++++++++++++------------------- src/components/Admin.js | 2 +- 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/src/App.js b/src/App.js index 6476b3b6..f7acb474 100644 --- a/src/App.js +++ b/src/App.js @@ -419,7 +419,7 @@ class App extends Component { let fund = await contracts.Links.funds(this.state.claimId).call() console.log("FUND FOR "+this.state.claimId+" IS: ", fund) - if (fund) { + if (fund&&parseInt(fund.nonce)>0) { this.setState({fund: fund}) @@ -450,69 +450,73 @@ class App extends Component { .catch((error) => { console.log(error); //Estimate Gas promise }); + }else{ + console.log("FUND IS NOT READY YET, WAITING...") + setTimeout(()=>{ + this.chainClaim(tx, contracts) + },3000) } this.forceUpdate(); } - relayClaim() { - console.log("DOING CLAIM THROUGH RELAY") - this.state.contracts.Links.funds(this.state.claimId).call().then((fund) => { - if (fund) { - this.setState({fund: fund}) - console.log("FUND: ", fund) - - let claimHash = this.state.web3.utils.soliditySha3( - {type: 'bytes32', value: this.state.claimId}, // fund id - {type: 'address', value: this.state.account}, // destination address - {type: 'uint256', value: fund[3]}, // nonce - {type: 'address', value: this.state.contracts.Links._address} // contract address - ) - console.log("claimHash", claimHash) - console.log("this.state.claimKey", this.state.claimKey) - let sig = this.state.web3.eth.accounts.sign(claimHash, this.state.claimKey); - sig = sig.signature - /* getGasPrice() is not implemented on Metamask, leaving the code as reference. */ - //this.state.web3.eth.getGasPrice() - //.then((gasPrice) => { - - console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account) - - this.setState({sending: true}) - let postData = { - id: this.state.claimId, - sig: sig, - claimHash: claimHash, - dest: this.state.account, + async relayClaim() { + console.log("DOING CLAIM THROUGH RELAY") + let fund = await this.state.contracts.Links.funds(this.state.claimId).call() + if (fund&&parseInt(fund.nonce)>0) { + this.setState({fund: fund}) + console.log("FUND: ", fund) + + let claimHash = this.state.web3.utils.soliditySha3( + {type: 'bytes32', value: this.state.claimId}, // fund id + {type: 'address', value: this.state.account}, // destination address + {type: 'uint256', value: fund[3]}, // nonce + {type: 'address', value: this.state.contracts.Links._address} // contract address + ) + console.log("claimHash", claimHash) + console.log("this.state.claimKey", this.state.claimKey) + let sig = this.state.web3.eth.accounts.sign(claimHash, this.state.claimKey); + sig = sig.signature + /* getGasPrice() is not implemented on Metamask, leaving the code as reference. */ + //this.state.web3.eth.getGasPrice() + //.then((gasPrice) => { + + console.log("CLAIM TX:", this.state.claimId, sig, claimHash, this.state.account) + + this.setState({sending: true}) + let postData = { + id: this.state.claimId, + sig: sig, + claimHash: claimHash, + dest: this.state.account, + } + console.log("CLAIM_RELAY:", CLAIM_RELAY," POSTDATA:",postData) + axios.post(CLAIM_RELAY + "/link", postData, { + headers: { + 'Content-Type': 'application/json', } - console.log("CLAIM_RELAY:", CLAIM_RELAY) - axios.post(CLAIM_RELAY + "/link", postData, { - headers: { - 'Content-Type': 'application/json', - } - }).then((response) => { - console.log("TX RESULT", response.data.transactionHash) - this.setState({claimed: true}) - setTimeout(() => { - this.setState({sending: false}, () => { - //alert("DONE") - window.location = "/" - }) - }, 2000) - }) - .catch((error) => { - console.log(error); //axios promise - }); + }).then((response) => { + console.log("TX RESULT", response.data.transactionHash) + this.setState({claimed: true}) + setTimeout(() => { + this.setState({sending: false}, () => { + //alert("DONE") + window.location = "/" + }) + }, 2000) + }) + .catch((error) => { + console.log(error); //axios promise + }); - //}) - //.catch((error) => { - // console.log(error); //Get Gas price promise - //}); - } - }) - .catch((error) => { - console.log(error); //FUNDS promise - }); + //}) + //.catch((error) => { + // console.log(error); //Get Gas price promise + //}); + }else{ + console.log("Fund is not valid yet, trying again....") + setTimeout(this.relayClaim,2000) + } } changeView = (view,cb) => { if(view=="exchange"||view=="main"/*||view.indexOf("account_")==0*/){ diff --git a/src/components/Admin.js b/src/components/Admin.js index 4bf678cc..f44e9295 100644 --- a/src/components/Admin.js +++ b/src/components/Admin.js @@ -217,7 +217,7 @@ export default class Advanced extends React.Component {