From bd308f61cd6ac8d4adabbf0ba1e2ac708be85ffa Mon Sep 17 00:00:00 2001 From: acerasino Date: Fri, 22 Feb 2019 12:35:31 +0100 Subject: [PATCH] #11 Set nonce manually in TradingWalletFacade --- src/facades/TradingWalletFacade.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/facades/TradingWalletFacade.js b/src/facades/TradingWalletFacade.js index dbcf4df..1ea1aea 100644 --- a/src/facades/TradingWalletFacade.js +++ b/src/facades/TradingWalletFacade.js @@ -42,7 +42,9 @@ class TradingWalletFacade { async throwIfTokenWalletEnought(personalWalletAddress, quantity) { const assetBalance = await this.erc20TokenService.getBalanceOfAsync(personalWalletAddress) - if (assetBalance < quantity) { + const assetBalanceToBigNumber = this.transactionLib.web3.toBigNumber(assetBalance) + const quantityToBigNumber = this.transactionLib.web3.toBigNumber(quantity) + if (assetBalanceToBigNumber.lt(quantityToBigNumber)) { const errorMessage = 'The asset balance is < than the quantity to depoist!' this.log.info({ personalWalletAddress, @@ -98,12 +100,13 @@ class TradingWalletFacade { quantity, ) const gasEstimationForApprove = await this.transactionLib.getGasEstimation(approveTransactionDraftObject) + const nonceForApprove = await this.transactionLib.getNonce(personalWalletAddress) if (allowanceToInt === 0 || (quantity > allowanceToInt && allowanceToInt > 0)) { const signedApproveData = await this.transactionLib.sign( approveTransactionDraftObject, privateKey, - null, + nonceForApprove, gasEstimationForApprove.gas, gasEstimationForApprove.gasPrice, ) @@ -117,6 +120,7 @@ class TradingWalletFacade { const signedTransactionDataForDeposit = await this.transactionLib.sign( depositTokenTransactionDraft, privateKey, + nonceForApprove + 1, depositTokenFixedGasEstimation, gasEstimationForApprove.gasPrice, )