2018-04-18 19:06:41 +00:00
|
|
|
class AccountList extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
error: false,
|
|
|
|
errorMessage: "",
|
|
|
|
accounts: []
|
|
|
|
};
|
2018-04-19 18:42:11 +00:00
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
this.handleCopyClick = this.handleCopyClick.bind(this);
|
2018-04-18 19:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async handleClick(e, updateAccountsCallback){
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
try {
|
|
|
|
updateAccountsCallback();
|
|
|
|
} catch(err) {
|
|
|
|
this.setState({
|
|
|
|
error: true,
|
|
|
|
errorMessage: e.name + ': ' + e.message
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-19 18:42:11 +00:00
|
|
|
handleCopyClick(e){
|
|
|
|
e.preventDefault();
|
2018-04-18 19:06:41 +00:00
|
|
|
|
2018-04-19 18:42:11 +00:00
|
|
|
var dummy = document.createElement("input");
|
|
|
|
document.body.appendChild(dummy);
|
|
|
|
dummy.setAttribute('value', "await web3.eth.getAccounts();");
|
|
|
|
dummy.select();
|
|
|
|
document.execCommand("copy");
|
|
|
|
document.body.removeChild(dummy);
|
|
|
|
}
|
2018-04-18 19:06:41 +00:00
|
|
|
|
|
|
|
render(){
|
|
|
|
return <ContractContext.Consumer>
|
|
|
|
{(context) => (
|
|
|
|
|
|
|
|
<div className="card function">
|
|
|
|
<div className="card-header">
|
|
|
|
<h3 className="card-title">Get Accounts</h3>
|
2018-04-19 18:42:11 +00:00
|
|
|
<div className="card-options">
|
|
|
|
<a href="#" onClick={this.handleCopyClick} title="Copy to clipboard"><i className="fe fe-copy"></i></a>
|
|
|
|
</div>
|
2018-04-18 19:06:41 +00:00
|
|
|
</div>
|
2018-04-19 13:59:48 +00:00
|
|
|
<CardAlert show={this.state.error} message={this.state.errorMessage} />
|
2018-04-18 19:06:41 +00:00
|
|
|
<div className="card-body row">
|
|
|
|
<div className="col-md-11">
|
|
|
|
<code>
|
|
|
|
await web3.eth.getAccounts();
|
|
|
|
<input type="text" id="accountsTxt" />
|
|
|
|
</code>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-1">
|
|
|
|
<button className="btn btn-primary ml-auto" onClick={event => this.handleClick(event, context.updateAccounts)}>⏎</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="card-footer">
|
|
|
|
<p><tt>accounts</tt> variable is available in the console</p>
|
|
|
|
<ul>
|
|
|
|
{
|
|
|
|
context.accounts.map((account, i) => <li key={i}>{account}</li>)
|
|
|
|
}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</ContractContext.Consumer>;
|
|
|
|
}
|
|
|
|
}
|