-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
214 additions
and
10 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
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,3 +1,4 @@ | ||
# Obtain a project ID from https://cloud.walletconnect.com | ||
NEXT_PUBLIC_PROJECT_ID="" | ||
NEXTAUTH_SECRET="" | ||
MAILSAC_API_KEY="" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { testMEmail } from './shared/fixtures/w3m-fixture' | ||
import { DeviceRegistrationPage } from './shared/pages/DeviceRegistrationPage' | ||
import { Email } from './shared/utils/email' | ||
|
||
// Prevent collissions by using a semi-random reserved Mailsac email | ||
const AVAILABLE_MAILSAC_ADDRESSES = 10 | ||
|
||
testMEmail.beforeEach(async ({ modalPage, context, modalValidator }) => { | ||
// Skip wagmi as it's not working | ||
if (modalPage.library === 'wagmi') { | ||
return | ||
} | ||
// This is prone to collissions and will be improved later | ||
const tempEmail = `web3modal${Math.floor( | ||
Math.random() * AVAILABLE_MAILSAC_ADDRESSES | ||
)}@mailsac.com` | ||
const mailsacApiKey = process.env['MAILSAC_API_KEY'] | ||
if (!mailsacApiKey) { | ||
throw new Error('MAILSAC_API_KEY is not set') | ||
} | ||
const email = new Email(mailsacApiKey) | ||
await email.deleteAllMessages(tempEmail) | ||
await modalPage.loginWithEmail(tempEmail) | ||
|
||
let latestMessage = await email.getNewMessage(tempEmail) | ||
let messageId = latestMessage._id | ||
|
||
if (!messageId) { | ||
throw new Error('No messageId found') | ||
} | ||
|
||
let otp = await email.getCodeFromEmail(tempEmail, messageId) | ||
|
||
if (otp.length !== 6) { | ||
// We got a device registration link so let's register first | ||
const drp = new DeviceRegistrationPage(await context.newPage(), otp) | ||
drp.load() | ||
await drp.approveDevice() | ||
|
||
latestMessage = await email.getNewMessage(tempEmail) | ||
messageId = latestMessage._id | ||
if (!messageId) { | ||
throw new Error('No messageId found') | ||
} | ||
otp = await email.getCodeFromEmail(tempEmail, messageId) | ||
} | ||
|
||
await modalPage.enterOTP(otp) | ||
await modalValidator.expectConnected() | ||
}) | ||
|
||
testMEmail('it should sign', async ({ modalPage, modalValidator }) => { | ||
testMEmail.skip(modalPage.library === 'wagmi', 'Tests are flaky on wagmi') | ||
await modalPage.sign() | ||
await modalPage.approveSign() | ||
await modalValidator.expectAcceptedSign() | ||
}) |
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
16 changes: 16 additions & 0 deletions
16
apps/laboratory/tests/shared/pages/DeviceRegistrationPage.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,16 @@ | ||
import type { Page } from '@playwright/test' | ||
|
||
export class DeviceRegistrationPage { | ||
constructor( | ||
public readonly page: Page, | ||
public readonly url: string | ||
) {} | ||
|
||
async load() { | ||
await this.page.goto(this.url) | ||
} | ||
|
||
async approveDevice() { | ||
await this.page.getByRole('button', { name: 'Approve' }).click() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Mailsac, type EmailMessage } from '@mailsac/api' | ||
|
||
export class Email { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
private readonly mailsac: Mailsac<any> | ||
private messageCount: number | ||
constructor(public readonly apiKey: string) { | ||
this.mailsac = new Mailsac({ headers: { 'Mailsac-Key': apiKey } }) | ||
this.messageCount = 0 | ||
} | ||
|
||
async deleteAllMessages(email: string) { | ||
this.messageCount = 0 | ||
|
||
return await this.mailsac.messages.deleteAllMessages(email) | ||
} | ||
|
||
async getNewMessage(email: string) { | ||
const timeout = new Promise<EmailMessage>((_, reject) => { | ||
setTimeout(() => reject(new Error('Timeout waiting for email')), 15000) | ||
}) | ||
|
||
const messagePoll = new Promise<EmailMessage>(resolve => { | ||
const interval = setInterval(async () => { | ||
const messages = await this.mailsac.messages.listMessages(email) | ||
if (messages.data.length > 0 && messages.data.length > this.messageCount) { | ||
clearInterval(interval) | ||
this.messageCount = messages.data.length | ||
const message = messages.data[0] | ||
|
||
if (!message) { | ||
throw new Error('No message found') | ||
} | ||
|
||
return resolve(message) | ||
} | ||
|
||
return undefined | ||
}, 500) | ||
}) | ||
|
||
return Promise.any([timeout, messagePoll]) | ||
} | ||
|
||
async getCodeFromEmail(email: string, messageId: string) { | ||
const result = await this.mailsac.messages.getBodyPlainText(email, messageId) | ||
|
||
if (result.data.includes('Approve this login')) { | ||
// Get the register.web3modal.com device registration URL | ||
const regex = /https:\/\/register.*/u | ||
const match = result.data.match(regex) | ||
if (match) { | ||
return match[0] | ||
} | ||
|
||
throw new Error(`No url found in email: ${result.data}`) | ||
} | ||
|
||
const otpRegex = /\d{3}\s?\d{3}/u | ||
const match = result.data.match(otpRegex) | ||
if (match) { | ||
return match[0].replace(/\s/gu, '') | ||
} | ||
|
||
throw new Error(`No code found in email: ${result.data}`) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
5101280
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web3modal-react-wagmi-ex – ./
web3modal-react-wagmi-ex-git-v3-walletconnect1.vercel.app
web3modal-react-wagmi-example.vercel.app
web3modal-react-wagmi-ex-walletconnect1.vercel.app
5101280
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web3modal-vue-wagmi-ex – ./
web3modal-vue-wagmi-ex-walletconnect1.vercel.app
web3modal-vue-wagmi-example.vercel.app
web3modal-vue-wagmi-ex-git-v3-walletconnect1.vercel.app
5101280
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web3modal-laboratory – ./
lab.web3modal.com
web3modal-laboratory-git-v3-walletconnect1.vercel.app
web3modal-laboratory-v3.vercel.app
web3modal-laboratory-walletconnect1.vercel.app