mirror of https://gitlab.com/ecentrics/drizzle
Ezerous
4 years ago
6 changed files with 50 additions and 69 deletions
@ -0,0 +1,22 @@ |
|||
import { WEB3_INITIALIZED } from '../web3/constants' |
|||
import { accountsFetched, accountsListening } from './accountsActions' |
|||
|
|||
export const accountsMiddleware = () => store => next => action => { |
|||
const { type } = action |
|||
|
|||
if (type === WEB3_INITIALIZED) { |
|||
if(!window.ethereum) |
|||
console.warn('No Metamask detected, not subscribed to account changes!') |
|||
else { |
|||
store.dispatch(accountsListening()); |
|||
window.ethereum.on('accountsChanged', function (accounts) { |
|||
console.debug("Account changed") |
|||
store.dispatch(accountsFetched(accounts)); |
|||
}); |
|||
} |
|||
} |
|||
return next(action) |
|||
} |
|||
|
|||
const initializedMiddleware = accountsMiddleware(undefined) |
|||
export default initializedMiddleware |
@ -1,5 +1,4 @@ |
|||
export const ACCOUNTS_FETCHING = 'ACCOUNTS_FETCHING' |
|||
export const ACCOUNTS_FETCHED = 'ACCOUNTS_FETCHED' |
|||
export const ACCOUNTS_FAILED = 'ACCOUNTS_FAILED' |
|||
export const SYNCING_ACCOUNTS = 'SYNCING_ACCOUNTS' |
|||
export const ACCOUNTS_POLLING = 'ACCOUNTS_POLLING' |
|||
export const ACCOUNTS_LISTENING = 'ACCOUNTS_LISTENING' |
|||
|
Loading…
Reference in new issue