-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add support for approve permissions (#998)
- Loading branch information
1 parent
2cd47a9
commit eed6330
Showing
8 changed files
with
147 additions
and
2 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
28 changes: 28 additions & 0 deletions
28
wallets/metamask/src/pages/NotificationPage/actions/approvePermission.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,28 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
|
||
const editTokenPermission = async (notificationPage: Page, customSpendLimit: number) => { | ||
await notificationPage.locator(Selectors.PermissionPage.approve.editPermission.editPermissionButton).click() | ||
|
||
await notificationPage.locator(Selectors.PermissionPage.approve.editPermission.customSpendLimitButton).click() | ||
|
||
await notificationPage | ||
.locator(Selectors.PermissionPage.approve.editPermission.customSpendLimitInput) | ||
.fill(customSpendLimit.toString()) | ||
|
||
await notificationPage.locator(Selectors.PermissionPage.approve.editPermission.saveButton).click() | ||
} | ||
|
||
const approveTokenPermission = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.PermissionPage.approve.confirmButton).click() | ||
} | ||
|
||
const rejectTokenPermission = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.PermissionPage.approve.rejectButton).click() | ||
} | ||
|
||
export const approvePermission = { | ||
editSpendLimit: editTokenPermission, | ||
approve: approveTokenPermission, | ||
reject: rejectTokenPermission | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './connectToDapp' | ||
export * from './signSimpleMessage' | ||
export * from './signStructuredMessage' | ||
export * from './approvePermission' | ||
export * from './transaction' | ||
export * from './network' |
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
4 changes: 3 additions & 1 deletion
4
wallets/metamask/src/pages/NotificationPage/selectors/index.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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import NetworkPage from './networkPage' | ||
import PermissionPage from './permissionPage' | ||
import SignaturePage from './signaturePage' | ||
import TransactionPage from './transactionPage' | ||
|
||
export default { | ||
SignaturePage, | ||
NetworkPage, | ||
TransactionPage | ||
TransactionPage, | ||
PermissionPage | ||
} |
19 changes: 19 additions & 0 deletions
19
wallets/metamask/src/pages/NotificationPage/selectors/permissionPage.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,19 @@ | ||
import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' | ||
|
||
const approve = { | ||
editPermission: { | ||
editPermissionButton: | ||
'.confirm-approve-content__edit-submission-button-container .confirm-approve-content__medium-link-text.cursor-pointer', | ||
customSpendLimitButton: | ||
'.edit-approval-permission-modal-content .edit-approval-permission__edit-section__option:last-of-type .edit-approval-permission__edit-section__radio-button', | ||
customSpendLimitInput: | ||
'.edit-approval-permission-modal-content .edit-approval-permission__edit-section__option-input input', | ||
saveButton: '.edit-approval-permission-modal-container .modal-container__footer > button.btn-primary' | ||
}, | ||
confirmButton: `.page-container__footer ${createDataTestSelector('page-container-footer-next')}`, | ||
rejectButton: `.page-container__footer ${createDataTestSelector('page-container-footer-cancel')}` | ||
} | ||
|
||
export default { | ||
approve | ||
} |
35 changes: 35 additions & 0 deletions
35
wallets/metamask/test/e2e/metamask/approvePermission.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,35 @@ | ||
import { testWithMetaMask } from '../testWithMetaMask' | ||
|
||
const test = testWithMetaMask.extend<{ switchChainAndDeployToken: () => Promise<void> }>({ | ||
switchChainAndDeployToken: async ({ page, metamask }, use) => { | ||
await use(async () => { | ||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.approveSwitchNetwork() | ||
|
||
await expect(page.locator('#tokenAddresses')).toBeEmpty() | ||
await page.locator('#createToken').click() | ||
|
||
await metamask.confirmTransaction() | ||
}) | ||
} | ||
}) | ||
|
||
const { expect } = test | ||
|
||
test('should approve tokens with the default limit', async ({ page, metamask, switchChainAndDeployToken }) => { | ||
await switchChainAndDeployToken() | ||
|
||
await page.locator('#approveTokens').click() | ||
|
||
await metamask.approvePermission() | ||
}) | ||
|
||
test('should approve tokens with the custom limit', async ({ page, metamask, switchChainAndDeployToken }) => { | ||
await switchChainAndDeployToken() | ||
|
||
await page.locator('#approveTokens').click() | ||
|
||
await metamask.approvePermission(420) | ||
}) |
21 changes: 21 additions & 0 deletions
21
wallets/metamask/test/e2e/metamask/rejectPermission.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,21 @@ | ||
import { testWithMetaMask } from '../testWithMetaMask' | ||
|
||
const test = testWithMetaMask | ||
|
||
const { expect } = test | ||
|
||
test('should reject approve request', async ({ page, metamask }) => { | ||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.approveSwitchNetwork() | ||
|
||
await expect(page.locator('#tokenAddresses')).toBeEmpty() | ||
await page.locator('#createToken').click() | ||
|
||
await metamask.confirmTransaction() | ||
|
||
await page.locator('#approveTokens').click() | ||
|
||
await metamask.rejectPermission() | ||
}) |