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

Display a warning and gas fee component for token allowance and NFT flow when transaction is expected to fail #17437

Merged

Conversation

VSaric
Copy link
Contributor

@VSaric VSaric commented Jan 26, 2023

Explanation

With this fixes, when MM loads a confirmation screen for a transaction that is expected to fail, it's now displaying the gas component. This has been seen so far on both the NFT approve and the new token allowance confirmation screens. Also when a transaction is expected to fail, it displays a warning. Approving a second time USDT drives to a failed transaction where should display a warning and the gas component.

Further explanation:

The gas component isn't displayed because we aren't set userAcknowledgedGasMissing in GasDetailsItem and EditGasFeeButton component in approve-content-card.js (this is content for token allowance flow) and confirm-approve-content.component.js (this is for NFT flow). Default value for userAcknowledgedGasMissing is false.

Code where default value for userAcknowledgedGasMissing is false in GasDisplayItem component: https://github.com/MetaMask/metamask-extension/blob/develop/ui/components/app/gas-details-item/gas-details-item.js#L19
Code where it is returning null in GasDisplayItem component: https://github.com/MetaMask/metamask-extension/blob/develop/ui/components/app/gas-details-item/gas-details-item.js#L35

Code where it is returning null in EditGasFeeButton component: https://github.com/MetaMask/metamask-extension/blob/develop/ui/components/app/edit-gas-fee-button/edit-gas-fee-button.js#L35

Now we are using renderSimulationFailureWarning to show a warning if it is true and if we want to proceed with a transaction that is expected to fail, we are setting userAcknowledgedGasMissing to true when we click on I want to proceed anyway link and then gas component will displays.

I also changed setshowContractDetails to setShowContractDetails what @darkwing suggested here.

Screenshots/Screencaps

Before

ERC20 token (token allowance flow)

Screen.Recording.2023-01-26.at.16.47.01.mov

ERC721 or ERC1155 token (NFT flow)

Screen.Recording.2023-01-26.at.16.48.24.mov

After

ERC20 token (token allowance flow)

Screen.Recording.2023-01-26.at.15.01.52.mov

ERC721 or ERC1155 token (NFT flow)

Screen.Recording.2023-01-26.at.15.06.14.mov

Manual Testing Steps

ERC20 token (token allowance)

  1. Go to USDT https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7#writeContract
  2. Click Write Contract
  3. Connect MM
  4. Click Approve
  5. Set amount and address
  6. Click on Write
  7. Approve on MM
  8. Click again Approve -- this transaction will fail. See how it is displays a warning and when user click on I want to proceed anyway link displays the gas component for this failing transaction (on the second page of token allowance flow)

ERC721 or ERC1155 token (NFT flow)

  1. Go to (erc721) https://etherscan.io/address/0x2a187453064356c898cae034eaed119e1663acb8#writeContract or (erc1155) https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d#writeContract
  2. Connect your wallet
  3. Go to approve and input a random address and a random token id (I used 1, it's important that you don't actually own that NFT)
  4. Click on Write
  5. See how it is displays a warning and when user click on I want to proceed anyway link displays the gas component for this failing transaction

@VSaric VSaric self-assigned this Jan 26, 2023
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@VSaric VSaric force-pushed the display-gas-fee-and-warning-for-failing-transactions branch from ca8dc8a to 41c2404 Compare January 27, 2023 10:54
@metamaskbot
Copy link
Collaborator

Builds ready [41c2404]
Page Load Metrics (1361 ± 109 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint98171131199
domContentLoaded104918831313228110
load108419551361227109
domInteractive104918821313228110
Bundle size diffs
  • background: 0 bytes
  • ui: 1382 bytes
  • common: 0 bytes

@danjm
Copy link
Contributor

danjm commented Jan 27, 2023

I think that another fix is required for the confirmation screens other than token allowance and NFT approvals. I have made a PR for that here: #17458

@VSaric
Copy link
Contributor Author

VSaric commented Jan 27, 2023

I think that another fix is required for the confirmation screens other than token allowance and NFT approvals. I have made a PR for that here: #17458

Oh I see, sorry for that @danjm! Do you want maybe to delete that line in confirm-transaction-base.component.js in this PR or it would be in separate PR that you opened?

I tried transfer and deprecate from etherscan here: https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7#writeContract and if we delete that condition in confirm-transaction-base.component.js it will display a warning message twice. You can see it on screenshots below:

Screenshot 2023-01-27 at 12 47 13

Screenshot 2023-01-27 at 12 50 20

@dzfjz
Copy link
Contributor

dzfjz commented Jan 27, 2023

Verified by QA

@VSaric VSaric marked this pull request as ready for review January 27, 2023 13:53
@VSaric VSaric requested a review from a team as a code owner January 27, 2023 13:53
@VSaric VSaric requested review from Gtonizuka and danjm January 27, 2023 13:53
@metamaskbot
Copy link
Collaborator

Builds ready [6070ff2]
Page Load Metrics (1619 ± 138 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1192841593718
domContentLoaded113520431593280134
load120220851619288138
domInteractive113520431593280134
Bundle size diffs
  • background: 0 bytes
  • ui: 1382 bytes
  • common: 0 bytes

}
/>
</Box>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be useful to extract out a small component for above warning display. It seems to be repeated a few places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jpuri Done here.

@jpuri
Copy link
Contributor

jpuri commented Jan 30, 2023

Will be nice to have more test coverage in the PR.

supportsEIP1559 &&
!renderSimulationFailureWarning
) {
return <GasDetailsItem userAcknowledgedGasMissing />;
Copy link
Contributor

Choose a reason for hiding this comment

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

A re-usable hook to get this value renderSimulationFailureWarning might be useful. I see this logic repeated a few places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jpuri Done here.

@VSaric VSaric force-pushed the display-gas-fee-and-warning-for-failing-transactions branch from 6070ff2 to cabe23b Compare February 1, 2023 13:05
@VSaric VSaric requested a review from jpuri February 1, 2023 13:08
@metamaskbot
Copy link
Collaborator

Builds ready [2bfc2ca]
Page Load Metrics (1388 ± 138 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1012591363316
domContentLoaded107420901358286137
load107420901388288138
domInteractive107420901358286137
Bundle size diffs
  • background: 0 bytes
  • ui: 5094 bytes
  • common: 0 bytes

@danjm danjm added the release-blocker This bug is blocking the next release label Feb 1, 2023
Copy link
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

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

lgtm!

@metamaskbot
Copy link
Collaborator

Builds ready [7e71360]
Page Load Metrics (1313 ± 124 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1012711415326
domContentLoaded95417861281256123
load97218951313258124
domInteractive95417861281256123
Bundle size diffs
  • background: 0 bytes
  • ui: 5094 bytes
  • common: 0 bytes

@brad-decker brad-decker merged commit 308151c into develop Feb 1, 2023
@brad-decker brad-decker deleted the display-gas-fee-and-warning-for-failing-transactions branch February 1, 2023 23:14
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2023
@@ -0,0 +1 @@
export { default } from './simulation-error-message';
Copy link
Contributor

Choose a reason for hiding this comment

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

A better place for this will be ui/components/app

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
rc-cherry-picked release-blocker This bug is blocking the next release
Projects
None yet
9 participants