Skip to content

Commit

Permalink
Replace parseInt with parseFloat in ethers.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jul 7, 2023
1 parent 123b1e7 commit ed1a8fc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function useEthers() {
// const gasEstimateInEth = ethers.utils.formatEther(gasEstimate)
const fee = maxPriorityFeePerGasInWei?.mul(gasEstimate).add(maxFeePerGasInWei)
const feeInWei = ethers.utils.formatEther(fee)
const feeInEth = (parseInt(feeInWei) / 10**18).toFixed(8).toString()
const feeInEth = (parseFloat(feeInWei) / 10**18).toFixed(8).toString()
return {
gasLimit: gasEstimate.toString(),
fee: feeInEth
Expand All @@ -80,7 +80,7 @@ export default function useEthers() {
const gasEstimate = await provider.estimateGas(unsignedTransaction as ethers.utils.Deferrable<ethers.providers.TransactionRequest>)
const fee = gasPrice.mul(gasEstimate)
const feeInWei = ethers.utils.formatEther(fee)
const feeInEth = (parseInt(feeInWei) / 10**18).toFixed(8).toString()
const feeInEth = (parseFloat(feeInWei) / 10**18).toFixed(8).toString()
return {
gasLimit: gasEstimate.toString(),
fee: feeInEth
Expand Down Expand Up @@ -141,7 +141,7 @@ export default function useEthers() {

async function getMaxETHAfterFees(rpcUrl: string, unsignedTx: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, totalAmount: string) {
const { fee } = await estimateEIP1559GasFee(rpcUrl, unsignedTx)
const total = parseInt(totalAmount) - parseInt(fee)
const total = parseFloat(totalAmount) - parseFloat(fee)
const maxAfterFees = ethers.utils.formatEther(total).toString()
return maxAfterFees
}
Expand Down Expand Up @@ -209,9 +209,9 @@ export default function useEthers() {
}
const ethFees = await estimateEIP1559GasFee(ethereumURL, tx)
const { fee, gasLimit } = ethFees
const requiredBalance = parseInt(value) + parseInt(fee)
const requiredBalance = parseFloat(value) + parseFloat(fee)
const balance = await getEthersBalance(from)
if (parseInt(balance) < requiredBalance) {
if (balance < requiredBalance) {
throw new Error('Insufficient balance')
}
console.log(`Sending ${value} ETH to ${to} with estimated ${fee} ETH in fees using ~${gasLimit.toString()} in gas.`)
Expand Down

0 comments on commit ed1a8fc

Please sign in to comment.