mirror of https://gitlab.com/ecentrics/drizzle
Ezerous
4 years ago
8 changed files with 29 additions and 35 deletions
@ -1,7 +1,7 @@ |
|||||
# @ezerous/drizzle |
# @ezerous/drizzle |
||||
|
|
||||
[![Version](https://img.shields.io/npm/v/@ezerous/drizzle.svg)](https://www.npmjs.com/package/@ezerous/drizzle) |
[![Version](https://img.shields.io/npm/v/@ezerous/drizzle.svg)](https://www.npmjs.com/package/@ezerous/drizzle) |
||||
[![Dependencies](https://img.shields.io/david/Ezerous/@ezerous/drizzle.svg)](https://david-dm.org/Ezerous/drizzle) |
[![Dependencies](https://img.shields.io/david/Ezerous/drizzle.svg)](https://david-dm.org/Ezerous/drizzle) |
||||
[![License](https://img.shields.io/npm/l/@ezerous/drizzle.svg)](https://www.npmjs.com/package/@ezerous/drizzle) |
[![License](https://img.shields.io/npm/l/@ezerous/drizzle.svg)](https://www.npmjs.com/package/@ezerous/drizzle) |
||||
|
|
||||
A reactive data-store for web3 and smart contracts. A modified version of [@drizzle/store](https://github.com/trufflesuite/drizzle/tree/develop/packages/store). |
A reactive data-store for web3 and smart contracts. A modified version of [@drizzle/store](https://github.com/trufflesuite/drizzle/tree/develop/packages/store). |
||||
|
@ -1,23 +1,24 @@ |
|||||
import { networkIdChanged, WEB3_INITIALIZED } from './web3Actions' |
import { networkIdChanged, WEB3_INITIALIZED } from './web3Actions' |
||||
|
|
||||
export const web3Middleware = web3 => store => next => action => { |
export const web3Middleware = () => store => next => action => { |
||||
const { type } = action |
const { type } = action |
||||
|
|
||||
if (type === WEB3_INITIALIZED) { |
if (type === WEB3_INITIALIZED) { |
||||
if(!window.ethereum) |
if(!window.ethereum) |
||||
console.warn('No Metamask detected, not subscribed to network changes!') |
console.warn('No Metamask detected, not subscribed to network changes!') |
||||
else { |
else { |
||||
web3 = action.web3; |
|
||||
window.ethereum.on('networkChanged', (networkId) => { |
window.ethereum.on('networkChanged', (networkId) => { |
||||
// Warning: 'networkChanged' is deprecated (EIP-1193)
|
// Warning: 'networkChanged' is deprecated (EIP-1193)
|
||||
const storedNetworkId = store.getState().web3.networkId; |
const storedNetworkId = store.getState().web3.networkId; |
||||
if(storedNetworkId && networkId !== storedNetworkId) |
if(storedNetworkId && (networkId !== storedNetworkId)){ |
||||
store.dispatch(networkIdChanged(web3, networkId)); |
store.dispatch(networkIdChanged(networkId)); // Just to be typical
|
||||
|
window.location.reload(); |
||||
|
} |
||||
}); |
}); |
||||
} |
} |
||||
} |
} |
||||
return next(action) |
return next(action) |
||||
} |
} |
||||
|
|
||||
const initializedMiddleware = web3Middleware(undefined) |
const initializedMiddleware = web3Middleware() |
||||
export default initializedMiddleware |
export default initializedMiddleware |
||||
|
Loading…
Reference in new issue