-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add support for
eth_signTypedData_(v3|v4)
- Loading branch information
1 parent
1efba09
commit 70e74a8
Showing
10 changed files
with
204 additions
and
19 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
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,2 +1,3 @@ | ||
export * from './connectToDapp' | ||
export * from './signSimpleMessage' | ||
export * from './signStructuredMessage' |
15 changes: 5 additions & 10 deletions
15
wallets/metamask/src/pages/NotificationPage/actions/signSimpleMessage.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
25 changes: 25 additions & 0 deletions
25
wallets/metamask/src/pages/NotificationPage/actions/signStructuredMessage.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,25 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
|
||
const signMessage = async (notificationPage: Page) => { | ||
const scrollDownButton = notificationPage.locator(Selectors.SignaturePage.structuredMessage.scrollDownButton) | ||
const signButton = notificationPage.locator(Selectors.SignaturePage.structuredMessage.signButton) | ||
|
||
while (await signButton.isDisabled()) { | ||
await scrollDownButton.click() | ||
} | ||
|
||
await notificationPage.locator(Selectors.SignaturePage.structuredMessage.signButton).click() | ||
} | ||
|
||
const rejectMessage = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.SignaturePage.structuredMessage.rejectButton).click() | ||
} | ||
|
||
// Used for: | ||
// - `eth_signTypedData_v3` | ||
// - `eth_signTypedData_v4` | ||
export const signStructuredMessage = { | ||
sign: signMessage, | ||
reject: rejectMessage | ||
} |
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
13 changes: 12 additions & 1 deletion
13
wallets/metamask/src/pages/NotificationPage/selectors/signaturePage.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 |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' | ||
|
||
export default { | ||
const simpleMessage = { | ||
signButton: `.request-signature__footer ${createDataTestSelector('request-signature__sign')}`, | ||
rejectButton: '.request-signature__footer button.btn-secondary' | ||
} | ||
|
||
const structuredMessage = { | ||
scrollDownButton: `.signature-request-message ${createDataTestSelector('signature-request-scroll-button')}`, | ||
signButton: `.signature-request-footer ${createDataTestSelector('signature-sign-button')}`, | ||
rejectButton: `.signature-request-footer ${createDataTestSelector('signature-cancel-button')}` | ||
} | ||
|
||
export default { | ||
simpleMessage, | ||
structuredMessage | ||
} |
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,50 @@ | ||
import type { Locator } from '@playwright/test' | ||
|
||
// Inlining the sleep function here cause this is one of the few places in the entire codebase where sleep should be used! | ||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
const timeouts = [0, 20, 50, 100, 100, 500] as const | ||
|
||
type State = 'visible' | 'hidden' | ||
|
||
// TODO: Box this function. | ||
// This functions mimics the one found in Playwright with a few small differences. | ||
// Custom implementation is needed because Playwright lists errors in the report even if they are caught. | ||
export async function waitFor(locator: Locator, state: State, timeout: number, shouldThrow = true) { | ||
let timeoutsSum = 0 | ||
let timeoutIndex = 0 | ||
|
||
let reachedTimeout = false | ||
|
||
while (!reachedTimeout) { | ||
let nextTimeout = timeouts.at(Math.min(timeoutIndex++, timeouts.length - 1)) as number | ||
|
||
if (timeoutsSum + nextTimeout > timeout) { | ||
nextTimeout = timeout - timeoutsSum | ||
reachedTimeout = true | ||
} else { | ||
timeoutsSum += nextTimeout | ||
} | ||
|
||
await sleep(nextTimeout) | ||
|
||
const result = await action(locator, state) | ||
if (result) { | ||
return result | ||
} | ||
} | ||
|
||
if (shouldThrow) { | ||
throw new Error(`Timeout ${timeout}ms exceeded.`) | ||
} | ||
|
||
return false | ||
} | ||
|
||
async function action(locator: Locator, state: State) { | ||
if (state === 'hidden') { | ||
return locator.isHidden() | ||
} | ||
|
||
return locator.isVisible() | ||
} |
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