Skip to content

Instantly share code, notes, and snippets.

@PaulLaux
Last active September 3, 2018 10:25
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 PaulLaux/4d4442b9c1779b73b963ac193d9f5cc5 to your computer and use it in GitHub Desktop.
Save PaulLaux/4d4442b9c1779b73b963ac193d9f5cc5 to your computer and use it in GitHub Desktop.
Updating ethereum transaction state using redux-saga channels
import { channel } from 'redux-saga';
const transactionChannel = channel();
/* Init Dapp */
function* initDappAsync(action) {
// ...
// fork to handle channel events
yield fork(handleChannelEvents);
}
/*
* Catch all events from the channel and create an action
*/
function* handleChannelEvents() {
while (true) {
const eventAction = yield take(transactionChannel);
switch (eventAction.type) {
// call action creator according to eventAction.type
case COMMIT_ETH_SEND_SUCCESS:
yield put(commitEthSendSuccess(eventAction.tx));
break;
case COMMIT_ETH_MINED_SUCCESS:
yield put(commitEthMinedSuccess(eventAction.receipt));
break;
case COMMIT_ETH_ERROR:
yield put(commitEthError(eventAction.error));
break;
default:
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment