1 import { RoutingContainer } from 'features/shared/components'
2 import { humanize } from 'utility/string'
3 import { UTXOpageSize, pageSize } from 'utility/environment'
4 import actions from 'actions'
6 const makeRoutes = (store, type, List, New, Show, options = {}) => {
7 const loadPage = ( state ) => {
8 if(type === 'transaction' || type === 'unspent'){
9 const query = state.location.query
10 const pageNumber = parseInt(state.location.query.page || 1)
11 const pageSizes = (type === 'unspent')? UTXOpageSize: pageSize
12 if (pageNumber == 1) {
13 store.dispatch(actions[type].fetchPage(query, pageNumber, { refresh: true, pageSize: pageSizes }))
15 store.dispatch(actions[type].fetchPage(query, pageNumber, { pageSize: pageSizes }))
18 store.dispatch(actions[type].fetchAll())
22 const childRoutes = []
31 if (options.childRoutes) {
32 childRoutes.push(...options.childRoutes)
43 path: options.path || type + 's',
44 component: RoutingContainer,
45 name: options.name || humanize(type + 's'),
46 name_zh: options.name_zh,
49 onEnter: (nextState, replace) => {
50 loadPage(nextState, replace)
52 onChange: (_, nextState, replace) => { loadPage(nextState, replace) }
54 childRoutes: childRoutes
58 export default makeRoutes