-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display transfer gas cost estimation (#174)
## Description Display gas estimation of transactions that will be executed ## Related Issue Or Context Closes: #157 ## How Has This Been Tested? Testing details. - [x] Mocked gas fee test ## Types of changes - [x] Transactions gas fee estimations for evm and substrate networks ## Checklist: - [x] Add tests.
- Loading branch information
1 parent
21ceb18
commit 7114f62
Showing
9 changed files
with
185 additions
and
11 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
6 changes: 6 additions & 0 deletions
6
packages/widget/src/components/transfer/fungible/transfer-detail/styles.ts
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
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
31 changes: 31 additions & 0 deletions
31
packages/widget/src/controllers/transfers/evm/gas-estimate.ts
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,31 @@ | ||
import { Web3Provider } from '@ethersproject/providers'; | ||
import type { EIP1193Provider } from '@web3-onboard/core'; | ||
import { ethers, type BigNumber, type PopulatedTransaction } from 'ethers'; | ||
|
||
/** | ||
* This method calculate the amount of gas | ||
* list of transactions will cost | ||
* @param {number} chainId blockchain ID | ||
* @param {Eip1193Provider} eip1193Provider EIP compatible provider | ||
* @param {string} sender address of signer connected with provider | ||
* @param {PopulatedTransaction[]} transactions list of EVM transactions | ||
* @returns {Promise<BigNumber>} gas cost in 18 decimals // or chain native decimals | ||
*/ | ||
export async function estimateEvmTransactionsGasCost( | ||
chainId: number, | ||
eip1193Provider: EIP1193Provider, | ||
sender: string, | ||
transactions: PopulatedTransaction[] | ||
): Promise<BigNumber> { | ||
const provider = new Web3Provider(eip1193Provider, chainId); | ||
const signer = provider.getSigner(sender); | ||
|
||
let cost = ethers.constants.Zero; | ||
for (const transaction of transactions) { | ||
const _cost = await signer.estimateGas(transaction); | ||
cost = cost.add(_cost); | ||
} | ||
|
||
const gasPrice = await provider.getGasPrice(); | ||
return gasPrice.mul(cost); | ||
} |
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
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