Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

augur-ui-react-components

Package Overview
Dependencies
Maintainers
4
Versions
221
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

augur-ui-react-components - npm Package Compare versions

Comparing version 3.0.11 to 3.0.12

src/modules/trade/components/trade-panel-row-order.jsx

3

package.json
{
"name": "augur-ui-react-components",
"version": "3.0.11",
"version": "3.0.12",
"description": "Augur UI React Components",

@@ -72,2 +72,3 @@ "author": "Baz (@thinkloop)",

"mocha": "2.5.3",
"moment": "2.14.1",
"npm-check-updates": "^2.7.0",

@@ -74,0 +75,0 @@ "onchange": "2.5.0",

@@ -21,3 +21,2 @@ import activePage from '../test/assertions/active-page';

import siteHeader from '../test/assertions/site-header';
import trade from '../test/assertions/trade';
import transactions from '../test/assertions/transactions';

@@ -48,3 +47,2 @@ import transactionsTotals from '../test/assertions/transactions-totals';

siteHeader,
trade,
transactions,

@@ -51,0 +49,0 @@ transactionsTotals,

@@ -15,2 +15,3 @@ import React, { Component, PropTypes } from 'react';

siteHeader: PropTypes.object,
sideOptions: PropTypes.array,
market: PropTypes.object,

@@ -62,3 +63,3 @@ priceTimeSeries: PropTypes.array,

onSubmitPlaceTrade={p.market.onSubmitPlaceTrade}
constants={p.market.constants}
orderSides={p.market.orderSides}
/>

@@ -65,0 +66,0 @@ );

import React from 'react';
import classnames from 'classnames';
import ValueDenomination from '../../common/components/value-denomination';
import Input from '../../common/components/input';
import Dropdown from '../../common/components/dropdown';
import Clickable from '../../common/components/clickable';
import TradePanelRowOutcome from '../../../modules/trade/components/trade-panel-row-outcome';
import TradePanelRowOrder from '../../../modules/trade/components/trade-panel-row-order';
const TradePanelBody = (p) => {
const itemRows = (outcomes, sideOptions) => {
const tableRows = [];
let orderBookRows = [];
const orderBookLength = Math.max(p.outcome.orderBook.bids.length, p.outcome.orderBook.asks.length);
const secondItemIndex = 1; // first item is displayed in different row
outcomes.map((outcome) => {
const orderBookMaxRows = outcome.orderBook.bids.length > outcome.orderBook.asks.length ? new Array(outcome.orderBook.bids.length) : new Array(outcome.orderBook.asks.length);
orderBookMaxRows.fill('');
for (let i = secondItemIndex; i < orderBookLength; i++) {
orderBookRows.push(
<TradePanelRowOrder
key={`outcome-${i}`}
outcome={p.outcome}
selectedOutcomeID={p.selectedOutcomeID}
orderSides={p.orderSides}
itemIndex={i}
/>
);
}
tableRows.push(
<tr
key={`${outcome.name}`}
className={classnames('trade-panel-row', 'clickable-row')}
onClick={event => {
event.stopPropagation();
p.updateSelectedOutcome(outcome.id);
}}
>
<th className="outcome-name">
{outcome.name}
</th>
<td className="last-price">
<ValueDenomination {...outcome.lastPrice} />
</td>
<td className="bid">
{!!outcome.topBid &&
<div>
<Clickable onClick={() => { outcome.trade.updateTradeOrder(outcome.id, outcome.topBid.shares.value, outcome.topBid.price.value, p.constants.ASK); }} >
<ValueDenomination className="top-bid" {...outcome.topBid.shares} />
</Clickable>
<span className="shares-at">@</span>
<Clickable onClick={() => { outcome.trade.updateTradeOrder(outcome.id, undefined, outcome.topBid.price.value); }}>
<ValueDenomination className="top-bid" {...outcome.topBid.price} />
</Clickable>
</div>
}
</td>
<td className="ask">
{!!outcome.topAsk &&
<div>
<Clickable onClick={() => { outcome.trade.updateTradeOrder(outcome.id, undefined, outcome.topAsk.price.value); }}>
<ValueDenomination className="top-ask" {...outcome.topAsk.price} />
</Clickable>
<span className="shares-at">@</span>
<Clickable onClick={() => { outcome.trade.updateTradeOrder(outcome.id, outcome.topAsk.shares.value, outcome.topAsk.price.value, p.constants.BID); }} >
<ValueDenomination className="top-ask" {...outcome.topAsk.shares} />
</Clickable>
</div>
}
</td>
<td>
<Dropdown
selected={sideOptions.find(opt => opt.value === outcome.trade.side)}
options={sideOptions}
onChange={(selectedOption) => { outcome.trade.updateTradeOrder(outcome.id, undefined, undefined, selectedOption); }}
/>
</td>
<td>
<Input
className="num-shares"
type="text"
value={outcome.trade.numShares}
isClearable={false}
onChange={(value) => outcome.trade.updateTradeOrder(outcome.id, parseFloat(value) || 0, undefined)}
/>
</td>
<td>
<Input
className="limit-price"
type="text"
value={outcome.trade.limitPrice}
isClearable={false}
onChange={(value) => outcome.trade.updateTradeOrder(outcome.id, undefined, parseFloat(value) || 0)}
/>
</td>
<td className="fee-to-pay" >
<ValueDenomination {...outcome.trade.tradeSummary.feeToPay} />
</td>
<td className="total-cost" >
<ValueDenomination {...outcome.trade.tradeSummary.totalEther} />
</td>
</tr>
);
orderBookMaxRows.map((cV, i) => {
if (i !== 0) {
tableRows.push(
<tr
key={`${outcome.name}-order-book-${i}`}
className={classnames('trade-panel-row', { displayNone: !(p.selectedOutcomeID === outcome.id) })}
>
<td colSpan="2"></td>
<td>
{!!outcome.orderBook.bids[i] &&
<div className="order-book-data bid">
<Clickable
onClick={event => {
event.stopPropagation();
outcome.trade.updateTradeOrder(outcome.id, outcome.orderBook.bids[i].shares.value, outcome.orderBook.bids[i].price.value, p.constants.ASK);
}}
>
<ValueDenomination className="shares" {...outcome.orderBook.bids[i].shares} />
</Clickable>
<span className="shares-at">@</span>
<Clickable
onClick={event => {
event.stopPropagation();
outcome.trade.updateTradeOrder(outcome.id, undefined, outcome.orderBook.bids[i].price.value);
}}
>
<ValueDenomination className="price" {...outcome.orderBook.bids[i].price} />
</Clickable>
</div>
}
</td>
<td>
{!!outcome.orderBook.asks[i] &&
<div className="order-book-data ask" >
<Clickable
onClick={event => {
event.stopPropagation();
outcome.trade.updateTradeOrder(outcome.id, undefined, outcome.orderBook.asks[i].price.value);
}}
>
<ValueDenomination className="price" {...outcome.orderBook.asks[i].price} />
</Clickable>
<span className="shares-at">@</span>
<Clickable
onClick={event => {
event.stopPropagation();
outcome.trade.updateTradeOrder(outcome.id, outcome.orderBook.asks[i].shares.value, outcome.orderBook.asks[i].price.value, p.constants.BID);
}}
>
<ValueDenomination className="shares" {...outcome.orderBook.asks[i].shares} />
</Clickable>
</div>
}
</td>
<td colSpan="5"></td>
</tr>
);
}
return null;
});
return null;
});
return tableRows;
};
return (
<tbody className="trade-panel-body">
{itemRows(p.outcomes, p.sideOptions)}
<tbody
id={`${p.outcome.name}-${p.outcome.id}`}
className="trade-panel-body"
>
<TradePanelRowOutcome
outcome={p.outcome}
sideOptions={p.sideOptions}
updateSelectedOutcome={p.updateSelectedOutcome}
orderSides={p.orderSides}
/>
{orderBookRows}
</tbody>

@@ -173,8 +39,9 @@ );

TradePanelBody.propTypes = {
outcomes: React.PropTypes.array,
outcome: React.PropTypes.object,
sideOptions: React.PropTypes.array,
selectedOutcomeID: React.PropTypes.string,
updateSelectedOutcome: React.PropTypes.func
updateSelectedOutcome: React.PropTypes.func,
orderSides: React.PropTypes.object
};
export default TradePanelBody;
import React from 'react';
import classnames from 'classnames';
import ValueDenomination from '../../../modules/common/components/value-denomination';
import TradePanelRowSummary from '../../../modules/trade/components/trade-panel-row-summary';
const TradePanelFooter = (p) => {
const transactions = [];
p.summary.tradeOrders.map((trade, i) => {
let type = null;
switch (trade.type) {
case p.constants.BID:
type = 'BUY';
break;
case p.constants.ASK:
type = 'SELL';
break;
default:
break;
}
transactions.push(
<tr
key={`${trade.data.outcomeName}${i}`}
className="trade-panel-row"
>
<td className="outcome-name">{trade.data.outcomeName}</td>
<td colSpan="2" >
<div className="individual-transaction-summary" >
<span className="transaction-type">{type}</span>
<div className="transaction-shares">
<ValueDenomination className="shares" {...trade.shares} />
</div>
<span className="shares-at">@</span>
<div className="transaction-price">
<ValueDenomination className="price" {...trade.ether} />
</div>
const TradePanelFooter = (p) => (
<tfoot className="transaction-summary">
<tr className={classnames('header-row', 'summary-title')}>
<td colSpan="9" >Trade Summary</td>
</tr>
<tr className={classnames('header-row', 'summary-headers')}>
<td>Outcomes</td>
<td colSpan="6">Transactions</td>
<td>Fee</td>
<td>Profit/Loss</td>
</tr>
{p.summary.tradeOrders.map((trade, i) => (
<TradePanelRowSummary
key={`${trade.data.outcomeName}-${i}`}
trade={trade}
orderSides={p.orderSides}
/>
))}
<tr className="summary-totals">
<td />
<td colSpan="2">
<div className="total-transaction-summary" >
<pre className="transaction-type"></pre>
<div className="transaction-shares">
<ValueDenomination className="shares" {...p.summary.totalShares} />
</div>
</td>
<td colSpan="4" />
<td className="fee-to-pay" >
<ValueDenomination {...trade.data.feeToPay} />
</td>
<td className="total-cost" >
{p.constants.BID === trade.type ? <ValueDenomination {...trade.etherNegative} /> : <ValueDenomination {...trade.ether} />}
</td>
</tr>
);
<pre className="shares-at"></pre>
<pre className="transaction-price"></pre>
</div>
</td>
<td colSpan="4" />
<td className="fee-to-pay" >
<ValueDenomination {...p.summary.feeToPay} />
</td>
<td className="total-cost" >
<ValueDenomination {...p.summary.totalEther} />
</td>
</tr>
</tfoot>
);
return null;
});
return (
<tfoot className="transaction-summary">
<tr className={classnames('header-row', 'summary-title')}>
<td colSpan="9" >Trade Summary</td>
</tr>
<tr className={classnames('header-row', 'summary-headers')}>
<td>Outcomes</td>
<td colSpan="6">Transactions</td>
<td>Fee</td>
<td>Profit/Loss</td>
</tr>
{transactions}
<tr className="summary-totals">
<td />
<td colSpan="2">
<div className="total-transaction-summary" >
<pre className="transaction-type"></pre>
<div className="transaction-shares">
<ValueDenomination className="shares" {...p.summary.totalShares} />
</div>
<pre className="shares-at"></pre>
<pre className="transaction-price"></pre>
</div>
</td>
<td colSpan="4" />
<td className="fee-to-pay" >
<ValueDenomination {...p.summary.feeToPay} />
</td>
<td className="total-cost" >
<ValueDenomination {...p.summary.totalEther} />
</td>
</tr>
</tfoot>
);
};
TradePanelFooter.propTypes = {
summary: React.PropTypes.object,
constants: React.PropTypes.object
orderSides: React.PropTypes.object
};
export default TradePanelFooter;

@@ -13,15 +13,18 @@ import React from 'react';

<TradePanelHeader selectedOutcomeID={p.selectedOutcomeID} />
{p.outcomes.map(outcome => (
<TradePanelBody
key={`${outcome.name}`}
outcome={outcome}
sideOptions={p.sideOptions}
selectedOutcomeID={p.selectedOutcomeID}
updateSelectedOutcome={p.updateSelectedOutcome}
orderSides={p.orderSides}
/>
))}
{p.tradeOrders && !!p.tradeOrders.length &&
<TradePanelFooter
summary={p.tradeSummary}
constants={p.constants}
orderSides={p.orderSides}
/>
}
<TradePanelBody
outcomes={p.outcomes}
sideOptions={p.sideOptions}
selectedOutcomeID={p.selectedOutcomeID}
updateSelectedOutcome={p.updateSelectedOutcome}
constants={p.constants}
/>
</table>

@@ -38,3 +41,3 @@ <div className="place-trade-container">

>
Place Trade{p.tradeOrders && p.tradeOrders.length > 1 ? 's' : ''}
Place Trade
</button>

@@ -53,5 +56,5 @@ </div>

onSubmitPlaceTrade: React.PropTypes.func,
constants: React.PropTypes.object
orderSides: React.PropTypes.object
};
export default TradePanel;

@@ -58,3 +58,3 @@ import activePage from './selectors/active-page';

selectors.market = {}; // selected market
selectors.market = markets[0]; // selected market -- set to the first market for tests
selectors.sideOptions = [{ value: BID, label: 'Buy' }, { value: ASK, label: 'Sell' }];

@@ -61,0 +61,0 @@ selectors.selectedOutcome = {

@@ -46,3 +46,3 @@ import { makeNumber } from '../utils/make-number';

orderBook: {},
constants: {
orderSides: {
BID: constants.BID,

@@ -76,5 +76,9 @@ ASK: constants.ASK

const limitPrice = outcome.trade.limitPrice || 0;
const profitLoss = outcome.trade.profitLoss;
const profitLoss = outcome.trade.side === constants.BID ? -(numShares * limitPrice) : numShares * limitPrice;
const cost = numShares * limitPrice;
p.feeToPay += feeToPay;
p.totalShares += outcome.trade.side === constants.BID ? numShares : -numShares;
p.totalEther += outcome.trade.side === constants.BID ? -cost : cost;
p.tradeOrders.push({

@@ -84,3 +88,4 @@ type: outcome.trade.side,

ether: makeNumber(limitPrice, 'eth'),
profitLoss,
feeToPay: makeNumber(feeToPay, 'eth'),
profitLoss: makeNumber(profitLoss, 'eth'),
data: {

@@ -91,5 +96,2 @@ outcomeName: outcome.name,

});
p.feeToPay += feeToPay;
p.totalShares += outcome.trade.side === constants.BID ? numShares : -numShares;
p.totalEther += outcome.trade.side === constants.BID ? -cost : cost;

@@ -100,3 +102,3 @@ return p;

tots.feeToPay = makeNumber(tots.feeToPay, 'eth');
tots.totalShares = makeNumber(tots.totalShares);
tots.totalShares = makeNumber(tots.totalShares, 'Shares');
tots.totalEther = makeNumber(tots.totalEther, 'eth');

@@ -284,4 +286,5 @@ tots.totalFees = makeNumber(tots.totalFees);

const outcome = m.outcomes.find((outcome) => outcome.id === outcomeId);
if (typeof shares !== 'undefined') {
outcome.trade.numShares = side === constants.BID ? shares : -shares;
outcome.trade.numShares = shares;
}

@@ -288,0 +291,0 @@ if (typeof limitPrice !== 'undefined') {

@@ -444,2 +444,3 @@ import { assert } from 'chai';

describe(`tradeOrder shape for ${i}`, () => {
describe('shares', () => {

@@ -452,11 +453,31 @@ it('should be defined', () => {

});
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');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.shares)
});
});
describe('sharesNegative', () => {
it('should be defined', () => {
assert.isDefined(trade.sharesNegative, 'shares is not defined');
});
it('should be an object', () => {
assert.isObject(trade.sharesNegative, 'shares is not an object');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.sharesNegative)
});
});
describe('limitPrice', () => {
it('should be defined', () => {
assert.isDefined(trade.limitPrice , `limitPrice isn't defined`);
});
it('should be a number', () => {
assert.isNumber(trade.limitPrice, `limitPrice isn't a number`);
});
});
describe('ether', () => {

@@ -470,12 +491,50 @@ it('should be defined', () => {

});
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');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.ether)
});
});
describe('etherNegative', () => {
it('should be defined', () => {
assert.isDefined(trade.etherNegative, 'etherNegative is not defined');
});
it('should be an object', () => {
assert.isObject(trade.etherNegative, 'etherNegative is not an object');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.etherNegative)
});
});
describe('feeToPay', () => {
it('should be defined', () => {
assert.isDefined(trade.feeToPay, 'feeToPay is not defined');
});
it('should be an object', () => {
assert.isObject(trade.feeToPay, 'feeToPay is not an object');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.feeToPay)
});
});
describe('profitLoss', () => {
it('should be defined', () => {
assert.isDefined(trade.profitLoss, 'profitLoss is not defined');
});
it('should be an object', () => {
assert.isObject(trade.profitLoss, 'profitLoss is not an object');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.profitLoss)
});
});
describe('gas', () => {

@@ -499,2 +558,66 @@ it('should be defined', () => {

});
describe('data', () => {
it('should be defined', () => {
assert.isDefined(trade.data, 'data is not defined');
});
it('should be an object', () => {
assert.isObject(trade.data, 'data is not an object');
});
describe('marketID', () => {
it('should be defined', () => {
assert.isDefined(trade.data.marketID, `marketID is not defined`);
});
it('should be a string', () => {
assert.isString(trade.data.marketID, `marketID is not a string`);
});
});
describe('outcomeID', () => {
it('should be defined', () => {
assert.isDefined(trade.data.outcomeID, `outcomeID is not defined`);
});
it('should be a string', () => {
assert.isString(trade.data.outcomeID, `outcomeID is not a string`);
});
});
describe('marketDescription', () => {
it('should be defined', () => {
assert.isDefined(trade.data.marketDescription, `marketDescription is not defined`);
});
it('should be a string', () => {
assert.isString(trade.data.marketDescription, `marketDescription is not a string`);
});
});
describe('outcomeName', () => {
it('should be defined', () => {
assert.isDefined(trade.data.outcomeName, `outcomeName is not defined`);
});
it('should be a string', () => {
assert.isString(trade.data.outcomeName, `outcomeName is not a string`);
});
});
describe('avgPrice', () => {
it('should be defined', () => {
assert.isDefined(trade.data.avgPrice, 'avgPrice is not defined');
});
it('should be an object', () => {
assert.isObject(trade.data.avgPrice, 'avgPrice is not an object');
});
it('should have the correct shape', () => {
assertFormattedNumber(trade.data.avgPrice)
});
});
});
});

