Skip to content

Commit

Permalink
♻️ refactor(metamask): Rename to approveTokenPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Jan 29, 2024
1 parent e823f64 commit 33dc8a0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 47 deletions.
64 changes: 32 additions & 32 deletions docs/api/classes/MetaMask.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This class is the heart of Synpress's MetaMask API.
- [addNetwork()](MetaMask.md#addnetwork)
- [addNewAccount()](MetaMask.md#addnewaccount)
- [approveNewNetwork()](MetaMask.md#approvenewnetwork)
- [approvePermission()](MetaMask.md#approvepermission)
- [approveSwitchNetwork()](MetaMask.md#approveswitchnetwork)
- [approveTokenPermission()](MetaMask.md#approvetokenpermission)
- [confirmSignature()](MetaMask.md#confirmsignature)
- [confirmTransaction()](MetaMask.md#confirmtransaction)
- [connectToDapp()](MetaMask.md#connecttodapp)
Expand All @@ -23,9 +23,9 @@ This class is the heart of Synpress's MetaMask API.
- [openSettings()](MetaMask.md#opensettings)
- [openSidebarMenu()](MetaMask.md#opensidebarmenu)
- [rejectNewNetwork()](MetaMask.md#rejectnewnetwork)
- [rejectPermission()](MetaMask.md#rejectpermission)
- [rejectSignature()](MetaMask.md#rejectsignature)
- [rejectSwitchNetwork()](MetaMask.md#rejectswitchnetwork)
- [rejectTokenPermission()](MetaMask.md#rejecttokenpermission)
- [rejectTransaction()](MetaMask.md#rejecttransaction)
- [resetAccount()](MetaMask.md#resetaccount)
- [switchAccount()](MetaMask.md#switchaccount)
Expand Down Expand Up @@ -138,16 +138,30 @@ Approves a new network request.
***
### approvePermission()
### approveSwitchNetwork()
```ts
approveSwitchNetwork(): Promise<void>
```
Approves a switch network request.
#### Returns
`Promise`\<`void`\>
***
### approveTokenPermission()
```ts
approvePermission(options?): Promise<void>
approveTokenPermission(options?): Promise<void>
```
Approves a permission request to spend tokens.
::: warning
This function does not work with the NFTs approvals.
For NFT approvals, use `confirmTransaction` method.
:::
#### Parameters
Expand All @@ -164,20 +178,6 @@ This function does not work with the NFTs approvals.
***
### approveSwitchNetwork()
```ts
approveSwitchNetwork(): Promise<void>
```
Approves a switch network request.
#### Returns
`Promise`\<`void`\>
***
### confirmSignature()
```ts
Expand Down Expand Up @@ -343,45 +343,45 @@ Rejects a new network request.
***
### rejectPermission()
### rejectSignature()
```ts
rejectPermission(): Promise<void>
rejectSignature(): Promise<void>
```
Rejects a permission request to spend tokens.
::: warning
This function does not work with the NFTs approvals.
:::
Rejects a signature request. This function supports all types of commonly used signatures.
#### Returns
`Promise`\<`void`\>
***
### rejectSignature()
### rejectSwitchNetwork()
```ts
rejectSignature(): Promise<void>
rejectSwitchNetwork(): Promise<void>
```
Rejects a signature request. This function supports all types of commonly used signatures.
Rejects a switch network request.
#### Returns
`Promise`\<`void`\>
***
### rejectSwitchNetwork()
### rejectTokenPermission()
```ts
rejectSwitchNetwork(): Promise<void>
rejectTokenPermission(): Promise<void>
```
Rejects a switch network request.
Rejects a permission request to spend tokens.
::: warning
For NFT approvals, use `confirmTransaction` method.
:::
#### Returns
Expand Down
12 changes: 6 additions & 6 deletions wallets/metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,34 +256,34 @@ export class MetaMask {
* Approves a permission request to spend tokens.
*
* ::: warning
* This function does not work with the NFTs approvals.
* For NFT approvals, use `confirmTransaction` method.
* :::
*
* @param options - The permission options.
* @param options.spendLimit - The spend limit to use for the permission.
* @param options.gasSetting - The gas setting to use for the approval transaction.
*/
async approvePermission(options?: { spendLimit?: 'max' | number; gasSetting?: GasSetting }) {
async approveTokenPermission(options?: { spendLimit?: 'max' | number; gasSetting?: GasSetting }) {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}

await this.notificationPage.approvePermission(this.extensionId, options)
await this.notificationPage.approveTokenPermission(this.extensionId, options)
}

/**
* Rejects a permission request to spend tokens.
*
* ::: warning
* This function does not work with the NFTs approvals.
* For NFT approvals, use `confirmTransaction` method.
* :::
*/
async rejectPermission() {
async rejectTokenPermission() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}

await this.notificationPage.rejectPermission(this.extensionId)
await this.notificationPage.rejectTokenPermission(this.extensionId)
}

/**
Expand Down
7 changes: 5 additions & 2 deletions wallets/metamask/src/pages/NotificationPage/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export class NotificationPage {
await transaction.confirmAndWaitForMining(this.page, notificationPage, options?.gasSetting ?? 'site')
}

async approvePermission(extensionId: string, options?: { spendLimit?: 'max' | number; gasSetting?: GasSetting }) {
async approveTokenPermission(
extensionId: string,
options?: { spendLimit?: 'max' | number; gasSetting?: GasSetting }
) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

if (options?.spendLimit !== undefined) {
Expand All @@ -118,7 +121,7 @@ export class NotificationPage {
await approvePermission.approve(notificationPage, options?.gasSetting ?? 'site')
}

async rejectPermission(extensionId: string) {
async rejectTokenPermission(extensionId: string) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

await approvePermission.reject(notificationPage)
Expand Down
12 changes: 6 additions & 6 deletions wallets/metamask/test/e2e/metamask/approvePermission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ describe('with default gas setting', () => {

await page.locator('#approveTokens').click()

await metamask.approvePermission()
await metamask.approveTokenPermission()
})

test('should approve tokens with the `max` limit', async ({ page, metamask, deployToken }) => {
await deployToken()

await page.locator('#approveTokens').click()

await metamask.approvePermission({ spendLimit: 'max' })
await metamask.approveTokenPermission({ spendLimit: 'max' })
})

test('should approve tokens with the custom limit', async ({ page, metamask, deployToken }) => {
await deployToken()

await page.locator('#approveTokens').click()

await metamask.approvePermission({ spendLimit: 420 })
await metamask.approveTokenPermission({ spendLimit: 420 })
})
})

Expand All @@ -49,7 +49,7 @@ describe('with custom gas setting', () => {

await page.locator('#approveTokens').click()

await metamask.approvePermission({
await metamask.approveTokenPermission({
gasSetting: 'site'
})
})
Expand All @@ -63,7 +63,7 @@ describe('with custom gas setting', () => {

await page.locator('#approveTokens').click()

await metamask.approvePermission({
await metamask.approveTokenPermission({
spendLimit: 'max',
gasSetting: {
maxBaseFee: 250,
Expand All @@ -81,7 +81,7 @@ describe('with custom gas setting', () => {

await page.locator('#approveTokens').click()

await metamask.approvePermission({
await metamask.approveTokenPermission({
spendLimit: 420,
gasSetting: {
maxBaseFee: 250,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ test('should reject approve request', async ({ page, metamask, connectToAnvil })

await page.locator('#approveTokens').click()

await metamask.rejectPermission()
await metamask.rejectTokenPermission()
})

0 comments on commit 33dc8a0

Please sign in to comment.