mirror of https://gitlab.com/ecentrics/drizzle
Ezerous
4 years ago
6 changed files with 38 additions and 23 deletions
@ -1,17 +1,8 @@ |
|||||
const ACCOUNTS_FETCHING = 'ACCOUNTS_FETCHING' |
import { ACCOUNT_BALANCES_FETCHING } from './constants' |
||||
|
|
||||
export function accountsFetching (results) { |
export function accountBalancesFetching (web3) { |
||||
return { |
return { |
||||
type: ACCOUNTS_FETCHING, |
type: ACCOUNT_BALANCES_FETCHING, |
||||
payload: results |
web3 |
||||
} |
|
||||
} |
|
||||
|
|
||||
const ACCOUNTS_FETCHED = 'ACCOUNTS_FETCHED' |
|
||||
|
|
||||
export function accountsFetched (results) { |
|
||||
return { |
|
||||
type: ACCOUNTS_FETCHED, |
|
||||
payload: results |
|
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,21 @@ |
|||||
|
import {WEB3_INITIALIZED} from '../web3/constants' |
||||
|
import { ACCOUNTS_FETCHED } from '../accounts/constants' |
||||
|
import { accountBalancesFetching } from './accountBalancesActions' |
||||
|
|
||||
|
export const accountBalancesMiddleware = web3 => store => next => action => { |
||||
|
const { type } = action; |
||||
|
|
||||
|
if (type === WEB3_INITIALIZED) |
||||
|
web3 = action.web3; |
||||
|
|
||||
|
if((type === ACCOUNTS_FETCHED) && web3){ |
||||
|
next(action); |
||||
|
store.dispatch(accountBalancesFetching(web3)); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
return next(action); |
||||
|
} |
||||
|
|
||||
|
const initializedMiddleware = accountBalancesMiddleware(undefined) |
||||
|
export default initializedMiddleware |
Loading…
Reference in new issue