@@ -653,11 +776,11 @@ });

describe('constants', () => {
let constants = market.constants;
describe('orderSides', () => {
let orderSides = market.orderSides;
it('should receive constants and be an object', () => {
assert.isDefined(constants, 'market.constants is not defined');
assert.isDefined(orderSides, 'market.orderSides is not defined');
});
it('should be an object', () => {
assert.isObject(constants, 'market.constatn is not an object');
assert.isObject(orderSides, 'market.orderSides is not an object');
});

@@ -667,7 +790,7 @@

it('should exist', () => {
assert.isDefined(constants.BID, 'BID is not defined');
assert.isDefined(orderSides.BID, 'BID is not defined');
});
it("should be a string + equal 'bid'", () => {
assert.strictEqual(constants.BID, 'bid', "BID is not strictly equal to 'bid'");
assert.strictEqual(orderSides.BID, 'bid', "BID is not strictly equal to 'bid'");
});

@@ -678,7 +801,7 @@ });

it('should exist', () => {
assert.isDefined(constants.ASK, 'ASK is not defined');
assert.isDefined(orderSides.ASK, 'ASK is not defined');
});
it("should be a string + equal 'ask'", () => {
assert.strictEqual(constants.ASK, 'ask', "ASK is not strictly equal to 'ask'");
assert.strictEqual(orderSides.ASK, 'ask', "ASK is not strictly equal to 'ask'");
});

@@ -688,2 +811,14 @@ });

});
describe('onSubmitPlaceTrade', () => {
let onSubmitPlaceTrade = market.onSubmitPlaceTrade;
it('should exist', () => {
assert.isDefined(onSubmitPlaceTrade, `onSubmitPlaceTrade isn't a function`);
});
it('should be a function', () => {
assert.isFunction(onSubmitPlaceTrade, `onSubmitPlaceTrade isn't a function`);
});
});
});

