diff --git a/wallets/metamask/src/metamask.ts b/wallets/metamask/src/metamask.ts index cc758b86b..f8514405a 100644 --- a/wallets/metamask/src/metamask.ts +++ b/wallets/metamask/src/metamask.ts @@ -115,12 +115,12 @@ export class MetaMask { await this.notificationPage.rejectSwitchNetwork(this.extensionId) } - async confirmTransaction(gasSetting: GasSetting = 'site') { + async confirmTransaction(options?: { gasSetting?: GasSetting }) { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR } - await this.notificationPage.confirmTransaction(this.extensionId, gasSetting) + await this.notificationPage.confirmTransaction(this.extensionId, options) } async rejectTransaction() { @@ -170,19 +170,19 @@ export class MetaMask { // ---- EXPERIMENTAL FEATURES ---- public readonly experimental = { - confirmTransactionAndWaitForMining: async (gasSetting: GasSetting = 'site') => - await this.confirmTransactionAndWaitForMining(gasSetting), + confirmTransactionAndWaitForMining: async (options?: { gasSetting?: GasSetting }) => + await this.confirmTransactionAndWaitForMining(options), // Note: `txIndex` starts from 0. openTransactionDetails: async (txIndex: number) => await this.openTransactionDetails(txIndex), closeTransactionDetails: async () => await this.closeTransactionDetails() } - private async confirmTransactionAndWaitForMining(gasSetting: GasSetting) { + private async confirmTransactionAndWaitForMining(options?: { gasSetting?: GasSetting }) { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR } - await this.notificationPage.confirmTransactionAndWaitForMining(this.extensionId, gasSetting) + await this.notificationPage.confirmTransactionAndWaitForMining(this.extensionId, options) } private async openTransactionDetails(txIndex: number) { diff --git a/wallets/metamask/src/pages/NotificationPage/page.ts b/wallets/metamask/src/pages/NotificationPage/page.ts index fa07970a7..1e9ed7934 100644 --- a/wallets/metamask/src/pages/NotificationPage/page.ts +++ b/wallets/metamask/src/pages/NotificationPage/page.ts @@ -90,10 +90,10 @@ export class NotificationPage { await network.rejectSwitchNetwork(notificationPage) } - async confirmTransaction(extensionId: string, gasSetting: GasSetting) { + async confirmTransaction(extensionId: string, options?: { gasSetting?: GasSetting }) { const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId) - await transaction.confirm(notificationPage, gasSetting) + await transaction.confirm(notificationPage, options?.gasSetting ?? 'site') } async rejectTransaction(extensionId: string) { @@ -102,10 +102,10 @@ export class NotificationPage { await transaction.reject(notificationPage) } - async confirmTransactionAndWaitForMining(extensionId: string, gasSetting: GasSetting) { + async confirmTransactionAndWaitForMining(extensionId: string, options?: { gasSetting?: GasSetting }) { const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId) - await transaction.confirmAndWaitForMining(this.page, notificationPage, gasSetting) + await transaction.confirmAndWaitForMining(this.page, notificationPage, options?.gasSetting ?? 'site') } async approvePermission(extensionId: string, options?: { spendLimit?: 'max' | number; gasSetting?: GasSetting }) { diff --git a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts index e213f9529..88044a3f0 100644 --- a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts +++ b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts @@ -49,7 +49,7 @@ describe('with custom gas setting', () => { }) => { await connectAndTriggerEIP1559Transaction() - await expect(metamask.confirmTransaction('low')).rejects.toThrowError( + await expect(metamask.confirmTransaction({ gasSetting: 'low' })).rejects.toThrowError( '[ConfirmTransaction] Estimated fee is not available for the "low" gas setting. By default, MetaMask would use the "site" gas setting in this case, however, this is not YOUR intention.' ) }) @@ -60,7 +60,7 @@ describe('with custom gas setting', () => { }) => { await connectAndTriggerEIP1559Transaction() - await expect(metamask.confirmTransaction('market')).rejects.toThrowError( + await expect(metamask.confirmTransaction({ gasSetting: 'market' })).rejects.toThrowError( '[ConfirmTransaction] Estimated fee is not available for the "market" gas setting. By default, MetaMask would use the "site" gas setting in this case, however, this is not YOUR intention.' ) }) @@ -71,7 +71,7 @@ describe('with custom gas setting', () => { }) => { await connectAndTriggerEIP1559Transaction() - await expect(metamask.confirmTransaction('aggressive')).rejects.toThrowError( + await expect(metamask.confirmTransaction({ gasSetting: 'aggressive' })).rejects.toThrowError( '[ConfirmTransaction] Estimated fee is not available for the "aggressive" gas setting. By default, MetaMask would use the "site" gas setting in this case, however, this is not YOUR intention.' ) }) @@ -82,7 +82,7 @@ describe('with custom gas setting', () => { }) => { await connectAndTriggerEIP1559Transaction() - await metamask.confirmTransaction('site') + await metamask.confirmTransaction({ gasSetting: 'site' }) }) describe('with advanced (manual) gas setting', () => { @@ -93,8 +93,10 @@ describe('with custom gas setting', () => { await connectAndTriggerEIP1559Transaction() const promise = metamask.confirmTransaction({ - maxBaseFee: 250, - priorityFee: 300 + gasSetting: { + maxBaseFee: 250, + priorityFee: 300 + } }) await expect(promise).rejects.toThrowError( @@ -112,9 +114,11 @@ describe('with custom gas setting', () => { await connectAndTriggerEIP1559Transaction() const promise = metamask.confirmTransaction({ - maxBaseFee: 250, - priorityFee: 150, - gasLimit: 10 + gasSetting: { + maxBaseFee: 250, + priorityFee: 150, + gasLimit: 10 + } }) await expect(promise).rejects.toThrowError( @@ -129,9 +133,11 @@ describe('with custom gas setting', () => { await connectAndTriggerEIP1559Transaction() await metamask.confirmTransaction({ - maxBaseFee: 250, - priorityFee: 150, - gasLimit: 250_000 + gasSetting: { + maxBaseFee: 250, + priorityFee: 150, + gasLimit: 250_000 + } }) }) @@ -139,8 +145,10 @@ describe('with custom gas setting', () => { await connectAndTriggerEIP1559Transaction() await metamask.confirmTransaction({ - maxBaseFee: 250, - priorityFee: 150 + gasSetting: { + maxBaseFee: 250, + priorityFee: 150 + } }) }) @@ -149,8 +157,10 @@ describe('with custom gas setting', () => { await connectAndTriggerEIP1559Transaction() await metamask.confirmTransaction({ - maxBaseFee: 250_000, - priorityFee: 150_000 + gasSetting: { + maxBaseFee: 250_000, + priorityFee: 150_000 + } }) }) })