Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose the higher gasLimit and gasPrice in the modal #72

Merged
merged 8 commits into from
Dec 6, 2021
Merged

Conversation

jessgusclark
Copy link
Member

@jessgusclark jessgusclark commented Dec 1, 2021

This PR does two things:

  1. Always estimate the gasPrice and gasLimit of a transaction but choose the highest one. It does not inform the user of the decision.
  2. Adds a loading message before the estimates and enhancement is finished.

Screenshot 2021-12-01 at 3 15 45 PM

It accomplishes these things by a custom hook that handles all three promises and the state of the gas. This moves the logic outside of the component so it is easier to read and can be reused in the future if needed.

Tests were updated to fix all issues with act/await/async/etc...

@jessgusclark jessgusclark changed the title Choose the higher gasLimit and gasPrice in the modal [DRAFT] Choose the higher gasLimit and gasPrice in the modal Dec 1, 2021
@jessgusclark jessgusclark changed the title [DRAFT] Choose the higher gasLimit and gasPrice in the modal Choose the higher gasLimit and gasPrice in the modal Dec 1, 2021
@jessgusclark jessgusclark marked this pull request as ready for review December 1, 2021 17:14
Copy link
Contributor

@ilanolkies ilanolkies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!! I will open an issue saying we need to decide if we need to notify the user

const gasLimitEstimate = wallet.smartWallet
.estimateDirectExecute(tx.to || '0x', tx.data || '0x')
.then((estimate: BigNumber) => {
if (tx.gasLimit && estimate.toNumber() < tx.gasLimit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tx.gasLimit && estimate.toNumber() < tx.gasLimit) {
if (tx.gasLimit && estimate.lt(tx.gasLimit)) {

?.getGasPrice()
.then((gp: BigNumber) => gp.mul('101').div('100'))
.then((estimate: BigNumber) => {
if (tx.gasPrice && estimate.toNumber() < tx.gasPrice) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tx.gasPrice && estimate.toNumber() < tx.gasPrice) {
if (tx.gasPrice && estimate.lt(tx.gasPrice)) {

@ilanolkies ilanolkies merged commit 1ab43f1 into main Dec 6, 2021
@ilanolkies ilanolkies added the lib Libraries and dependencies label Jan 14, 2022
@ilanolkies ilanolkies added this to the v1.0.0 milestone Jan 14, 2022
@ilanolkies ilanolkies added tx Transactions and removed lib Libraries and dependencies labels Jan 14, 2022
@jessgusclark jessgusclark deleted the higher-gas branch February 14, 2023 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tx Transactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants