Skip to content

Commit 9fcd712

Browse files
oyershovCamille
authored and
Camille
committed
Feature: incremental order book support (#1765)
Peatio introduced the support of incremental order-book from version 2.4 You can enable this feature in frontend with the following configuration in env.js: ```json { incrementalOrderBook: true } ```
1 parent 92121e7 commit 9fcd712

File tree

30 files changed

+554
-52
lines changed

30 files changed

+554
-52
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
*Dockerfile*
22
*docker-compose*
33
node_modules
4-

.drone.yml

+21-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ steps:
2525
- yarn test:ci --collectCoverage=true
2626
- yarn build
2727

28+
- name: "Build enterprise image"
29+
image: plugins/gcr
30+
environment:
31+
BUILD_EXPIRE: "3 month"
32+
NPM_AUTH_TOKEN:
33+
from_secret: drone_npm_auth_token
34+
REACT_APP_BUILD_VERSION: Enterprise
35+
settings:
36+
repo: gcr.io/openware-production/baseapp
37+
build_args_from_env:
38+
- BUILD_EXPIRE
39+
- REACT_APP_BUILD_VERSION
40+
- NPM_AUTH_TOKEN
41+
json_key:
42+
from_secret: openware_gcp_creds_base64
43+
when:
44+
branch:
45+
- rc/**
46+
2847
- name: "Stage with mock server"
2948
image: instrumentisto/rsync-ssh
3049
environment:
@@ -117,12 +136,12 @@ steps:
117136
environment:
118137
NPM_AUTH_TOKEN:
119138
from_secret: drone_npm_auth_token
120-
BUILD_DOMAIN: $(cat .domains)
139+
BUILD_EXPIRE: "3 month"
121140
REACT_APP_BUILD_VERSION: Enterprise
122141
settings:
123142
repo: gcr.io/openware-production/baseapp
124143
build_args_from_env:
125-
- BUILD_DOMAIN
144+
- BUILD_EXPIRE
126145
- REACT_APP_BUILD_VERSION
127146
- NPM_AUTH_TOKEN
128147
json_key:
@@ -133,7 +152,6 @@ steps:
133152
environment:
134153
NPM_AUTH_TOKEN:
135154
from_secret: drone_npm_auth_token
136-
BUILD_EXPIRE: $(date -d "+1 month" +%s000)
137155
REACT_APP_BUILD_VERSION: Lite
138156
REACT_APP_TENKO_PUBLIC_KEY:
139157
from_secret: tenko_public_key
@@ -146,7 +164,6 @@ steps:
146164
build_args_from_env:
147165
- REACT_APP_BUILD_VERSION
148166
- REACT_APP_TENKO_PUBLIC_KEY
149-
- BUILD_EXPIRE
150167
- NPM_AUTH_TOKEN
151168
registry: quay.io
152169

Dockerfile

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ USER node
1515

1616
ENV REACT_APP_TENKO_PUBLIC_KEY=${REACT_APP_TENKO_PUBLIC_KEY}
1717
ENV REACT_APP_BUILD_VERSION=${REACT_APP_BUILD_VERSION}
18-
ENV BUILD_EXPIRE=${BUILD_EXPIRE}
19-
ENV BUILD_DOMAIN=${BUILD_DOMAIN:-""}
20-
ENV REACT_APP_BUILD_EXPIRE=${BUILD_EXPIRE}
2118
ENV NPM_AUTH_TOKEN=${NPM_AUTH_TOKEN}
2219

2320
RUN cd src/containers/ && unlink index.ts && ln -s index${REACT_APP_BUILD_VERSION}.ts index.ts
2421
RUN echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
2522
RUN yarn install
26-
RUN REACT_APP_GIT_SHA=$(git rev-parse --short HEAD) bash -c 'yarn build'
23+
RUN ./scripts/build.sh
2724

2825
FROM nginx:mainline-alpine
2926

public/config/env.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ window.env = {
1616
rangerReconnectPeriod: '1',
1717
msAlertDisplayTime: '5000',
1818
licenseKey: '',
19+
incrementalOrderBook: true,
1920
};

scripts/build.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
export REACT_APP_GIT_SHA=$(git rev-parse --short HEAD)
4+
if [ $REACT_APP_BUILD_VERSION = "Enterprise" ]
5+
then
6+
export BUILD_DOMAIN=${BUILD_DOMAIN:-$(cat .domains)}
7+
[ -n "$BUILD_EXPIRE" ] && export REACT_APP_BUILD_EXPIRE=$(date -d "+${BUILD_EXPIRE}" +%s000)
8+
fi
9+
10+
yarn build

src/api/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const defaultConfig: Config = {
2020
gaTrackerKey: '',
2121
msAlertDisplayTime: '5000',
2222
licenseKey: '',
23+
incrementalOrderBook: false,
2324
};
2425

2526
export const Cryptobase = {
@@ -50,3 +51,4 @@ export const captchaType = () => Cryptobase.config.captcha.captchaType;
5051
export const gaTrackerKey = (): string => Cryptobase.config.gaTrackerKey || '';
5152
export const msAlertDisplayTime = (): string => Cryptobase.config.msAlertDisplayTime || '5000';
5253
export const rangerReconnectPeriod = (): number => Cryptobase.config.rangerReconnectPeriod ? Number(Cryptobase.config.rangerReconnectPeriod) : 1;
54+
export const incrementalOrderBook = (): boolean => Cryptobase.config.incrementalOrderBook || false;

src/api/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export interface Config {
1919
gaTrackerKey?: string;
2020
msAlertDisplayTime?: string;
2121
licenseKey?: string;
22+
incrementalOrderBook: boolean;
2223
}

src/containers/MarketDepth/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Decimal, MarketDepths } from '@openware/components';
22
import * as React from 'react';
33
import { FormattedMessage } from 'react-intl';
4-
import { connect, MapStateToProps } from 'react-redux';
4+
import { connect } from 'react-redux';
55
import {
66
Market,
77
RootState,
@@ -134,7 +134,7 @@ class MarketDepthContainer extends React.Component<Props> {
134134
}
135135
}
136136

137-
const mapStateToProps: MapStateToProps<ReduxProps, {}, RootState> = state => ({
137+
const mapStateToProps = (state: RootState) => ({
138138
asksItems: selectDepthAsks(state),
139139
bidsItems: selectDepthBids(state),
140140
currentMarket: selectCurrentMarket(state),

src/containers/Markets/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
injectIntl,
77
} from 'react-intl';
88
import { connect, MapDispatchToPropsFunction } from 'react-redux';
9+
import { incrementalOrderBook } from '../../api';
910
import { RootState, selectUserInfo, setCurrentPrice, User } from '../../modules';
1011
import {
1112
Market,
@@ -17,7 +18,7 @@ import {
1718
setCurrentMarket,
1819
Ticker,
1920
} from '../../modules/public/markets';
20-
import { depthFetch, orderBookFetch } from '../../modules/public/orderBook';
21+
import { depthFetch } from '../../modules/public/orderBook';
2122
import { walletsFetch } from '../../modules/user/wallets';
2223

2324
interface ReduxProps {
@@ -34,7 +35,6 @@ interface DispatchProps {
3435
setCurrentMarket: typeof setCurrentMarket;
3536
depthFetch: typeof depthFetch;
3637
walletsFetch: typeof walletsFetch;
37-
orderBookFetch: typeof orderBookFetch;
3838
tickers: typeof marketsTickersFetch;
3939
setCurrentPrice: typeof setCurrentPrice;
4040
}
@@ -107,8 +107,9 @@ class MarketsContainer extends React.Component<Props> {
107107

108108
if (!currentMarket || currentMarket.id !== marketToSet.id) {
109109
this.props.setCurrentMarket(marketToSet);
110-
this.props.depthFetch(marketToSet);
111-
this.props.orderBookFetch(marketToSet);
110+
if (!incrementalOrderBook()) {
111+
this.props.depthFetch(marketToSet);
112+
}
112113
}
113114
};
114115
}
@@ -126,7 +127,6 @@ const mapDispatchToProps: MapDispatchToPropsFunction<DispatchProps, {}> =
126127
setCurrentMarket: (market: Market) => dispatch(setCurrentMarket(market)),
127128
walletsFetch: () => dispatch(walletsFetch()),
128129
depthFetch: (market: Market) => dispatch(depthFetch(market)),
129-
orderBookFetch: (market: Market) => dispatch(orderBookFetch(market)),
130130
tickers: () => dispatch(marketsTickersFetch()),
131131
setCurrentPrice: payload => dispatch(setCurrentPrice(payload)),
132132
});

src/containers/Order/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
RootState,
1313
selectCurrentPrice,
1414
selectDepthAsks,
15-
selectDepthBids, selectUserLoggedIn,
15+
selectDepthBids,
16+
selectUserLoggedIn,
1617
selectWallets,
1718
setCurrentPrice,
1819
Wallet, walletsFetch,

src/containers/OrderBook/OrderBook.pcss

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
}
139139

140140
&:first-child {
141+
flex-direction: column-reverse;
141142
top: 0;
142143
right: 0;
143144
left: 0;

src/containers/OrderBook/index.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { CombinedOrderBook, Decimal, Loader } from '@openware/components';
22
import classNames from 'classnames';
33
import * as React from 'react';
44
import { InjectedIntlProps, injectIntl } from 'react-intl';
5-
import {
6-
connect,
7-
MapDispatchToPropsFunction,
8-
MapStateToProps,
9-
} from 'react-redux';
5+
import { connect, MapDispatchToPropsFunction } from 'react-redux';
106
import { accumulateVolume, calcMaxVolume, sortAsks, sortBids } from '../../helpers';
117
import {
128
Market,
@@ -21,11 +17,11 @@ import {
2117
} from '../../modules';
2218

2319
interface ReduxProps {
24-
bids: string[][];
25-
isLoading: boolean;
2620
asks: string[][];
21+
bids: string[][];
2722
currentMarket: Market | undefined;
2823
currentPrice: number | undefined;
24+
orderBookLoading: boolean;
2925
}
3026

3127
interface DispatchProps {
@@ -63,17 +59,21 @@ class OrderBookContainer extends React.Component<Props, State> {
6359
}
6460

6561
public render() {
66-
const { bids, isLoading, asks } = this.props;
62+
const {
63+
asks,
64+
bids,
65+
orderBookLoading,
66+
} = this.props;
6767
const isLarge = this.state.width > breakpoint;
6868
const cn = classNames('pg-combined-order-book ', {
69-
'cr-combined-order-book--loading': isLoading,
69+
'cr-combined-order-book--loading': orderBookLoading,
7070
'pg-combined-order-book--no-data-first': (!asks.length && !isLarge) || (!bids.length && isLarge),
7171
'pg-combined-order-book--no-data-second': (!bids.length && !isLarge) || (!asks.length && isLarge),
7272
});
7373

7474
return (
7575
<div className={cn} ref={this.orderRef}>
76-
{isLoading ? <div><Loader /></div> : this.orderBook(sortBids(bids), sortAsks(asks))}
76+
{orderBookLoading ? <div><Loader /></div> : this.orderBook(sortBids(bids), sortAsks(asks))}
7777
</div>
7878
);
7979
}
@@ -188,10 +188,10 @@ class OrderBookContainer extends React.Component<Props, State> {
188188
};
189189
}
190190

191-
const mapStateToProps: MapStateToProps<ReduxProps, {}, RootState> = state => ({
191+
const mapStateToProps = (state: RootState) => ({
192192
bids: selectDepthBids(state),
193193
asks: selectDepthAsks(state),
194-
isLoading: selectDepthLoading(state),
194+
orderBookLoading: selectDepthLoading(state),
195195
currentMarket: selectCurrentMarket(state),
196196
currentPrice: selectCurrentPrice(state),
197197
marketTickers: selectMarketTickers(state),

src/containers/Sidebar/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class SidebarContainer extends React.Component<Props, State> {
9393
const path = url.includes('/trading') && currentMarket ? `/trading/${currentMarket.id}` : url;
9494
const isActive = (url === '/trading/' && address.includes('/trading')) || address === url;
9595
return (
96-
<Link to={path} onClick={handleLinkChange} className={`${isActive && 'route-selected'}`}>
97-
<div className="pg-sidebar-wrapper-nav-item" key={index}>
96+
<Link to={path} key={index} onClick={handleLinkChange} className={`${isActive && 'route-selected'}`}>
97+
<div className="pg-sidebar-wrapper-nav-item">
9898
<div className="pg-sidebar-wrapper-nav-item-img-wrapper">
9999
<img
100100
className="pg-sidebar-wrapper-nav-item-img"

src/containers/ToolBar/MarketSelector/MarketsList/index.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
intlShape,
88
} from 'react-intl';
99
import { connect } from 'react-redux';
10+
import { incrementalOrderBook } from '../../../../api';
1011
import { SortAsc, SortDefault, SortDesc } from '../../../../assets/images/SortIcons';
1112
import {
1213
depthFetch,
1314
Market,
14-
orderBookFetch,
1515
RootState,
1616
selectCurrentMarket,
1717
selectMarkets,
@@ -32,7 +32,6 @@ interface ReduxProps {
3232
interface DispatchProps {
3333
setCurrentMarket: typeof setCurrentMarket;
3434
depthFetch: typeof depthFetch;
35-
orderBookFetch: typeof orderBookFetch;
3635
setCurrentPrice: typeof setCurrentPrice;
3736
}
3837

@@ -98,8 +97,9 @@ class MarketsListComponent extends React.Component<Props, State> {
9897
this.props.setCurrentPrice();
9998
if (marketToSet) {
10099
this.props.setCurrentMarket(marketToSet);
101-
this.props.depthFetch(marketToSet);
102-
this.props.orderBookFetch(marketToSet);
100+
if (!incrementalOrderBook()) {
101+
this.props.depthFetch(marketToSet);
102+
}
103103
}
104104
};
105105

@@ -210,7 +210,6 @@ const mapStateToProps = (state: RootState): ReduxProps => ({
210210
const mapDispatchToProps = {
211211
setCurrentMarket,
212212
depthFetch,
213-
orderBookFetch,
214213
setCurrentPrice,
215214
};
216215

0 commit comments

Comments
 (0)