Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyOneJMJQ authored May 29, 2018
2 parents 6ccdbe1 + d97f110 commit 051e859
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
17 changes: 14 additions & 3 deletions dist/drizzle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/blocks/blocksSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function* processBlock({block, drizzle, web3}) {

if (txs.length > 0)
{
// Loop through txs looking for contract address
// Loop through txs looking for any contract address of interest
for (var i = 0; i < txs.length; i++)
{
var from = txs[i].from || ''
Expand Down
71 changes: 33 additions & 38 deletions src/web3/web3Saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,51 @@ var Web3 = require('web3')
*/

export function* initializeWeb3({options}) {
var web3 = {}

// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof window.web3 !== 'undefined') {
// Use Mist/MetaMask's provider.
web3 = new Web3(window.web3.currentProvider)
web3.eth.cacheSendTransaction = (txObject) => put({type: 'SEND_WEB3_TX', txObject, stackId, web3})
try {
var web3 = {}

console.log('Injected web3 detected.')
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof window.web3 !== 'undefined') {
// Use Mist/MetaMask's provider.
web3 = new Web3(window.web3.currentProvider)
web3.eth.cacheSendTransaction = (txObject) => put({type: 'SEND_WEB3_TX', txObject, stackId, web3})

yield put({type: 'WEB3_INITIALIZED'})

return web3
} else {
if (options.fallback) {
// Attempt fallback if no web3 injection.
console.log('No web3 instance injected, using fallback.')
console.log('Injected web3 detected.')

switch (options.fallback.type) {
case 'ws':
var provider = new Web3.providers.WebsocketProvider(options.fallback.url)
web3 = new Web3(provider)
yield put({type: 'WEB3_INITIALIZED'})

return web3
} else {
if (options.fallback) {
// Attempt fallback if no web3 injection.
console.log('No web3 instance injected, using fallback.')

// Attach drizzle functions
web3.eth['cacheSendTransaction'] = (txObject) => put({type: 'SEND_WEB3_TX', txObject, stackId, web3})
switch (options.fallback.type) {
case 'ws':
var provider = new Web3.providers.WebsocketProvider(options.fallback.url)
web3 = new Web3(provider)

yield put({type: 'WEB3_INITIALIZED'})
// Attach drizzle functions
web3.eth['cacheSendTransaction'] = (txObject) => put({type: 'SEND_WEB3_TX', txObject, stackId, web3})

return web3
yield put({type: 'WEB3_INITIALIZED'})

break
default:
// Invalid options; throw.
throw "Invalid web3 fallback provided."
}
}
return web3

// Out of web3 options; throw.
throw "Cannot find injected web3 or valid fallback."
}
}
break
default:
// Invalid options; throw.
throw "Invalid web3 fallback provided."
}
}

function* callInitializeWeb3(action) {
try {
const web3 = yield call(initializeWeb3, {options: action.options})
return web3
// Out of web3 options; throw.
throw "Cannot find injected web3 or valid fallback."
}
}
catch (error) {
store.dispatch({type: 'WEB3_FAILED', error})
yield put({type: 'WEB3_FAILED', error})
console.error('Error intializing web3:')
console.error(error)
}
Expand Down Expand Up @@ -130,7 +126,6 @@ function* callSendTx({txObject, stackId, web3}) {
}

function* web3Saga() {
yield takeLatest('WEB3_INITIALIZING', callInitializeWeb3)
yield takeLatest('NETWORK_ID_FETCHING', getNetworkId)
yield takeEvery('SEND_WEB3_TX', callSendTx)
}
Expand Down

0 comments on commit 051e859

Please sign in to comment.