OSDN Git Service

update the account selection page.
[bytom/bytom-electron.git] / src / features / shared / routes.js
index d71f9d0..eb7e6b9 100644 (file)
@@ -1,10 +1,41 @@
 import { RoutingContainer } from 'features/shared/components'
 import { humanize } from 'utility/string'
+import { UTXOpageSize, pageSize } from 'utility/environment'
 import actions from 'actions'
 
 const makeRoutes = (store, type, List, New, Show, options = {}) => {
-  const loadPage = () => {
-    store.dispatch(actions[type].fetchAll())
+  const loadPage = ( state ) => {
+    const promise = new Promise((resolve, reject) => {
+      let accountAlias = store.getState().account.currentAccount
+      if(!accountAlias) {
+        store.dispatch(actions.account.setDefaultAccount()).then(resp => {
+          resolve(resp)
+        })
+      }else{
+        resolve(accountAlias)
+      }
+    })
+
+    promise.then((accountAlias)=>{
+      if(type === 'transaction' || type === 'unspent'){
+        const query = state.location.query
+        const unconfirmed = store.getState().transaction.unconfirm
+        const pageNumber = parseInt(state.location.query.page || 1)
+        const pageSizes = (type === 'unspent')? UTXOpageSize: pageSize
+        let options = {pageSize: pageSizes}
+        if (pageNumber == 1) {
+          options = type==='transaction'? {...options,refresh: true,  accountAlias , unconfirmed:true }: options
+          store.dispatch(actions[type].fetchPage(query, pageNumber, options))
+        } else {
+          options = type==='transaction'? {...options, accountAlias , unconfirmed }: options
+          store.dispatch(actions[type].fetchPage(query, pageNumber,  options ))
+        }
+      }else if(type === 'balance'){
+        store.dispatch(actions[type].fetchAll({accountAlias}))
+      }else{
+        store.dispatch(actions[type].fetchAll())
+      }
+    })
   }
 
   const childRoutes = []
@@ -30,8 +61,7 @@ const makeRoutes = (store, type, List, New, Show, options = {}) => {
   return {
     path: options.path || type + 's',
     component: RoutingContainer,
-    name: options.name || humanize(type + 's'),
-    name_zh: options.name_zh,
+    name: options.name || humanize(type),
     indexRoute: {
       component: List,
       onEnter: (nextState, replace) => {