diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-28 11:38:09 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-28 11:38:09 +0800 |
commit | 0a19ba3014ac68c1c94fcb376bc1ddb5081db757 (patch) | |
tree | 0f7a8572c1fb6172b3f0474dd6e6356f569f8760 /packages/website/ts/utils/utils.ts | |
parent | 88bd0f5328863141564faf2718118594732b66ca (diff) | |
download | dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.tar dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.tar.gz dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.tar.bz2 dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.tar.lz dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.tar.xz dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.tar.zst dexon-sol-tools-0a19ba3014ac68c1c94fcb376bc1ddb5081db757.zip |
Fix tslint issues
Diffstat (limited to 'packages/website/ts/utils/utils.ts')
-rw-r--r-- | packages/website/ts/utils/utils.ts | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index eb4c5be3a..8b23b6a40 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -1,23 +1,24 @@ +import {ExchangeContractErrs, ZeroExError} from '0x.js'; +import BigNumber from 'bignumber.js'; +import deepEqual = require('deep-equal'); +import ethUtil = require('ethereumjs-util'); +import isMobile = require('is-mobile'); import * as _ from 'lodash'; +import * as moment from 'moment'; import { - SideToAssetToken, - SignatureData, + EtherscanLinkSuffixes, + Networks, Order, - Side, - TokenByAddress, OrderParty, ScreenWidths, - EtherscanLinkSuffixes, + Side, + SideToAssetToken, + SignatureData, Token, - Networks, + TokenByAddress, } from 'ts/types'; -import * as moment from 'moment'; -import isMobile = require('is-mobile'); -import * as u2f from 'ts/vendor/u2f_api'; -import deepEqual = require('deep-equal'); -import ethUtil = require('ethereumjs-util'); -import BigNumber from 'bignumber.js'; import {constants} from 'ts/utils/constants'; +import * as u2f from 'ts/vendor/u2f_api'; const LG_MIN_EM = 64; const MD_MIN_EM = 52; @@ -101,7 +102,7 @@ export const utils = { console.log(message); /* tslint:enable */ }, - sleepAsync(ms: number) { + async sleepAsync(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); }, deepEqual(actual: any, expected: any, opts?: {strict: boolean}) { @@ -212,4 +213,53 @@ export const utils = { const isUniqueSymbol = _.isUndefined(tokenWithSameSymbolIfExists); return isUniqueName && isUniqueSymbol; }, + zeroExErrToHumanReadableErrMsg(error: ZeroExError|ExchangeContractErrs, takerAddress: string): string { + const ZeroExErrorToHumanReadableError: {[error: string]: string} = { + [ZeroExError.ExchangeContractDoesNotExist]: 'Exchange contract does not exist', + [ZeroExError.EtherTokenContractDoesNotExist]: 'EtherToken contract does not exist', + [ZeroExError.TokenTransferProxyContractDoesNotExist]: 'TokenTransferProxy contract does not exist', + [ZeroExError.TokenRegistryContractDoesNotExist]: 'TokenRegistry contract does not exist', + [ZeroExError.TokenContractDoesNotExist]: 'Token contract does not exist', + [ZeroExError.ZRXContractDoesNotExist]: 'ZRX contract does not exist', + [ZeroExError.UnhandledError]: 'Unhandled error occured', + [ZeroExError.UserHasNoAssociatedAddress]: 'User has no addresses available', + [ZeroExError.InvalidSignature]: 'Order signature is not valid', + [ZeroExError.ContractNotDeployedOnNetwork]: 'Contract is not deployed on the detected network', + [ZeroExError.InvalidJump]: 'Invalid jump occured while executing the transaction', + [ZeroExError.OutOfGas]: 'Transaction ran out of gas', + [ZeroExError.NoNetworkId]: 'No network id detected', + }; + const exchangeContractErrorToHumanReadableError: {[error: string]: string} = { + [ExchangeContractErrs.OrderFillExpired]: 'This order has expired', + [ExchangeContractErrs.OrderCancelExpired]: 'This order has expired', + [ExchangeContractErrs.OrderCancelAmountZero]: 'Order cancel amount can\'t be 0', + [ExchangeContractErrs.OrderAlreadyCancelledOrFilled]: + 'This order has already been completely filled or cancelled', + [ExchangeContractErrs.OrderFillAmountZero]: 'Order fill amount can\'t be 0', + [ExchangeContractErrs.OrderRemainingFillAmountZero]: + 'This order has already been completely filled or cancelled', + [ExchangeContractErrs.OrderFillRoundingError]: 'Rounding error will occur when filling this order', + [ExchangeContractErrs.InsufficientTakerBalance]: + 'Taker no longer has a sufficient balance to complete this order', + [ExchangeContractErrs.InsufficientTakerAllowance]: + 'Taker no longer has a sufficient allowance to complete this order', + [ExchangeContractErrs.InsufficientMakerBalance]: + 'Maker no longer has a sufficient balance to complete this order', + [ExchangeContractErrs.InsufficientMakerAllowance]: + 'Maker no longer has a sufficient allowance to complete this order', + [ExchangeContractErrs.InsufficientTakerFeeBalance]: 'Taker no longer has a sufficient balance to pay fees', + [ExchangeContractErrs.InsufficientTakerFeeAllowance]: + 'Taker no longer has a sufficient allowance to pay fees', + [ExchangeContractErrs.InsufficientMakerFeeBalance]: 'Maker no longer has a sufficient balance to pay fees', + [ExchangeContractErrs.InsufficientMakerFeeAllowance]: + 'Maker no longer has a sufficient allowance to pay fees', + [ExchangeContractErrs.TransactionSenderIsNotFillOrderTaker]: + `This order can only be filled by ${takerAddress}`, + [ExchangeContractErrs.InsufficientRemainingFillAmount]: + 'Insufficient remaining fill amount', + }; + const humanReadableErrorMsg = exchangeContractErrorToHumanReadableError[error] || + ZeroExErrorToHumanReadableError[error]; + return humanReadableErrorMsg; + }, }; |