augur-ui-react-components
Advanced tools
Comparing version 3.0.6 to 3.0.7
{ | ||
"name": "augur-ui-react-components", | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"description": "Augur UI React Components", | ||
@@ -51,3 +51,3 @@ "author": "Baz (@thinkloop)", | ||
"babel-preset-es2015": "6.9.0", | ||
"babel-preset-react": "6.5.0", | ||
"babel-preset-react": "6.11.1", | ||
"babel-preset-stage-0": "6.5.0", | ||
@@ -62,6 +62,6 @@ "babel-register": "6.9.0", | ||
"envify": "3.4.1", | ||
"eslint": "2.13.1", | ||
"eslint": "3.0.1", | ||
"eslint-config-airbnb": "9.0.1", | ||
"eslint-plugin-import": "1.9.2", | ||
"eslint-plugin-jsx-a11y": "1.5.3", | ||
"eslint-plugin-import": "1.10.2", | ||
"eslint-plugin-jsx-a11y": "1.5.5", | ||
"eslint-plugin-react": "5.2.2", | ||
@@ -74,10 +74,10 @@ "exorcist": "0.4.0", | ||
"mocha": "2.5.3", | ||
"npm-check-updates": "2.6.7", | ||
"npm-check-updates": "^2.7.0", | ||
"onchange": "2.5.0", | ||
"react": "15.1.0", | ||
"react": "15.2.0", | ||
"react-datetime": "2.3.2", | ||
"react-dom": "15.1.0", | ||
"react-highcharts": "8.3.3", | ||
"rimraf": "2.5.2", | ||
"uglify-js": "2.6.4", | ||
"react-dom": "15.2.0", | ||
"react-highcharts": "8.4.1", | ||
"rimraf": "2.5.3", | ||
"uglify-js": "2.7.0", | ||
"watchify": "3.7.0" | ||
@@ -84,0 +84,0 @@ }, |
@@ -21,3 +21,3 @@ import React from 'react'; | ||
loginAccount: p.loginAccount, | ||
positionsSummary: p.marketsTotals.positionsSummary, | ||
positionsSummary: p.positionsSummary, | ||
transactionsTotals: p.transactionsTotals, | ||
@@ -56,4 +56,4 @@ isTransactionsWorking: p.isTransactionsWorking, | ||
siteHeader={p.siteHeader} | ||
positionsSummary={p.marketsTotals.positionsSummary} | ||
markets={p.markets} | ||
positionsSummary={p.positionsSummary} | ||
positionsMarkets={p.positionsMarkets} | ||
/> | ||
@@ -60,0 +60,0 @@ ); |
@@ -8,15 +8,19 @@ import React, { PropTypes } from 'react'; | ||
<div className="bids"> | ||
<h5>Bids</h5> | ||
{p.bids.map((bid, i) => ( | ||
<article key={bid.price.full} className="bid-ask bid"> | ||
<Clickable | ||
onClick={() => { p.updateTradeOrder(p.outcome.id, bid.shares.value, bid.price.value, 'ask'); }} | ||
> | ||
<ValueDenomination className="shares" {...bid.shares} /> | ||
</Clickable> | ||
<Clickable onClick={() => { p.updateTradeOrder(p.outcome.id, 0, bid.price.value); }}> | ||
<ValueDenomination className="price" {...bid.price} /> | ||
</Clickable> | ||
</article> | ||
))} | ||
{p.bids.map((bid, i) => { | ||
if (i !== 0) { | ||
return ( | ||
<article key={bid.price.full} className="bid-ask bid"> | ||
<Clickable | ||
onClick={() => { p.updateTradeOrder(p.outcome.id, bid.shares.value, bid.price.value, 'ask'); }} | ||
> | ||
<ValueDenomination className="shares" {...bid.shares} /> | ||
</Clickable> | ||
<Clickable onClick={() => { p.updateTradeOrder(p.outcome.id, 0, bid.price.value); }}> | ||
<ValueDenomination className="price" {...bid.price} /> | ||
</Clickable> | ||
</article> | ||
); | ||
} | ||
return null; | ||
})} | ||
{!p.bids.length && | ||
@@ -30,15 +34,19 @@ <article className="bid-ask ask"> | ||
<div className="asks"> | ||
<h5>Asks</h5> | ||
{p.asks.map((ask, i) => ( | ||
<article key={ask.price.full} className="bid-ask ask"> | ||
<Clickable onClick={() => { p.updateTradeOrder(p.outcome.id, 0, ask.price.value); }}> | ||
<ValueDenomination className="price" {...ask.price} /> | ||
</Clickable> | ||
<Clickable | ||
onClick={() => { p.updateTradeOrder(p.outcome.id, ask.shares.value, ask.price.value, 'bid'); }} | ||
> | ||
<ValueDenomination className="shares" {...ask.shares} /> | ||
</Clickable> | ||
</article> | ||
))} | ||
{p.asks.map((ask, i) => { | ||
if (i !== 0) { | ||
return ( | ||
<article key={ask.price.full} className="bid-ask ask"> | ||
<Clickable onClick={() => { p.updateTradeOrder(p.outcome.id, 0, ask.price.value); }}> | ||
<ValueDenomination className="price" {...ask.price} /> | ||
</Clickable> | ||
<Clickable | ||
onClick={() => { p.updateTradeOrder(p.outcome.id, ask.shares.value, ask.price.value, 'bid'); }} | ||
> | ||
<ValueDenomination className="shares" {...ask.shares} /> | ||
</Clickable> | ||
</article> | ||
); | ||
} | ||
return null; | ||
})} | ||
{!p.asks.length && | ||
@@ -45,0 +53,0 @@ <article className="bid-ask ask"> |
@@ -21,5 +21,5 @@ /* | ||
onClick = () => { | ||
onClick = event => { | ||
if (typeof this.props.onClick === 'function') { | ||
this.props.onClick(); | ||
this.props.onClick(event); | ||
} | ||
@@ -26,0 +26,0 @@ } |
@@ -12,7 +12,5 @@ import React, { PropTypes } from 'react'; | ||
<div className="fee"> | ||
<h4>Set the trading fee for your market</h4> | ||
<h4>Set the taker's fee</h4> | ||
<p> | ||
The Trading Fee is a percentage fee charged against the value of any trade made in the market. | ||
You'll receive 50% of all fees charged during the lifetime of your market - with the other | ||
50% being awarded to those reporting the outcome. | ||
The taker fee is a percentage fee charged to the 'Taker' against the value of any trade made in the market. | ||
</p> | ||
@@ -31,5 +29,5 @@ <Input | ||
<div className="fee"> | ||
<h4>Set the maker's share of the trading fee</h4> | ||
<h4>Set the maker's fee</h4> | ||
<p> | ||
The Maker Fee is the percentage split the 'Maker' of an order must pay of the trading fee with the remaining percentage being paid by the 'Taker'. | ||
The maker fee is a percentage fee charged to the 'Maker' against the value of any trade made in the market. | ||
</p> | ||
@@ -50,3 +48,3 @@ <Input | ||
<p> | ||
Initial liquidity is the amount of ether you're putting into the market to get trading started. | ||
Initial liquidity is the amount of ether you're putting into the market to get trading started. | ||
The Market Maker will use these funds to buy shares - which are then sold back to those | ||
@@ -53,0 +51,0 @@ wanting to trade your market when the market opens. Any initial liquidity remaining when |
@@ -6,3 +6,3 @@ import React, { Component, PropTypes } from 'react'; | ||
import Basics from '../../market/components/basics'; | ||
import TradePanel from '../../trade/components/trade-panel'; | ||
import TradePanel from '../../../modules/trade/components/trade-panel'; | ||
import ReportPanel from '../../reports/components/report-panel'; | ||
@@ -55,7 +55,10 @@ import MarketPositions from '../../market/components/market-positions'; | ||
key="trade-panel" | ||
outcomes={p.market.outcomes} | ||
sideOptions={p.sideOptions} | ||
updateSelectedOutcome={p.updateSelectedOutcome} | ||
selectedOutcomeID={p.selectedOutcomeID} | ||
{...p.market} | ||
{...p.market.tradeSummary} | ||
tradeOrders={p.market.tradeSummary.tradeOrders} | ||
tradeSummary={p.market.tradeSummary} | ||
onSubmitPlaceTrade={p.market.onSubmitPlaceTrade} | ||
constants={p.market.constants} | ||
/> | ||
@@ -62,0 +65,0 @@ ); |
@@ -19,5 +19,5 @@ import React from 'react'; | ||
<div className="position-group"> | ||
<div className="position-pair per-share-gain"> | ||
<span className="title">per share gain/loss</span> | ||
<ValueDenomination {...p.shareChange} /> | ||
<div className="position-pair purchase-price"> | ||
<span className="title">avg. purchase price</span> | ||
<ValueDenomination {...p.purchasePrice} /> | ||
</div> | ||
@@ -28,11 +28,11 @@ <div className="position-pair last-price"> | ||
</div> | ||
<div className="position-pair purchase-price"> | ||
<span className="title">avg. purchase price</span> | ||
<ValueDenomination {...p.purchasePrice} /> | ||
<div className="position-pair per-share-gain"> | ||
<span className="title">per share gain/loss</span> | ||
<ValueDenomination {...p.shareChange} /> | ||
</div> | ||
</div> | ||
<div className="position-group"> | ||
<div className="position-pair net-change"> | ||
<span className="title">net gain/loss</span> | ||
<ValueDenomination {...p.netChange} /> | ||
<div className="position-pair total-cost"> | ||
<span className="title">total cost</span> | ||
<ValueDenomination {...p.totalCost} /> | ||
</div> | ||
@@ -43,5 +43,5 @@ <div className="position-pair total-value"> | ||
</div> | ||
<div className="position-pair total-cost"> | ||
<span className="title">total cost</span> | ||
<ValueDenomination {...p.totalCost} /> | ||
<div className="position-pair net-change"> | ||
<span className="title">net gain/loss</span> | ||
<ValueDenomination {...p.netChange} /> | ||
</div> | ||
@@ -48,0 +48,0 @@ </div> |
@@ -19,9 +19,9 @@ import React from 'react'; | ||
<div className="l-container"> | ||
{!!p.markets && !!p.markets.length && p.markets.map(market => ( | ||
<div key={market.id} className="positions-container"> | ||
<span className="description">{market.description}</span> | ||
{!!market.positionOutcomes && !!market.positionOutcomes.length && | ||
{!!p.positionsMarkets && !!p.positionsMarkets.length && p.positionsMarkets.map(positionsMarket => ( | ||
<div key={positionsMarket.id} className="positions-container"> | ||
<span className="description">{positionsMarket.description}</span> | ||
{!!positionsMarket.outcomes && !!positionsMarket.outcomes.length && | ||
<Positions | ||
className="page-content positions-content" | ||
outcomes={market.positionOutcomes} | ||
outcomes={positionsMarket.outcomes} | ||
/> | ||
@@ -42,5 +42,5 @@ } | ||
positionsSummary: React.PropTypes.object, | ||
markets: React.PropTypes.array | ||
positionsMarkets: React.PropTypes.array | ||
}; | ||
export default PositionsPage; |
import React from 'react'; | ||
import TradePanelItem from './trade-panel-item'; | ||
import Transaction from '../../transactions/components/transaction'; | ||
import TradePanelHeader from '../../../modules/trade/components/trade-panel-header'; | ||
import TradePanelFooter from '../../../modules/trade/components/trade-panel-footer'; | ||
import TradePanelBody from '../../../modules/trade/components/trade-panel-body'; | ||
const TradePanel = (p) => ( | ||
<section className="trade-panel"> | ||
<div className="trade-builder"> | ||
<div className="trade-panel-item-header"> | ||
<span className="outcome-name"> </span> | ||
<span className="last-price">Last</span> | ||
<span className="top-bid">Top Bid</span> | ||
<span className="top-ask">Top Ask</span> | ||
<span className="num-shares">Side</span> | ||
<span className="num-shares">Shares</span> | ||
<span className="limit-price">Limit</span> | ||
<span className="fee-to-pay">Fee</span> | ||
<span className="total-cost">Profit/Loss</span> | ||
</div> | ||
{p.outcomes && p.outcomes.map(outcome => ( | ||
<TradePanelItem | ||
key={outcome.id} | ||
sideOptions={p.sideOptions} | ||
updateSelectedOutcome={p.updateSelectedOutcome} | ||
selectedOutcomeID={p.selectedOutcomeID} | ||
{...outcome} | ||
{...outcome.trade} | ||
<div | ||
className="trade-panel" | ||
onClick={() => p.updateSelectedOutcome(null)} | ||
> | ||
<table className="trade-builder"> | ||
<TradePanelHeader selectedOutcomeID={p.selectedOutcomeID} /> | ||
{p.tradeOrders && !!p.tradeOrders.length && | ||
<TradePanelFooter | ||
summary={p.tradeSummary} | ||
constants={p.constants} | ||
/> | ||
))} | ||
</div> | ||
{p.tradeOrders && !!p.tradeOrders.length && | ||
<div className="trade-orders"> | ||
<h5>Trade Summary</h5> | ||
{p.tradeOrders && p.tradeOrders.map((tradeOrder, i) => ( | ||
<Transaction | ||
key={i} | ||
className="order" | ||
{...tradeOrder} | ||
status={undefined} | ||
/> | ||
))} | ||
<Transaction | ||
type="trade_summary" | ||
shares={p.totalShares} | ||
className="order total" | ||
ether={p.totalEther} | ||
gas={p.totalGas} | ||
status={undefined} | ||
/> | ||
</div> | ||
} | ||
} | ||
<TradePanelBody | ||
outcomes={p.outcomes} | ||
sideOptions={p.sideOptions} | ||
selectedOutcomeID={p.selectedOutcomeID} | ||
updateSelectedOutcome={p.updateSelectedOutcome} | ||
constants={p.constants} | ||
/> | ||
</table> | ||
<div className="place-trade-container"> | ||
<button | ||
className="button place-trade" disabled={!p.tradeOrders || !p.tradeOrders.length} | ||
onClick={p.onSubmitPlaceTrade} | ||
className="button place-trade" | ||
disabled={!p.tradeOrders || !!!p.tradeOrders.length} | ||
onClick={event => { | ||
event.stopPropagation(); | ||
p.onSubmitPlaceTrade(); | ||
}} | ||
> | ||
Place Trade | ||
Place Trade{p.tradeOrders && p.tradeOrders.length > 1 ? 's' : ''} | ||
</button> | ||
</div> | ||
</section> | ||
</div> | ||
); | ||
@@ -66,6 +45,11 @@ | ||
outcomes: React.PropTypes.array, | ||
sideOptions: React.PropTypes.array, | ||
updateSelectedOutcome: React.PropTypes.func, | ||
selectedOutcomeID: React.PropTypes.string, | ||
tradeOrders: React.PropTypes.array, | ||
onSubmitPlaceTrade: React.PropTypes.func | ||
tradeSummary: React.PropTypes.object, | ||
onSubmitPlaceTrade: React.PropTypes.func, | ||
constants: React.PropTypes.object | ||
}; | ||
export default TradePanel; |
@@ -7,4 +7,4 @@ import React from 'react'; | ||
SELL_SHARES, | ||
BID_SHARES, | ||
ASK_SHARES, | ||
BID, | ||
ASK, | ||
SUBMIT_REPORT, | ||
@@ -22,5 +22,5 @@ GENERATE_ORDER_BOOK, | ||
case BUY_SHARES: | ||
case BID_SHARES: | ||
case BID: | ||
case SELL_SHARES: | ||
case ASK_SHARES: | ||
case ASK: | ||
switch (p.type) { | ||
@@ -30,3 +30,3 @@ case BUY_SHARES: | ||
break; | ||
case BID_SHARES: | ||
case BID: | ||
nodes.action = 'BID'; | ||
@@ -37,3 +37,3 @@ break; | ||
break; | ||
case ASK_SHARES: | ||
case ASK: | ||
nodes.action = 'ASK'; | ||
@@ -40,0 +40,0 @@ break; |
export const BUY_SHARES = 'buy_shares'; | ||
export const SELL_SHARES = 'sell_shares'; | ||
export const TRADE_SUMMARY = 'trade_summary'; | ||
export const BID_SHARES = 'bid_shares'; | ||
export const ASK_SHARES = 'ask_shares'; | ||
export const BID = 'bid'; | ||
export const ASK = 'ask'; | ||
export const CREATE_MARKET = 'create_market'; | ||
@@ -7,0 +7,0 @@ export const SUBMIT_REPORT = 'submit_report'; |
@@ -6,5 +6,12 @@ import loginAccount from './selectors/login-account'; | ||
import createMarketForm from './selectors/create-market-form'; | ||
import marketsTotals from './selectors/markets-totals'; | ||
import positionsSummary from './selectors/positions-summary'; | ||
import positionsMarkets from './selectors/positions-markets'; | ||
import { MARKETS, MAKE, POSITIONS, TRANSACTIONS, M } from './modules/site/constants/pages'; | ||
import { LOGIN } from './modules/auth/constants/auth-types'; | ||
import { | ||
BID, | ||
ASK | ||
} from './modules/transactions/constants/types'; | ||
@@ -23,3 +30,6 @@ const selectors = { | ||
filters, | ||
createMarketForm | ||
createMarketForm, | ||
marketsTotals, | ||
positionsSummary, | ||
positionsMarkets | ||
}; | ||
@@ -56,3 +66,3 @@ | ||
selectors.market = {}; // selected market | ||
selectors.sideOptions = [{ value: 'bid', label: 'Buy' }, { value: 'ask', label: 'Sell' }]; | ||
selectors.sideOptions = [{ value: BID, label: 'Buy' }, { value: ASK, label: 'Sell' }]; | ||
selectors.selectedOutcome = { | ||
@@ -63,3 +73,3 @@ updateSelectedOutcome: (selectedOutcomeID) => { | ||
...selectors.selectedOutcome, | ||
selectedOutcomeID: selectors.selectedOutcome.selectedOutcomeID !== selectedOutcomeID ? selectedOutcomeID : null | ||
selectedOutcomeID | ||
} | ||
@@ -70,84 +80,3 @@ }); | ||
}; | ||
selectors.marketsTotals = { | ||
positionsSummary: { numPositions: | ||
{ value: 100, | ||
formattedValue: 100, | ||
formatted: '100', | ||
roundedValue: 100, | ||
rounded: '100', | ||
minimized: '100', | ||
denomination: 'Positions', | ||
full: '100Positions' }, | ||
qtyShares: | ||
{ value: 500, | ||
formattedValue: 500, | ||
formatted: '500', | ||
roundedValue: 500, | ||
rounded: '500', | ||
minimized: '500', | ||
denomination: 'Shares', | ||
full: '500Shares' }, | ||
purchasePrice: | ||
{ value: 20, | ||
formattedValue: 20, | ||
formatted: '+20.00', | ||
roundedValue: 20, | ||
rounded: '+20.0', | ||
minimized: '+20', | ||
denomination: 'Eth', | ||
full: '+20.00Eth' }, | ||
totalValue: | ||
{ value: 1000, | ||
formattedValue: 1000, | ||
formatted: '+1,000.00', | ||
roundedValue: 1000, | ||
rounded: '+1,000.0', | ||
minimized: '+1,000', | ||
denomination: 'Eth', | ||
full: '+1,000.00Eth' }, | ||
totalCost: | ||
{ value: 10000, | ||
formattedValue: 10000, | ||
formatted: '+10,000.00', | ||
roundedValue: 10000, | ||
rounded: '+10,000.0', | ||
minimized: '+10,000', | ||
denomination: 'Eth', | ||
full: '+10,000.00Eth' }, | ||
shareChange: | ||
{ value: -18, | ||
formattedValue: -18, | ||
formatted: '-18.00', | ||
roundedValue: -18, | ||
rounded: '-18.0', | ||
minimized: '-18', | ||
denomination: 'Eth', | ||
full: '-18.00Eth' }, | ||
gainPercent: | ||
{ value: -90, | ||
formattedValue: -90, | ||
formatted: '-90.0', | ||
roundedValue: -90, | ||
rounded: '-90', | ||
minimized: '-90', | ||
denomination: '%', | ||
full: '-90.0%' }, | ||
netChange: | ||
{ value: -9000, | ||
formattedValue: -9000, | ||
formatted: '-9,000.00', | ||
roundedValue: -9000, | ||
rounded: '-9,000.0', | ||
minimized: '-9,000', | ||
denomination: 'Eth', | ||
full: '-9,000.00Eth' }, | ||
positions: 50 }, | ||
numAll: 6, | ||
numFavorites: 4, | ||
numPendingReports: 3, | ||
numUnpaginated: 7, | ||
numFiltered: 7, | ||
}; | ||
selectors.onChangeSort = (prop, isDesc) => { | ||
@@ -154,0 +83,0 @@ let isDescending = isDesc; |
@@ -5,10 +5,2 @@ import { makeNumber } from '../utils/make-number'; | ||
import { M } from '../modules/site/constants/pages'; | ||
import { | ||
// CREATE_MARKET, | ||
BUY_SHARES, | ||
// SELL_SHARES, | ||
// BID_SHARES, | ||
// ASK_SHARES, | ||
// SUBMIT_REPORT | ||
} from '../modules/transactions/constants/types'; | ||
@@ -20,2 +12,6 @@ module.exports = makeMarkets(); | ||
const types = ['binary', 'categorical', 'scalar']; | ||
const constants = { | ||
BID: 'bid', | ||
ASK: 'ask' | ||
}; | ||
@@ -35,3 +31,7 @@ for (let i = 0; i < numMarkets; i++) { | ||
description: `Will the dwerps achieve a mwerp by the end of zwerp ${(index + 1)}?`, | ||
endDate: { formatted: `${d.getFullYear()}/${d.getMonth()}/${d.getDate()}`, full: d.toISOString() }, | ||
endDate: { | ||
value: d, | ||
formatted: `${d.getFullYear()}/${d.getMonth()}/${d.getDate()}`, | ||
full: d.toISOString() | ||
}, | ||
endDateLabel: (d < new Date()) ? 'ended' : 'ends', | ||
@@ -48,3 +48,7 @@ takerFeePercent: makeNumber(randomInt(1, 10), '%', true), | ||
}, | ||
orderBook: {} | ||
orderBook: {}, | ||
constants: { | ||
BID: constants.BID, | ||
ASK: constants.ASK | ||
} | ||
}; | ||
@@ -62,2 +66,4 @@ | ||
m.onSubmitPlaceTrade = () => {}; // No action in dummy selector | ||
// trade summary | ||
@@ -71,23 +77,30 @@ Object.defineProperty(m, 'tradeSummary', { | ||
const feeToPay = 0.02 * outcome.trade.numShares * outcome.trade.limitPrice; | ||
const numShares = outcome.trade.numShares; | ||
const limitPrice = outcome.trade.limitPrice || 0; | ||
const profitLoss = outcome.trade.profitLoss; | ||
const cost = numShares * limitPrice; | ||
p.tradeOrders.push({ | ||
type: BUY_SHARES, | ||
shares: makeNumber(numShares), | ||
ether: makeNumber(cost), | ||
data: { outcomeName: 'MAYBE', marketDescription: m.description } | ||
type: outcome.trade.side, | ||
shares: makeNumber(numShares, 'Shares'), | ||
ether: makeNumber(limitPrice, 'eth'), | ||
profitLoss, | ||
data: { | ||
outcomeName: outcome.name, | ||
marketDescription: m.description | ||
} | ||
}); | ||
p.totalShares += numShares; | ||
p.totalEther += cost; | ||
p.feeToPay += feeToPay; | ||
p.totalShares += outcome.trade.side === constants.BID ? numShares : -numShares; | ||
p.totalEther += outcome.trade.side === constants.BID ? -cost : cost; | ||
return p; | ||
}, { totalShares: 0, totalEther: 0, totalFees: 0, totalGas: 0, tradeOrders: [] }); | ||
}, { feeToPay: 0, totalShares: 0, totalEther: 0, totalFees: 0, totalGas: 0, tradeOrders: [] }); | ||
tots.feeToPay = makeNumber(tots.feeToPay, 'eth'); | ||
tots.totalShares = makeNumber(tots.totalShares); | ||
tots.totalEther = makeNumber(tots.totalEther); | ||
tots.totalEther = makeNumber(tots.totalEther, 'eth'); | ||
tots.totalFees = makeNumber(tots.totalFees); | ||
tots.totalGas = makeNumber(tots.totalGas); | ||
tots.onSubmitPlaceTrade = () => { | ||
}; | ||
@@ -128,2 +141,7 @@ return tots; | ||
numPositions: makeNumber(3, 'Positions', true), | ||
qtyShares: makeNumber(10, 'Shares'), | ||
purchasePrice: makeNumber(0.5, 'eth'), | ||
totalCost: makeNumber(5, 'eth'), | ||
shareChange: makeNumber(1, 'Shares'), | ||
netChange: makeNumber(1, 'eth'), | ||
totalValue: makeNumber(985, 'eth'), | ||
@@ -218,2 +236,4 @@ gainPercent: makeNumber(15, '%') | ||
const outcomes = []; | ||
const orderBook = selectOrderBook(); | ||
let outcome; | ||
@@ -223,3 +243,3 @@ let percentLeft = 100; | ||
for (let i = 0; i < numOutcomes; i++) { | ||
outcome = makeOutcome(i, percentLeft); | ||
outcome = makeOutcome(i, percentLeft, orderBook); | ||
percentLeft = percentLeft - outcome.lastPricePercent.value; | ||
@@ -235,6 +255,7 @@ outcomes.push(outcome); | ||
function makeOutcome(index, percentLeft) { | ||
function makeOutcome(index, percentLeft, orderBook) { | ||
const lastPrice = randomInt(0, percentLeft) / 100; | ||
const outcome = { | ||
id: index.toString(), | ||
marketID: index.toString(), | ||
name: makeName(index), | ||
@@ -253,7 +274,8 @@ lastPrice: makeNumber(lastPrice, 'eth'), | ||
trade: { | ||
side: 'bid', | ||
side: constants.BID, | ||
numShares: 0, | ||
limitPrice: 0, | ||
tradeSummary: { | ||
totalEther: makeNumber(0) | ||
totalEther: makeNumber(0, 'eth'), | ||
feeToPay: makeNumber(0, 'eth') | ||
}, | ||
@@ -269,3 +291,3 @@ /** | ||
if (typeof shares !== 'undefined') { | ||
outcome.trade.numShares = shares; | ||
outcome.trade.numShares = side === constants.BID ? shares : -shares; | ||
} | ||
@@ -278,10 +300,22 @@ if (typeof limitPrice !== 'undefined') { | ||
} | ||
outcome.trade.profitLoss = makeNumber(Math.round(outcome.trade.numShares * outcome.trade.limitPrice * 100) / 100, 'eth'); | ||
outcome.trade.tradeSummary.feeToPay = makeNumber(Math.round(0.02 * outcome.trade.limitPrice * outcome.trade.numShares * 100) / 100, 'eth'); | ||
const totEth = side === constants.BID ? -(outcome.trade.numShares * outcome.trade.limitPrice) : outcome.trade.numShares * outcome.trade.limitPrice; | ||
outcome.trade.tradeSummary.totalEther = makeNumber(Math.round(totEth * 100) / 100, 'eth'); | ||
require('../selectors').update(); | ||
} | ||
}, | ||
orderBook: selectOrderBook() | ||
topBid: { | ||
price: orderBook.bids[0].price, | ||
shares: orderBook.bids[0].shares | ||
}, | ||
topAsk: { | ||
price: orderBook.asks[0].price, | ||
shares: orderBook.asks[0].shares | ||
}, | ||
orderBook | ||
}; | ||
outcome.topBid = outcome.orderBook.bids[0].price; | ||
outcome.topAsk = outcome.orderBook.asks[0].price; | ||
return outcome; | ||
@@ -288,0 +322,0 @@ |
@@ -1,7 +0,6 @@ | ||
var assert = require('chai').assert; | ||
// activePage: String, | ||
function activePageAssertion(actual) { | ||
assert.isDefined(actual, `activePage isn't defined`); | ||
assert.isString(actual, `activePage isn't a string`); | ||
} | ||
module.exports = activePageAssertion; | ||
import { assert } from 'chai'; | ||
export default function (activePage) { | ||
assert.isDefined(activePage, `activePage isn't defined`); | ||
assert.isString(activePage, `activePage isn't a string`); | ||
} |
import { assert } from 'chai'; | ||
// <formatted number>: { | ||
// value: Number, | ||
// formattedValue: Number, | ||
// formatted: String, | ||
// roundedValue: Number, | ||
// rounded: String, | ||
// minimized: String, | ||
// denomination: String, | ||
// full: String | ||
// } | ||
export default function (actual) { | ||
assert.isDefined(actual, `formatted number doesn't exist`); | ||
assert.isObject(actual, `formatted number isn't an object`); | ||
assert.isDefined(actual.value, `volume formatted number value isn't defined`); | ||
assert.isNumber(actual.value, `volume formatted number value isn't a number`); | ||
assert.isDefined(actual.formattedValue, `volume formatted number formattedValue isn't defined`); | ||
assert.isNumber(actual.formattedValue, `volume formatted number formattedValue isn't a number`); | ||
assert.isDefined(actual.formatted, `volume formatted number formatted isn't defined`); | ||
assert.isString(actual.formatted, `volume formatted number formatted isn't a string`); | ||
assert.isDefined(actual.roundedValue, `volume formatted number roundedValue isn't defined`); | ||
assert.isNumber(actual.roundedValue, `volume formatted number roundedValue isn't a number`); | ||
assert.isDefined(actual.rounded, `volume formatted number rounded isn't defined`); | ||
assert.isString(actual.rounded, `volume formatted number rounded isn't a string`); | ||
assert.isDefined(actual.minimized, `volume formatted number minimized isn't defined`); | ||
assert.isString(actual.minimized, `volume formatted number minimized isn't a string`); | ||
assert.isDefined(actual.denomination, `volume formatted number denomination isn't defined`); | ||
assert.isString(actual.denomination, `volume formatted number denomination isn't a String`); | ||
assert.isDefined(actual.full, `volume formatted number full isn't defined`); | ||
assert.isString(actual.full, `volume formatted number full isn't a string`); | ||
} | ||
export default function (actual, label = 'Formatted number') { | ||
describe(label, () => { | ||
describe('value', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.value, `value isn't defined`); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(actual.value, `value isn't a number`); | ||
}); | ||
}); | ||
describe('formattedValue', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.formattedValue, `formattedValue isn't defined`); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(actual.formattedValue, `formattedValue isn't a number`); | ||
}); | ||
}); | ||
describe('formatted', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.formatted, `formatted isn't defined`); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(actual.formatted, `formatted isn't a string`); | ||
}); | ||
}); | ||
describe('roundedValue', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.roundedValue, `roundedValue isn't defined`); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(actual.roundedValue, `roundedValue isn't a number`); | ||
}); | ||
}); | ||
describe('rounded', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.rounded, `rounded isn't defined`); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(actual.rounded, `rounded isn't a string`); | ||
}); | ||
}); | ||
describe('minimized', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.minimized, `minimized isn't defined`); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(actual.minimized, `minimized isn't a string`); | ||
}); | ||
}); | ||
describe('denomination', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.denomination, `denomination isn't defined`); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(actual.denomination, `denomination isn't a String`); | ||
}); | ||
}); | ||
describe('full', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.full, `full isn't defined`); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(actual.full, `full isn't a string`); | ||
}); | ||
}); | ||
}); | ||
}; |
import { assert } from 'chai'; | ||
import endDateShape from '../../test/assertions/common/endDateShape'; | ||
import initialFairPricesShape from '../../test/assertions/common/initialFairPricesShape'; | ||
import percentNumberShape from '../../test/assertions/common/percentNumberShape'; | ||
import numberShape from '../../test/assertions/common/numberShape'; | ||
import assertEndDate from '../../test/assertions/common/end-date'; | ||
import assertInitialFairPrices from '../../test/assertions/common/initial-fair-prices'; | ||
import assertFormattedNumber from '../../test/assertions/common/formatted-number'; | ||
@@ -42,3 +41,3 @@ function step1(actual){ | ||
assert.isObject(actual.initialFairPrices, 'initialFairPrices is not an object'); | ||
initialFairPricesShape(actual.initialFairPrices); | ||
assertInitialFairPrices(actual.initialFairPrices, 'createMarketForm'); | ||
}); | ||
@@ -50,3 +49,3 @@ | ||
}); | ||
it('should receive descriptionMaxLength and be a number', () => { | ||
@@ -128,3 +127,3 @@ assert.isDefined(actual.descriptionMaxLength, 'descriptionMaxLength is not defined'); | ||
assert.isObject(actual.initialFairPrices, 'initialFairPrices is not an object'); | ||
initialFairPricesShape(actual.initialFairPrices); | ||
assertInitialFairPrices(actual.initialFairPrices, 'createMarketForm'); | ||
}); | ||
@@ -169,3 +168,3 @@ | ||
assert.isObject(actual.endDate, 'endDate is not an array'); | ||
endDateShape(actual.endDate); | ||
assertEndDate(actual.endDate, 'createMarketForm'); | ||
}); | ||
@@ -176,3 +175,3 @@ | ||
assert.isObject(actual.takerFeePercent, 'takerFeePercent is not an object'); | ||
percentNumberShape(actual.takerFeePercent); | ||
assertFormattedNumber(actual.takerFeePercent, 'createMarketForm.takerFeePercent'); | ||
}); | ||
@@ -183,3 +182,3 @@ | ||
assert.isObject(actual.makerFeePercent, 'makerFeePercent is not an object'); | ||
percentNumberShape(actual.makerFeePercent); | ||
assertFormattedNumber(actual.makerFeePercent, 'createMarketForm.makerFeePercent'); | ||
}); | ||
@@ -195,3 +194,3 @@ | ||
assert.isObject(actual.volume, 'volume is not an object'); | ||
numberShape(actual.volume); | ||
assertFormattedNumber(actual.volume, 'createMarketForm.volume'); | ||
}); | ||
@@ -202,3 +201,3 @@ | ||
assert.isObject(actual.initialFairPrices, 'initialFairPrices is not an object'); | ||
initialFairPricesShape(actual.initialFairPrices); | ||
assertInitialFairPrices(actual.initialFairPrices, 'createMarketForm'); | ||
}); | ||
@@ -209,3 +208,3 @@ | ||
assert.isObject(actual.bestStartingQuantityFormatted, 'bestStartingQuantityFormatted is not an object'); | ||
numberShape(actual.bestStartingQuantityFormatted); | ||
assertFormattedNumber(actual.bestStartingQuantityFormatted, 'createMarketForm.bestStartingQuantityFormatted'); | ||
}); | ||
@@ -216,3 +215,3 @@ | ||
assert.isObject(actual.startingQuantityFormatted, 'startingQuantityFormatted is not an object'); | ||
numberShape(actual.startingQuantityFormatted); | ||
assertFormattedNumber(actual.startingQuantityFormatted, 'createMarketForm.startingQuantityFormatted'); | ||
}); | ||
@@ -223,3 +222,3 @@ | ||
assert.isObject(actual.priceWidthFormatted, 'priceWidthFormatted is not an object'); | ||
numberShape(actual.priceWidthFormatted); | ||
assertFormattedNumber(actual.priceWidthFormatted, 'createMarketForm.priceWidthFormatted'); | ||
}); | ||
@@ -226,0 +225,0 @@ }); |
@@ -20,2 +20,3 @@ var activePage = require('./activePage'); | ||
var update = require('./update'); | ||
var trade = require('./trade'); | ||
@@ -41,3 +42,4 @@ module.exports = { | ||
transactionsTotals: transactionsTotals, | ||
update: update | ||
update: update, | ||
trade: trade | ||
}; |
@@ -1,110 +0,677 @@ | ||
var assert = require('chai').assert; | ||
import { assert } from 'chai'; | ||
import assertFormattedNumber from '../../test/assertions/common/formatted-number'; | ||
import assertEndDate from '../../test/assertions/common/end-date'; | ||
import percentNumberShape from '../../test/assertions/common/percentNumberShape'; | ||
import numberShape from '../../test/assertions/common/numberShape'; | ||
// markets: | ||
// [ { id: String, | ||
// type: String, | ||
// description: String, | ||
// endDate: Object, | ||
// endDateLabel: String, | ||
// tradingFeePercent: Object, | ||
// volume: Object, | ||
// isOpen: Boolean, | ||
// isPendingReport: Boolean, | ||
// marketLink: Object, | ||
// tags: Object, | ||
// outcomes: Object, | ||
// reportableOutcomes: Object, | ||
// tradeSummary: Function, | ||
// priceTimeSeries: Object, | ||
// positionsSummary: Object, | ||
// report: Object }, | ||
// ... | ||
// ] | ||
function marketAssertion(actual) { | ||
assert.isDefined(actual, `markets is empty.`) | ||
assert.isObject(actual, `markets[0] (market) isn't an object`); | ||
describe('augur-ui-react-components market state', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual, `markets is empty.`) | ||
}); | ||
assert.isDefined(actual.id, `market.id isn't defined.`); | ||
assert.isString(actual.id, `market.id isn't a string`); | ||
it('should be an object', () => { | ||
assert.isObject(actual, `markets[0] (market) isn't an object`); | ||
}); | ||
assert.isDefined(actual.type, `market.type isn't defined.`); | ||
assert.isString(actual.type, `market.type isn't a string`); | ||
describe('id', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.id, `id isn't defined.`); | ||
}); | ||
assert.isDefined(actual.description, `market.description isn't defined`); | ||
assert.isString(actual.description, `market.description isn't a string`); | ||
it('should be a string', () => { | ||
assert.isString(actual.id, `id isn't a string`); | ||
}); | ||
}); | ||
assert.isDefined(actual.endDate, `market.endDate isn't defined`); | ||
assert.isObject(actual.endDate, `market.endDate isn't an object`); | ||
describe('type', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.type, `type isn't defined.`); | ||
}); | ||
assert.isDefined(actual.endDateLabel, `market.endDateLabel isn't defined`); | ||
assert.isString(actual.endDateLabel, `market.endDateLabel isn't an string`); | ||
it('should be a string', () => { | ||
assert.isString(actual.type, `type isn't a string`); | ||
}); | ||
}); | ||
assert.isDefined(actual.takerFeePercent, `market.takerFeePercent isn't defined`); | ||
assert.isObject(actual.takerFeePercent, `market.takerFeePercent isn't an object`); | ||
percentNumberShape(actual.takerFeePercent); | ||
describe('description', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.description, `description isn't defined`); | ||
}); | ||
assert.isDefined(actual.makerFeePercent, `market.makerFeePercent isn't defined`); | ||
assert.isObject(actual.makerFeePercent, `market.makerFeePercent isn't an object`); | ||
percentNumberShape(actual.makerFeePercent); | ||
it('should be a string', () => { | ||
assert.isString(actual.description, `description isn't a string`); | ||
}); | ||
}); | ||
assert.isDefined(actual.volume, `market.volume isn't defined`); | ||
assert.isObject(actual.volume, `market.volume isn't an object`); | ||
numberShape(actual.volume); | ||
describe('endDate', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.endDate, `endDate isn't defined`); | ||
}); | ||
assert.isDefined(actual.isOpen, `market.isOpen isn't defined`); | ||
assert.isBoolean(actual.isOpen, `market.isOpen isn't a boolean`); | ||
it('should have the correct shape', () => { | ||
assertEndDate(actual.endDate, 'market'); | ||
}); | ||
}); | ||
assert.isDefined(actual.isPendingReport, `market.isPendingReport isn't defined`); | ||
assert.isBoolean(actual.isPendingReport, `market.isPendingReport isn't a boolean`); | ||
describe('endDateLabel', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.endDateLabel, `market.endDateLabel isn't defined`); | ||
}); | ||
assert.isDefined(actual.marketLink, `market.marketLink isn't defined`); | ||
assert.isObject(actual.marketLink, `market.marketLink isn't an object`); | ||
marketLinkAssertion(actual.marketLink); | ||
it('should be a string', () => { | ||
assert.isString(actual.endDateLabel, `market.endDateLabel isn't an string`); | ||
}); | ||
}); | ||
assert.isDefined(actual.tags, `market.tags isn't defined`); | ||
assert.isArray(actual.tags, `market.tags isn't an array`); | ||
describe('takerFeePercent', () => { | ||
it('should receive a takerFeePercent and be an object', () => { | ||
assert.isDefined(actual.takerFeePercent, `market.takerFeePercent isn't defined`); | ||
}); | ||
assert.isDefined(actual.outcomes, `market.outcomes isn't defined`); | ||
assert.isArray(actual.outcomes, `market.outcomes isn't an array`); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(actual.takerFeePercent, 'market.takerFeePercent'); | ||
}); | ||
}); | ||
assert.isDefined(actual.reportableOutcomes, `market.reportableOutcomes isn't defined`); | ||
assert.isArray(actual.reportableOutcomes, `market.reportableOutcomes isn't an array`); | ||
describe('makerFeePercent', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.makerFeePercent, `market.makerFeePercent isn't defined`); | ||
}); | ||
assert.isDefined(actual.tradeSummary, `market.tradeSummary isn't defined`); | ||
assert.isObject(actual.tradeSummary, `market.tradeSummary isn't a object`); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(actual.makerFeePercent, 'market.makerFeePercent'); | ||
}); | ||
}); | ||
assert.isDefined(actual.priceTimeSeries, `market.priceTimeSeries isn't defined`); | ||
assert.isArray(actual.priceTimeSeries, `market.priceTimeSeries isn't an array`); | ||
describe('volume', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.volume, `market.volume isn't defined`); | ||
}); | ||
assert.isDefined(actual.positionsSummary, `market.positionsSummary isn't defined`); | ||
assert.isObject(actual.positionsSummary, `market.positionsSummary isn't an object`); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(actual.volume, 'market.volume'); | ||
}); | ||
}); | ||
assert.isDefined(actual.report, `market.report isn't defined`); | ||
assert.isObject(actual.report, `market.report isn't an object`); | ||
reportAssertion(actual.report); | ||
describe('isOpen', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.isOpen, `market.isOpen isn't defined`); | ||
}); | ||
assert.isDefined(actual.orderBook, `market.orderBook isn't defined`); | ||
assert.isObject(actual.orderBook, `market.orderBook isn't an object`); | ||
it('should be a boolean', () => { | ||
assert.isBoolean(actual.isOpen, `market.isOpen isn't a boolean`); | ||
}); | ||
}); | ||
describe('isPendingReport', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.isPendingReport, `market.isPendingReport isn't defined`); | ||
}); | ||
it('should be a boolean', () => { | ||
assert.isBoolean(actual.isPendingReport, `market.isPendingReport isn't a boolean`); | ||
}); | ||
}); | ||
describe('marketLink', () => { | ||
it('should receive a marketLink and be an object', () => { | ||
assert.isDefined(actual.marketLink, `market.marketLink isn't defined`); | ||
}); | ||
it('should have the correct shape', () => { | ||
marketLinkAssertion(actual.marketLink); | ||
}); | ||
}); | ||
describe('tags', () => { | ||
let tags = actual.tags; | ||
it('should exist', () => { | ||
assert.isDefined(tags, `market.tags isn't defined`); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(tags, `market.tags isn't an array`); | ||
}); | ||
tags.map((tag, i) => { | ||
describe(`tag ${i}`, () => { | ||
describe('name', () => { | ||
it('should exist', () => { | ||
assert.isDefined(tag.name, 'name is not defined'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(tag.name, 'name is not a string'); | ||
}); | ||
}); | ||
describe('onClick', () => { | ||
it('should exist', () => { | ||
assert.isDefined(tag.onClick, 'onClick is not defined'); | ||
}); | ||
it('should be a function', () => { | ||
assert.typeOf(tag.onClick, 'function', 'name is not a function'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('outcomes', () => { | ||
it('should exist', () => { | ||
assert.isDefined(actual.outcomes, `market.outcomes isn't defined`); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(actual.outcomes, `market.outcomes isn't an array`); | ||
}); | ||
actual.outcomes.map((outcome, i) => { | ||
describe(`outcome ${i}`, () => { | ||
describe('id', () => { | ||
it('should exist', () => { | ||
assert.isDefined(outcome.id, 'id does not exist'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(outcome.id, 'id is not a string'); | ||
}); | ||
}); | ||
describe('name', () => { | ||
it('should exist', () => { | ||
assert.isDefined(outcome.name, 'name does not exist'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(outcome.name, 'name is not a string'); | ||
}); | ||
}); | ||
describe('marketID', () => { | ||
it('should exist', () => { | ||
assert.isDefined(outcome.marketID, 'marketID does not exist'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(outcome.marketID, 'marketID is not a string'); | ||
}); | ||
}); | ||
describe('lastPrice', () => { | ||
it('should exist', () => { | ||
assert.isDefined(outcome.lastPrice, 'lastPrice does not exist'); | ||
}); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(outcome.lastPrice, `market.outcomes[${i}].lastPrice`); | ||
}); | ||
}); | ||
describe('lastPricePercent', () => { | ||
it('should exist', () => { | ||
assert.isDefined(outcome.lastPricePercent, 'lastPricePercent does not exist'); | ||
}); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(outcome.lastPricePercent, `market.outcomet[${i}].lastPricePercent`); | ||
}); | ||
}); | ||
describe('trade', () => { | ||
let trade = outcome.trade; | ||
it('should exist', () => { | ||
assert.isDefined(trade, 'trade does not exist'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(trade, 'trade is not an object'); | ||
}) | ||
describe('side', () => { | ||
it('should exist', () => { | ||
assert.isDefined(trade.side, 'side does not exist'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(trade.side, 'side is not a string'); | ||
}); | ||
}); | ||
describe('numShares', () => { | ||
it('should exist', () => { | ||
assert.isDefined(trade.numShares, 'numShares does not exist'); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(trade.numShares, 'numShares is not a number'); | ||
}); | ||
}); | ||
describe('limitPrice', () => { | ||
it('should exist', () => { | ||
assert.isDefined(trade.limitPrice, 'limitPrice does not exist'); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(trade.limitPrice, 'limitPrice is not a number'); | ||
}); | ||
}); | ||
describe('tradeSummary', () => { // NOTE -- shallow check here due to deep check further down of the same selector method | ||
it('should exist', () => { | ||
assert.isDefined(trade.tradeSummary, 'tradeSummary does not exist'); | ||
}); | ||
it('should be a number', () => { | ||
assert.isObject(trade.tradeSummary, 'tradeSummary is not a object'); | ||
}); | ||
}); | ||
describe('updateTradeOrder', () => { | ||
it('should exist', () => { | ||
assert.isDefined(trade.updateTradeOrder, 'updateTradeOrder does not exist'); | ||
}); | ||
it('should be a function', () => { | ||
assert.typeOf(trade.updateTradeOrder, 'function', 'updateTradeOrder is not a function'); | ||
}); | ||
}); | ||
}); | ||
describe('orderBook', () => { // NOTE -- shallow check here due to deep check further down of the same selector method | ||
let orderBook = outcome.orderBook; | ||
it('should exist', () => { | ||
assert.isDefined(orderBook, 'orderBook does not exist'); | ||
}); | ||
it('should be a function', () => { | ||
assert.isObject(orderBook, 'orderBook is not an object'); | ||
}); | ||
describe('bids', () => { | ||
it('should exist', () => { | ||
assert.isDefined(orderBook.bids, `bids isn't defined`); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(orderBook.bids, `bids isn't an array`); | ||
}); | ||
}); | ||
describe('asks', () => { | ||
it('should exist', () => { | ||
assert.isDefined(orderBook.asks, `asks isn't defined`); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(orderBook.asks, `asks isn't an array`); | ||
}); | ||
}); | ||
}); | ||
describe('topBid', () => { // NOTE -- shallow check here due to deep check further down of the same selector method | ||
it('should exist', () => { | ||
assert.isDefined(outcome.topBid, 'topBid does not exist'); | ||
}); | ||
}); | ||
describe('topAsk', () => { // NOTE -- shallow check here due to deep check further down of the same selector method | ||
it('should exist', () => { | ||
assert.isDefined(outcome.topAsk, 'topAsk does not exist'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('reportableOutcomes', () => { // NOTE -- other outcomes reside in this array, only testing unique item | ||
it('should exist', () => { | ||
assert.isDefined(actual.reportableOutcomes, `market.reportableOutcomes isn't defined`); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(actual.reportableOutcomes, `market.reportableOutcomes isn't an array`); | ||
}); | ||
describe('indeterminate outcome', () => { | ||
const indeterminateItem = actual.reportableOutcomes[actual.reportableOutcomes.length - 1]; | ||
it('should exist', () => { | ||
assert.isDefined(indeterminateItem, 'indeterminateItem does not exist'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(indeterminateItem, 'indeterminateItem is not an object'); | ||
}); | ||
describe('id', () => { | ||
it('should exist', () => { | ||
assert.isDefined(indeterminateItem.id, 'id does not exist'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(indeterminateItem.id, 'id is not a string'); | ||
}); | ||
}); | ||
describe('name', () => { | ||
it('should exist', () => { | ||
assert.isDefined(indeterminateItem.name, 'name does not exist'); | ||
}); | ||
it('should be a string', () => { | ||
assert.isString(indeterminateItem.name, 'name is not a string'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('tradeSummary', () => { | ||
let tradeSummary = actual.tradeSummary; | ||
it('should exist', () => { | ||
assert.isDefined(tradeSummary, 'tradeSummary is not defined'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(tradeSummary, 'tradeSummary is not an object'); | ||
}); | ||
describe('totalShares', () => { | ||
it('should exist', () => { | ||
assert.isDefined(tradeSummary.totalShares, 'totalShares is not defined'); | ||
}); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(tradeSummary.totalShares, 'market.tradeSummary.totalShares'); | ||
}); | ||
}); | ||
describe('totalEther', () => { | ||
it('should exist', () => { | ||
assert.isDefined(tradeSummary.totalEther, 'totalEther is not defined'); | ||
}); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(tradeSummary.totalEther, 'market.tradeSummary.totalEther'); | ||
}); | ||
}); | ||
describe('totalGas', () => { | ||
it('should exist', () => { | ||
assert.isDefined(tradeSummary.totalGas, 'totalGas is not defined'); | ||
}); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(tradeSummary.totalGas, 'market.tradeSummary.totalGas'); | ||
}); | ||
}); | ||
describe('feeToPay', () => { | ||
it('should exist', () => { | ||
assert.isDefined(tradeSummary.feeToPay, 'feeToPay is not defined'); | ||
}); | ||
it('should have the correct shape', () => { | ||
assertFormattedNumber(tradeSummary.feeToPay, 'market.tradeSummary.feeToPay'); | ||
}); | ||
}); | ||
describe('tradeOrders', () => { | ||
let tradeOrders = tradeSummary.tradeOrders; | ||
it('should exist', () => { | ||
assert.isDefined(tradeOrders, 'tradeOrders is not defined'); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(tradeOrders, 'tradeOrders is not an array'); | ||
}); | ||
tradeOrders.map((trade, i) => { | ||
describe(`tradeOrder shape for ${i}`, () => { | ||
describe('shares', () => { | ||
it('should be defined', () => { | ||
assert.isDefined(trade.shares, 'shares is not defined'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(trade.shares, 'shares is not an object'); | ||
}); | ||
describe('value', () => { | ||
it('should be defined', () => { | ||
assert.isDefined(trade.shares.value, 'shares is not defined'); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(trade.shares.value, 'shares is not a number'); | ||
}); | ||
}); | ||
}); | ||
describe('ether', () => { | ||
it('should be defined', () => { | ||
assert.isDefined(trade.ether, 'ether is not defined'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(trade.ether, 'ether is not an object'); | ||
}); | ||
describe('value', () => { | ||
it('should be defined', () => { | ||
assert.isDefined(trade.ether.value, 'ether is not defined'); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(trade.ether.value, 'ether is not a number'); | ||
}); | ||
}); | ||
}); | ||
describe('gas', () => { | ||
it('should be defined', () => { | ||
assert.isDefined(trade.gas, 'gas is not defined'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(trade.gas, 'gas is not an object'); | ||
}); | ||
describe('value', () => { | ||
it('should be defined', () => { | ||
assert.isDefined(trade.gas.value, 'gas is not defined'); | ||
}); | ||
it('should be a number', () => { | ||
assert.isNumber(trade.gas.value, 'gas is not a number'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('priceTimeSeries', () => { | ||
it('[TODO] flesh out the full shape'); // Holding on this temporarily until we can better test trading | ||
it('should exist', () => { | ||
assert.isDefined(actual.priceTimeSeries, `market.priceTimeSeries isn't defined`); | ||
}); | ||
it('should be an array', () => { | ||
assert.isArray(actual.priceTimeSeries, `market.priceTimeSeries isn't an array`); | ||
}); | ||
}); | ||
describe('positionsSummary', () => { | ||
let positionsSummary = actual.positionsSummary; | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary, 'positionsSummary is not defined'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(positionsSummary, 'positionsSummary is not an object'); | ||
}); | ||
describe('numPositions', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.numPositions, 'numPositions is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.numPositions, 'market.positionsSummary.numPositions'); | ||
}); | ||
}); | ||
describe('qtyShares', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.qtyShares, 'qtyShares is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.qtyShares, 'market.positionsSummary.qtyShares'); | ||
}); | ||
}); | ||
describe('purchasePrice', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.purchasePrice, 'purchasePrice is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.purchasePrice, 'market.positionsSummary.purchasePrice'); | ||
}); | ||
}); | ||
describe('totalValue', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.totalValue, 'totalValue is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.totalValue, 'market.positionsSummary.totalValue'); | ||
}); | ||
}); | ||
describe('totalCost', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.totalCost, 'totalCost is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.totalCost, 'market.positionsSummary.totalCost'); | ||
}); | ||
}); | ||
describe('shareChange', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.shareChange, 'shareChange is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.shareChange, 'market.positionsSummary.shareChange'); | ||
}); | ||
}); | ||
describe('gainPercent', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.gainPercent, 'gainPercent is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.gainPercent, 'market.positionsSummary.gainPercent'); | ||
}); | ||
}); | ||
describe('netChange', () => { | ||
it('should exist', () => { | ||
assert.isDefined(positionsSummary.netChange, 'netChange is not defined'); | ||
}); | ||
it('should be the correct shape', () => { | ||
assertFormattedNumber(positionsSummary.netChange, 'market.positionsSummary.netChange'); | ||
}); | ||
}); | ||
}); | ||
describe('report', () => { | ||
const report = actual.report; | ||
it('should exist', () => { | ||
assert.isDefined(report, `market.report isn't defined`); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(report, 'report is not an object'); | ||
}); | ||
describe('isUnethical', () => { | ||
it('should exist', () => { | ||
assert.isDefined(report.isUnethical, `isUnethical isn't defined`); | ||
}); | ||
it('should be a boolean', () => { | ||
assert.isBoolean(report.isUnethical, `isUnethical isn't a boolean`); | ||
}); | ||
}); | ||
describe('onSubmitReport', () => { | ||
it('should exist', () => { | ||
assert.isDefined(report.onSubmitReport, `onSubmitReport isn't defined`); | ||
}); | ||
it('should be a function', () => { | ||
assert.typeOf(report.onSubmitReport, 'function', `onSubmitReport isn't a function`); | ||
}); | ||
}); | ||
}); | ||
describe('orderBook', () => { | ||
it('[TODO] further assert shape'); | ||
it('should receive an orderBook and be an object', () => { | ||
assert.isDefined(actual.orderBook, `market.orderBook isn't defined`); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(actual.orderBook, `market.orderBook isn't an object`); | ||
}); | ||
}); | ||
describe('constants', () => { | ||
let constants = actual.constants; | ||
it('should receive constants and be an object', () => { | ||
assert.isDefined(constants, 'market.constants is not defined'); | ||
}); | ||
it('should be an object', () => { | ||
assert.isObject(constants, 'market.constatn is not an object'); | ||
}); | ||
describe('BID', () => { | ||
it('should exist', () => { | ||
assert.isDefined(constants.BID, 'BID is not defined'); | ||
}); | ||
it("should be a string + equal 'bid'", () => { | ||
assert.strictEqual(constants.BID, 'bid', "BID is not strictly equal to 'bid'"); | ||
}); | ||
}); | ||
describe('ASK', () => { | ||
it('should exist', () => { | ||
assert.isDefined(constants.ASK, 'ASK is not defined'); | ||
}); | ||
it("should be a string + equal 'ask'", () => { | ||
assert.strictEqual(constants.ASK, 'ask', "ASK is not strictly equal to 'ask'"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
// report: { | ||
// isUnethical: Boolean, | ||
// onSubmitReport: [Function: onSubmitReport] | ||
// } | ||
function reportAssertion(actual) { | ||
assert.isDefined(actual, `market doesn't have a report object`); | ||
assert.isObject(actual, `market.report isn't an object`); | ||
assert.isDefined(actual.isUnethical, `market.report.isUnethical isn't defined`); | ||
assert.isBoolean(actual.isUnethical, `market.report.isUnethical isn't a boolean`); | ||
assert.isDefined(actual.onSubmitReport, `market.report.onSubmitReport isn't defined`); | ||
assert.isFunction(actual.onSubmitReport, `market.report.onSubmitReport isn't a function`); | ||
} | ||
// marketLink: { | ||
// text: string, | ||
// className: string, | ||
// onClick: [Function: onClick] | ||
// } | ||
function marketLinkAssertion(actual) { | ||
@@ -122,5 +689,4 @@ assert.isDefined(actual, `market.marketLink isn't defined`); | ||
module.exports = { | ||
marketAssertion: marketAssertion, | ||
reportAssertion: reportAssertion, | ||
marketAssertion, | ||
marketLinkAssertion: marketLinkAssertion | ||
}; |
var assert = require('chai').assert; | ||
// marketsTotals: | ||
// { | ||
// numAll: 1, | ||
// numFavorites: 0, | ||
// numFiltered: 0, | ||
// numPendingReports: 19, | ||
// numUnpaginated: 0, | ||
// positionsSummary: | ||
// { | ||
// gainPercent: [Object], | ||
// netChange: [Object], | ||
// numPositions: [Object], | ||
// positions: undefined/[Object], | ||
// purchasePrice: [Object], | ||
// qtyShares: [Object], | ||
// shareChange: [Object], | ||
// totalCost: [Object], | ||
// totalValue: [Object], | ||
// } | ||
// }, | ||
/* | ||
marketsTotals: { | ||
numAll: 1, | ||
numFavorites: 0, | ||
numFiltered: 0, | ||
numPendingReports: 19, | ||
numUnpaginated: 0 | ||
} | ||
*/ | ||
function checkDefinedAndNumber(obj, name) { | ||
@@ -27,23 +18,2 @@ assert.isDefined(obj, `marketsTotals.${name} isn't defined`); | ||
function checkPositionSummaryObject(obj, name) { | ||
assert.isDefined(obj, `positionsSummary.${name} isn't defined`); | ||
assert.isObject(obj, `positionsSummary.${name} isn't a object`); | ||
assert.isDefined(obj.value, `${name}.value isn't defined`); | ||
assert.isNumber(obj.value, `${name}.value isn't a number`); | ||
assert.isDefined(obj.formattedValue, `${name}.formattedValue isn't defined`); | ||
assert.isNumber(obj.formattedValue, `${name}.formattedValue isn't a number`); | ||
assert.isDefined(obj.formatted, `${name}.formatted isn't defined`); | ||
assert.isString(obj.formatted, `${name}.formatted isn't a string`); | ||
assert.isDefined(obj.roundedValue, `${name}.roundedValue isn't defined`); | ||
assert.isNumber(obj.roundedValue, `${name}.roundedValue isn't a number`); | ||
assert.isDefined(obj.rounded, `${name}.rounded isn't defined`); | ||
assert.isString(obj.rounded, `${name}.rounded isn't a string`); | ||
assert.isDefined(obj.minimized, `${name}.minimized isn't defined`); | ||
assert.isString(obj.minimized, `${name}.minimized isn't a string`); | ||
assert.isDefined(obj.denomination, `${name}.denomination isn't defined`); | ||
assert.isString(obj.denomination, `${name}.denomination isn't a string`); | ||
assert.isDefined(obj.full, `${name}.full isn't defined`); | ||
assert.isString(obj.full, `${name}.full isn't a string`); | ||
} | ||
function marketsTotalsAssertion(actual) { | ||
@@ -58,23 +28,4 @@ assert.isDefined(actual, `marketsTotals isn't defined`); | ||
checkDefinedAndNumber(actual.numUnpaginated, `numUnpaginated`); | ||
assert.isDefined(actual.positionsSummary, `marketsTotals.positionsSummary isn't defined`); | ||
assert.isObject(actual.positionsSummary, `marketsTotals.positionsSummary isn't an object as expected`); | ||
} | ||
function positionsSummaryAssertion(actual) { | ||
assert.isDefined(actual, `positionsSummary isn't defined`); | ||
assert.isObject(actual, `positionsSummary isn't an object`); | ||
checkPositionSummaryObject(actual.gainPercent, 'gainPercent'); | ||
checkPositionSummaryObject(actual.netChange, 'netChange'); | ||
checkPositionSummaryObject(actual.numPositions, 'numPositions'); | ||
checkPositionSummaryObject(actual.purchasePrice, 'purchasePrice'); | ||
checkPositionSummaryObject(actual.qtyShares, 'qtyShares'); | ||
checkPositionSummaryObject(actual.shareChange, 'shareChange'); | ||
checkPositionSummaryObject(actual.totalCost, 'totalCost'); | ||
checkPositionSummaryObject(actual.totalValue, 'totalValue'); | ||
} | ||
module.exports = { | ||
marketsTotalsAssertion: marketsTotalsAssertion, | ||
positionsSummaryAssertion: positionsSummaryAssertion | ||
}; | ||
module.exports = marketsTotalsAssertion; |
import selectors from '../src/selectors'; | ||
import * as assertions from './assertions/marketsTotals'; | ||
import marketsTotalAssertion from './assertions/marketsTotals'; | ||
describe(`selectors.marketsTotals tests:`, () => { | ||
// marketsTotals: | ||
// { positionsSummary: | ||
// { numPositions: [Object], | ||
// totalValue: [Object], | ||
// gainPercent: [Object] }, | ||
// numPendingReports: 19 }, | ||
it(`should contain a marketsTotal and is the expected shape`, () => { | ||
let actual = selectors.marketsTotals; | ||
assertions.marketsTotalsAssertion(actual); | ||
marketsTotalAssertion(actual); | ||
}); | ||
it(`marketsTotal should contain a positionsSummary object with the correct shape`, () => { | ||
let actual = selectors.marketsTotals.positionsSummary; | ||
// console.log(actual); | ||
assertions.positionsSummaryAssertion(actual); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1898014
277
7666