mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Remove try...catch from TokenUtils
This commit is contained in:
parent
d387076a08
commit
911cb59b4b
@ -36,7 +36,6 @@ export async function approve<G extends boolean = false>(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let result = null
|
|
||||||
const amountFormatted = await amountToUnits(web3, tokenAddress, amount, tokenDecimals)
|
const amountFormatted = await amountToUnits(web3, tokenAddress, amount, tokenDecimals)
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
account,
|
account,
|
||||||
@ -46,18 +45,12 @@ export async function approve<G extends boolean = false>(
|
|||||||
)
|
)
|
||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
try {
|
const trxReceipt = await tokenContract.methods.approve(spender, amountFormatted).send({
|
||||||
result = await tokenContract.methods.approve(spender, amountFormatted).send({
|
|
||||||
from: account,
|
from: account,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(web3, null)
|
gasPrice: await getFairGasPrice(web3, null)
|
||||||
})
|
})
|
||||||
} catch (e) {
|
return trxReceipt
|
||||||
LoggerInstance.error(
|
|
||||||
`ERROR: Failed to approve spender to spend tokens : ${e.message}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +71,6 @@ export async function transfer<G extends boolean = false>(
|
|||||||
): Promise<G extends false ? TransactionReceipt : number> {
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const tokenContract = new web3.eth.Contract(minAbi, tokenAddress)
|
const tokenContract = new web3.eth.Contract(minAbi, tokenAddress)
|
||||||
|
|
||||||
let result = null
|
|
||||||
const amountFormatted = await amountToUnits(web3, tokenAddress, amount)
|
const amountFormatted = await amountToUnits(web3, tokenAddress, amount)
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
account,
|
account,
|
||||||
@ -88,16 +80,14 @@ export async function transfer<G extends boolean = false>(
|
|||||||
)
|
)
|
||||||
if (estimateGas) return estGas
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
try {
|
const trxReceipt = await tokenContract.methods
|
||||||
result = await tokenContract.methods.transfer(recipient, amountFormatted).send({
|
.transfer(recipient, amountFormatted)
|
||||||
|
.send({
|
||||||
from: account,
|
from: account,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(web3, null)
|
gasPrice: await getFairGasPrice(web3, null)
|
||||||
})
|
})
|
||||||
} catch (e) {
|
return trxReceipt
|
||||||
LoggerInstance.error(`ERROR: Failed to transfer tokens : ${e.message}`)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user