From 911cb59b4bea98b72fbd82bb0542dffd7abff1d0 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Tue, 21 Jun 2022 11:47:24 +0200 Subject: [PATCH] Remove try...catch from TokenUtils --- src/utils/TokenUtils.ts | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/utils/TokenUtils.ts b/src/utils/TokenUtils.ts index c034e714..9a3a4370 100644 --- a/src/utils/TokenUtils.ts +++ b/src/utils/TokenUtils.ts @@ -36,7 +36,6 @@ export async function approve( return null } } - let result = null const amountFormatted = await amountToUnits(web3, tokenAddress, amount, tokenDecimals) const estGas = await calculateEstimatedGas( account, @@ -46,18 +45,12 @@ export async function approve( ) if (estimateGas) return estGas - try { - result = await tokenContract.methods.approve(spender, amountFormatted).send({ - from: account, - gas: estGas + 1, - gasPrice: await getFairGasPrice(web3, null) - }) - } catch (e) { - LoggerInstance.error( - `ERROR: Failed to approve spender to spend tokens : ${e.message}` - ) - } - return result + const trxReceipt = await tokenContract.methods.approve(spender, amountFormatted).send({ + from: account, + gas: estGas + 1, + gasPrice: await getFairGasPrice(web3, null) + }) + return trxReceipt } /** @@ -78,7 +71,6 @@ export async function transfer( ): Promise { const tokenContract = new web3.eth.Contract(minAbi, tokenAddress) - let result = null const amountFormatted = await amountToUnits(web3, tokenAddress, amount) const estGas = await calculateEstimatedGas( account, @@ -88,16 +80,14 @@ export async function transfer( ) if (estimateGas) return estGas - try { - result = await tokenContract.methods.transfer(recipient, amountFormatted).send({ + const trxReceipt = await tokenContract.methods + .transfer(recipient, amountFormatted) + .send({ from: account, gas: estGas + 1, gasPrice: await getFairGasPrice(web3, null) }) - } catch (e) { - LoggerInstance.error(`ERROR: Failed to transfer tokens : ${e.message}`) - } - return result + return trxReceipt } /**