Skip to content

Commit

Permalink
Merge pull request #223 from AntonNazarenko/fix/orderhistory
Browse files Browse the repository at this point in the history
add dynamic order history table
  • Loading branch information
prdn authored Oct 29, 2020
2 parents 2e25563 + 56a66de commit 9501c1e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 44 deletions.
11 changes: 8 additions & 3 deletions src/components/OrderHistoryTable/OrderHistoryTable.columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ export default [{
dataKey: 'amount',
width: 120,
cellRenderer: ({ rowData = {} }) => (rowData.amount < 0 // eslint-disable-line
? <span className='hfui-red'>{rowData.amount}</span>
: <span className='hfui-green'>{rowData.amount}</span>
? <span className='hfui-red'>{rowData.originalAmount}</span>
: <span className='hfui-green'>{rowData.originalAmount}</span>
),
}, {
label: 'Type',
dataKey: 'type',
width: 100,
width: 150,
cellRenderer: ({ rowData = {} }) => rowData.type,
}, {
label: 'Status',
dataKey: 'status',
width: 100,
cellRenderer: ({ rowData = {} }) => rowData.status,
}]
11 changes: 11 additions & 0 deletions src/components/OrderHistoryTable/OrderHistoryTable.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { connect } from 'react-redux'

import OrderHistoryTable from './OrderHistoryTable'

const mapStateToProps = (state = {}) => ({
orderHistory: state.ws.orderHistory.orders,
}) //eslint-disable-line

const mapDispatchToProps = dispatch => ({}) //eslint-disable-line

export default connect(mapStateToProps, mapDispatchToProps)(OrderHistoryTable)
43 changes: 43 additions & 0 deletions src/components/OrderHistoryTable/OrderHistoryTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'

import Table from '../../ui/Table'
import Panel from '../../ui/Panel'
import OrderHistoryTableColumns from './OrderHistoryTable.columns'
import { propTypes, defaultProps } from './OrderHistoryTable.props'

export default class OrderHistoryTable extends React.PureComponent {
static propTypes = propTypes
static defaultProps = defaultProps

constructor(props) {
super(props)
this.onRowClick = this.onRowClick.bind(this)
}

onRowClick({ index } = {}) {
const { onSelect, orders } = this.props
onSelect(orders[index])
}

render() {
const {
onRemove, dark, orderHistory,
} = this.props
return (
<Panel
label='ORDER HISTORY'
onRemove={onRemove}
dark={dark}
darkHeader={dark}
>
<Table
data={orderHistory}
columns={OrderHistoryTableColumns}
onRowClick={this.onRowClick}
defaultSortBy='mts'
defaultSortDirection='ASC'
/>
</Panel>
)
}
}
43 changes: 2 additions & 41 deletions src/components/OrderHistoryTable/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
import React from 'react'
import OrderHistoryTable from './OrderHistoryTable.container'

import Table from '../../ui/Table'
import Panel from '../../ui/Panel'
import OrderHistoryTableColumns from './OrderHistoryTable.columns'
import { propTypes, defaultProps } from './OrderHistoryTable.props'

export default class OrderHistoryTable extends React.PureComponent {
static propTypes = propTypes
static defaultProps = defaultProps

constructor(props) {
super(props)
this.onRowClick = this.onRowClick.bind(this)
}

onRowClick({ index } = {}) {
const { onSelect, orders } = this.props
onSelect(orders[index])
}

render() {
const { orders, onRemove, dark } = this.props

return (
<Panel
label='ORDER HISTORY'
onRemove={onRemove}
dark={dark}
darkHeader={dark}
>
<Table
data={orders}
columns={OrderHistoryTableColumns}
onRowClick={this.onRowClick}
defaultSortBy='mts'
defaultSortDirection='ASC'
/>
</Panel>
)
}
}
export default OrderHistoryTable
2 changes: 2 additions & 0 deletions src/redux/reducers/ws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import apiClients from './api_clients'
import positions from './positions'
import balances from './balances'
import orders from './orders'
import orderHistory from './order_history'
import algoOrders from './algo_orders'
import backtest from './backtest'

Expand All @@ -21,6 +22,7 @@ export default combineReducers({
positions,
balances,
orders,
orderHistory,
apiClients,
strategies,
tickers,
Expand Down
29 changes: 29 additions & 0 deletions src/redux/reducers/ws/order_history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import types from '../../constants/ws'
import { orderAdapter } from '../../adapters/ws'

const getInitialState = () => {
return {}
}

export default (state = getInitialState(), action = {}) => {
const { type, payload = [] } = action

switch (type) {
case types.DATA_ORDER_CLOSE: {
const { order = [] } = payload
const { orders = [] } = state
const o = orderAdapter(order)
return {
...state,
orders: [
o,
...orders,
],
}
}

default: {
return state
}
}
}

0 comments on commit 9501c1e

Please sign in to comment.