Skip to content

Instantly share code, notes, and snippets.

@alant
Last active December 24, 2018 11:11
Show Gist options
  • Save alant/0f0527421f17cc31fbba0a4830b34b8a to your computer and use it in GitHub Desktop.
Save alant/0f0527421f17cc31fbba0a4830b34b8a to your computer and use it in GitHub Desktop.
...
class Edit extends Component {
...
handleSubmit = (event) => {
this.contracts.SimpleStorage.methods.set.cacheSend(this.state.newVal);
event.preventDefault();
}
componentDidUpdate(prevProps) {
const { onRedirectToHomeDone } = this.props;
if (this.props.redirectToHome && this.props.redirectToHome !== prevProps.redirectToHome) {
this.props.history.push('/');
onRedirectToHomeDone();
}
}
...
render() {
const { onMetaMaskCheckDone, onTxErrorDone } = this.props;
return (
<div>
<form onSubmit={this.handleSubmit}>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="contractDataInput">New Value:</InputLabel>
<Input onChange={this.handleChange} id="contractDataInput" name="contractDataInput" autoFocus />
</FormControl>
<Button type="submit" variant="contained" color="primary">
Set
</Button>
</form>
<Dialog
open={this.props.checkMetaMask}
onClose={onMetaMaskCheckDone}
...
>
<DialogTitle id="alert-dialog-title">{"It's time to check your metamask extension"}
...
</Dialog>
<Snackbar
anchorOrigin={{ 'vertical': 'bottom', 'horizontal': 'right'} }
open={this.props.metaMaskReject}
autoHideDuration={6000}
onClose={onTxErrorDone}
...
message={<span id="message-id">You rejected the TX</span>}
...
/>
</div>
);
}
}
...
const mapStateToProps = state => {
return {
checkMetaMask: state.dappReducer.checkMetaMask,
metaMaskReject: state.dappReducer.metaMaskReject,
redirectToHome: state.dappReducer.redirectToHome
}
}
const mapDispatchToProps = dispatch => {
return {
onMetaMaskCheckDone: () => dispatch({ type: "CHECK_METAMASK_DONE" }),
onTxErrorDone: () => dispatch({ type: "TX_ERROR_METAMASK_DONE" }),
onRedirectToHomeDone: () => dispatch({ type: "REDIRECT_TO_HOME_DONE"})
};
};
export default drizzleConnect(Edit, mapStateToProps, mapDispatchToProps);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment