From a4bf2c59942bcceeec86c813a484092e0c8b9786 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 4 Sep 2020 20:27:43 +0300 Subject: [PATCH 1/5] Listen to network changes --- package.json | 2 +- src/Drizzle.js | 2 +- .../accountBalancesMiddleware.js | 2 +- src/accounts/accountsMiddleware.js | 6 +-- src/drizzleStatus/drizzleStatusSaga.js | 10 ++--- src/index.js | 40 ++++--------------- src/rootSaga.js | 4 +- src/web3/{constants.js => web3Actions.js} | 8 ++++ src/web3/web3Middleware.js | 21 ++++++++++ src/web3/web3Reducer.js | 5 ++- src/web3/web3Saga.js | 26 +++++++----- 11 files changed, 68 insertions(+), 58 deletions(-) rename src/web3/{constants.js => web3Actions.js} (74%) create mode 100644 src/web3/web3Middleware.js diff --git a/package.json b/package.json index 3d5db05..4ababd0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ezerous/drizzle", - "version": "0.1.0", + "version": "0.2.0", "description": "A reactive data-store for web3 and smart contracts.", "license": "MIT", "author": "Ezerous ", diff --git a/src/Drizzle.js b/src/Drizzle.js index 02c50ec..ee40798 100644 --- a/src/Drizzle.js +++ b/src/Drizzle.js @@ -6,7 +6,7 @@ import * as ContractActions from './contracts/constants' import * as DrizzleActions from './drizzleStatus/drizzleActions' // Load as promise so that async Drizzle initialization can still resolve -var isEnvReadyPromise = new Promise((resolve, reject) => { +const isEnvReadyPromise = new Promise((resolve) => { const hasNavigator = typeof navigator !== 'undefined' const hasWindow = typeof window !== 'undefined' const hasDocument = typeof document !== 'undefined' diff --git a/src/accountBalances/accountBalancesMiddleware.js b/src/accountBalances/accountBalancesMiddleware.js index dcf3fc0..d784474 100644 --- a/src/accountBalances/accountBalancesMiddleware.js +++ b/src/accountBalances/accountBalancesMiddleware.js @@ -1,4 +1,4 @@ -import { WEB3_INITIALIZED } from '../web3/constants' +import { WEB3_INITIALIZED } from '../web3/web3Actions' import { accountBalancesFetching } from './accountBalancesActions' import { ACCOUNTS_FETCHED } from '../accounts/accountsActions' diff --git a/src/accounts/accountsMiddleware.js b/src/accounts/accountsMiddleware.js index 73c3151..4c9128f 100644 --- a/src/accounts/accountsMiddleware.js +++ b/src/accounts/accountsMiddleware.js @@ -1,14 +1,14 @@ -import { WEB3_INITIALIZED } from '../web3/constants' +import { WEB3_INITIALIZED } from '../web3/web3Actions' import { accountsFetched, accountsListening } from './accountsActions' -export const accountsMiddleware = () => store => next => action => { +export const accountsMiddleware = web3 => store => next => action => { const { type } = action if (type === WEB3_INITIALIZED) { if(!window.ethereum) console.warn('No Metamask detected, not subscribed to account changes!') else { - const { web3 } = action; + web3 = action.web3; window.ethereum.on('accountsChanged', accounts => { // For some reason accounts here are returned with lowercase letters, so we need to patch them let patchedAccounts = Array.from(accounts); diff --git a/src/drizzleStatus/drizzleStatusSaga.js b/src/drizzleStatus/drizzleStatusSaga.js index db28571..1e37b09 100644 --- a/src/drizzleStatus/drizzleStatusSaga.js +++ b/src/drizzleStatus/drizzleStatusSaga.js @@ -7,7 +7,7 @@ import { getAccountBalances } from '../accountBalances/accountBalancesSaga' import * as DrizzleActions from './drizzleActions' import * as BlocksActions from '../blocks/blockActions' -import { NETWORK_IDS, NETWORK_MISMATCH } from '../web3/constants' +import { NETWORK_IDS, NETWORK_MISMATCH } from '../web3/web3Actions' export function * initializeDrizzle (action) { try { @@ -35,10 +35,10 @@ export function * initializeDrizzle (action) { yield call(getAccountBalances, { web3 }) // Instantiate contracts passed through via options. - for (var i = 0; i < options.contracts.length; i++) { - var contractConfig = options.contracts[i] - var events = [] - var contractName = contractConfig.contractName + for (let i = 0; i < options.contracts.length; i++) { + const contractConfig = options.contracts[i] + let events = [] + const contractName = contractConfig.contractName if (contractName in options.events) { events = options.events[contractName] diff --git a/src/index.js b/src/index.js index 83a3eb3..1f48a64 100644 --- a/src/index.js +++ b/src/index.js @@ -7,53 +7,27 @@ import * as EventActions from './contracts/constants' import * as AccountActions from './accounts/accountsActions' // Reducers -import accountsReducer from './accounts/accountsReducer' -import accountBalancesReducer from './accountBalances/accountBalancesReducer' -import blocksReducer from './blocks/blocksReducer' -import contractsReducer from './contracts/contractsReducer' -import drizzleStatusReducer from './drizzleStatus/drizzleStatusReducer' -import transactionsReducer from './transactions/transactionsReducer' -import transactionStackReducer from './transactions/transactionStackReducer' -import web3Reducer from './web3/web3Reducer' +import drizzleReducers from './reducer' // Middleware import drizzleMiddleware from './drizzle-middleware' import accountsMiddleware from './accounts/accountsMiddleware' import accountBalancesMiddleware from './accountBalances/accountBalancesMiddleware' +import web3Middleware from './web3/web3Middleware' // Sagas -import accountBalancesSaga from './accountBalances/accountBalancesSaga' -import blocksSaga from './blocks/blocksSaga' -import contractsSaga from './contracts/contractsSaga' -import drizzleStatusSaga from './drizzleStatus/drizzleStatusSaga' - -const drizzleReducers = { - accounts: accountsReducer, - accountBalances: accountBalancesReducer, - contracts: contractsReducer, - currentBlock: blocksReducer, - drizzleStatus: drizzleStatusReducer, - transactions: transactionsReducer, - transactionStack: transactionStackReducer, - web3: web3Reducer -} +import drizzleSagas from './rootSaga' const drizzleMiddlewares = [ drizzleMiddleware, accountsMiddleware, - accountBalancesMiddleware -] - -const drizzleSagas = [ - accountBalancesSaga, - blocksSaga, - contractsSaga, - drizzleStatusSaga + accountBalancesMiddleware, + web3Middleware ] const drizzleActions = { - AccountActions, - EventActions + account: AccountActions, + event: EventActions } export { diff --git a/src/rootSaga.js b/src/rootSaga.js index d165edc..e592e9a 100644 --- a/src/rootSaga.js +++ b/src/rootSaga.js @@ -2,10 +2,12 @@ import accountBalancesSaga from './accountBalances/accountBalancesSaga' import blocksSaga from './blocks/blocksSaga' import contractsSaga from './contracts/contractsSaga' import drizzleStatusSaga from './drizzleStatus/drizzleStatusSaga' +import web3Saga from './web3/web3Saga' export default [ accountBalancesSaga, blocksSaga, contractsSaga, - drizzleStatusSaga + drizzleStatusSaga, + web3Saga ] diff --git a/src/web3/constants.js b/src/web3/web3Actions.js similarity index 74% rename from src/web3/constants.js rename to src/web3/web3Actions.js index 2943c92..6b5ead3 100644 --- a/src/web3/constants.js +++ b/src/web3/web3Actions.js @@ -4,6 +4,7 @@ export const WEB3_FAILED = 'WEB3_FAILED' export const WEB3_USER_DENIED = 'WEB3_USER_DENIED' export const NETWORK_ID_FETCHED = 'NETWORK_ID_FETCHED' +export const NETWORK_ID_CHANGED = 'NETWORK_ID_CHANGED' export const NETWORK_ID_FAILED = 'NETWORK_ID_FAILED' export const NETWORK_MISMATCH = 'NETWORK_MISMATCH' @@ -15,3 +16,10 @@ export const NETWORK_IDS = { kovan: 42, ganache: 5777 } + +export function networkIdChanged (web3) { + return { + type: NETWORK_ID_CHANGED, + web3 + } +} diff --git a/src/web3/web3Middleware.js b/src/web3/web3Middleware.js new file mode 100644 index 0000000..02a3aaa --- /dev/null +++ b/src/web3/web3Middleware.js @@ -0,0 +1,21 @@ +import { networkIdChanged, WEB3_INITIALIZED } from './web3Actions' + +export const web3Middleware = web3 => store => next => action => { + const { type } = action + + if (type === WEB3_INITIALIZED) { + if(!window.ethereum) + console.warn('No Metamask detected, not subscribed to network changes!') + else { + web3 = action.web3; + window.ethereum.on('networkChanged', () => { + // We could have listened to 'networkChanged' but it is deprecated (EIP-1193) + store.dispatch(networkIdChanged(web3)); + }); + } + } + return next(action) +} + +const initializedMiddleware = web3Middleware(undefined) +export default initializedMiddleware diff --git a/src/web3/web3Reducer.js b/src/web3/web3Reducer.js index e29677e..b81c50a 100644 --- a/src/web3/web3Reducer.js +++ b/src/web3/web3Reducer.js @@ -1,4 +1,4 @@ -import * as Action from './constants' +import * as Action from './web3Actions' const initialState = { status: '' @@ -33,7 +33,8 @@ const web3Reducer = (state = initialState, action) => { } } - if (action.type === Action.NETWORK_ID_FETCHED) { + if (action.type === Action.NETWORK_ID_FETCHED + || action.type === Action.NETWORK_ID_CHANGED) { return { ...state, networkId: action.networkId diff --git a/src/web3/web3Saga.js b/src/web3/web3Saga.js index cb13747..eeff7b5 100644 --- a/src/web3/web3Saga.js +++ b/src/web3/web3Saga.js @@ -1,12 +1,11 @@ -import { call, put } from 'redux-saga/effects' -import * as Action from './constants' +import { call, put, takeLatest } from 'redux-saga/effects' +import * as Action from './web3Actions' const Web3 = require('web3'); /* * Initialization */ - export function * initializeWeb3 (options) { try { let web3 = {} @@ -35,7 +34,6 @@ export function * initializeWeb3 (options) { } catch (error) { console.error(error) yield put({ type: Action.WEB3_FAILED }) - return } } else if (typeof window.web3 !== 'undefined') { // Checking if Web3 has been injected by the browser (Mist/MetaMask) @@ -71,20 +69,26 @@ export function * initializeWeb3 (options) { } /* - * Network ID + * Fetch Network ID */ - export function * getNetworkId ({ web3 }) { try { - const networkId = yield call(web3.eth.net.getId) + const networkId = yield call(web3.eth.net.getId); - yield put({ type: Action.NETWORK_ID_FETCHED, networkId }) + yield put({ type: Action.NETWORK_ID_FETCHED, networkId }); return networkId } catch (error) { - yield put({ type: Action.NETWORK_ID_FAILED, error }) + yield put({ type: Action.NETWORK_ID_FAILED, error }); - console.error('Error fetching network ID:') - console.error(error) + console.error('Error fetching network ID:'); + console.error(error); } } + +function * web3Saga () { + yield takeLatest(Action.NETWORK_ID_CHANGED, getNetworkId); +} + +export default web3Saga + From 19561c2335327f85cee38428665b0962961005d2 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 5 Sep 2020 13:17:33 +0300 Subject: [PATCH 2/5] Check if contracts are deployed on current network before adding them --- src/contractStateUtils.js | 1 + src/contracts/constants.js | 1 + src/contracts/contractsReducer.js | 11 +++++++++++ src/contracts/contractsSaga.js | 20 +++++++++++++++++--- src/drizzleStatus/drizzleStatusSaga.js | 10 ++++++++-- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/contractStateUtils.js b/src/contractStateUtils.js index 8457648..6ed534a 100644 --- a/src/contractStateUtils.js +++ b/src/contractStateUtils.js @@ -22,6 +22,7 @@ export const generateContractInitialState = contractConfig => { return { initialized: false, synced: false, + deployed: true, ...objectOfConstants } } diff --git a/src/contracts/constants.js b/src/contracts/constants.js index c98ab27..54d4f54 100644 --- a/src/contracts/constants.js +++ b/src/contracts/constants.js @@ -4,6 +4,7 @@ export const EVENT_ERROR = 'EVENT_ERROR' export const LISTEN_FOR_EVENT = 'LISTEN_FOR_EVENT' export const CONTRACT_INITIALIZING = 'CONTRACT_INITIALIZING' export const CONTRACT_INITIALIZED = 'CONTRACT_INITIALIZED' +export const CONTRACT_NOT_DEPLOYED = 'CONTRACT_NOT_DEPLOYED' export const GOT_CONTRACT_VAR = 'GOT_CONTRACT_VAR' export const DELETE_CONTRACT = 'DELETE_CONTRACT' export const CONTRACT_SYNCING = 'CONTRACT_SYNCING' diff --git a/src/contracts/contractsReducer.js b/src/contracts/contractsReducer.js index 8af3006..540ded4 100644 --- a/src/contracts/contractsReducer.js +++ b/src/contracts/contractsReducer.js @@ -29,6 +29,17 @@ const contractsReducer = (state = initialState, action) => { } } + // Contract not found on the current network + if (action.type === ContractActions.CONTRACT_NOT_DEPLOYED) { + return { + ...state, + [action.name]: { + ...state[action.name], + deployed: false + } + } + } + if (action.type === ContractActions.DELETE_CONTRACT) { const { [action.contractName]: omitted, ...rest } = state return rest diff --git a/src/contracts/contractsSaga.js b/src/contracts/contractsSaga.js index 1ba4395..0c7e507 100644 --- a/src/contracts/contractsSaga.js +++ b/src/contracts/contractsSaga.js @@ -2,6 +2,8 @@ import { END, eventChannel } from 'redux-saga' import { call, put, select, take, takeEvery } from 'redux-saga/effects' import * as ContractActions from './constants' import * as TransactionsActions from '../transactions/transactionsActions' +import { ACCOUNTS_FAILED, ACCOUNTS_FETCHED, ACCOUNTS_FETCHING } from '../accounts/accountsActions' +import { getNetworkId } from '../web3/web3Saga' /* * Events @@ -199,7 +201,7 @@ function * callCallContractFn ({ } catch (error) { console.error(error) - var errorArgs = { + const errorArgs = { name: contract.contractName, variable: contract.abi[fnIndex].name, argsHash: argsHash, @@ -230,8 +232,8 @@ function * callSyncContract (action) { delete contractFnsState.events // Iterate over functions and hashes - for (var fnName in contractFnsState) { - for (var argsHash in contractFnsState[fnName]) { + for (let fnName in contractFnsState) { + for (let argsHash in contractFnsState[fnName]) { const fnIndex = contractFnsState[fnName][argsHash].fnIndex const args = contractFnsState[fnName][argsHash].args @@ -271,6 +273,18 @@ function isSendOrCallOptions (options) { return false } +export function * isContractDeployed ({ web3, contractConfig }) { + const networkId = yield call(getNetworkId, { web3 }) + if(contractConfig.networks[networkId]){ + const contractAddress = contractConfig.networks[networkId].address; + + const fetchedByteCode = yield call(web3.eth.getCode, contractAddress); + if(fetchedByteCode === contractConfig.deployedBytecode) + return true; + } + return false; +} + function * contractsSaga () { yield takeEvery(ContractActions.SEND_CONTRACT_TX, callSendContractTx) yield takeEvery(ContractActions.CALL_CONTRACT_FN, callCallContractFn) diff --git a/src/drizzleStatus/drizzleStatusSaga.js b/src/drizzleStatus/drizzleStatusSaga.js index 1e37b09..f0526f6 100644 --- a/src/drizzleStatus/drizzleStatusSaga.js +++ b/src/drizzleStatus/drizzleStatusSaga.js @@ -8,6 +8,8 @@ import * as DrizzleActions from './drizzleActions' import * as BlocksActions from '../blocks/blockActions' import { NETWORK_IDS, NETWORK_MISMATCH } from '../web3/web3Actions' +import { CONTRACT_NOT_DEPLOYED } from '../contracts/constants' +import { isContractDeployed } from '../contracts/contractsSaga' export function * initializeDrizzle (action) { try { @@ -38,12 +40,16 @@ export function * initializeDrizzle (action) { for (let i = 0; i < options.contracts.length; i++) { const contractConfig = options.contracts[i] let events = [] - const contractName = contractConfig.contractName - + const contractName = contractConfig.contractName; if (contractName in options.events) { events = options.events[contractName] } + if(!(yield call(isContractDeployed, { web3, contractConfig }))){ + yield put({ type: CONTRACT_NOT_DEPLOYED, name: contractName }) + throw `Contract ${contractName} not deployed on this network` + } + yield call([drizzle, drizzle.addContract], contractConfig, events) } From 7a67f9d4a9faa662c35bb6e23b3e941b82d8f6bb Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 5 Sep 2020 15:11:33 +0300 Subject: [PATCH 3/5] Reinitialize drizzle on network changes --- src/contracts/contractsSaga.js | 2 +- src/drizzle-middleware.js | 9 +++++++++ src/drizzleStatus/drizzleStatusSaga.js | 2 +- src/rootSaga.js | 4 +--- src/web3/web3Actions.js | 6 ++++-- src/web3/web3Middleware.js | 8 +++++--- src/web3/web3Saga.js | 7 ------- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/contracts/contractsSaga.js b/src/contracts/contractsSaga.js index 0c7e507..5021f1c 100644 --- a/src/contracts/contractsSaga.js +++ b/src/contracts/contractsSaga.js @@ -274,7 +274,7 @@ function isSendOrCallOptions (options) { } export function * isContractDeployed ({ web3, contractConfig }) { - const networkId = yield call(getNetworkId, { web3 }) + const networkId = yield call(web3.eth.net.getId); if(contractConfig.networks[networkId]){ const contractAddress = contractConfig.networks[networkId].address; diff --git a/src/drizzle-middleware.js b/src/drizzle-middleware.js index 0718af2..71d96f4 100644 --- a/src/drizzle-middleware.js +++ b/src/drizzle-middleware.js @@ -1,6 +1,7 @@ import * as DrizzleActions from './drizzleStatus/drizzleActions' import * as ContractActions from './contracts/constants' import { ACCOUNTS_FETCHED } from './accounts/accountsActions' +import { NETWORK_ID_CHANGED } from './web3/web3Actions' export const drizzleMiddleware = drizzleInstance => store => next => action => { const { type } = action @@ -9,6 +10,14 @@ export const drizzleMiddleware = drizzleInstance => store => next => action => { drizzleInstance = action.drizzle } + if (type === NETWORK_ID_CHANGED) { + store.dispatch({ + type: DrizzleActions.DRIZZLE_INITIALIZING, + drizzle: drizzleInstance, + options: drizzleInstance.options + }) + } + if ( type === ACCOUNTS_FETCHED && drizzleInstance && diff --git a/src/drizzleStatus/drizzleStatusSaga.js b/src/drizzleStatus/drizzleStatusSaga.js index f0526f6..42f76b6 100644 --- a/src/drizzleStatus/drizzleStatusSaga.js +++ b/src/drizzleStatus/drizzleStatusSaga.js @@ -7,7 +7,7 @@ import { getAccountBalances } from '../accountBalances/accountBalancesSaga' import * as DrizzleActions from './drizzleActions' import * as BlocksActions from '../blocks/blockActions' -import { NETWORK_IDS, NETWORK_MISMATCH } from '../web3/web3Actions' +import { NETWORK_ID_CHANGED, NETWORK_IDS, NETWORK_MISMATCH } from '../web3/web3Actions' import { CONTRACT_NOT_DEPLOYED } from '../contracts/constants' import { isContractDeployed } from '../contracts/contractsSaga' diff --git a/src/rootSaga.js b/src/rootSaga.js index e592e9a..d165edc 100644 --- a/src/rootSaga.js +++ b/src/rootSaga.js @@ -2,12 +2,10 @@ import accountBalancesSaga from './accountBalances/accountBalancesSaga' import blocksSaga from './blocks/blocksSaga' import contractsSaga from './contracts/contractsSaga' import drizzleStatusSaga from './drizzleStatus/drizzleStatusSaga' -import web3Saga from './web3/web3Saga' export default [ accountBalancesSaga, blocksSaga, contractsSaga, - drizzleStatusSaga, - web3Saga + drizzleStatusSaga ] diff --git a/src/web3/web3Actions.js b/src/web3/web3Actions.js index 6b5ead3..2175bdc 100644 --- a/src/web3/web3Actions.js +++ b/src/web3/web3Actions.js @@ -3,6 +3,7 @@ export const WEB3_INITIALIZED = 'WEB3_INITIALIZED' export const WEB3_FAILED = 'WEB3_FAILED' export const WEB3_USER_DENIED = 'WEB3_USER_DENIED' +export const NETWORK_ID_FETCHING = 'NETWORK_ID_FETCHING' export const NETWORK_ID_FETCHED = 'NETWORK_ID_FETCHED' export const NETWORK_ID_CHANGED = 'NETWORK_ID_CHANGED' export const NETWORK_ID_FAILED = 'NETWORK_ID_FAILED' @@ -17,9 +18,10 @@ export const NETWORK_IDS = { ganache: 5777 } -export function networkIdChanged (web3) { +export function networkIdChanged (web3, networkId) { return { type: NETWORK_ID_CHANGED, - web3 + web3, + networkId } } diff --git a/src/web3/web3Middleware.js b/src/web3/web3Middleware.js index 02a3aaa..2c4557c 100644 --- a/src/web3/web3Middleware.js +++ b/src/web3/web3Middleware.js @@ -8,9 +8,11 @@ export const web3Middleware = web3 => store => next => action => { console.warn('No Metamask detected, not subscribed to network changes!') else { web3 = action.web3; - window.ethereum.on('networkChanged', () => { - // We could have listened to 'networkChanged' but it is deprecated (EIP-1193) - store.dispatch(networkIdChanged(web3)); + window.ethereum.on('networkChanged', (networkId) => { + // Warning: 'networkChanged' is deprecated (EIP-1193) + const storedNetworkId = store.getState().web3.networkId; + if(storedNetworkId && networkId !== storedNetworkId) + store.dispatch(networkIdChanged(web3, networkId)); }); } } diff --git a/src/web3/web3Saga.js b/src/web3/web3Saga.js index eeff7b5..9171e75 100644 --- a/src/web3/web3Saga.js +++ b/src/web3/web3Saga.js @@ -85,10 +85,3 @@ export function * getNetworkId ({ web3 }) { console.error(error); } } - -function * web3Saga () { - yield takeLatest(Action.NETWORK_ID_CHANGED, getNetworkId); -} - -export default web3Saga - From bea7dddff05b0011093f843e4fb1d56bce52fe17 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 5 Sep 2020 15:13:29 +0300 Subject: [PATCH 4/5] Cleanup --- src/accountBalances/accountBalancesSaga.js | 2 +- src/blocks/blocksSaga.js | 2 +- src/contracts/contractsSaga.js | 2 -- src/drizzleStatus/drizzleStatusSaga.js | 4 ++-- src/generateStore.js | 2 +- src/mergeOptions.js | 2 +- src/web3/web3Saga.js | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/accountBalances/accountBalancesSaga.js b/src/accountBalances/accountBalancesSaga.js index 6fa67ea..377e28c 100644 --- a/src/accountBalances/accountBalancesSaga.js +++ b/src/accountBalances/accountBalancesSaga.js @@ -1,7 +1,7 @@ import { call, put, select, takeLatest } from 'redux-saga/effects' import { - ACCOUNT_BALANCES_FAILED, ACCOUNT_BALANCE_FETCHED, + ACCOUNT_BALANCES_FAILED, ACCOUNT_BALANCES_FETCHED, ACCOUNT_BALANCES_FETCHING } from './accountBalancesActions' diff --git a/src/blocks/blocksSaga.js b/src/blocks/blocksSaga.js index 8292263..091e7bc 100644 --- a/src/blocks/blocksSaga.js +++ b/src/blocks/blocksSaga.js @@ -1,5 +1,5 @@ import { END, eventChannel } from 'redux-saga' -import { call, put, take, takeEvery, takeLatest, all } from 'redux-saga/effects' +import { all, call, put, take, takeEvery, takeLatest } from 'redux-saga/effects' import * as BlocksActions from './blockActions' /* diff --git a/src/contracts/contractsSaga.js b/src/contracts/contractsSaga.js index 5021f1c..d50d342 100644 --- a/src/contracts/contractsSaga.js +++ b/src/contracts/contractsSaga.js @@ -2,8 +2,6 @@ import { END, eventChannel } from 'redux-saga' import { call, put, select, take, takeEvery } from 'redux-saga/effects' import * as ContractActions from './constants' import * as TransactionsActions from '../transactions/transactionsActions' -import { ACCOUNTS_FAILED, ACCOUNTS_FETCHED, ACCOUNTS_FETCHING } from '../accounts/accountsActions' -import { getNetworkId } from '../web3/web3Saga' /* * Events diff --git a/src/drizzleStatus/drizzleStatusSaga.js b/src/drizzleStatus/drizzleStatusSaga.js index 42f76b6..7879f5e 100644 --- a/src/drizzleStatus/drizzleStatusSaga.js +++ b/src/drizzleStatus/drizzleStatusSaga.js @@ -1,13 +1,13 @@ import { call, put, takeLatest } from 'redux-saga/effects' // Initialization Functions -import { initializeWeb3, getNetworkId } from '../web3/web3Saga' +import { getNetworkId, initializeWeb3 } from '../web3/web3Saga' import { getAccounts } from '../accounts/accountsSaga' import { getAccountBalances } from '../accountBalances/accountBalancesSaga' import * as DrizzleActions from './drizzleActions' import * as BlocksActions from '../blocks/blockActions' -import { NETWORK_ID_CHANGED, NETWORK_IDS, NETWORK_MISMATCH } from '../web3/web3Actions' +import { NETWORK_IDS, NETWORK_MISMATCH } from '../web3/web3Actions' import { CONTRACT_NOT_DEPLOYED } from '../contracts/constants' import { isContractDeployed } from '../contracts/contractsSaga' diff --git a/src/generateStore.js b/src/generateStore.js index 7d12a67..603b364 100644 --- a/src/generateStore.js +++ b/src/generateStore.js @@ -1,5 +1,5 @@ import { all, fork } from 'redux-saga/effects' -import { createStore, applyMiddleware, compose, combineReducers } from 'redux' +import { applyMiddleware, combineReducers, compose, createStore } from 'redux' import createSagaMiddleware from 'redux-saga' import drizzleSagas from './rootSaga' import drizzleReducers from './reducer' diff --git a/src/mergeOptions.js b/src/mergeOptions.js index f30bd87..10ddeae 100644 --- a/src/mergeOptions.js +++ b/src/mergeOptions.js @@ -1,5 +1,5 @@ const merge = require('deepmerge'); -import isPlainObject from 'is-plain-object'; +import isPlainObject from 'is-plain-object' export default function (defaultOptions, newOptions) { return merge(defaultOptions, newOptions, { diff --git a/src/web3/web3Saga.js b/src/web3/web3Saga.js index 9171e75..d3fc3ee 100644 --- a/src/web3/web3Saga.js +++ b/src/web3/web3Saga.js @@ -1,4 +1,4 @@ -import { call, put, takeLatest } from 'redux-saga/effects' +import { call, put } from 'redux-saga/effects' import * as Action from './web3Actions' const Web3 = require('web3'); From 85b4b12fda20c15b7514ddb56d8cdbac4f3f8d6d Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 5 Sep 2020 15:20:12 +0300 Subject: [PATCH 5/5] Don't throw error upon readding existing contracts (drizzle reinit) --- src/Drizzle.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Drizzle.js b/src/Drizzle.js index ee40798..b52eeed 100644 --- a/src/Drizzle.js +++ b/src/Drizzle.js @@ -81,12 +81,6 @@ class Drizzle { events ) - if (this.contracts[drizzleContract.contractName]) { - throw new Error( - `Contract already exists: ${drizzleContract.contractName}` - ) - } - this.store.dispatch({ type: ContractActions.CONTRACT_INITIALIZING, contractConfig }) this.contracts[drizzleContract.contractName] = drizzleContract