Skip to content

Commit

Permalink
fix: switchToMetamaskNotification broken for tx confirmation
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Mucha <[email protected]>
  • Loading branch information
drptbl committed Oct 26, 2021
1 parent ac5e678 commit 7d22e77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 2 additions & 0 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ module.exports = {
},
confirmTransaction: async () => {
const isKovanTestnet = getNetwork().networkName === 'kovan';
// todo: remove waitForTimeout below after improving switchToMetamaskNotification
await puppeteer.metamaskWindow().waitForTimeout(1000);
const notificationPage = await puppeteer.switchToMetamaskNotification();
const currentGasFee = await puppeteer.waitAndGetValue(
confirmPageElements.gasFeeInput,
Expand Down
18 changes: 5 additions & 13 deletions commands/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ let puppeteerBrowser;
let mainWindow;
let metamaskWindow;

let switchToMetamaskNotificationRetries;

module.exports = {
puppeteerBrowser: () => {
return puppeteerBrowser;
Expand Down Expand Up @@ -98,24 +96,18 @@ module.exports = {
return true;
},
switchToMetamaskNotification: async () => {
await metamaskWindow.waitForTimeout(500);
// todo: wait for page to be initialized before triggering waitFor
// todo: wait for spinning loader to be gone before triggering waitFor
// todo: get rid of waitForTimeout after fixing above
// todo: all of the above are issues related to metamask notification of tx confirmation
await module.exports.metamaskWindow().waitForTimeout(3000);
let pages = await puppeteerBrowser.pages();
for (const page of pages) {
if (page.url().includes('notification')) {
switchToMetamaskNotificationRetries = 0;
await page.bringToFront();
return page;
}
}

// 24*500ms = 12 seconds in total
if (switchToMetamaskNotificationRetries < 24) {
switchToMetamaskNotificationRetries++;
const page = await module.exports.switchToMetamaskNotification();
return page;
} else {
return false;
}
},
waitFor: async (selector, page = metamaskWindow) => {
await page.waitForFunction(
Expand Down

0 comments on commit 7d22e77

Please sign in to comment.