@@ -690,0 +825,0 @@ }

@@ -5,4 +5,6 @@ import { assert } from 'chai';

assert.isObject(selectedOutcome, `selectedOutcome isn't an object`);
assert.isDefined(selectedOutcome.selectedOutcomeID, `selectedOutcome isn't an object`);
assert.isDefined(selectedOutcome.selectedOutcomeID, `selectedOutcome isn't defined`);
assert.isFunction(selectedOutcome.updateSelectedOutcome, `updateSelectedOutcome isn't a function`);
assert.isDefined(selectedOutcome.updateSelectedOutcome, `updateSelectedOutcome isn't defined`);
};
import { assert } from 'chai';
export default function(sideOptions) {
describe('augur-ui-react-components trade sideOptions state', () => {
describe('sideOptions', () => {
it('should exist', () => {
assert.isDefined(sideOptions, 'outcomes is not defined');
assert.isDefined(sideOptions, `sideOptions isn't defined`);
});
it('should be an array', () => {
assert.isArray(sideOptions, 'outcomes is not an array');
assert.isArray(sideOptions, `sideOptions isn't an array`);
});
sideOptions.forEach(option => {
describe('option', () => {
it('should be an object', () => {
assert.isObject(option, `option isn't an object`);
});
describe('value', () => {
it('should exist', () => {
assert.isDefined(option.value, `value isn't defined`);
});
it('should be a string', () => {
assert.isString(option.value, `value isn't a string`);
});
});
describe('label', () => {
it('should exist', () => {
assert.isDefined(option.label, `label isn't defined`);
});
it('should be a string', () => {
assert.isString(option.label, `label isn't a string`);
});
});
});
});
});
}

@@ -7,2 +7,2 @@ import selectors from '../src/selectors';

assertions[selectorKey](selectors[selectorKey]);
});
});

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc