Skip to content

Commit

Permalink
Merge pull request #8 from ProofSuite/trade_history
Browse files Browse the repository at this point in the history
<TradeHistory /> completed
  • Loading branch information
Dvisacker authored Jul 14, 2018
2 parents 3e4e27d + a35b4d0 commit d9119cb
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 11 deletions.
19 changes: 19 additions & 0 deletions src/components/TradeHistory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```js
import TradeHistoryRenderer from '../../components/TradeHistoryRenderer';
```

#### Properties
* `tradeHistory` - List of Trades
* `loggedIn` - LoggedIn state
* `loading` - Loading state of trade list
* `decimals` - Number of figures to show after decimal point

#### Example
```js
<OrderBookRenderer
tradeHistory={tradeHistory}
loggedIn={true}
loading={false}
decimals={7}
/>
```
53 changes: 53 additions & 0 deletions src/components/TradeHistory/TradeHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { reduceDecimals, toDate } from '../../utils/converters';
import Loading from '../Loading';
import { Colors } from '@blueprintjs/core';
import styled from 'styled-components';
import type { ListRow, TradeListContainerTypes, TradeListTypes } from '../../types/tradeHistory';

const TradeHistory = (props: TradeListContainerTypes) => {
const { decimals, loading, tradeHistory } = props;
return loading ? <Loading /> : <HistroyList tradeHistory={tradeHistory} decimals={decimals} />;
};
export default TradeHistory;

const HistroyList = (props: TradeListTypes) => {
const { decimals, tradeHistory } = props;
return (
<div className="list-container pt-dark">
<ul className="pt-list-unstyled heading">
<li className="heading">
<span className="index">#</span>
<span className="time">Time</span>
<span className="type">Type</span>
<span className="amount">Amount</span>
<span className="price">Price</span>
</li>
</ul>
<ul className="pt-list-unstyled list">
{tradeHistory.map((trade, index) => <Row key={index} props={{ trade, decimals: decimals, index }} />)}
</ul>
</div>
);
};

const Row = ({ props }: ListRow) => {
const { trade, decimals, index } = props;
return (
<li className="not-heading">
<span className="index">{index + 1}</span>
<span className="time">{toDate(trade.time)}</span>
{trade.type === 'sell' ? <Sell>{trade.type}</Sell> : <Buy>{trade.type}</Buy>}
<span className="amount">{reduceDecimals(trade.amount, decimals)}</span>
<span className="price">{reduceDecimals(trade.price, decimals)}</span>
</li>
);
};

const Sell = styled.span`
color: ${Colors.RED4};
`;

const Buy = styled.span`
color: ${Colors.GREEN5};
`;
68 changes: 68 additions & 0 deletions src/components/TradeHistory/TradeHistoryRenderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//@flow
import React from 'react';
import TradeHistory from './TradeHistory';
import { Card, Tab, Tabs, Button } from '@blueprintjs/core';
import { sortArray } from '../../utils/helpers';

type Props = {
tradeHistory: Array<Object>,
loading: boolean,
decimals?: number,
loggedIn: boolean,
};
type State = {
selectedTabId: string,
};

class TradeHistoryRenderer extends React.PureComponent<Props, State> {
static defaultProps = {
decimals: 7,
};
state = {
selectedTabId: 'all',
};
changeTab = (tabId: string) => {
this.setState({
selectedTabId: tabId,
});
};

render() {
const {
props: { loading, tradeHistory, decimals, loggedIn },
state: { selectedTabId },
changeTab,
} = this;
return (
<Card className="pt-dark trade-history">
<h5>Trade History</h5>
<Tabs id="TabsExample" selectedTabId={selectedTabId} onChange={changeTab}>
<Tab
id="all"
title="Market"
panel={<TradeHistory loading={loading} tradeHistory={tradeHistory} decimals={decimals} />}
/>
<Tab
id="mine"
title="Mine"
panel={
loggedIn ? (
<TradeHistory
loading={loading}
tradeHistory={sortArray(tradeHistory, 'time', 'desc')}
decimals={decimals}
/>
) : (
<Login />
)
}
/>
</Tabs>
</Card>
);
}
}

export default TradeHistoryRenderer;

const Login = () => <Button large={true} intent="primary" text="Login" />;
3 changes: 3 additions & 0 deletions src/components/TradeHistory/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import TradeHistoryRenderer from './TradeHistoryRenderer';

export default TradeHistoryRenderer;
28 changes: 28 additions & 0 deletions src/components/TradeHistory/stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { text, withKnobs } from '@storybook/addon-knobs/react';
import { withInfo } from '@storybook/addon-info';
import TradeHistoryRenderer from './index';
import README from './README.md';
import * as tradeHistory from '../../jsons/tradeHistory.json';

storiesOf('TradeHistory', module)
.addDecorator(withKnobs)
.add(
'Loading state',
withInfo({ text: README, source: false })(() => (
<TradeHistoryRenderer tradeHistory={tradeHistory.list} loggedIn={true} loading={true} decimals={7} />
))
)
.add(
'Not LoggedIn',
withInfo({ text: README, source: false })(() => (
<TradeHistoryRenderer tradeHistory={tradeHistory.list} loggedIn={false} loading={false} decimals={7} />
))
)
.add(
'LoggedIn',
withInfo({ text: README, source: false })(() => (
<TradeHistoryRenderer tradeHistory={tradeHistory.list} loading={false} loggedIn={true} decimals={7} />
))
);
106 changes: 102 additions & 4 deletions src/styles/css/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/styles/css/index.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/styles/scss/index.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@import "../../../node_modules/@blueprintjs/core/lib/css/blueprint.css";
@import "../../../node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css";
@import "../../../node_modules/@blueprintjs/table/lib/css/table.css";
@import "vars";
@import "global";
@import "orderForm";
@import "orderBook";

@import "../../../node_modules/@blueprintjs/core/lib/css/blueprint.css";
@import "../../../node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css";
@import "../../../node_modules/@blueprintjs/table/lib/css/table.css";
@import "tradeHistory";
3 changes: 2 additions & 1 deletion src/styles/scss/orderBook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
.list {
height: 90%;
overflow-y: scroll;
margin-top: 3px;
}
}
ul {
Expand Down Expand Up @@ -87,7 +88,7 @@
}
}
ul.heading {
box-shadow: 0px 1px 2px 1px #2f3c46;
box-shadow: 0px 4px 2px -1px $shadow;
}
.loading-overlay {
height: 91%;
Expand Down
Loading

0 comments on commit d9119cb

Please sign in to comment.