Skip to content

Instantly share code, notes, and snippets.

@bakasura980
Last active April 29, 2020 12:24
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/6d2f24c2be92491ef2ef87274daf7faa to your computer and use it in GitHub Desktop.
Save bakasura980/6d2f24c2be92491ef2ef87274daf7faa to your computer and use it in GitHub Desktop.
EOSLime shape TodoApplication [ Connector ]
// ./index.js
import React from 'react';
import { TodoFormHtml } from './renders/todo-form';
import TodoManager from './services/todo-manager';
class TodoApplication extends Component {
constructor() {
this.state = {
// Blockchain service
todoManager: null,
// New Todo description
newTodoDescription: ''
}
}
// React method comming from Component class
async componentDidMount () {
// Make sure methods will be visible in todo-form render
this.addTodo = this.addTodo.bind(this);
this.onNewTodoDescription = this.onNewTodoDescription.bind(this);
// Instantiate Blockchain service
const todoManager = await TodoManager.build();
this.setState({ todoManager });
}
// Visualise our "Add Todo" button
render () {
return (
<div>
{TodoFormHtml(this)}
</div>
);
}
// Update Todo description on input box entering
onNewTodoDescription (event) {
this.setState({ newTodoDescription: event.target.value });
}
/*
Once "Add Todo" button is clicked we are trigerring
a transaction to be broadcated in the blockchain
(Create Todo in the blockchain)
*/
async addTodo () {
/*
Create a new Todo on chain by providing its description
By successfully broadcating a transaction you will get its
status and id in return
*/
const txReceipt = await this.state.todoManager.addTodo(this.state.newTodoDescription);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment