-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f09239
commit 6d12c41
Showing
2 changed files
with
24 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { formatGwei } from 'viem' | ||
|
||
/** | ||
* Calculates the estimated gas fee in Gwei. | ||
* TODO: Hardcoding gas limit to 200k for now, update dynamically | ||
Check failure on line 5 in packages/synapse-interface/utils/calculateGasFeeInGwei.ts GitHub Actions / lint
|
||
* @param {string} gasPrice - The current gas price in Gwei as a string. | ||
* @param {number} gasLimit - Function to format a value as Gwei. | ||
* @returns {number|null} The formatted estimated gas cost, or null if the calculation is not possible. | ||
*/ | ||
export const calculateGasFeeInGwei = (gasPrice?: string, gasLimit = 200000) => { | ||
if (!gasPrice) return null | ||
|
||
const estimatedGasCostInGwei = gasLimit * parseFloat(gasPrice) | ||
|
||
const oneGwei = parseFloat(formatGwei(1n)) | ||
|
||
const formattedEstimatedGasCost = estimatedGasCostInGwei | ||
? estimatedGasCostInGwei * oneGwei | ||
: null | ||
|
||
return formattedEstimatedGasCost | ||
} |