|
@ -11,6 +11,8 @@ class RightSideBar extends Component { |
|
|
super(props); |
|
|
super(props); |
|
|
|
|
|
|
|
|
this.handleMessageDismiss = this.handleMessageDismiss.bind(this); |
|
|
this.handleMessageDismiss = this.handleMessageDismiss.bind(this); |
|
|
|
|
|
this.updateTransactions = this.updateTransactions.bind(this); |
|
|
|
|
|
this.completeWithOrbitInteractions = this.completeWithOrbitInteractions.bind(this); |
|
|
|
|
|
|
|
|
this.drizzle = context.drizzle; |
|
|
this.drizzle = context.drizzle; |
|
|
this.transactionsStackIds = []; |
|
|
this.transactionsStackIds = []; |
|
@ -76,7 +78,11 @@ class RightSideBar extends Component { |
|
|
return (transactionMessages); |
|
|
return (transactionMessages); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentDidUpdate(){ |
|
|
componentDidUpdate(){ //Maybe change to componentWillReceiveProps()
|
|
|
|
|
|
this.updateTransactions(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateTransactions(){ |
|
|
for (var index = 0; index < this.props.transactionsQueue.length; ++index) { |
|
|
for (var index = 0; index < this.props.transactionsQueue.length; ++index) { |
|
|
let transaction = this.props.transactionsQueue[index]; |
|
|
let transaction = this.props.transactionsQueue[index]; |
|
|
|
|
|
|
|
@ -102,7 +108,7 @@ class RightSideBar extends Component { |
|
|
if (this.props.transactionStack[this.transactionsStackIds[index]]){ |
|
|
if (this.props.transactionStack[this.transactionsStackIds[index]]){ |
|
|
/* User confirmed the transaction */ |
|
|
/* User confirmed the transaction */ |
|
|
|
|
|
|
|
|
//Gets transaciton's hash
|
|
|
//Gets transaction's hash
|
|
|
this.transactionsTxHashes[index] = (this.props |
|
|
this.transactionsTxHashes[index] = (this.props |
|
|
.transactionStack[this.transactionsStackIds[index]]); |
|
|
.transactionStack[this.transactionsStackIds[index]]); |
|
|
this.props.store.dispatch(updateTransaction(index, { |
|
|
this.props.store.dispatch(updateTransaction(index, { |
|
@ -129,9 +135,8 @@ class RightSideBar extends Component { |
|
|
this.setState({ |
|
|
this.setState({ |
|
|
transactionsCompletionTime: transactionsCompletionTimeShallowCopy |
|
|
transactionsCompletionTime: transactionsCompletionTimeShallowCopy |
|
|
}); |
|
|
}); |
|
|
if (this.props.transactionsQueue[index].callback){ |
|
|
|
|
|
this.props.transactionsQueue[index].callback(data); |
|
|
this.completeWithOrbitInteractions(this.props.transactionsQueue[index], data); |
|
|
} |
|
|
|
|
|
} else if (this.props.transactions[this.transactionsTxHashes[index]] |
|
|
} else if (this.props.transactions[this.transactionsTxHashes[index]] |
|
|
.status === "error"){ |
|
|
.status === "error"){ |
|
|
/* Transaction failed to complete */ |
|
|
/* Transaction failed to complete */ |
|
@ -146,13 +151,34 @@ class RightSideBar extends Component { |
|
|
this.setState({ |
|
|
this.setState({ |
|
|
transactionsCompletionTime: transactionsCompletionTimeShallowCopy |
|
|
transactionsCompletionTime: transactionsCompletionTimeShallowCopy |
|
|
}); |
|
|
}); |
|
|
if (this.props.transactionsQueue[index].callback){ |
|
|
//TODO handle this gracefully
|
|
|
this.props.transactionsQueue[index].callback(null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async completeWithOrbitInteractions(transaction, returnData){ |
|
|
|
|
|
switch (transaction.event){ |
|
|
|
|
|
case 'TopicCreated': |
|
|
|
|
|
await this.props.orbitDB.topicsDB.put(returnData.topicID, { |
|
|
|
|
|
subject: transaction.userInputs.topicSubject |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await this.props.orbitDB.postsDB.put(returnData.postID, { |
|
|
|
|
|
subject: transaction.userInputs.topicSubject, |
|
|
|
|
|
content: transaction.userInputs.topicMessage |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
case 'PostCreated': |
|
|
|
|
|
await this.props.orbitDB.postsDB.put(returnData.postID, { |
|
|
|
|
|
subject: transaction.userInputs.postSubject, |
|
|
|
|
|
content: transaction.userInputs.postMessage |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; //This transaction doesn't need a DB interaction to complete
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
RightSideBar.contextTypes = { |
|
|
RightSideBar.contextTypes = { |
|
@ -161,6 +187,7 @@ RightSideBar.contextTypes = { |
|
|
|
|
|
|
|
|
const mapStateToProps = state => { |
|
|
const mapStateToProps = state => { |
|
|
return { |
|
|
return { |
|
|
|
|
|
orbitDB: state.orbitDB, |
|
|
transactionsQueue: state.transactionsQueue.transactions, |
|
|
transactionsQueue: state.transactionsQueue.transactions, |
|
|
transactions: state.transactions, |
|
|
transactions: state.transactions, |
|
|
transactionStack: state.transactionStack |
|
|
transactionStack: state.transactionStack |
|
|