-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disable the confirm button when there is a blocking alert (#27347)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> This PR aims to disable the confirm button when there is a blocking alert. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27347?quickstart=1) Fixes: #27147 1. Go to test dapp 2. Don't have funds 3. Trigger malicious mint erc20 on Sepolia 4. Click on Review alerts or 1. Go to test dapp 2. Click Sign In With Ethereum Bad Domain 3. Click Confirm 4. See the friction modal <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> [Screencast from 23-09-2024 17:57:22.webm](https://github.com/user-attachments/assets/4c00284c-93d3-4b1b-9553-39eda67b7924) <!-- [screenshots/recordings] --> <!-- [screenshots/recordings] --> - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
1 parent
080fd23
commit 83cd96d
Showing
4 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
test/e2e/tests/confirmations/alerts/insufficient-funds.spec.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,85 @@ | ||
import { strict as assert } from 'assert'; | ||
import FixtureBuilder from '../../../fixture-builder'; | ||
import { | ||
PRIVATE_KEY, | ||
convertETHToHexGwei, | ||
withFixtures, | ||
WINDOW_TITLES, | ||
} from '../../../helpers'; | ||
import { SMART_CONTRACTS } from '../../../seeder/smart-contracts'; | ||
import { | ||
TestSuiteArguments, | ||
openDAppWithContract, | ||
} from '../transactions/shared'; | ||
import { Driver } from '../../../webdriver/driver'; | ||
|
||
describe('Alert for insufficient funds @no-mmi', function () { | ||
it('Shows an alert when the user tries to send a transaction with insufficient funds', async function () { | ||
const nftSmartContract = SMART_CONTRACTS.NFTS; | ||
const ganacheOptions = { | ||
accounts: [ | ||
{ | ||
secretKey: PRIVATE_KEY, | ||
balance: convertETHToHexGwei(0.0053), // Low balance only to create the contract and then trigger the alert for insufficient funds | ||
}, | ||
], | ||
}; | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.withPreferencesController({ | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
isRedesignedConfirmationsDeveloperEnabled: true, | ||
}, | ||
}) | ||
.build(), | ||
ganacheOptions, | ||
smartContract: nftSmartContract, | ||
title: this.test?.fullTitle(), | ||
}, | ||
async ({ driver, contractRegistry }: TestSuiteArguments) => { | ||
await openDAppWithContract(driver, contractRegistry, nftSmartContract); | ||
|
||
await mintNft(driver); | ||
|
||
await verifyAlertForInsufficientBalance(driver); | ||
|
||
await verifyConfirmationIsDisabled(driver); | ||
}, | ||
); | ||
}); | ||
}); | ||
|
||
async function verifyConfirmationIsDisabled(driver: Driver) { | ||
const confirmButton = await driver.findElement( | ||
'[data-testid="confirm-footer-button"]', | ||
); | ||
assert.equal(await confirmButton.isEnabled(), false); | ||
} | ||
|
||
async function verifyAlertForInsufficientBalance(driver: Driver) { | ||
const alert = await driver.findElement('[data-testid="inline-alert"]'); | ||
assert.equal(await alert.getText(), 'Alert'); | ||
await driver.clickElementSafe('.confirm-scroll-to-bottom__button'); | ||
await driver.clickElement('[data-testid="inline-alert"]'); | ||
|
||
const alertDescription = await driver.findElement( | ||
'[data-testid="alert-modal__selected-alert"]', | ||
); | ||
const alertDescriptionText = await alertDescription.getText(); | ||
assert.equal( | ||
alertDescriptionText, | ||
'You do not have enough ETH in your account to pay for transaction fees.', | ||
); | ||
} | ||
|
||
async function mintNft(driver: Driver) { | ||
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); | ||
await driver.clickElement(`#mintButton`); | ||
|
||
await driver.waitUntilXWindowHandles(3); | ||
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); | ||
} |
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