aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-02-07 22:26:53 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-02-07 22:26:53 +0800
commit10fb6061ccf66bd117ba13ea2ed1cfe7373096d0 (patch)
treeeec62a55708805e0e714033700e6410b909f1849
parent223df8006a30a95db544a2af080224a4d9d2d474 (diff)
downloaddexon-sol-tools-10fb6061ccf66bd117ba13ea2ed1cfe7373096d0.tar.gz
dexon-sol-tools-10fb6061ccf66bd117ba13ea2ed1cfe7373096d0.tar.zst
dexon-sol-tools-10fb6061ccf66bd117ba13ea2ed1cfe7373096d0.zip
Introduce makerToken and takerToken fields for unsigned token metadata
-rw-r--r--packages/website/ts/components/fill_order.tsx71
-rw-r--r--packages/website/ts/schemas/order_schema.ts12
-rw-r--r--packages/website/ts/schemas/order_taker_schema.ts9
-rw-r--r--packages/website/ts/schemas/token_schema.ts3
-rw-r--r--packages/website/ts/schemas/validator.ts2
-rw-r--r--packages/website/ts/types.ts15
-rw-r--r--packages/website/ts/utils/utils.ts28
7 files changed, 68 insertions, 72 deletions
diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx
index 06a7932f6..674110b75 100644
--- a/packages/website/ts/components/fill_order.tsx
+++ b/packages/website/ts/components/fill_order.tsx
@@ -182,7 +182,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
);
}
private _renderVisualOrder() {
- const takerTokenAddress = this.state.parsedOrder.taker.token.address;
+ const takerTokenAddress = this.state.parsedOrder.takerTokenAddress;
const takerToken = this.props.tokenByAddress[takerTokenAddress];
const orderTakerAmount = new BigNumber(this.state.parsedOrder.takerTokenAmount);
const orderMakerAmount = new BigNumber(this.state.parsedOrder.makerTokenAmount);
@@ -190,8 +190,8 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
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.makerTokenAddress;
const makerToken = this.props.tokenByAddress[makerTokenAddress];
const makerAssetToken = {
amount: orderMakerAmount.times(takerAssetToken.amount).div(orderTakerAmount),
@@ -201,8 +201,8 @@ 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
+ const orderTaker = !_.isEmpty(this.state.parsedOrder.taker)
+ ? this.state.parsedOrder.taker
: this.props.userAddress;
const parsedOrderExpiration = new BigNumber(this.state.parsedOrder.expirationUnixTimestampSec);
const exchangeRate = orderMakerAmount.div(orderTakerAmount);
@@ -213,7 +213,7 @@ 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.maker === this.props.userAddress;
const expiryDate = utils.convertToReadableDateTimeFromUnixTimestamp(parsedOrderExpiration);
return (
<div className="pt3 pb1">
@@ -224,13 +224,10 @@ 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.maker} diameter={23} />
</div>
<div className="col col-6">
- <EthereumAddress
- address={this.state.parsedOrder.maker.address}
- networkId={this.props.networkId}
- />
+ <EthereumAddress address={this.state.parsedOrder.maker} networkId={this.props.networkId} />
</div>
</div>
</div>
@@ -238,7 +235,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
<div className="lg-px4 md-px4 sm-px1 pt1">
<VisualOrder
orderTakerAddress={orderTaker}
- orderMakerAddress={this.state.parsedOrder.maker.address}
+ orderMakerAddress={this.state.parsedOrder.maker}
makerAssetToken={makerAssetToken}
takerAssetToken={takerAssetToken}
tokenByAddress={this.props.tokenByAddress}
@@ -361,15 +358,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.makerTokenAddress];
+ const takerTokenIfExists = this.props.tokenByAddress[this.state.parsedOrder.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.makerToken,
+ address: this.state.parsedOrder.makerTokenAddress,
iconUrl: undefined,
isTracked: false,
isRegistered: false,
@@ -381,7 +379,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.takerToken,
+ address: this.state.parsedOrder.takerTokenAddress,
iconUrl: undefined,
isTracked: false,
isRegistered: false,
@@ -425,20 +424,20 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
exchangeContractAddress: parsedOrder.exchangeContractAddress,
expirationUnixTimestampSec: expiration,
feeRecipient: parsedOrder.feeRecipient,
- maker: parsedOrder.maker.address,
+ maker: parsedOrder.maker,
makerFee: parsedMakerFee,
- makerTokenAddress: parsedOrder.maker.token.address,
+ makerTokenAddress: parsedOrder.makerTokenAddress,
makerTokenAmount: makerAmount,
salt,
- taker: _.isEmpty(parsedOrder.taker.address) ? constants.NULL_ADDRESS : parsedOrder.taker.address,
+ taker: _.isEmpty(parsedOrder.taker) ? constants.NULL_ADDRESS : parsedOrder.taker,
takerFee: parsedTakerFee,
- takerTokenAddress: parsedOrder.taker.token.address,
+ takerTokenAddress: parsedOrder.takerTokenAddress,
takerTokenAmount: takerAmount,
};
const orderHash = ZeroEx.getOrderHashHex(zeroExOrder);
const signature = parsedOrder.ecSignature;
- const isValidSignature = ZeroEx.isValidSignature(signature.hash, signature, parsedOrder.maker.address);
+ const isValidSignature = ZeroEx.isValidSignature(signature.hash, signature, parsedOrder.maker);
if (this.props.networkId !== parsedOrder.networkId) {
orderJSONErrMsg = `This order was made on another Ethereum network
(id: ${parsedOrder.networkId}). Connect to this network to fill.`;
@@ -481,10 +480,10 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
const orderHash = parsedOrder.ecSignature.hash;
unavailableTakerAmount = await this.props.blockchain.getUnavailableTakerAmountAsync(orderHash);
const isMakerTokenAddressInRegistry = await this.props.blockchain.isAddressInTokenRegistryAsync(
- parsedOrder.maker.token.address,
+ parsedOrder.makerTokenAddress,
);
const isTakerTokenAddressInRegistry = await this.props.blockchain.isAddressInTokenRegistryAsync(
- parsedOrder.taker.token.address,
+ parsedOrder.takerTokenAddress,
);
this.setState({
isMakerTokenAddressInRegistry,
@@ -530,10 +529,10 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
}
const signedOrder = this.props.blockchain.portalOrderToSignedOrder(
- parsedOrder.maker.address,
- parsedOrder.taker.address,
- parsedOrder.maker.token.address,
- parsedOrder.taker.token.address,
+ parsedOrder.maker,
+ parsedOrder.taker,
+ parsedOrder.makerTokenAddress,
+ parsedOrder.takerTokenAddress,
new BigNumber(parsedOrder.makerTokenAmount),
new BigNumber(parsedOrder.takerTokenAmount),
new BigNumber(parsedOrder.makerFee),
@@ -551,7 +550,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.taker);
}
}
if (!_.isEmpty(globalErrMsg)) {
@@ -562,7 +561,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.takerToken.symbol}-${networkName}`;
try {
const orderFilledAmount: BigNumber = await this.props.blockchain.fillOrderAsync(
signedOrder,
@@ -633,10 +632,10 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
const takerTokenAmount = new BigNumber(parsedOrder.takerTokenAmount);
const signedOrder = this.props.blockchain.portalOrderToSignedOrder(
- parsedOrder.maker.address,
- parsedOrder.taker.address,
- parsedOrder.maker.token.address,
- parsedOrder.taker.token.address,
+ parsedOrder.maker,
+ parsedOrder.taker,
+ parsedOrder.makerTokenAddress,
+ parsedOrder.takerTokenAddress,
new BigNumber(parsedOrder.makerTokenAmount),
takerTokenAmount,
new BigNumber(parsedOrder.makerFee),
@@ -651,7 +650,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
try {
await this.props.blockchain.validateCancelOrderThrowIfInvalidAsync(signedOrder, availableTakerTokenAmount);
} catch (err) {
- globalErrMsg = utils.zeroExErrToHumanReadableErrMsg(err.message, parsedOrder.taker.address);
+ globalErrMsg = utils.zeroExErrToHumanReadableErrMsg(err.message, parsedOrder.taker);
}
if (!_.isEmpty(globalErrMsg)) {
this.setState({
@@ -661,7 +660,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.makerToken.symbol}-${networkName}`;
try {
await this.props.blockchain.cancelOrderAsync(signedOrder, availableTakerTokenAmount);
this.setState({
diff --git a/packages/website/ts/schemas/order_schema.ts b/packages/website/ts/schemas/order_schema.ts
index ccf4af671..6ddc9e445 100644
--- a/packages/website/ts/schemas/order_schema.ts
+++ b/packages/website/ts/schemas/order_schema.ts
@@ -1,8 +1,12 @@
export const orderSchema = {
id: '/Order',
properties: {
- maker: { $ref: '/OrderTaker' },
- taker: { $ref: '/OrderTaker' },
+ maker: { type: 'string' },
+ taker: { type: 'string' },
+ makerTokenAddress: { type: 'string' },
+ takerTokenAddress: { type: 'string' },
+ makerToken: { $ref: '/Token' },
+ takerToken: { $ref: '/Token' },
makerFee: { type: 'string' },
takerFee: { type: 'string' },
makerTokenAmount: { type: 'string' },
@@ -17,6 +21,10 @@ export const orderSchema = {
required: [
'maker',
'taker',
+ 'makerTokenAddress',
+ 'takerTokenAddress',
+ 'makerToken',
+ 'takerToken',
'makerFee',
'takerFee',
'makerTokenAmount',
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 bce71f74b..000000000
--- a/packages/website/ts/schemas/order_taker_schema.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export const orderTakerSchema = {
- id: '/OrderTaker',
- properties: {
- address: { type: 'string' },
- token: { $ref: '/Token' },
- },
- required: ['address', 'token'],
- type: 'object',
-};
diff --git a/packages/website/ts/schemas/token_schema.ts b/packages/website/ts/schemas/token_schema.ts
index 92b53a463..34cd6f676 100644
--- a/packages/website/ts/schemas/token_schema.ts
+++ b/packages/website/ts/schemas/token_schema.ts
@@ -4,8 +4,7 @@ export const tokenSchema = {
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/validator.ts b/packages/website/ts/schemas/validator.ts
index 5177501c6..e2ffc7b79 100644
--- a/packages/website/ts/schemas/validator.ts
+++ b/packages/website/ts/schemas/validator.ts
@@ -1,6 +1,5 @@
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';
@@ -10,7 +9,6 @@ export class SchemaValidator {
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) {
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index 823f6f785..42788d0e4 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -80,14 +80,19 @@ export interface Order {
networkId: number;
}
-export interface SerializedOrderParty {
- address: string;
- token: OrderToken;
+export interface SerializedOrderToken {
+ name: string;
+ symbol: string;
+ decimals: number;
}
export interface SerializedOrder {
- maker: SerializedOrderParty;
- taker: SerializedOrderParty;
+ maker: string;
+ taker: string;
+ makerTokenAddress: string;
+ takerTokenAddress: string;
+ makerToken: SerializedOrderToken;
+ takerToken: SerializedOrderToken;
makerFee: string;
takerFee: string;
makerTokenAmount: string;
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index cc0689868..447a92fec 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -75,27 +75,23 @@ export const utils = {
const makerToken = tokenByAddress[sideToAssetToken[Side.Deposit].address];
const takerToken = tokenByAddress[sideToAssetToken[Side.Receive].address];
const order = {
+ maker: orderMakerAddress,
+ taker: orderTakerAddress,
makerFee: makerFee.toString(),
takerFee: takerFee.toString(),
makerTokenAmount: sideToAssetToken[Side.Deposit].amount.toString(),
takerTokenAmount: sideToAssetToken[Side.Receive].amount.toString(),
- maker: {
- address: orderMakerAddress,
- token: {
- name: makerToken.name,
- symbol: makerToken.symbol,
- decimals: makerToken.decimals,
- address: makerToken.address,
- },
+ makerTokenAddress: makerToken.address,
+ takerTokenAddress: takerToken.address,
+ makerToken: {
+ name: makerToken.name,
+ symbol: makerToken.symbol,
+ decimals: makerToken.decimals,
},
- taker: {
- address: orderTakerAddress,
- token: {
- name: takerToken.name,
- symbol: takerToken.symbol,
- decimals: takerToken.decimals,
- address: takerToken.address,
- },
+ takerToken: {
+ name: takerToken.name,
+ symbol: takerToken.symbol,
+ decimals: takerToken.decimals,
},
expirationUnixTimestampSec: expirationUnixTimestampSec.toString(),
feeRecipient,