OSDN Git Service

update the account selection on account page.
authorZhiting Lin <zlin035@uottawa.ca>
Thu, 4 Jul 2019 07:30:15 +0000 (15:30 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Thu, 4 Jul 2019 07:30:15 +0000 (15:30 +0800)
src/features/accounts/actions.js
src/features/accounts/components/List.jsx
src/features/accounts/components/ListItem.jsx
src/features/shared/routes.js

index 74eefd3..156e422 100644 (file)
@@ -13,6 +13,12 @@ const update = baseUpdateActions(type, {
   jsonFields: ['tags']
 })
 
+const switchAccount = (accountAlias) => {
+  return (dispatch) => {
+    dispatch({type: 'SET_CURRENT_ACCOUNT', account: accountAlias})
+  }
+}
+
 let actions = {
   ...list,
   ...create,
@@ -25,7 +31,8 @@ let actions = {
   },
   listAddresses: (accountId) => {
     return chainClient().accounts.listAddresses({accountId})
-  }
+  },
+  switchAccount
 }
 
 export default actions
index 5c22cdc..bd3d561 100644 (file)
@@ -1,12 +1,29 @@
 import { BaseList, TableList } from 'features/shared/components'
-
 import ListItem from './ListItem'
 import {withNamespaces} from 'react-i18next'
+import React from 'react'
+import { actions } from 'features/accounts'
 
 const type = 'account'
 
+class List extends React.Component {
+
+  render() {
+    const ItemList = BaseList.ItemList
+    const items = this.props.items
+    items.map(item =>{
+      if(item.alias === this.props.currentAccount){
+        item.isUsed = true
+      }else {
+        item.isUsed= false
+      }
+    })
+    return (<ItemList {...this.props} items = {items}/>)
+  }
+}
 const mapStateToProps = (state, ownProps) => {
   return {
+    currentAccount: state.account.currentAccount,
     ...BaseList.mapStateToProps(type, ListItem, {
       wrapperComponent: TableList,
       wrapperProps: {
@@ -15,7 +32,17 @@ const mapStateToProps = (state, ownProps) => {
     })(state)
   }
 }
+
+const mapDispatchToProps = (dispatch) => ({
+  ...BaseList.mapDispatchToProps(type)(dispatch),
+  itemActions: {
+    switch: (account) => {
+      dispatch(actions.switchAccount(account))
+    }
+  },
+})
 export default withNamespaces('translations') (BaseList.connect(
   mapStateToProps,
-  BaseList.mapDispatchToProps(type)
+  mapDispatchToProps,
+  (List)
 ))
index 39a1ab9..f969829 100644 (file)
@@ -9,13 +9,22 @@ class ListItem extends React.Component {
 
     return(
       <tr>
-        <td>{item.alias || '-'}</td>
-        <td><code>{item.id}</code></td>
         <td>
           <Link to={`/accounts/${item.id}`}>
-            {t('commonWords.viewDetails')} →
+            {item.alias || '-'}
           </Link>
         </td>
+        <td><code>{item.id}</code></td>
+        <td>
+          {item.isUsed?
+            <button className='btn btn-default btn-sx' disabled>
+              inused
+            </button>:
+            <button className='btn btn-primary btn-xs' onClick={() => this.props.switch(item.alias)}>
+              switch
+          </button>
+          }
+        </td>
       </tr>
     )
   }
index 211b5e0..c06d7b0 100644 (file)
@@ -11,10 +11,13 @@ const makeRoutes = (store, type, List, New, Show, options = {}) => {
       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) {
-        store.dispatch(actions[type].fetchPage(query, pageNumber, { refresh: true, pageSize: pageSizes , accountAlias , unconfirmed:true }))
+        options = type==='transaction'? {...options,refresh: true,  accountAlias , unconfirmed:true }: options
+        store.dispatch(actions[type].fetchPage(query, pageNumber, options))
       } else {
-        store.dispatch(actions[type].fetchPage(query, pageNumber,  { pageSize: pageSizes , accountAlias , unconfirmed } ))
+        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}))