-
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
11 changed files
with
115 additions
and
8 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="" | ||
MAILSEC_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { testMEmail } from './shared/fixtures/w3m-fixture' | ||
import { Email } from './shared/utils/email' | ||
|
||
testMEmail.beforeEach(async ({ modalPage }) => { | ||
const tempEmail = `web3modal@mailsac.com` // TODO: we pay per user so need to improve this | ||
const email = new Email(process.env['MAILSAC_API_KEY']!) | ||
await email.deleteAllMessages(tempEmail) | ||
await modalPage.loginWithEmail(tempEmail) | ||
|
||
const latestMessage: any = await email.getNewMessage(tempEmail) | ||
const messageId = latestMessage._id | ||
const otp = await email.getCodeFromEmail(tempEmail, messageId) | ||
|
||
await modalPage.enterOTP(otp) | ||
}) | ||
|
||
testMEmail('it should sign', async ({ modalValidator }) => { | ||
await modalValidator.expectConnected() | ||
// TODO Implement sign | ||
}) |
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
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,48 @@ | ||
import { Mailsac, type EmailMessage } from '@mailsac/api' | ||
|
||
export class Email { | ||
private readonly mailsac: Mailsac<any> | ||
private messageCount: any | ||
constructor(public readonly apiKey: string) { | ||
this.mailsac = new Mailsac({ headers: { "Mailsac-Key": apiKey } }) | ||
this.messageCount = undefined | ||
} | ||
|
||
async deleteAllMessages(email: string) { | ||
this.messageCount = 0 | ||
return await this.mailsac.messages.deleteAllMessages(email) | ||
} | ||
|
||
async getNewMessage(email: string) { | ||
const timeout = new Promise((_, reject) => { | ||
setTimeout(() => { | ||
reject('timeout') | ||
}, 25000) | ||
}) | ||
|
||
const messagePoll = new Promise((resolve) => { | ||
const interval = setInterval(async () => { | ||
const messages = await this.mailsac.messages.listMessages(email) | ||
if (messages.data.length > this.messageCount) { | ||
clearInterval(interval) | ||
this.messageCount = messages.data.length | ||
const message = messages.data[messages.data.length - 1] as EmailMessage | ||
return resolve(message) | ||
} | ||
}, 500) | ||
}) | ||
|
||
return Promise.any([timeout, messagePoll]) | ||
} | ||
|
||
async getCodeFromEmail(email: string, messageId: string) { | ||
const result = await this.mailsac.messages.getBodyPlainText(email, messageId) | ||
const regex = /\d{3}\s?\d{3}/ | ||
const match = result.data.match(regex) | ||
if (match) { | ||
return match[0].replace(/\s/g, '') | ||
} else { | ||
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