Code removal for test run
This commit is contained in:
parent
263e9fb041
commit
68a6bae9cf
|
@ -51,9 +51,9 @@ class CreateUser extends Component {
|
||||||
//const result = await createAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 });
|
//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
|
// 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
|
// 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) });
|
// return this.setState({ isLoading: false, error: 'Error executing transaction, transaction details: ' + JSON.stringify(result) });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Completed of async action, set loading state back
|
// Completed of async action, set loading state back
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
|
|
|
@ -50,11 +50,11 @@ class DoTweet extends Component{
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// estimate gas before sending tweet transaction
|
// 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
|
// send the tweet transaction plus a little extra gas in case the contract state
|
||||||
// has changed since we've done our gas estimate
|
// 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
|
// remove loading state
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
|
|
|
@ -53,20 +53,20 @@ class UpdateUser extends Component {
|
||||||
|
|
||||||
const { account, user } = this.props;
|
const { account, user } = this.props;
|
||||||
const { description } = this.state;
|
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
|
// get a gas estimate for the transaction with the input username
|
||||||
// and description
|
// 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 {
|
try {
|
||||||
// send the transaction with our gas estimate (plus a little bit more in case the contract)
|
// send the transaction with our gas estimate (plus a little bit more in case the contract)
|
||||||
// state has changed since we got our estimate
|
// 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', ''))) {
|
// 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) });
|
// 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
|
// stop loading state, and render the form as successful
|
||||||
this.setState({ isLoading: false, formState: 'success', formUpdated: false });
|
this.setState({ isLoading: false, formState: 'success', formUpdated: false });
|
||||||
|
|
|
@ -36,12 +36,13 @@ class UserTweets extends Component {
|
||||||
*/
|
*/
|
||||||
_getUserDetails = async(username) => {
|
_getUserDetails = async(username) => {
|
||||||
// get user details and update state
|
// 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
|
// update picture url for ipfs
|
||||||
user.picture = user.picture.length > 0 ? EmbarkJS.Storage.getUrl(user.picture) : imgAvatar;
|
//user.picture = user.picture.length > 0 ? EmbarkJS.Storage.getUrl(user.picture) : imgAvatar;
|
||||||
// TODO: update to Date.js
|
|
||||||
user.creationDate = this._formatDate(user.creationDate);
|
// format the user.creationDate for display
|
||||||
|
//user.creationDate = this._formatDate(user.creationDate);
|
||||||
|
|
||||||
this.setState({user: user});
|
this.setState({user: user});
|
||||||
}
|
}
|
||||||
|
@ -55,26 +56,27 @@ class UserTweets extends Component {
|
||||||
* @returns {null}
|
* @returns {null}
|
||||||
*/
|
*/
|
||||||
_subscribeToNewTweetEvent(username){
|
_subscribeToNewTweetEvent(username){
|
||||||
this.event = DTwitter.events.NewTweet({
|
// this.event = DTwitter.events.NewTweet({
|
||||||
filter: {_from: web3.utils.keccak256(username)},
|
// filter: {_from: web3.utils.keccak256(username)},
|
||||||
fromBlock: 1
|
// fromBlock: 1
|
||||||
}, (err, event) => {
|
// }, (err, event) => {
|
||||||
if (err){
|
// if (err){
|
||||||
this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent');
|
// this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent');
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.on('data', (event) => {
|
// .on('data', (event) => {
|
||||||
let tweets = this.state.tweets;
|
// let tweets = this.state.tweets;
|
||||||
tweets.push({
|
|
||||||
content: event.returnValues.tweet,
|
// tweets.push({
|
||||||
// TODO: update to Date.js
|
// content: event.returnValues.tweet,
|
||||||
time: this._formatDate(event.returnValues.time)
|
// time: this._formatDate(event.returnValues.time)
|
||||||
});
|
// });
|
||||||
this.setState({tweets: tweets});
|
|
||||||
})
|
// this.setState({tweets: tweets});
|
||||||
.on('error', function(error){
|
// })
|
||||||
this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent');
|
// .on('error', function(error){
|
||||||
});
|
// this.props.onError(err, 'UserTweets._subscribeToNewTweetEvent');
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,15 +74,15 @@ contract DTwitter {
|
||||||
// reject if sending adddress already created a user
|
// reject if sending adddress already created a user
|
||||||
require(owners[msg.sender] == 0);
|
require(owners[msg.sender] == 0);
|
||||||
|
|
||||||
// add a user to the users mapping and populate details
|
// add a user to the users mapping and populate details (creationDate, owner, username, description)
|
||||||
users[usernameHash].creationDate = now;
|
// users[usernameHash].creationDate = now;
|
||||||
users[usernameHash].owner = msg.sender;
|
// users[usernameHash].owner = msg.sender;
|
||||||
users[usernameHash].username = username;
|
// users[usernameHash].username = username;
|
||||||
users[usernameHash].description = description;
|
// users[usernameHash].description = description;
|
||||||
|
|
||||||
// add entry to our owners mapping so we can retrieve
|
// add entry to our owners mapping so we can retrieve
|
||||||
// user by their addres
|
// user by their addres
|
||||||
owners[msg.sender] = usernameHash;
|
// owners[msg.sender] = usernameHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,13 +99,13 @@ contract DTwitter {
|
||||||
require(users[usernameHash].owner == msg.sender);
|
require(users[usernameHash].owner == msg.sender);
|
||||||
|
|
||||||
// update the description (could be empty)
|
// 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
|
// only update the user's picture if the hash passed in is
|
||||||
// not empty or null (essentially disallows deletions)
|
// not empty or null (essentially disallows deletions)
|
||||||
if (bytes(pictureHash).length > 0) {
|
// if (bytes(pictureHash).length > 0) {
|
||||||
users[usernameHash].picture = pictureHash;
|
// users[usernameHash].picture = pictureHash;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,17 +138,17 @@ contract DTwitter {
|
||||||
// ensure the retrieved user is indeed the sender
|
// ensure the retrieved user is indeed the sender
|
||||||
require(users[usernameHash].owner == msg.sender);
|
require(users[usernameHash].owner == msg.sender);
|
||||||
|
|
||||||
// get our user
|
// get our user from the usernameHash
|
||||||
User storage user = users[usernameHash];
|
//User storage user = users[usernameHash];
|
||||||
|
|
||||||
// get our new tweet index
|
// get our new tweet index
|
||||||
uint tweetIndex = user.tweets.length++;
|
//uint tweetIndex = user.tweets.length++;
|
||||||
|
|
||||||
// update the user's tweets
|
// update the user's tweets at the tweet index
|
||||||
user.tweets[tweetIndex] = content;
|
//user.tweets[tweetIndex] = content;
|
||||||
|
|
||||||
// emit the tweet event and notify the listeners
|
// emit the tweet event and notify the listeners
|
||||||
emit NewTweet(usernameHash, content, now);
|
//emit NewTweet(usernameHash, content, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue