From 68a6bae9cf00f9505084a8303681f53df41a4828 Mon Sep 17 00:00:00 2001 From: emizzle Date: Wed, 18 Jul 2018 12:05:40 +0200 Subject: [PATCH] Code removal for test run --- app/js/components/CreateUser.js | 6 ++-- app/js/components/DoTweet.js | 4 +-- app/js/components/UpdateUser.js | 12 ++++---- app/js/components/UserTweets.js | 50 +++++++++++++++++---------------- contracts/DTwitter.sol | 32 ++++++++++----------- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/app/js/components/CreateUser.js b/app/js/components/CreateUser.js index 6a2c1dc..ff15bf2 100644 --- a/app/js/components/CreateUser.js +++ b/app/js/components/CreateUser.js @@ -51,9 +51,9 @@ class CreateUser extends Component { //const result = await createAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); // check result status. if status is false or '0x0', show user the tx details to debug error - if (result.status && !Boolean(result.status.toString().replace('0x', ''))) { // possible result values: '0x0', '0x1', or false, true - return this.setState({ isLoading: false, error: 'Error executing transaction, transaction details: ' + JSON.stringify(result) }); - } + // if (result.status && !Boolean(result.status.toString().replace('0x', ''))) { // possible result values: '0x0', '0x1', or false, true + // return this.setState({ isLoading: false, error: 'Error executing transaction, transaction details: ' + JSON.stringify(result) }); + // } // Completed of async action, set loading state back this.setState({ isLoading: false }); diff --git a/app/js/components/DoTweet.js b/app/js/components/DoTweet.js index d156c4a..bbca803 100644 --- a/app/js/components/DoTweet.js +++ b/app/js/components/DoTweet.js @@ -50,11 +50,11 @@ class DoTweet extends Component{ try{ // estimate gas before sending tweet transaction - const gasEstimate = await tweet.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 }); + //const gasEstimate = await tweet.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 }); // send the tweet transaction plus a little extra gas in case the contract state // has changed since we've done our gas estimate - await tweet.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); + //await tweet.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); // remove loading state this.setState({ isLoading: false }); diff --git a/app/js/components/UpdateUser.js b/app/js/components/UpdateUser.js index 6f39994..42ef751 100644 --- a/app/js/components/UpdateUser.js +++ b/app/js/components/UpdateUser.js @@ -53,20 +53,20 @@ class UpdateUser extends Component { const { account, user } = this.props; const { description } = this.state; - const editAccount = DTwitter.methods.editAccount(web3.utils.keccak256(user.username), description, hash); + //const editAccount = DTwitter.methods.editAccount(web3.utils.keccak256(user.username), description, hash); // get a gas estimate for the transaction with the input username // and description - const gasEstimate = await editAccount.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 }); + //const gasEstimate = await editAccount.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 }); try { // send the transaction with our gas estimate (plus a little bit more in case the contract) // state has changed since we got our estimate - const result = await editAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); + //const result = await editAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); - if (result.status && !Boolean(result.status.toString().replace('0x', ''))) { - return this.setState({ isLoading: false, formState: 'error', formUpdated: false, error: 'Error executing transaction, transaction details: ' + JSON.stringify(result) }); - } + // if (result.status && !Boolean(result.status.toString().replace('0x', ''))) { + // return this.setState({ isLoading: false, formState: 'error', formUpdated: false, error: 'Error executing transaction, transaction details: ' + JSON.stringify(result) }); + // } // stop loading state, and render the form as successful this.setState({ isLoading: false, formState: 'success', formUpdated: false }); diff --git a/app/js/components/UserTweets.js b/app/js/components/UserTweets.js index bcfa9c2..6a48b75 100644 --- a/app/js/components/UserTweets.js +++ b/app/js/components/UserTweets.js @@ -36,12 +36,13 @@ class UserTweets extends Component { */ _getUserDetails = async(username) => { // get user details and update state - let user = await DTwitter.methods.users(web3.utils.keccak256(username)).call(); + //let user = await DTwitter.methods.users(web3.utils.keccak256(username)).call(); // update picture url for ipfs - user.picture = user.picture.length > 0 ? EmbarkJS.Storage.getUrl(user.picture) : imgAvatar; - // TODO: update to Date.js - user.creationDate = this._formatDate(user.creationDate); + //user.picture = user.picture.length > 0 ? EmbarkJS.Storage.getUrl(user.picture) : imgAvatar; + + // format the user.creationDate for display + //user.creationDate = this._formatDate(user.creationDate); this.setState({user: user}); } @@ -55,26 +56,27 @@ class UserTweets extends Component { * @returns {null} */ _subscribeToNewTweetEvent(username){ - this.event = DTwitter.events.NewTweet({ - filter: {_from: web3.utils.keccak256(username)}, - fromBlock: 1 - }, (err, event) => { - if (err){ - this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent'); - } - }) - .on('data', (event) => { - let tweets = this.state.tweets; - tweets.push({ - content: event.returnValues.tweet, - // TODO: update to Date.js - time: this._formatDate(event.returnValues.time) - }); - this.setState({tweets: tweets}); - }) - .on('error', function(error){ - this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent'); - }); + // this.event = DTwitter.events.NewTweet({ + // filter: {_from: web3.utils.keccak256(username)}, + // fromBlock: 1 + // }, (err, event) => { + // if (err){ + // this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent'); + // } + // }) + // .on('data', (event) => { + // let tweets = this.state.tweets; + + // tweets.push({ + // content: event.returnValues.tweet, + // time: this._formatDate(event.returnValues.time) + // }); + + // this.setState({tweets: tweets}); + // }) + // .on('error', function(error){ + // this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent'); + // }); } /** diff --git a/contracts/DTwitter.sol b/contracts/DTwitter.sol index 7c45ab7..9224cb2 100644 --- a/contracts/DTwitter.sol +++ b/contracts/DTwitter.sol @@ -74,15 +74,15 @@ contract DTwitter { // reject if sending adddress already created a user require(owners[msg.sender] == 0); - // add a user to the users mapping and populate details - users[usernameHash].creationDate = now; - users[usernameHash].owner = msg.sender; - users[usernameHash].username = username; - users[usernameHash].description = description; + // add a user to the users mapping and populate details (creationDate, owner, username, description) + // users[usernameHash].creationDate = now; + // users[usernameHash].owner = msg.sender; + // users[usernameHash].username = username; + // users[usernameHash].description = description; // add entry to our owners mapping so we can retrieve // user by their addres - owners[msg.sender] = usernameHash; + // owners[msg.sender] = usernameHash; } /** @@ -99,13 +99,13 @@ contract DTwitter { require(users[usernameHash].owner == msg.sender); // update the description (could be empty) - users[usernameHash].description = description; + //users[usernameHash].description = description; // only update the user's picture if the hash passed in is // not empty or null (essentially disallows deletions) - if (bytes(pictureHash).length > 0) { - users[usernameHash].picture = pictureHash; - } + // if (bytes(pictureHash).length > 0) { + // users[usernameHash].picture = pictureHash; + // } } /** @@ -138,17 +138,17 @@ contract DTwitter { // ensure the retrieved user is indeed the sender require(users[usernameHash].owner == msg.sender); - // get our user - User storage user = users[usernameHash]; + // get our user from the usernameHash + //User storage user = users[usernameHash]; // get our new tweet index - uint tweetIndex = user.tweets.length++; + //uint tweetIndex = user.tweets.length++; - // update the user's tweets - user.tweets[tweetIndex] = content; + // update the user's tweets at the tweet index + //user.tweets[tweetIndex] = content; // emit the tweet event and notify the listeners - emit NewTweet(usernameHash, content, now); + //emit NewTweet(usernameHash, content, now); } }