aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2018-02-09 16:27:08 +0800
committerGitHub <noreply@github.com>2018-02-09 16:27:08 +0800
commit936f6ac10fe55257d846204ce4e5bd39ca27c78d (patch)
treef76cca84a55f979103a027282b289693a1f78491 /packages/website/ts
parent7e04c4f24b789a2ce8f4a5884212cfb1e508b508 (diff)
parent43cf8d30bdab025cdcda888897d35b25ad455031 (diff)
downloaddexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.tar
dexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.tar.gz
dexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.tar.bz2
dexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.tar.lz
dexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.tar.xz
dexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.tar.zst
dexon-sol-tools-936f6ac10fe55257d846204ce4e5bd39ca27c78d.zip
Merge pull request #379 from 0xProject/portal_json
Make portal order JSON compatible with 0x.js
Diffstat (limited to 'packages/website/ts')
-rw-r--r--packages/website/ts/blockchain.ts57
-rw-r--r--packages/website/ts/components/fill_order.tsx147
-rw-r--r--packages/website/ts/components/fill_order_json.tsx7
-rw-r--r--packages/website/ts/components/generate_order/generate_order_form.tsx38
-rw-r--r--packages/website/ts/components/order_json.tsx12
-rw-r--r--packages/website/ts/components/portal.tsx7
-rw-r--r--packages/website/ts/components/visual_order.tsx2
-rw-r--r--packages/website/ts/containers/generate_order_form.tsx7
-rw-r--r--packages/website/ts/redux/dispatcher.ts8
-rw-r--r--packages/website/ts/redux/reducer.ts14
-rw-r--r--packages/website/ts/schemas/metadata_schema.ts9
-rw-r--r--packages/website/ts/schemas/order_schema.ts15
-rw-r--r--packages/website/ts/schemas/order_taker_schema.ts11
-rw-r--r--packages/website/ts/schemas/portal_order_schema.ts9
-rw-r--r--packages/website/ts/schemas/portal_token_metadata.ts (renamed from packages/website/ts/schemas/token_schema.ts)7
-rw-r--r--packages/website/ts/schemas/signature_data_schema.ts11
-rw-r--r--packages/website/ts/schemas/validator.ts27
-rw-r--r--packages/website/ts/types.ts45
-rw-r--r--packages/website/ts/utils/utils.ts47
19 files changed, 189 insertions, 291 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index 099efb405..db3872a32 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -2,6 +2,7 @@ import {
BlockParam,
BlockRange,
DecodedLogEvent,
+ ECSignature,
ExchangeContractEventArgs,
ExchangeEvents,
IndexedFilterValues,
@@ -35,10 +36,10 @@ import {
BlockchainErrs,
ContractInstance,
EtherscanLinkSuffixes,
+ Order as PortalOrder,
ProviderType,
Side,
SideToAssetToken,
- SignatureData,
Token,
TokenByAddress,
} from 'ts/types';
@@ -288,39 +289,24 @@ export class Blockchain {
}),
);
}
- public portalOrderToSignedOrder(
- maker: string,
- taker: string,
- makerTokenAddress: string,
- takerTokenAddress: string,
- makerTokenAmount: BigNumber,
- takerTokenAmount: BigNumber,
- makerFee: BigNumber,
- takerFee: BigNumber,
- expirationUnixTimestampSec: BigNumber,
- feeRecipient: string,
- signatureData: SignatureData,
- salt: BigNumber,
- ): SignedOrder {
- const ecSignature = signatureData;
+ public portalOrderToZeroExOrder(portalOrder: PortalOrder): SignedOrder {
const exchangeContractAddress = this.getExchangeContractAddressIfExists();
- const takerOrNullAddress = _.isEmpty(taker) ? constants.NULL_ADDRESS : taker;
- const signedOrder = {
- ecSignature,
+ const zeroExSignedOrder = {
exchangeContractAddress,
- expirationUnixTimestampSec,
- feeRecipient,
- maker,
- makerFee,
- makerTokenAddress,
- makerTokenAmount,
- salt,
- taker: takerOrNullAddress,
- takerFee,
- takerTokenAddress,
- takerTokenAmount,
+ maker: portalOrder.signedOrder.maker,
+ taker: portalOrder.signedOrder.taker,
+ makerTokenAddress: portalOrder.signedOrder.makerTokenAddress,
+ takerTokenAddress: portalOrder.signedOrder.takerTokenAddress,
+ makerTokenAmount: new BigNumber(portalOrder.signedOrder.makerTokenAmount),
+ takerTokenAmount: new BigNumber(portalOrder.signedOrder.takerTokenAmount),
+ makerFee: new BigNumber(portalOrder.signedOrder.makerFee),
+ takerFee: new BigNumber(portalOrder.signedOrder.takerFee),
+ expirationUnixTimestampSec: new BigNumber(portalOrder.signedOrder.expirationUnixTimestampSec),
+ feeRecipient: portalOrder.signedOrder.feeRecipient,
+ ecSignature: portalOrder.signedOrder.ecSignature,
+ salt: new BigNumber(portalOrder.signedOrder.salt),
};
- return signedOrder;
+ return zeroExSignedOrder;
}
public async fillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber): Promise<BigNumber> {
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
@@ -413,7 +399,7 @@ export class Blockchain {
return newTokenBalancePromise;
}
- public async signOrderHashAsync(orderHash: string): Promise<SignatureData> {
+ public async signOrderHashAsync(orderHash: string): Promise<ECSignature> {
utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');
const makerAddress = this._userAddress;
// If makerAddress is undefined, this means they have a web3 instance injected into their browser
@@ -436,11 +422,8 @@ export class Blockchain {
makerAddress,
shouldAddPersonalMessagePrefix,
);
- const signatureData = _.extend({}, ecSignature, {
- hash: orderHash,
- });
- this._dispatcher.updateSignatureData(signatureData);
- return signatureData;
+ this._dispatcher.updateECSignature(ecSignature);
+ return ecSignature;
}
public async mintTestTokensAsync(token: Token) {
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx
index 97f616be2..51e44134c 100644
--- a/packages/website/ts/components/fill_order.tsx
+++ b/packages/website/ts/components/fill_order.tsx
@@ -18,8 +18,8 @@ import { EthereumAddress } from 'ts/components/ui/ethereum_address';
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 { portalOrderSchema } from 'ts/schemas/portal_order_schema';
+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<FillOrderProps, FillOrderState> {
- private _validator: SchemaValidator;
private _isUnmounted: boolean;
constructor(props: FillOrderProps) {
super(props);
@@ -82,7 +81,6 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
isConfirmingTokenTracking: false,
tokensToTrack: [],
};
- this._validator = new SchemaValidator();
}
public componentWillMount() {
if (!_.isEmpty(this.state.orderJSON)) {
@@ -109,7 +107,6 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
<FillOrderJSON
blockchain={this.props.blockchain}
tokenByAddress={this.props.tokenByAddress}
- networkId={this.props.networkId}
orderJSON={this.state.orderJSON}
onFillOrderJSONChanged={this._onFillOrderJSONChanged.bind(this)}
/>
@@ -136,7 +133,6 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
<FillOrderJSON
blockchain={this.props.blockchain}
tokenByAddress={this.props.tokenByAddress}
- networkId={this.props.networkId}
orderJSON={this.state.orderJSON}
onFillOrderJSONChanged={this._onFillOrderJSONChanged.bind(this)}
/>
@@ -182,16 +178,16 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
);
}
private _renderVisualOrder() {
- const takerTokenAddress = this.state.parsedOrder.taker.token.address;
+ const takerTokenAddress = this.state.parsedOrder.signedOrder.takerTokenAddress;
const takerToken = this.props.tokenByAddress[takerTokenAddress];
- const orderTakerAmount = new BigNumber(this.state.parsedOrder.taker.amount);
- const orderMakerAmount = new BigNumber(this.state.parsedOrder.maker.amount);
+ const orderTakerAmount = new BigNumber(this.state.parsedOrder.signedOrder.takerTokenAmount);
+ const orderMakerAmount = new BigNumber(this.state.parsedOrder.signedOrder.makerTokenAmount);
const takerAssetToken = {
amount: orderTakerAmount.minus(this.state.unavailableTakerAmount),
symbol: takerToken.symbol,
};
- const fillToken = this.props.tokenByAddress[takerToken.address];
- const makerTokenAddress = this.state.parsedOrder.maker.token.address;
+ const fillToken = this.props.tokenByAddress[takerTokenAddress];
+ const makerTokenAddress = this.state.parsedOrder.signedOrder.makerTokenAddress;
const makerToken = this.props.tokenByAddress[makerTokenAddress];
const makerAssetToken = {
amount: orderMakerAmount.times(takerAssetToken.amount).div(orderTakerAmount),
@@ -201,10 +197,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
amount: this.props.orderFillAmount,
symbol: takerToken.symbol,
};
- const orderTaker = !_.isEmpty(this.state.parsedOrder.taker.address)
- ? this.state.parsedOrder.taker.address
- : this.props.userAddress;
- const parsedOrderExpiration = new BigNumber(this.state.parsedOrder.expiration);
+ const parsedOrderExpiration = new BigNumber(this.state.parsedOrder.signedOrder.expirationUnixTimestampSec);
const exchangeRate = orderMakerAmount.div(orderTakerAmount);
let orderReceiveAmount = 0;
@@ -213,7 +206,8 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
orderReceiveAmount = this._formatCurrencyAmount(orderReceiveAmountBigNumber, makerToken.decimals);
}
const isUserMaker =
- !_.isUndefined(this.state.parsedOrder) && this.state.parsedOrder.maker.address === this.props.userAddress;
+ !_.isUndefined(this.state.parsedOrder) &&
+ this.state.parsedOrder.signedOrder.maker === this.props.userAddress;
const expiryDate = utils.convertToReadableDateTimeFromUnixTimestamp(parsedOrderExpiration);
return (
<div className="pt3 pb1">
@@ -224,11 +218,11 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
Maker:
</div>
<div className="col col-2 pr1">
- <Identicon address={this.state.parsedOrder.maker.address} diameter={23} />
+ <Identicon address={this.state.parsedOrder.signedOrder.maker} diameter={23} />
</div>
<div className="col col-6">
<EthereumAddress
- address={this.state.parsedOrder.maker.address}
+ address={this.state.parsedOrder.signedOrder.maker}
networkId={this.props.networkId}
/>
</div>
@@ -237,8 +231,6 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
<div className="lg-px4 md-px4 sm-px0">
<div className="lg-px4 md-px4 sm-px1 pt1">
<VisualOrder
- orderTakerAddress={orderTaker}
- orderMakerAddress={this.state.parsedOrder.maker.address}
makerAssetToken={makerAssetToken}
takerAssetToken={takerAssetToken}
tokenByAddress={this.props.tokenByAddress}
@@ -361,15 +353,16 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
return;
}
- const makerTokenIfExists = this.props.tokenByAddress[this.state.parsedOrder.maker.token.address];
- const takerTokenIfExists = this.props.tokenByAddress[this.state.parsedOrder.taker.token.address];
+ const makerTokenIfExists = this.props.tokenByAddress[this.state.parsedOrder.signedOrder.makerTokenAddress];
+ const takerTokenIfExists = this.props.tokenByAddress[this.state.parsedOrder.signedOrder.takerTokenAddress];
- const tokensToTrack = [];
+ const tokensToTrack: Token[] = [];
const isUnseenMakerToken = _.isUndefined(makerTokenIfExists);
const isMakerTokenTracked = !_.isUndefined(makerTokenIfExists) && makerTokenIfExists.isTracked;
if (isUnseenMakerToken) {
tokensToTrack.push({
- ...this.state.parsedOrder.maker.token,
+ ...this.state.parsedOrder.metadata.makerToken,
+ address: this.state.parsedOrder.signedOrder.makerTokenAddress,
iconUrl: undefined,
isTracked: false,
isRegistered: false,
@@ -381,7 +374,8 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
const isTakerTokenTracked = !_.isUndefined(takerTokenIfExists) && takerTokenIfExists.isTracked;
if (isUnseenTakerToken) {
tokensToTrack.push({
- ...this.state.parsedOrder.taker.token,
+ ...this.state.parsedOrder.metadata.takerToken,
+ address: this.state.parsedOrder.signedOrder.takerTokenAddress,
iconUrl: undefined,
isTracked: false,
isRegistered: false,
@@ -403,9 +397,10 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
private async _validateFillOrderFireAndForgetAsync(orderJSON: string) {
let orderJSONErrMsg = '';
let parsedOrder: Order;
+ let orderHash: string;
try {
const order = JSON.parse(orderJSON);
- const validationResult = this._validator.validate(order, orderSchema);
+ const validationResult = validator.validate(order, portalOrderSchema);
if (validationResult.errors.length > 0) {
orderJSONErrMsg = 'Submitted order JSON is not a valid order';
utils.consoleLog(`Unexpected order JSON validation error: ${validationResult.errors.join(', ')}`);
@@ -413,41 +408,36 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
}
parsedOrder = order;
- const exchangeContractAddr = this.props.blockchain.getExchangeContractAddressIfExists();
- const makerAmount = new BigNumber(parsedOrder.maker.amount);
- const takerAmount = new BigNumber(parsedOrder.taker.amount);
- const expiration = new BigNumber(parsedOrder.expiration);
- const salt = new BigNumber(parsedOrder.salt);
- const parsedMakerFee = new BigNumber(parsedOrder.maker.feeAmount);
- const parsedTakerFee = new BigNumber(parsedOrder.taker.feeAmount);
+ const makerAmount = new BigNumber(parsedOrder.signedOrder.makerTokenAmount);
+ const takerAmount = new BigNumber(parsedOrder.signedOrder.takerTokenAmount);
+ const expiration = new BigNumber(parsedOrder.signedOrder.expirationUnixTimestampSec);
+ const salt = new BigNumber(parsedOrder.signedOrder.salt);
+ const parsedMakerFee = new BigNumber(parsedOrder.signedOrder.makerFee);
+ const parsedTakerFee = new BigNumber(parsedOrder.signedOrder.takerFee);
const zeroExOrder: ZeroExOrder = {
- exchangeContractAddress: parsedOrder.exchangeContract,
+ exchangeContractAddress: parsedOrder.signedOrder.exchangeContractAddress,
expirationUnixTimestampSec: expiration,
- feeRecipient: parsedOrder.feeRecipient,
- maker: parsedOrder.maker.address,
+ feeRecipient: parsedOrder.signedOrder.feeRecipient,
+ maker: parsedOrder.signedOrder.maker,
makerFee: parsedMakerFee,
- makerTokenAddress: parsedOrder.maker.token.address,
+ makerTokenAddress: parsedOrder.signedOrder.makerTokenAddress,
makerTokenAmount: makerAmount,
salt,
- taker: _.isEmpty(parsedOrder.taker.address) ? constants.NULL_ADDRESS : parsedOrder.taker.address,
+ taker: _.isEmpty(parsedOrder.signedOrder.taker)
+ ? constants.NULL_ADDRESS
+ : parsedOrder.signedOrder.taker,
takerFee: parsedTakerFee,
- takerTokenAddress: parsedOrder.taker.token.address,
+ takerTokenAddress: parsedOrder.signedOrder.takerTokenAddress,
takerTokenAmount: takerAmount,
};
- const orderHash = ZeroEx.getOrderHashHex(zeroExOrder);
+ orderHash = ZeroEx.getOrderHashHex(zeroExOrder);
- const signature = parsedOrder.signature;
- const isValidSignature = ZeroEx.isValidSignature(signature.hash, signature, parsedOrder.maker.address);
- if (this.props.networkId !== parsedOrder.networkId) {
- orderJSONErrMsg = `This order was made on another Ethereum network
- (id: ${parsedOrder.networkId}). Connect to this network to fill.`;
- parsedOrder = undefined;
- } else if (exchangeContractAddr !== parsedOrder.exchangeContract) {
- orderJSONErrMsg = 'This order was made using a deprecated 0x Exchange contract.';
- parsedOrder = undefined;
- } else if (orderHash !== signature.hash) {
- orderJSONErrMsg = 'Order hash does not match supplied plaintext values';
+ 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) {
+ orderJSONErrMsg = 'This order was made on another network or using a deprecated Exchange contract';
parsedOrder = undefined;
} else if (!isValidSignature) {
orderJSONErrMsg = 'Order signature is invalid';
@@ -478,13 +468,12 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
// Clear cache entry if user updates orderJSON to invalid entry
this.props.dispatcher.updateUserSuppliedOrderCache(undefined);
} else {
- const orderHash = parsedOrder.signature.hash;
unavailableTakerAmount = await this.props.blockchain.getUnavailableTakerAmountAsync(orderHash);
const isMakerTokenAddressInRegistry = await this.props.blockchain.isAddressInTokenRegistryAsync(
- parsedOrder.maker.token.address,
+ parsedOrder.signedOrder.makerTokenAddress,
);
const isTakerTokenAddressInRegistry = await this.props.blockchain.isAddressInTokenRegistryAsync(
- parsedOrder.taker.token.address,
+ parsedOrder.signedOrder.takerTokenAddress,
);
this.setState({
isMakerTokenAddressInRegistry,
@@ -529,20 +518,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
globalErrMsg = 'You must specify a fill amount';
}
- const signedOrder = this.props.blockchain.portalOrderToSignedOrder(
- parsedOrder.maker.address,
- parsedOrder.taker.address,
- parsedOrder.maker.token.address,
- parsedOrder.taker.token.address,
- new BigNumber(parsedOrder.maker.amount),
- new BigNumber(parsedOrder.taker.amount),
- new BigNumber(parsedOrder.maker.feeAmount),
- new BigNumber(parsedOrder.taker.feeAmount),
- new BigNumber(this.state.parsedOrder.expiration),
- parsedOrder.feeRecipient,
- parsedOrder.signature,
- new BigNumber(parsedOrder.salt),
- );
+ const signedOrder = this.props.blockchain.portalOrderToZeroExOrder(parsedOrder);
if (_.isEmpty(globalErrMsg)) {
try {
await this.props.blockchain.validateFillOrderThrowIfInvalidAsync(
@@ -551,7 +527,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
this.props.userAddress,
);
} catch (err) {
- globalErrMsg = utils.zeroExErrToHumanReadableErrMsg(err.message, parsedOrder.taker.address);
+ globalErrMsg = utils.zeroExErrToHumanReadableErrMsg(err.message, parsedOrder.signedOrder.taker);
}
}
if (!_.isEmpty(globalErrMsg)) {
@@ -562,7 +538,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
return;
}
const networkName = constants.NETWORK_NAME_BY_ID[this.props.networkId];
- const eventLabel = `${parsedOrder.taker.token.symbol}-${networkName}`;
+ const eventLabel = `${parsedOrder.metadata.takerToken.symbol}-${networkName}`;
try {
const orderFilledAmount: BigNumber = await this.props.blockchain.fillOrderAsync(
signedOrder,
@@ -572,7 +548,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
category: 'Portal',
action: 'Fill Order Success',
label: eventLabel,
- value: parsedOrder.taker.amount,
+ value: parsedOrder.signedOrder.takerTokenAmount,
});
// After fill completes, let's force fetch the token balances
this.props.dispatcher.forceTokenStateRefetch();
@@ -591,7 +567,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
category: 'Portal',
action: 'Fill Order Failure',
label: eventLabel,
- value: parsedOrder.taker.amount,
+ value: parsedOrder.signedOrder.takerTokenAmount,
});
const errMsg = `${err}`;
if (utils.didUserDenyWeb3Request(errMsg)) {
@@ -618,7 +594,6 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
});
const parsedOrder = this.state.parsedOrder;
- const orderHash = parsedOrder.signature.hash;
const takerAddress = this.props.userAddress;
if (_.isUndefined(takerAddress)) {
@@ -630,28 +605,16 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
}
let globalErrMsg = '';
- const takerTokenAmount = new BigNumber(parsedOrder.taker.amount);
+ const takerTokenAmount = new BigNumber(parsedOrder.signedOrder.takerTokenAmount);
- const signedOrder = this.props.blockchain.portalOrderToSignedOrder(
- parsedOrder.maker.address,
- parsedOrder.taker.address,
- parsedOrder.maker.token.address,
- parsedOrder.taker.token.address,
- new BigNumber(parsedOrder.maker.amount),
- takerTokenAmount,
- new BigNumber(parsedOrder.maker.feeAmount),
- new BigNumber(parsedOrder.taker.feeAmount),
- new BigNumber(this.state.parsedOrder.expiration),
- parsedOrder.feeRecipient,
- parsedOrder.signature,
- new BigNumber(parsedOrder.salt),
- );
+ const signedOrder = this.props.blockchain.portalOrderToZeroExOrder(parsedOrder);
+ const orderHash = ZeroEx.getOrderHashHex(signedOrder);
const unavailableTakerAmount = await this.props.blockchain.getUnavailableTakerAmountAsync(orderHash);
const availableTakerTokenAmount = takerTokenAmount.minus(unavailableTakerAmount);
try {
await this.props.blockchain.validateCancelOrderThrowIfInvalidAsync(signedOrder, availableTakerTokenAmount);
} catch (err) {
- globalErrMsg = utils.zeroExErrToHumanReadableErrMsg(err.message, parsedOrder.taker.address);
+ globalErrMsg = utils.zeroExErrToHumanReadableErrMsg(err.message, parsedOrder.signedOrder.taker);
}
if (!_.isEmpty(globalErrMsg)) {
this.setState({
@@ -661,7 +624,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
return;
}
const networkName = constants.NETWORK_NAME_BY_ID[this.props.networkId];
- const eventLabel = `${parsedOrder.maker.token.symbol}-${networkName}`;
+ const eventLabel = `${parsedOrder.metadata.makerToken.symbol}-${networkName}`;
try {
await this.props.blockchain.cancelOrderAsync(signedOrder, availableTakerTokenAmount);
this.setState({
@@ -674,7 +637,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
category: 'Portal',
action: 'Cancel Order Success',
label: eventLabel,
- value: parsedOrder.maker.amount,
+ value: parsedOrder.signedOrder.makerTokenAmount,
});
return;
} catch (err) {
@@ -689,7 +652,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
category: 'Portal',
action: 'Cancel Order Failure',
label: eventLabel,
- value: parsedOrder.maker.amount,
+ value: parsedOrder.signedOrder.makerTokenAmount,
});
globalErrMsg = 'Failed to cancel order, please refresh and try again';
utils.consoleLog(`${err}`);
diff --git a/packages/website/ts/components/fill_order_json.tsx b/packages/website/ts/components/fill_order_json.tsx
index f8e43481a..7d5351ec4 100644
--- a/packages/website/ts/components/fill_order_json.tsx
+++ b/packages/website/ts/components/fill_order_json.tsx
@@ -12,7 +12,6 @@ import { utils } from 'ts/utils/utils';
interface FillOrderJSONProps {
blockchain: Blockchain;
tokenByAddress: TokenByAddress;
- networkId: number;
orderJSON: string;
onFillOrderJSONChanged: (event: any) => void;
}
@@ -34,8 +33,7 @@ export class FillOrderJSON extends React.Component<FillOrderJSONProps, FillOrder
},
};
const hintOrderExpiryTimestamp = utils.initialOrderExpiryUnixTimestampSec();
- const hintSignatureData = {
- hash: '0xf965a9978a0381ab58f5a2408ad967c...',
+ const hintECSignature = {
r: '0xf01103f759e2289a28593eaf22e5820032...',
s: '937862111edcba395f8a9e0cc1b2c5e12320...',
v: 27,
@@ -43,7 +41,6 @@ export class FillOrderJSON extends React.Component<FillOrderJSONProps, FillOrder
const hintSalt = ZeroEx.generatePseudoRandomSalt();
const feeRecipient = constants.NULL_ADDRESS;
const hintOrder = utils.generateOrder(
- this.props.networkId,
exchangeContract,
hintSideToAssetToken,
hintOrderExpiryTimestamp,
@@ -52,7 +49,7 @@ export class FillOrderJSON extends React.Component<FillOrderJSONProps, FillOrder
constants.MAKER_FEE,
constants.TAKER_FEE,
feeRecipient,
- hintSignatureData,
+ hintECSignature,
this.props.tokenByAddress,
hintSalt,
);
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 c9417f5a4..a3f222784 100644
--- a/packages/website/ts/components/generate_order/generate_order_form.tsx
+++ b/packages/website/ts/components/generate_order/generate_order_form.tsx
@@ -1,4 +1,4 @@
-import { Order, ZeroEx } from '0x.js';
+import { ECSignature, Order, ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import Dialog from 'material-ui/Dialog';
@@ -17,18 +17,9 @@ import { HelpTooltip } from 'ts/components/ui/help_tooltip';
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 {
- AlertTypes,
- BlockchainErrs,
- HashData,
- Side,
- SideToAssetToken,
- SignatureData,
- Token,
- TokenByAddress,
-} from 'ts/types';
+import { portalOrderSchema } from 'ts/schemas/portal_order_schema';
+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';
import { errorReporter } from 'ts/utils/error_reporter';
@@ -49,7 +40,7 @@ interface GenerateOrderFormProps {
orderExpiryTimestamp: BigNumber;
networkId: number;
userAddress: string;
- orderSignatureData: SignatureData;
+ orderECSignature: ECSignature;
orderTakerAddress: string;
orderSalt: BigNumber;
sideToAssetToken: SideToAssetToken;
@@ -64,7 +55,6 @@ interface GenerateOrderFormState {
}
export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, GenerateOrderFormState> {
- private _validator: SchemaValidator;
constructor(props: GenerateOrderFormProps) {
super(props);
this.state = {
@@ -72,7 +62,6 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
shouldShowIncompleteErrs: false,
signingState: SigningState.UNSIGNED,
};
- this._validator = new SchemaValidator();
}
public componentDidMount() {
window.scrollTo(0, 0);
@@ -88,6 +77,8 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
allowed to fill this order. If no taker is<br> \
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 (
<div className="clearfix mb2 lg-px4 md-px4 sm-px2">
<h3>Generate an order</h3>
@@ -168,7 +159,7 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
<div className="pt1 flex mx-auto">
<IdenticonAddressInput
label="Taker"
- initialAddress={this.props.orderTakerAddress}
+ initialAddress={initialTakerAddress}
updateOrderAddress={this._updateOrderAddress.bind(this)}
/>
<div className="pt3">
@@ -209,14 +200,13 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
<OrderJSON
exchangeContractIfExists={exchangeContractIfExists}
orderExpiryTimestamp={this.props.orderExpiryTimestamp}
- orderSignatureData={this.props.orderSignatureData}
+ orderECSignature={this.props.orderECSignature}
orderTakerAddress={this.props.orderTakerAddress}
orderMakerAddress={this.props.userAddress}
orderSalt={this.props.orderSalt}
orderMakerFee={this.props.hashData.makerFee}
orderTakerFee={this.props.hashData.takerFee}
orderFeeRecipient={this.props.hashData.feeRecipientAddress}
- networkId={this.props.networkId}
sideToAssetToken={this.props.sideToAssetToken}
tokenByAddress={this.props.tokenByAddress}
/>
@@ -327,9 +317,8 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
let globalErrMsg = '';
try {
- const signatureData = await this.props.blockchain.signOrderHashAsync(orderHash);
+ const ecSignature = await this.props.blockchain.signOrderHashAsync(orderHash);
const order = utils.generateOrder(
- this.props.networkId,
exchangeContractAddr,
this.props.sideToAssetToken,
hashData.orderExpiryTimestamp,
@@ -338,11 +327,11 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
hashData.makerFee,
hashData.takerFee,
hashData.feeRecipientAddress,
- signatureData,
+ ecSignature,
this.props.tokenByAddress,
hashData.orderSalt,
);
- const validationResult = this._validator.validate(order, orderSchema);
+ const validationResult = validator.validate(order, portalOrderSchema);
if (validationResult.errors.length > 0) {
globalErrMsg = 'Order signing failed. Please refresh and try again';
utils.consoleLog(`Unexpected error occured: Order validation failed:
@@ -367,7 +356,8 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
}
private _updateOrderAddress(address?: string): void {
if (!_.isUndefined(address)) {
- this.props.dispatcher.updateOrderTakerAddress(address);
+ const normalizedAddress = _.isEmpty(address) ? ZeroEx.NULL_ADDRESS : address;
+ this.props.dispatcher.updateOrderTakerAddress(normalizedAddress);
}
}
}
diff --git a/packages/website/ts/components/order_json.tsx b/packages/website/ts/components/order_json.tsx
index 1b6b32a04..a5dd9ebc1 100644
--- a/packages/website/ts/components/order_json.tsx
+++ b/packages/website/ts/components/order_json.tsx
@@ -1,10 +1,11 @@
+import { ECSignature } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import Paper from 'material-ui/Paper';
import TextField from 'material-ui/TextField';
import * as React from 'react';
import { CopyIcon } from 'ts/components/ui/copy_icon';
-import { SideToAssetToken, SignatureData, TokenByAddress, WebsitePaths } from 'ts/types';
+import { SideToAssetToken, TokenByAddress, WebsitePaths } from 'ts/types';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
import { errorReporter } from 'ts/utils/error_reporter';
@@ -13,14 +14,13 @@ import { utils } from 'ts/utils/utils';
interface OrderJSONProps {
exchangeContractIfExists: string;
orderExpiryTimestamp: BigNumber;
- orderSignatureData: SignatureData;
+ orderECSignature: ECSignature;
orderTakerAddress: string;
orderMakerAddress: string;
orderSalt: BigNumber;
orderMakerFee: BigNumber;
orderTakerFee: BigNumber;
orderFeeRecipient: string;
- networkId: number;
sideToAssetToken: SideToAssetToken;
tokenByAddress: TokenByAddress;
}
@@ -40,7 +40,6 @@ export class OrderJSON extends React.Component<OrderJSONProps, OrderJSONState> {
}
public render() {
const order = utils.generateOrder(
- this.props.networkId,
this.props.exchangeContractIfExists,
this.props.sideToAssetToken,
this.props.orderExpiryTimestamp,
@@ -49,7 +48,7 @@ export class OrderJSON extends React.Component<OrderJSONProps, OrderJSONState> {
this.props.orderMakerFee,
this.props.orderTakerFee,
this.props.orderFeeRecipient,
- this.props.orderSignatureData,
+ this.props.orderECSignature,
this.props.tokenByAddress,
this.props.orderSalt,
);
@@ -162,7 +161,6 @@ You can see and fill it here: ${this.state.shareLink}`);
}
private _getOrderUrl() {
const order = utils.generateOrder(
- this.props.networkId,
this.props.exchangeContractIfExists,
this.props.sideToAssetToken,
this.props.orderExpiryTimestamp,
@@ -171,7 +169,7 @@ You can see and fill it here: ${this.state.shareLink}`);
this.props.orderMakerFee,
this.props.orderTakerFee,
this.props.orderFeeRecipient,
- this.props.orderSignatureData,
+ this.props.orderECSignature,
this.props.tokenByAddress,
this.props.orderSalt,
);
diff --git a/packages/website/ts/components/portal.tsx b/packages/website/ts/components/portal.tsx
index 92589f75c..0409f28c0 100644
--- a/packages/website/ts/components/portal.tsx
+++ b/packages/website/ts/components/portal.tsx
@@ -21,8 +21,8 @@ import { FlashMessage } from 'ts/components/ui/flash_message';
import { GenerateOrderForm } from 'ts/containers/generate_order_form';
import { localStorage } from 'ts/local_storage/local_storage';
import { Dispatcher } from 'ts/redux/dispatcher';
-import { orderSchema } from 'ts/schemas/order_schema';
-import { SchemaValidator } from 'ts/schemas/validator';
+import { portalOrderSchema } from 'ts/schemas/portal_order_schema';
+import { validator } from 'ts/schemas/validator';
import { BlockchainErrs, HashData, Order, ProviderType, ScreenWidths, TokenByAddress, WebsitePaths } from 'ts/types';
import { colors } from 'ts/utils/colors';
import { configs } from 'ts/utils/configs';
@@ -367,9 +367,8 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> {
return undefined;
}
- const validator = new SchemaValidator();
const order = JSON.parse(decodeURIComponent(orderPair[1]));
- const validationResult = validator.validate(order, orderSchema);
+ const validationResult = validator.validate(order, portalOrderSchema);
if (validationResult.errors.length > 0) {
utils.consoleLog(`Invalid shared order: ${validationResult.errors}`);
return undefined;
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;
diff --git a/packages/website/ts/containers/generate_order_form.tsx b/packages/website/ts/containers/generate_order_form.tsx
index 57863dbae..8c5deb690 100644
--- a/packages/website/ts/containers/generate_order_form.tsx
+++ b/packages/website/ts/containers/generate_order_form.tsx
@@ -1,3 +1,4 @@
+import { ECSignature } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
@@ -6,7 +7,7 @@ import { Blockchain } from 'ts/blockchain';
import { GenerateOrderForm as GenerateOrderFormComponent } from 'ts/components/generate_order/generate_order_form';
import { Dispatcher } from 'ts/redux/dispatcher';
import { State } from 'ts/redux/reducer';
-import { BlockchainErrs, HashData, SideToAssetToken, SignatureData, TokenByAddress } from 'ts/types';
+import { BlockchainErrs, HashData, SideToAssetToken, TokenByAddress } from 'ts/types';
interface GenerateOrderFormProps {
blockchain: Blockchain;
@@ -18,7 +19,7 @@ interface ConnectedState {
blockchainErr: BlockchainErrs;
blockchainIsLoaded: boolean;
orderExpiryTimestamp: BigNumber;
- orderSignatureData: SignatureData;
+ orderECSignature: ECSignature;
userAddress: string;
orderTakerAddress: string;
orderSalt: BigNumber;
@@ -32,7 +33,7 @@ const mapStateToProps = (state: State, ownProps: GenerateOrderFormProps): Connec
blockchainErr: state.blockchainErr,
blockchainIsLoaded: state.blockchainIsLoaded,
orderExpiryTimestamp: state.orderExpiryTimestamp,
- orderSignatureData: state.orderSignatureData,
+ orderECSignature: state.orderECSignature,
orderTakerAddress: state.orderTakerAddress,
orderSalt: state.orderSalt,
networkId: state.networkId,
diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts
index 87415b285..925f2aa29 100644
--- a/packages/website/ts/redux/dispatcher.ts
+++ b/packages/website/ts/redux/dispatcher.ts
@@ -1,3 +1,4 @@
+import { ECSignature } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import { Dispatch } from 'redux';
import { State } from 'ts/redux/reducer';
@@ -10,7 +11,6 @@ import {
ScreenWidths,
Side,
SideToAssetToken,
- SignatureData,
Token,
TokenByAddress,
} from 'ts/types';
@@ -148,10 +148,10 @@ export class Dispatcher {
type: ActionTypes.ForceTokenStateRefetch,
});
}
- public updateSignatureData(signatureData: SignatureData) {
+ public updateECSignature(ecSignature: ECSignature) {
this._dispatch({
- data: signatureData,
- type: ActionTypes.UpdateOrderSignatureData,
+ data: ecSignature,
+ type: ActionTypes.UpdateOrderECSignature,
});
}
public updateUserEtherBalance(balance: BigNumber) {
diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts
index 7b0b03dae..c2a21dc07 100644
--- a/packages/website/ts/redux/reducer.ts
+++ b/packages/website/ts/redux/reducer.ts
@@ -1,4 +1,4 @@
-import { ZeroEx } from '0x.js';
+import { ECSignature, ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as moment from 'moment';
@@ -11,7 +11,6 @@ import {
ScreenWidths,
Side,
SideToAssetToken,
- SignatureData,
TokenByAddress,
} from 'ts/types';
import { utils } from 'ts/utils/utils';
@@ -29,7 +28,7 @@ export interface State {
orderExpiryTimestamp: BigNumber;
orderFillAmount: BigNumber;
orderTakerAddress: string;
- orderSignatureData: SignatureData;
+ orderECSignature: ECSignature;
orderSalt: BigNumber;
nodeVersion: string;
screenWidth: ScreenWidths;
@@ -59,13 +58,12 @@ const INITIAL_STATE: State = {
networkId: undefined,
orderExpiryTimestamp: utils.initialOrderExpiryUnixTimestampSec(),
orderFillAmount: undefined,
- orderSignatureData: {
- hash: '',
+ orderECSignature: {
r: '',
s: '',
v: 27,
},
- orderTakerAddress: '',
+ orderTakerAddress: ZeroEx.NULL_ADDRESS,
orderSalt: ZeroEx.generatePseudoRandomSalt(),
nodeVersion: undefined,
screenWidth: utils.getScreenWidth(),
@@ -188,10 +186,10 @@ export function reducer(state: State = INITIAL_STATE, action: Action) {
lastForceTokenStateRefetch: moment().unix(),
};
- case ActionTypes.UpdateOrderSignatureData: {
+ case ActionTypes.UpdateOrderECSignature: {
return {
...state,
- orderSignatureData: action.data,
+ orderECSignature: action.data,
};
}
diff --git a/packages/website/ts/schemas/metadata_schema.ts b/packages/website/ts/schemas/metadata_schema.ts
new file mode 100644
index 000000000..cd4045d10
--- /dev/null
+++ b/packages/website/ts/schemas/metadata_schema.ts
@@ -0,0 +1,9 @@
+export const orderMetadataSchema = {
+ id: '/OrderMetadata',
+ properties: {
+ makerToken: { $ref: '/PortalTokenMetadata' },
+ takerToken: { $ref: '/PortalTokenMetadata' },
+ },
+ required: ['makerToken', 'takerToken'],
+ type: 'object',
+};
diff --git a/packages/website/ts/schemas/order_schema.ts b/packages/website/ts/schemas/order_schema.ts
deleted file mode 100644
index bfbf9eb8b..000000000
--- a/packages/website/ts/schemas/order_schema.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-export const orderSchema = {
- id: '/Order',
- properties: {
- maker: { $ref: '/OrderTaker' },
- taker: { $ref: '/OrderTaker' },
- salt: { type: 'string' },
- signature: { $ref: '/SignatureData' },
- expiration: { type: 'string' },
- feeRecipient: { type: 'string' },
- exchangeContract: { type: 'string' },
- networkId: { type: 'number' },
- },
- required: ['maker', 'taker', 'salt', 'signature', 'expiration', 'feeRecipient', 'exchangeContract', 'networkId'],
- type: 'object',
-};
diff --git a/packages/website/ts/schemas/order_taker_schema.ts b/packages/website/ts/schemas/order_taker_schema.ts
deleted file mode 100644
index c784c29c5..000000000
--- a/packages/website/ts/schemas/order_taker_schema.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export const orderTakerSchema = {
- id: '/OrderTaker',
- properties: {
- address: { type: 'string' },
- token: { $ref: '/Token' },
- amount: { type: 'string' },
- feeAmount: { type: 'string' },
- },
- required: ['address', 'token', 'amount', 'feeAmount'],
- type: 'object',
-};
diff --git a/packages/website/ts/schemas/portal_order_schema.ts b/packages/website/ts/schemas/portal_order_schema.ts
new file mode 100644
index 000000000..ea8aeabc6
--- /dev/null
+++ b/packages/website/ts/schemas/portal_order_schema.ts
@@ -0,0 +1,9 @@
+export const portalOrderSchema = {
+ id: '/PortalOrder',
+ properties: {
+ signedOrder: { $ref: '/SignedOrder' },
+ metadata: { $ref: '/OrderMetadata' },
+ },
+ required: ['signedOrder', 'metadata'],
+ type: 'object',
+};
diff --git a/packages/website/ts/schemas/token_schema.ts b/packages/website/ts/schemas/portal_token_metadata.ts
index 92b53a463..0455c2ac1 100644
--- a/packages/website/ts/schemas/token_schema.ts
+++ b/packages/website/ts/schemas/portal_token_metadata.ts
@@ -1,11 +1,10 @@
-export const tokenSchema = {
- id: '/Token',
+export const portalTokenMetadataSchema = {
+ id: '/PortalTokenMetadata',
properties: {
name: { type: 'string' },
symbol: { type: 'string' },
decimals: { type: 'number' },
- address: { type: 'string' },
},
- required: ['name', 'symbol', 'decimals', 'address'],
+ required: ['name', 'symbol', 'decimals'],
type: 'object',
};
diff --git a/packages/website/ts/schemas/signature_data_schema.ts b/packages/website/ts/schemas/signature_data_schema.ts
deleted file mode 100644
index 8d3f15926..000000000
--- a/packages/website/ts/schemas/signature_data_schema.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export const signatureDataSchema = {
- id: '/SignatureData',
- properties: {
- hash: { type: 'string' },
- r: { type: 'string' },
- s: { type: 'string' },
- v: { type: 'number' },
- },
- required: ['hash', 'r', 's', 'v'],
- type: 'object',
-};
diff --git a/packages/website/ts/schemas/validator.ts b/packages/website/ts/schemas/validator.ts
index 5177501c6..dac0f0098 100644
--- a/packages/website/ts/schemas/validator.ts
+++ b/packages/website/ts/schemas/validator.ts
@@ -1,19 +1,12 @@
+import { SchemaValidator } from '@0xproject/json-schemas';
import { Schema as JSONSchema, Validator } from 'jsonschema';
-import { orderSchema } from 'ts/schemas/order_schema';
-import { orderTakerSchema } from 'ts/schemas/order_taker_schema';
-import { signatureDataSchema } from 'ts/schemas/signature_data_schema';
-import { tokenSchema } from 'ts/schemas/token_schema';
+import { orderMetadataSchema } from 'ts/schemas/metadata_schema';
+import { portalOrderSchema } from 'ts/schemas/portal_order_schema';
+import { portalTokenMetadataSchema } from 'ts/schemas/portal_token_metadata';
-export class SchemaValidator {
- private _validator: Validator;
- constructor() {
- this._validator = new Validator();
- this._validator.addSchema(signatureDataSchema as JSONSchema, signatureDataSchema.id);
- this._validator.addSchema(tokenSchema as JSONSchema, tokenSchema.id);
- this._validator.addSchema(orderTakerSchema as JSONSchema, orderTakerSchema.id);
- this._validator.addSchema(orderSchema as JSONSchema, orderSchema.id);
- }
- public validate(instance: object, schema: Schema) {
- return this._validator.validate(instance, schema);
- }
-}
+const validator = new SchemaValidator();
+validator.addSchema(portalTokenMetadataSchema);
+validator.addSchema(orderMetadataSchema);
+validator.addSchema(portalOrderSchema);
+
+export { validator };
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index c48c88cae..19fc24852 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -1,3 +1,4 @@
+import { ECSignature } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
@@ -34,13 +35,6 @@ export interface SideToAssetToken {
[side: string]: AssetToken;
}
-export interface SignatureData {
- hash: string;
- r: string;
- s: string;
- v: number;
-}
-
export interface HashData {
depositAmount: BigNumber;
depositTokenContractAddr: string;
@@ -59,25 +53,32 @@ export interface OrderToken {
name: string;
symbol: string;
decimals: number;
- address: string;
}
-export interface OrderParty {
- address: string;
- token: OrderToken;
- amount: string;
- feeAmount: string;
+export interface SignedOrder {
+ maker: string;
+ taker: string;
+ makerTokenAddress: string;
+ takerTokenAddress: string;
+ makerFee: string;
+ takerFee: string;
+ makerTokenAmount: string;
+ takerTokenAmount: string;
+ expirationUnixTimestampSec: string;
+ feeRecipient: string;
+ salt: string;
+ ecSignature: ECSignature;
+ exchangeContractAddress: string;
+}
+
+export interface OrderMetadata {
+ makerToken: OrderToken;
+ takerToken: OrderToken;
}
export interface Order {
- maker: OrderParty;
- taker: OrderParty;
- expiration: string;
- feeRecipient: string;
- salt: string;
- signature: SignatureData;
- exchangeContract: string;
- networkId: number;
+ signedOrder: SignedOrder;
+ metadata: OrderMetadata;
}
export interface Fill {
@@ -118,7 +119,7 @@ export enum ActionTypes {
UpdateChosenAssetTokenAddress = 'UPDATE_CHOSEN_ASSET_TOKEN_ADDRESS',
UpdateOrderTakerAddress = 'UPDATE_ORDER_TAKER_ADDRESS',
UpdateOrderSalt = 'UPDATE_ORDER_SALT',
- UpdateOrderSignatureData = 'UPDATE_ORDER_SIGNATURE_DATA',
+ UpdateOrderECSignature = 'UPDATE_ORDER_EC_SIGNATURE',
UpdateTokenByAddress = 'UPDATE_TOKEN_BY_ADDRESS',
RemoveTokenFromTokenByAddress = 'REMOVE_TOKEN_FROM_TOKEN_BY_ADDRESS',
ForceTokenStateRefetch = 'FORCE_TOKEN_STATE_REFETCH',
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index a7865d41b..c38f84c92 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -1,4 +1,4 @@
-import { ExchangeContractErrs, ZeroExError } from '0x.js';
+import { ECSignature, ExchangeContractErrs, ZeroEx, ZeroExError } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import deepEqual = require('deep-equal');
import isMobile = require('is-mobile');
@@ -11,7 +11,6 @@ import {
ScreenWidths,
Side,
SideToAssetToken,
- SignatureData,
Token,
TokenByAddress,
} from 'ts/types';
@@ -59,50 +58,48 @@ export const utils = {
return formattedDate;
},
generateOrder(
- networkId: number,
- exchangeContract: string,
+ exchangeContractAddress: string,
sideToAssetToken: SideToAssetToken,
- orderExpiryTimestamp: BigNumber,
+ expirationUnixTimestampSec: BigNumber,
orderTakerAddress: string,
orderMakerAddress: string,
makerFee: BigNumber,
takerFee: BigNumber,
feeRecipient: string,
- signatureData: SignatureData,
+ ecSignature: ECSignature,
tokenByAddress: TokenByAddress,
orderSalt: BigNumber,
): Order {
const makerToken = tokenByAddress[sideToAssetToken[Side.Deposit].address];
const takerToken = tokenByAddress[sideToAssetToken[Side.Receive].address];
const order = {
- maker: {
- address: orderMakerAddress,
- token: {
+ signedOrder: {
+ maker: orderMakerAddress,
+ taker: orderTakerAddress,
+ makerFee: makerFee.toString(),
+ takerFee: takerFee.toString(),
+ makerTokenAmount: sideToAssetToken[Side.Deposit].amount.toString(),
+ takerTokenAmount: sideToAssetToken[Side.Receive].amount.toString(),
+ makerTokenAddress: makerToken.address,
+ takerTokenAddress: takerToken.address,
+ expirationUnixTimestampSec: expirationUnixTimestampSec.toString(),
+ feeRecipient,
+ salt: orderSalt.toString(),
+ ecSignature,
+ exchangeContractAddress,
+ },
+ metadata: {
+ makerToken: {
name: makerToken.name,
symbol: makerToken.symbol,
decimals: makerToken.decimals,
- address: makerToken.address,
},
- amount: sideToAssetToken[Side.Deposit].amount.toString(),
- feeAmount: makerFee.toString(),
- },
- taker: {
- address: orderTakerAddress,
- token: {
+ takerToken: {
name: takerToken.name,
symbol: takerToken.symbol,
decimals: takerToken.decimals,
- address: takerToken.address,
},
- amount: sideToAssetToken[Side.Receive].amount.toString(),
- feeAmount: takerFee.toString(),
},
- expiration: orderExpiryTimestamp.toString(),
- feeRecipient,
- salt: orderSalt.toString(),
- signature: signatureData,
- exchangeContract,
- networkId,
};
return order;
},