Last active
September 3, 2018 10:25
-
-
Save PaulLaux/4d4442b9c1779b73b963ac193d9f5cc5 to your computer and use it in GitHub Desktop.
Updating ethereum transaction state using redux-saga channels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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