aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website')
-rw-r--r--packages/website/ts/blockchain.ts13
-rw-r--r--packages/website/ts/components/fill_order.tsx26
-rw-r--r--packages/website/ts/components/generate_order/generate_order_form.tsx7
-rw-r--r--packages/website/ts/components/portal/portal.tsx2
-rw-r--r--packages/website/ts/schemas/portal_order_schema.ts2
-rw-r--r--packages/website/ts/utils/order_parser.ts19
-rw-r--r--packages/website/ts/utils/utils.ts2
7 files changed, 41 insertions, 30 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index c2d0551bf..baf8002cd 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -414,6 +414,15 @@ export class Blockchain {
const lowercaseAddress = address.toLowerCase();
return Web3Wrapper.isAddress(lowercaseAddress);
}
+ public async isValidSignatureAsync(data: string, signature: string, signerAddress: string): Promise<boolean> {
+ const result = await signatureUtils.isValidSignatureAsync(
+ this._contractWrappers.getProvider(),
+ data,
+ signature,
+ signerAddress,
+ );
+ return result;
+ }
public async pollTokenBalanceAsync(token: Token): Promise<BigNumber> {
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
@@ -451,10 +460,10 @@ export class Blockchain {
throw new Error('Tried to send a sign request but user has no associated addresses');
}
this._showFlashMessageIfLedger();
-
const provider = this._contractWrappers.getProvider();
const isLedgerSigner = !_.isUndefined(this._ledgerSubprovider);
- const isMetaMaskSigner = utils.getProviderType(provider) === Providers.Metamask;
+ const injectedProvider = Blockchain._getInjectedWeb3().currentProvider;
+ const isMetaMaskSigner = utils.getProviderType(injectedProvider) === Providers.Metamask;
let signerType = SignerType.Default;
if (isLedgerSigner) {
signerType = SignerType.Ledger;
diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx
index 60eccff34..f24d065f4 100644
--- a/packages/website/ts/components/fill_order.tsx
+++ b/packages/website/ts/components/fill_order.tsx
@@ -26,6 +26,7 @@ import { AlertTypes, BlockchainErrs, PortalOrder, Token, TokenByAddress, Website
import { analytics } from 'ts/utils/analytics';
import { constants } from 'ts/utils/constants';
import { errorReporter } from 'ts/utils/error_reporter';
+import { orderParser } from 'ts/utils/order_parser';
import { utils } from 'ts/utils/utils';
interface FillOrderProps {
@@ -418,7 +419,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
let parsedOrder: PortalOrder;
let orderHash: string;
try {
- const order = JSON.parse(orderJSON);
+ const order = orderParser.parseJsonString(orderJSON);
const validationResult = validator.validate(order, portalOrderSchema);
if (validationResult.errors.length > 0) {
orderJSONErrMsg = 'Submitted order JSON is not a valid order';
@@ -427,28 +428,12 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
}
parsedOrder = order;
const signedOrder = parsedOrder.signedOrder;
- const zeroExOrder: ZeroExOrder = {
- exchangeAddress: signedOrder.exchangeAddress,
- expirationTimeSeconds: signedOrder.expirationTimeSeconds,
- feeRecipientAddress: signedOrder.feeRecipientAddress,
- makerAddress: signedOrder.makerAddress,
- makerFee: signedOrder.makerFee,
- makerAssetData: signedOrder.makerAssetData,
- makerAssetAmount: signedOrder.makerAssetAmount,
- salt: signedOrder.salt,
- takerAddress: _.isEmpty(signedOrder.takerAddress) ? constants.NULL_ADDRESS : signedOrder.takerAddress,
- takerFee: signedOrder.takerFee,
- takerAssetData: signedOrder.takerAssetData,
- takerAssetAmount: signedOrder.takerAssetAmount,
- senderAddress: signedOrder.senderAddress,
- };
- orderHash = orderHashUtils.getOrderHashHex(zeroExOrder);
+ orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const exchangeContractAddr = this.props.blockchain.getExchangeContractAddressIfExists();
const signature = signedOrder.signature;
- const ecSignature = signatureUtils.parseECSignature(signature);
- const isSignatureValid = signatureUtils.isValidECSignature(
+ const isSignatureValid = await this.props.blockchain.isValidSignatureAsync(
orderHash,
- ecSignature,
+ signature,
signedOrder.makerAddress,
);
if (exchangeContractAddr !== signedOrder.exchangeAddress) {
@@ -500,6 +485,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
});
}
+ console.log(parsedOrder);
this.setState({
didOrderValidationRun: true,
orderJSON,
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 9eb50f3d7..bb6265170 100644
--- a/packages/website/ts/components/generate_order/generate_order_form.tsx
+++ b/packages/website/ts/components/generate_order/generate_order_form.tsx
@@ -331,7 +331,7 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
salt: hashData.orderSalt,
takerAddress: hashData.orderTakerAddress,
takerFee: hashData.takerFee,
- takerAssetData: hashData.receiveTokenContractAddr,
+ takerAssetData,
takerAssetAmount: hashData.receiveAmount,
};
const orderHash = orderHashUtils.getOrderHashHex(zeroExOrder);
@@ -339,7 +339,7 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
let globalErrMsg = '';
let order;
try {
- const ecSignature = await this.props.blockchain.signOrderHashAsync(orderHash);
+ const signature = await this.props.blockchain.signOrderHashAsync(orderHash);
order = utils.generateOrder(
exchangeAddress,
this.props.sideToAssetToken,
@@ -349,10 +349,11 @@ export class GenerateOrderForm extends React.Component<GenerateOrderFormProps, G
hashData.makerFee,
hashData.takerFee,
hashData.feeRecipientAddress,
- ecSignature,
+ signature,
this.props.tokenByAddress,
hashData.orderSalt,
);
+ console.log(order);
const validationResult = validator.validate(order, portalOrderSchema);
if (validationResult.errors.length > 0) {
globalErrMsg = 'Order signing failed. Please refresh and try again';
diff --git a/packages/website/ts/components/portal/portal.tsx b/packages/website/ts/components/portal/portal.tsx
index 047464e03..b8d7ceea9 100644
--- a/packages/website/ts/components/portal/portal.tsx
+++ b/packages/website/ts/components/portal/portal.tsx
@@ -118,7 +118,7 @@ export class Portal extends React.Component<PortalProps, PortalState> {
private readonly _throttledScreenWidthUpdate: () => void;
constructor(props: PortalProps) {
super(props);
- this._sharedOrderIfExists = orderParser.parse(window.location.search);
+ this._sharedOrderIfExists = orderParser.parseQueryString(window.location.search);
this._throttledScreenWidthUpdate = _.throttle(this._updateScreenWidth.bind(this), THROTTLE_TIMEOUT);
const didAcceptPortalDisclaimer = localStorage.getItemIfExists(constants.LOCAL_STORAGE_KEY_ACCEPT_DISCLAIMER);
const hasAcceptedDisclaimer =
diff --git a/packages/website/ts/schemas/portal_order_schema.ts b/packages/website/ts/schemas/portal_order_schema.ts
index ea8aeabc6..15e61f5e4 100644
--- a/packages/website/ts/schemas/portal_order_schema.ts
+++ b/packages/website/ts/schemas/portal_order_schema.ts
@@ -1,7 +1,7 @@
export const portalOrderSchema = {
id: '/PortalOrder',
properties: {
- signedOrder: { $ref: '/SignedOrder' },
+ signedOrder: { $ref: '/signedOrderSchema' },
metadata: { $ref: '/OrderMetadata' },
},
required: ['signedOrder', 'metadata'],
diff --git a/packages/website/ts/utils/order_parser.ts b/packages/website/ts/utils/order_parser.ts
index e542bb484..2e1d4d2f2 100644
--- a/packages/website/ts/utils/order_parser.ts
+++ b/packages/website/ts/utils/order_parser.ts
@@ -6,7 +6,7 @@ import { validator } from 'ts/schemas/validator';
import { PortalOrder } from 'ts/types';
export const orderParser = {
- parse(queryString: string): PortalOrder | undefined {
+ parseQueryString(queryString: string): PortalOrder | undefined {
if (queryString.length === 0) {
return undefined;
}
@@ -28,7 +28,22 @@ export const orderParser = {
logUtils.log(`Invalid shared order: ${validationResult.errors}`);
return undefined;
}
- const result = convertOrderStringFieldsToBigNumber(order);
+ const signedOrder = _.get(order, 'signedOrder');
+ const convertedSignedOrder = convertOrderStringFieldsToBigNumber(signedOrder);
+ const result = {
+ ...order,
+ signedOrder: convertedSignedOrder,
+ };
+ return result;
+ },
+ parseJsonString(orderJson: string): PortalOrder {
+ const order = JSON.parse(orderJson);
+ const signedOrder = _.get(order, 'signedOrder');
+ const convertedSignedOrder = convertOrderStringFieldsToBigNumber(signedOrder);
+ const result = {
+ ...order,
+ signedOrder: convertedSignedOrder,
+ };
return result;
},
};
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index ab9852d16..eda0e513d 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -1,5 +1,5 @@
import { ContractWrappersError } from '@0xproject/contract-wrappers';
-import { assetDataUtils, OrderError, signatureUtils } from '@0xproject/order-utils';
+import { assetDataUtils, OrderError } from '@0xproject/order-utils';
import { constants as sharedConstants, Networks } from '@0xproject/react-shared';
import { ECSignature, ExchangeContractErrs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';