From 1233c33116a389f34ac90768c5ef43c8bbfbf514 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Feb 2018 16:23:20 +0100 Subject: Address feedback --- packages/website/ts/components/fill_order.tsx | 71 ++++++++++------------ .../generate_order/generate_order_form.tsx | 17 +++--- packages/website/ts/components/portal.tsx | 3 +- packages/website/ts/components/visual_order.tsx | 2 - 4 files changed, 43 insertions(+), 50 deletions(-) (limited to 'packages/website/ts/components') diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx index 4252747ec..2582581b1 100644 --- a/packages/website/ts/components/fill_order.tsx +++ b/packages/website/ts/components/fill_order.tsx @@ -19,7 +19,7 @@ import { Identicon } from 'ts/components/ui/identicon'; import { VisualOrder } from 'ts/components/visual_order'; import { Dispatcher } from 'ts/redux/dispatcher'; import { orderSchema } from 'ts/schemas/order_schema'; -import { SchemaValidator } from 'ts/schemas/validator'; +import { validator } from 'ts/schemas/validator'; import { AlertTypes, BlockchainErrs, Order, Token, TokenByAddress, WebsitePaths } from 'ts/types'; import { colors } from 'ts/utils/colors'; import { constants } from 'ts/utils/constants'; @@ -59,7 +59,6 @@ interface FillOrderState { } export class FillOrder extends React.Component { - private _validator: SchemaValidator; private _isUnmounted: boolean; constructor(props: FillOrderProps) { super(props); @@ -82,7 +81,6 @@ export class FillOrder extends React.Component { isConfirmingTokenTracking: false, tokensToTrack: [], }; - this._validator = new SchemaValidator(); } public componentWillMount() { if (!_.isEmpty(this.state.orderJSON)) { @@ -199,9 +197,6 @@ export class FillOrder extends React.Component { amount: this.props.orderFillAmount, symbol: takerToken.symbol, }; - const orderTaker = !_.isEmpty(this.state.parsedOrder.signedOrder.taker) - ? this.state.parsedOrder.signedOrder.taker - : this.props.userAddress; const parsedOrderExpiration = new BigNumber(this.state.parsedOrder.signedOrder.expirationUnixTimestampSec); const exchangeRate = orderMakerAmount.div(orderTakerAmount); @@ -236,8 +231,6 @@ export class FillOrder extends React.Component {
{ let orderHash: string; try { const order = JSON.parse(orderJSON); - const validationResult = this._validator.validate(order, orderSchema); + const validationResult = validator.validate(order, orderSchema); if (validationResult.errors.length > 0) { orderJSONErrMsg = 'Submitted order JSON is not a valid order'; utils.consoleLog(`Unexpected order JSON validation error: ${validationResult.errors.join(', ')}`); @@ -415,7 +408,6 @@ export class FillOrder extends React.Component { } parsedOrder = order; - const exchangeContractAddr = this.props.blockchain.getExchangeContractAddressIfExists(); const makerAmount = new BigNumber(parsedOrder.signedOrder.makerTokenAmount); const takerAmount = new BigNumber(parsedOrder.signedOrder.takerTokenAmount); const expiration = new BigNumber(parsedOrder.signedOrder.expirationUnixTimestampSec); @@ -441,6 +433,7 @@ export class FillOrder extends React.Component { }; orderHash = ZeroEx.getOrderHashHex(zeroExOrder); + const exchangeContractAddr = this.props.blockchain.getExchangeContractAddressIfExists(); const signature = parsedOrder.signedOrder.ecSignature; const isValidSignature = ZeroEx.isValidSignature(orderHash, signature, parsedOrder.signedOrder.maker); if (exchangeContractAddr !== parsedOrder.signedOrder.exchangeContractAddress) { @@ -525,20 +518,21 @@ export class FillOrder extends React.Component { globalErrMsg = 'You must specify a fill amount'; } - const signedOrder = this.props.blockchain.portalOrderToSignedOrder( - parsedOrder.signedOrder.maker, - parsedOrder.signedOrder.taker, - parsedOrder.signedOrder.makerTokenAddress, - parsedOrder.signedOrder.takerTokenAddress, - new BigNumber(parsedOrder.signedOrder.makerTokenAmount), - new BigNumber(parsedOrder.signedOrder.takerTokenAmount), - new BigNumber(parsedOrder.signedOrder.makerFee), - new BigNumber(parsedOrder.signedOrder.takerFee), - new BigNumber(this.state.parsedOrder.signedOrder.expirationUnixTimestampSec), - parsedOrder.signedOrder.feeRecipient, - parsedOrder.signedOrder.ecSignature, - new BigNumber(parsedOrder.signedOrder.salt), - ); + const signedOrder = { + exchangeContractAddress: this.props.blockchain.getExchangeContractAddressIfExists(), + maker: parsedOrder.signedOrder.maker, + taker: _.isEmpty(parsedOrder.signedOrder.taker) ? constants.NULL_ADDRESS : parsedOrder.signedOrder.taker, + makerTokenAddress: parsedOrder.signedOrder.makerTokenAddress, + takerTokenAddress: parsedOrder.signedOrder.takerTokenAddress, + makerTokenAmount: new BigNumber(parsedOrder.signedOrder.makerTokenAmount), + takerTokenAmount: new BigNumber(parsedOrder.signedOrder.takerTokenAmount), + makerFee: new BigNumber(parsedOrder.signedOrder.makerFee), + takerFee: new BigNumber(parsedOrder.signedOrder.takerFee), + expirationUnixTimestampSec: new BigNumber(this.state.parsedOrder.signedOrder.expirationUnixTimestampSec), + feeRecipient: parsedOrder.signedOrder.feeRecipient, + ecSignature: parsedOrder.signedOrder.ecSignature, + salt: new BigNumber(parsedOrder.signedOrder.salt), + }; if (_.isEmpty(globalErrMsg)) { try { await this.props.blockchain.validateFillOrderThrowIfInvalidAsync( @@ -627,20 +621,21 @@ export class FillOrder extends React.Component { const takerTokenAmount = new BigNumber(parsedOrder.signedOrder.takerTokenAmount); - const signedOrder = this.props.blockchain.portalOrderToSignedOrder( - parsedOrder.signedOrder.maker, - parsedOrder.signedOrder.taker, - parsedOrder.signedOrder.makerTokenAddress, - parsedOrder.signedOrder.takerTokenAddress, - new BigNumber(parsedOrder.signedOrder.makerTokenAmount), - takerTokenAmount, - new BigNumber(parsedOrder.signedOrder.makerFee), - new BigNumber(parsedOrder.signedOrder.takerFee), - new BigNumber(this.state.parsedOrder.signedOrder.expirationUnixTimestampSec), - parsedOrder.signedOrder.feeRecipient, - parsedOrder.signedOrder.ecSignature, - new BigNumber(parsedOrder.signedOrder.salt), - ); + const signedOrder = { + exchangeContractAddress: this.props.blockchain.getExchangeContractAddressIfExists(), + maker: parsedOrder.signedOrder.maker, + taker: parsedOrder.signedOrder.taker, + makerTokenAddress: parsedOrder.signedOrder.makerTokenAddress, + takerTokenAddress: parsedOrder.signedOrder.takerTokenAddress, + makerTokenAmount: new BigNumber(parsedOrder.signedOrder.makerTokenAmount), + takerTokenAmount: new BigNumber(parsedOrder.signedOrder.takerTokenAmount), + makerFee: new BigNumber(parsedOrder.signedOrder.makerFee), + takerFee: new BigNumber(parsedOrder.signedOrder.takerFee), + expirationUnixTimestampSec: new BigNumber(this.state.parsedOrder.signedOrder.expirationUnixTimestampSec), + feeRecipient: parsedOrder.signedOrder.feeRecipient, + ecSignature: parsedOrder.signedOrder.ecSignature, + salt: new BigNumber(parsedOrder.signedOrder.salt), + }; const orderHash = ZeroEx.getOrderHashHex(signedOrder); const unavailableTakerAmount = await this.props.blockchain.getUnavailableTakerAmountAsync(orderHash); const availableTakerTokenAmount = takerTokenAmount.minus(unavailableTakerAmount); diff --git a/packages/website/ts/components/generate_order/generate_order_form.tsx b/packages/website/ts/components/generate_order/generate_order_form.tsx index 5f1cf3c8e..fcabd4844 100644 --- a/packages/website/ts/components/generate_order/generate_order_form.tsx +++ b/packages/website/ts/components/generate_order/generate_order_form.tsx @@ -18,7 +18,7 @@ import { LifeCycleRaisedButton } from 'ts/components/ui/lifecycle_raised_button' import { SwapIcon } from 'ts/components/ui/swap_icon'; import { Dispatcher } from 'ts/redux/dispatcher'; import { orderSchema } from 'ts/schemas/order_schema'; -import { SchemaValidator } from 'ts/schemas/validator'; +import { validator } from 'ts/schemas/validator'; import { AlertTypes, BlockchainErrs, HashData, Side, SideToAssetToken, Token, TokenByAddress } from 'ts/types'; import { colors } from 'ts/utils/colors'; import { constants } from 'ts/utils/constants'; @@ -55,7 +55,6 @@ interface GenerateOrderFormState { } export class GenerateOrderForm extends React.Component { - private _validator: SchemaValidator; constructor(props: GenerateOrderFormProps) { super(props); this.state = { @@ -63,7 +62,6 @@ export class GenerateOrderForm extends React.Component \ specified, anyone is able to fill it.'; const exchangeContractIfExists = this.props.blockchain.getExchangeContractAddressIfExists(); + const initialTakerAddress = + this.props.orderTakerAddress === ZeroEx.NULL_ADDRESS ? '' : this.props.orderTakerAddress; return (

Generate an order

@@ -159,7 +159,7 @@ export class GenerateOrderForm extends React.Component
@@ -317,7 +317,7 @@ export class GenerateOrderForm extends React.Component 0) { globalErrMsg = 'Order signing failed. Please refresh and try again'; utils.consoleLog(`Unexpected error occured: Order validation failed: @@ -356,7 +356,8 @@ export class GenerateOrderForm extends React.Component { return undefined; } - const validator = new SchemaValidator(); const order = JSON.parse(decodeURIComponent(orderPair[1])); const validationResult = validator.validate(order, orderSchema); if (validationResult.errors.length > 0) { diff --git a/packages/website/ts/components/visual_order.tsx b/packages/website/ts/components/visual_order.tsx index 092954086..ec2d47f39 100644 --- a/packages/website/ts/components/visual_order.tsx +++ b/packages/website/ts/components/visual_order.tsx @@ -8,8 +8,6 @@ import { utils } from 'ts/utils/utils'; const PRECISION = 5; interface VisualOrderProps { - orderTakerAddress: string; - orderMakerAddress: string; makerAssetToken: AssetToken; takerAssetToken: AssetToken; makerToken: Token; -- cgit v1.2.3