diff --git a/web/.env b/web/.env index e88b1015..ef7dad9b 100644 --- a/web/.env +++ b/web/.env @@ -4,4 +4,9 @@ REACT_APP_NODE_URL=http://localhost:8545 REACT_APP_HYDRO_PROXY_ADDRESS=0x04f67E8b7C39A25e100847Cb167460D715215FEb REACT_APP_HYDRO_TOKEN_ADDRESS=0x4C4Fa7E8EA4cFCfC93DEAE2c0Cff142a1DD3a218 REACT_APP_WETH_TOKEN_ADDRESS=0x4a817489643A89a1428b2DD441c3fbe4DBf44789 -REACT_APP_NETWORK_ID=66 \ No newline at end of file +REACT_APP_NETWORK_ID=66 +REACT_APP_DAI_PRICE_IN_DOLLAR=1.00437 +REACT_APP_HOT_PRICE_IN_DOLLAR=0.00067 +REACT_APP_WETH_PRICE_IN_DOLLAR=168.21835 +REACT_APP_COIN_VASE_API_ADDRESS=https://rest.coinapi.io/v1 +REACT_APP_COIN_BASE_API_KEY=87822C5B-06F8-4231-B362-B4CA756B6CCC \ No newline at end of file diff --git a/web/src/App.js b/web/src/App.js index 508d7a76..de7649bb 100755 --- a/web/src/App.js +++ b/web/src/App.js @@ -1,6 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; -import { loadMarkets, loadTradeHistory } from './actions/markets'; +import { loadMarkets, loadExchange, loadTradeHistory } from './actions/markets'; import Header from './components/Header'; import WebsocketConnector from './components/WebsocketConnector'; import OrderBook from './components/Orderbook'; @@ -38,6 +38,7 @@ class App extends React.PureComponent { componentDidMount() { const { dispatch, currentMarket } = this.props; dispatch(loadMarkets()); + dispatch(loadExchange()); if (parseInt(env.NETWORK_ID) === 66) { this.initTestBrowserWallet(); } diff --git a/web/src/actions/markets.js b/web/src/actions/markets.js index ef534549..a322ec22 100644 --- a/web/src/actions/markets.js +++ b/web/src/actions/markets.js @@ -24,6 +24,24 @@ export const loadMarkets = () => { }; }; +export const loadExchange = () => { + return async (dispatch, getState) => { + try { + const res = await Promise.all([api.coinBaseGet('/exchangerate/DAI/USD'), api.coinBaseGet('/exchangerate/HOT/USD'), api.coinBaseGet('/exchangerate/ETH/USD')]); + if (res) { + const dollarExchange = {DAI: res[0]['data']['rate'], HOT: res[1]['data']['rate'], WETH: res[2]['data']['rate']} + return dispatch({ + type: 'LOAD_DOLLAR_EXCHANGE_RATE', + payload: dollarExchange + }); + } + } catch (error) { + console.log(error); + return; + } + } +} + // load current market trade history export const loadTradeHistory = marketID => { return async (dispatch, getState) => { diff --git a/web/src/components/Orderbook/index.js b/web/src/components/Orderbook/index.js index c06d9c35..bfd3c4d5 100644 --- a/web/src/components/Orderbook/index.js +++ b/web/src/components/Orderbook/index.js @@ -37,28 +37,52 @@ class OrderBook extends React.Component { this.lastUpdatedAt = new Date(); } + maxAmount(asks) { + let max = 0; + asks.forEach(element => { + const amount = element[1].toFixed(this.props.currentMarket.amountDecimals); + if (max < amount) { + max = amount; + } + }); + return max; + } + + calculateBarWidth(maxAmount, Amount) { + const width = ~~((Amount / maxAmount) * 20); //20 is the max percentage + return width + '%'; + } + render() { - let { bids, asks, websocketConnected, currentMarket } = this.props; + const { bids, asks, websocketConnected, currentMarket, dollarExchangeRate } = this.props; + const asksArray = asks.slice(-20).reverse().toArray(); + const bidsArray = bids.slice(-20).reverse().toArray(); + const asksMaxAmount = this.maxAmount(asksArray); + const bidsMaxAmount = this.maxAmount(bidsArray); return ( -
{amount.toFixed(currentMarket.amountDecimals)}
+ +{amount.toFixed(currentMarket.amountDecimals)}