diff options
Diffstat (limited to 'packages/0x.js/src/utils/exchange_transfer_simulator.ts')
-rw-r--r-- | packages/0x.js/src/utils/exchange_transfer_simulator.ts | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/packages/0x.js/src/utils/exchange_transfer_simulator.ts b/packages/0x.js/src/utils/exchange_transfer_simulator.ts index c3a2d1585..00a0efd3f 100644 --- a/packages/0x.js/src/utils/exchange_transfer_simulator.ts +++ b/packages/0x.js/src/utils/exchange_transfer_simulator.ts @@ -36,6 +36,11 @@ const ERR_MSG_MAPPING = { export class ExchangeTransferSimulator { private store: BalanceAndProxyAllowanceLazyStore; private UNLIMITED_ALLOWANCE_IN_BASE_UNITS: BigNumber; + private static throwValidationError(failureReason: FailureReason, tradeSide: TradeSide, + transferType: TransferType): never { + const errMsg = ERR_MSG_MAPPING[failureReason][tradeSide][transferType]; + throw new Error(errMsg); + } constructor(token: TokenWrapper) { this.store = new BalanceAndProxyAllowanceLazyStore(token); this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS = token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; @@ -55,10 +60,10 @@ export class ExchangeTransferSimulator { const balance = await this.store.getBalanceAsync(tokenAddress, from); const proxyAllowance = await this.store.getProxyAllowanceAsync(tokenAddress, from); if (proxyAllowance.lessThan(amountInBaseUnits)) { - this.throwValidationError(FailureReason.ProxyAllowance, tradeSide, transferType); + ExchangeTransferSimulator.throwValidationError(FailureReason.ProxyAllowance, tradeSide, transferType); } if (balance.lessThan(amountInBaseUnits)) { - this.throwValidationError(FailureReason.Balance, tradeSide, transferType); + ExchangeTransferSimulator.throwValidationError(FailureReason.Balance, tradeSide, transferType); } await this.decreaseProxyAllowanceAsync(tokenAddress, from, amountInBaseUnits); await this.decreaseBalanceAsync(tokenAddress, from, amountInBaseUnits); @@ -81,9 +86,4 @@ export class ExchangeTransferSimulator { const balance = await this.store.getBalanceAsync(tokenAddress, userAddress); this.store.setBalance(tokenAddress, userAddress, balance.minus(amountInBaseUnits)); } - private throwValidationError(failureReason: FailureReason, tradeSide: TradeSide, - transferType: TransferType): never { - const errMsg = ERR_MSG_MAPPING[failureReason][tradeSide][transferType]; - throw new Error(errMsg); - } } |