-
-
Save bakasura980/654a4f8d70940c16daf7af3ea7574515 to your computer and use it in GitHub Desktop.
EOSLime shape blockchain service - moveTodo function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async moveTodo (todo, inState) { | |
// Move todo only if the new state is different | |
// Skip usless transactions | |
if (todo.status === TODO_STATES[inState]) { | |
return false; | |
} | |
// Call contract method "update" in the blockchain | |
const txReceipt = await this.todoContract.update(todo.id, TODO_STATES[inState]); | |
/* | |
Update todo's state in local todosList cache | |
only if the move transaction has been successful | |
Skip contract requests on change | |
*/ | |
const todoIndex = this.todosList[todo.state].findIndex((todoElement) => todoElement.id === todo.id); | |
this.todosList[todo.state].splice(todoIndex, 1); | |
this.todosList[inState].push(todo); | |
todo.status = TODO_STATES[inState]; | |
todo.state = inState; | |
return txReceipt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment