Skip to content

Commit

Permalink
fix initial subscription message for ethereum sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
salomegeo committed May 2, 2018
1 parent af61b37 commit b83adfc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export default ({ api, coreSagas }) => {
}
yield put(actions.auth.authenticate())
yield put(actions.core.webSocket.bitcoin.startSocket())
yield put(actions.core.webSocket.ethereum.startSocket())
yield put(actions.core.webSocket.bch.startSocket())
yield call(coreSagas.kvStore.root.fetchRoot, askSecondPasswordEnhancer)
yield put(actions.core.webSocket.ethereum.startSocket())
yield put(actions.alerts.displaySuccess('Login successful'))
yield put(actions.router.push('/home'))
yield put(actions.goals.runGoals())
Expand Down
26 changes: 14 additions & 12 deletions packages/blockchain-wallet-v4/src/redux/webSocket/ethereum/sagas.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import { takeEvery, call, put, select } from 'redux-saga/effects'
import { takeEvery, call, put, select, take } from 'redux-saga/effects'
import * as A from '../../actions'
import * as AT from './actionTypes'
import * as ethAT from '../../kvStore/ethereum/actionTypes'
import * as ethSelectors from '../../data/ethereum/selectors'
import * as ethActions from '../../data/ethereum/actions'

const ACCOUNT_SUB = 'account_sub'
const BLOCK_SUB = 'block_sub'

// TO REVIEW
export default ({ api, ethSocket }) => {
const send = ethSocket.send.bind(ethSocket)

const onOpen = function * () {
// XXX we need to get account addresses here
// const subscribeInfo = yield select(ethSelectors.getDefaultAddress)
yield call(send, JSON.stringify({op: 'block_sub'}))
yield call(send, JSON.stringify({op: 'account_sub', account: '0xe6cbafa68fdd504e7f7d79acb8349c767bf7e94a'}))// "0x0e23F536b5509eca1Cf4a1ef2E541589EaB4479C"}))
const metadata = yield take(ethAT.FETCH_METADATA_ETHEREUM_SUCCESS)
yield call(send, JSON.stringify({op: BLOCK_SUB}))
yield call(send, JSON.stringify({op: ACCOUNT_SUB, account: metadata.payload.address}))
}

const onMessage = function * (action) {
const message = action.payload
console.log('received ethereum message', message)
// console.log('received ethereum message', message)

switch (message.op) {
case 'utx':
case ACCOUNT_SUB:
//const walletContext = yield select(walletSelectors.getWalletContext)
//yield put(ethActions.fetchData(walletContext))
//yield put(ethActions.fetchTransactions('', true))
break
case 'block':
//const newBlock = message.x
//yield put(A.data.bitcoin.setBitcoinLatestBlock(newBlock.blockIndex, newBlock.hash, newBlock.height, newBlock.time))
//yield put(ethActions.fetchTransactions('', true))
case BLOCK_SUB:
console.log('ethereum block ', message)
yield put(ethActions.fetchLatestBlock())
yield put(ethActions.fetchTransactions('', true))
break
case 'pong':
break
Expand Down

0 comments on commit b83adfc

Please sign in to comment.