forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
desktop#47 added basic trade view - still needs formatting and some f…
…ield adds
- Loading branch information
Showing
4 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import {compose} from 'recompose' | ||
import Table from 'react-bootstrap/lib/Table' | ||
import {FormattedMessage} from 'react-intl' | ||
|
||
import mapKeys from 'lodash/mapKeys' | ||
import camelCase from 'lodash/camelCase' | ||
|
||
import AccountLink from './shared/AccountLink' | ||
import Asset from './shared/Asset' | ||
import {withDataFetchingContainer} from './shared/DataFetchingContainer' | ||
import {withPaging} from './shared/Paging' | ||
import {withSpinner} from './shared/Spinner' | ||
import TimeSynchronisedFormattedRelative from './shared/TimeSynchronizedFormattedRelative' | ||
|
||
const Trade = ({trade, parentRenderTimestamp}) => { | ||
const Base = ( | ||
<div> | ||
<AccountLink account={trade.baseAccount} /> {trade.baseAmount}{' '} | ||
<Asset | ||
code={trade.baseAssetCode} | ||
issuer={trade.baseAssetIssuer} | ||
type={trade.baseAssetType} | ||
/> | ||
</div> | ||
) | ||
const Counter = ( | ||
<div> | ||
<AccountLink account={trade.counterAccount} /> {trade.counterAmount}{' '} | ||
<Asset | ||
code={trade.counterAssetCode} | ||
issuer={trade.counterAssetIssuer} | ||
type={trade.counterAssetType} | ||
/> | ||
</div> | ||
) | ||
return ( | ||
<tr key={trade.id} className="trade"> | ||
<td>{trade.baseIsSeller ? Base : Counter}</td> | ||
<td>{trade.baseIsSeller ? Counter : Base}</td> | ||
<td> | ||
<span title={trade.time}> | ||
<TimeSynchronisedFormattedRelative | ||
initialNow={parentRenderTimestamp} | ||
value={trade.time} | ||
/> | ||
</span> | ||
</td> | ||
</tr> | ||
) | ||
} | ||
|
||
const TradeTable = ({compact, server, parentRenderTimestamp, records}) => ( | ||
<Table id="trade-table" className="table-striped table-hover table-condensed"> | ||
<thead> | ||
<tr> | ||
<th> | ||
<FormattedMessage id="Sell" /> | ||
</th> | ||
<th> | ||
<FormattedMessage id="Buy" /> | ||
</th> | ||
<th> | ||
<FormattedMessage id="time" /> | ||
</th> | ||
<th /> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{records.map(trade => ( | ||
<Trade | ||
key={trade.id} | ||
compact={compact} | ||
trade={trade} | ||
parentRenderTimestamp={parentRenderTimestamp} | ||
/> | ||
))} | ||
</tbody> | ||
</Table> | ||
) | ||
|
||
TradeTable.propTypes = { | ||
compact: PropTypes.bool, | ||
parentRenderTimestamp: PropTypes.number, | ||
records: PropTypes.array.isRequired, | ||
server: PropTypes.object.isRequired, | ||
} | ||
|
||
const rspRecToPropsRec = record => { | ||
record.time = record.ledger_close_time | ||
return mapKeys(record, (v, k) => camelCase(k)) | ||
} | ||
|
||
const fetchRecords = ({account, limit, server}) => { | ||
const builder = server.trades() | ||
if (account) builder.forAccount(account) | ||
builder.limit(limit) | ||
builder.order('desc') | ||
return builder.call() | ||
} | ||
|
||
const callBuilder = props => props.server.trades() | ||
|
||
const enhance = compose( | ||
withPaging(), | ||
withDataFetchingContainer(fetchRecords, rspRecToPropsRec, callBuilder), | ||
withSpinner() | ||
) | ||
|
||
export default enhance(TradeTable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
import Grid from 'react-bootstrap/lib/Grid' | ||
import Panel from 'react-bootstrap/lib/Panel' | ||
import Row from 'react-bootstrap/lib/Row' | ||
import {injectIntl} from 'react-intl' | ||
import TradeTable from './TradeTable' | ||
|
||
class Trades extends React.Component { | ||
render() { | ||
const {formatMessage} = this.props.intl | ||
return ( | ||
<Grid> | ||
<Row> | ||
<Panel header={formatMessage({id: 'trades'})}> | ||
<TradeTable compact={false} limit={50} usePaging /> | ||
</Panel> | ||
</Row> | ||
</Grid> | ||
) | ||
} | ||
} | ||
|
||
export default injectIntl(Trades) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters