Skip to content

Instantly share code, notes, and snippets.

@bakasura980
Last active April 29, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakasura980/654a4f8d70940c16daf7af3ea7574515 to your computer and use it in GitHub Desktop.
Save bakasura980/654a4f8d70940c16daf7af3ea7574515 to your computer and use it in GitHub Desktop.
EOSLime shape blockchain service - moveTodo function
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