refactor removeProvider action, watcher middleware wip
This commit is contained in:
parent
f8426d3174
commit
8e5af74312
|
@ -4,6 +4,6 @@ import { type Provider } from '~/logic/wallets/store/model/provider'
|
||||||
|
|
||||||
export const ADD_PROVIDER = 'ADD_PROVIDER'
|
export const ADD_PROVIDER = 'ADD_PROVIDER'
|
||||||
|
|
||||||
const addProvider = createAction(ADD_PROVIDER, (provider: Provider) => provider)
|
const addProvider = createAction<string, *, *>(ADD_PROVIDER, (provider: Provider) => provider)
|
||||||
|
|
||||||
export default addProvider
|
export default addProvider
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
export * from './addProvider'
|
export * from './addProvider'
|
||||||
export * from './fetchProvider'
|
export * from './fetchProvider'
|
||||||
|
export * from './removeProvider'
|
||||||
export { default as addProvider } from './addProvider'
|
export { default as addProvider } from './addProvider'
|
||||||
export { default as fetchProvider } from './fetchProvider'
|
export { default as fetchProvider } from './fetchProvider'
|
||||||
export { default as removeProvider } from './removeProvider'
|
export { default as removeProvider } from './removeProvider'
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import { createAction } from 'redux-actions'
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||||
import { makeProvider, type ProviderProps, type Provider } from '~/logic/wallets/store/model/provider'
|
|
||||||
import { NOTIFICATIONS, showSnackbar } from '~/logic/notifications'
|
import { NOTIFICATIONS, showSnackbar } from '~/logic/notifications'
|
||||||
import addProvider from './addProvider'
|
|
||||||
|
|
||||||
export default (enqueueSnackbar: Function, closeSnackbar: Function) => async (dispatch: ReduxDispatch<*>) => {
|
export const REMOVE_PROVIDER = 'REMOVE_PROVIDER'
|
||||||
const providerProps: ProviderProps = {
|
|
||||||
name: '',
|
|
||||||
available: false,
|
|
||||||
loaded: false,
|
|
||||||
account: '',
|
|
||||||
network: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider: Provider = makeProvider(providerProps)
|
const removeProvider = createAction<string, *, *>(REMOVE_PROVIDER)
|
||||||
|
|
||||||
|
export default (enqueueSnackbar: Function, closeSnackbar: Function) => (dispatch: ReduxDispatch<*>) => {
|
||||||
showSnackbar(NOTIFICATIONS.WALLET_DISCONNECTED_MSG, enqueueSnackbar, closeSnackbar)
|
showSnackbar(NOTIFICATIONS.WALLET_DISCONNECTED_MSG, enqueueSnackbar, closeSnackbar)
|
||||||
|
|
||||||
dispatch(addProvider(provider))
|
dispatch(removeProvider())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,26 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import type { Store, AnyAction } from 'redux'
|
||||||
|
import { type GlobalState } from '~/store/'
|
||||||
|
import { ADD_PROVIDER, REMOVE_PROVIDER } from '../actions'
|
||||||
|
|
||||||
|
const watchedActions = [
|
||||||
|
ADD_PROVIDER,
|
||||||
|
REMOVE_PROVIDER,
|
||||||
|
]
|
||||||
|
|
||||||
|
const providerWatcherMware = (store: Store<GlobalState>) => (next: Function) => async (action: AnyAction) => {
|
||||||
|
const handledAction = next(action)
|
||||||
|
|
||||||
|
if (watchedActions.includes(action.type)) {
|
||||||
|
const state: GlobalState = store.getState()
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handledAction
|
||||||
|
}
|
||||||
|
|
||||||
|
export default providerWatcherMware
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import { handleActions, type ActionType } from 'redux-actions'
|
import { handleActions, type ActionType } from 'redux-actions'
|
||||||
import { makeProvider, type Provider } from '~/logic/wallets/store/model/provider'
|
import { makeProvider, type Provider } from '~/logic/wallets/store/model/provider'
|
||||||
import addProvider, { ADD_PROVIDER } from '~/logic/wallets/store/actions/addProvider'
|
import addProvider, { ADD_PROVIDER } from '~/logic/wallets/store/actions/addProvider'
|
||||||
|
import { REMOVE_PROVIDER } from '~/logic/wallets/store/actions/removeProvider'
|
||||||
|
|
||||||
export const PROVIDER_REDUCER_ID = 'providers'
|
export const PROVIDER_REDUCER_ID = 'providers'
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ export type State = Provider
|
||||||
export default handleActions<State, Function>(
|
export default handleActions<State, Function>(
|
||||||
{
|
{
|
||||||
[ADD_PROVIDER]: (state: State, { payload }: ActionType<typeof addProvider>) => makeProvider(payload),
|
[ADD_PROVIDER]: (state: State, { payload }: ActionType<typeof addProvider>) => makeProvider(payload),
|
||||||
|
[REMOVE_PROVIDER]: () => makeProvider(),
|
||||||
},
|
},
|
||||||
makeProvider(),
|
makeProvider(),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue