From e5a2159f3b6d3beef6cfd3cd5dab71661d1ddc38 Mon Sep 17 00:00:00 2001
From: Ariella Vu <20778143+digiwand@users.noreply.github.com>
Date: Mon, 23 Sep 2024 21:59:59 +0800
Subject: [PATCH] fix: [cherrypick][V12.3.0] Redesign Signature Message date
values (#27305)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## **Description**
Cherry-pick https://github.com/MetaMask/metamask-extension/pull/27249
for v12.3.0
Fix date values:
- Formerly, conversations were converting values as if they were
milliseconds. However, these values come from Solidity where these
timestamps are unix timestamps in seconds.
- Support -1 (no expiration) value
- Display "expiry" as a date instead of a unix timestamp
This PR fixes the conversion.
[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27249?quickstart=1)
Fixes: https://github.com/MetaMask/metamask-extension/issues/27137
1. Go to test-dapp
2. Request Permit or another TypedSign request
3. Observe deadlines and dates
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
---
app/_locales/en/messages.json | 3 +
test/data/confirmations/typed_sign.ts | 27 +-
.../confirmations/signatures/permit.spec.ts | 2 +-
.../app/confirm/info/row/date.stories.tsx | 4 +-
.../app/confirm/info/row/date.test.tsx | 4 +-
ui/components/app/confirm/info/row/date.tsx | 11 +-
ui/helpers/utils/util.js | 14 +-
ui/helpers/utils/util.test.js | 8 +-
.../personal-sign/siwe-sign/siwe-sign.tsx | 4 +-
.../__snapshots__/typed-sign.test.tsx.snap | 589 +++++++++++++++++-
.../info/typed-sign/typed-sign.test.tsx | 17 +
.../row/__snapshots__/dataTree.test.tsx.snap | 99 +++
.../components/confirm/row/dataTree.test.tsx | 13 +
.../components/confirm/row/dataTree.tsx | 23 +-
.../__snapshots__/confirm.test.tsx.snap | 12 +-
15 files changed, 801 insertions(+), 29 deletions(-)
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json
index c3683becebbd..75ff076121df 100644
--- a/app/_locales/en/messages.json
+++ b/app/_locales/en/messages.json
@@ -3253,6 +3253,9 @@
"nonceFieldHeading": {
"message": "Custom nonce"
},
+ "none": {
+ "message": "None"
+ },
"notBusy": {
"message": "Not busy"
},
diff --git a/test/data/confirmations/typed_sign.ts b/test/data/confirmations/typed_sign.ts
index 3dd236ca9fa6..a63423e17ae9 100644
--- a/test/data/confirmations/typed_sign.ts
+++ b/test/data/confirmations/typed_sign.ts
@@ -1,3 +1,4 @@
+import { TransactionType } from '@metamask/transaction-controller';
import { SignatureRequestType } from '../../../ui/pages/confirmations/types/confirm';
export const unapprovedTypedSignMsgV1 = {
@@ -169,12 +170,13 @@ export const permitSignatureMsg = {
data: '{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Permit":[{"name":"owner","type":"address"},{"name":"spender","type":"address"},{"name":"value","type":"uint256"},{"name":"nonce","type":"uint256"},{"name":"deadline","type":"uint256"}]},"primaryType":"Permit","domain":{"name":"MyToken","version":"1","verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC","chainId":1},"message":{"owner":"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477","spender":"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","value":3000,"nonce":0,"deadline":50000000000}}',
from: '0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
version: 'V4',
+ requestId: 14,
signatureMethod: 'eth_signTypedData_v4',
origin: 'https://metamask.github.io',
},
} as SignatureRequestType;
-export const permitBatchSignatureMsg = {
+export const permitSignatureMsgWithNoDeadline = {
id: '0b1787a0-1c44-11ef-b70d-e7064bd7b659',
securityAlertResponse: {
reason: 'loading',
@@ -184,10 +186,30 @@ export const permitBatchSignatureMsg = {
status: 'unapproved',
time: 1716826404122,
type: 'eth_signTypedData',
+ msgParams: {
+ data: '{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Permit":[{"name":"owner","type":"address"},{"name":"spender","type":"address"},{"name":"value","type":"uint256"},{"name":"nonce","type":"uint256"},{"name":"deadline","type":"uint256"}]},"primaryType":"Permit","domain":{"name":"MyToken","version":"1","verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC","chainId":1},"message":{"owner":"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477","spender":"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","value":3000,"nonce":0,"deadline":-1}}',
+ from: '0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
+ version: 'V4',
+ signatureMethod: 'eth_signTypedData_v4',
+ origin: 'https://metamask.github.io',
+ },
+} as SignatureRequestType;
+
+export const permitBatchSignatureMsg = {
+ id: '0b1787a0-1c44-11ef-b70d-e7064bd7b659',
+ securityAlertResponse: {
+ reason: 'loading',
+ result_type: 'validation_in_progress',
+ securityAlertId: 'ab21395f-2190-472f-8cfa-3d224e7529d8',
+ },
+ status: 'unapproved',
+ time: 1716826404122,
+ type: TransactionType.signTypedData,
msgParams: {
data: '{"types":{"PermitBatch":[{"name":"details","type":"PermitDetails[]"},{"name":"spender","type":"address"},{"name":"sigDeadline","type":"uint256"}],"PermitDetails":[{"name":"token","type":"address"},{"name":"amount","type":"uint160"},{"name":"expiration","type":"uint48"},{"name":"nonce","type":"uint48"}],"EIP712Domain":[{"name":"name","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}]},"domain":{"name":"Permit2","chainId":"1","verifyingContract":"0x000000000022d473030f116ddee9f6b43ac78ba3"},"primaryType":"PermitBatch","message":{"details":[{"token":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","amount":"1461501637330902918203684832716283019655932542975","expiration":"1722887542","nonce":"5"},{"token":"0xb0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","amount":"2461501637330902918203684832716283019655932542975","expiration":"1722887642","nonce":"6"}],"spender":"0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad","sigDeadline":"1720297342"}}',
from: '0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
version: 'V4',
+ requestId: 15,
signatureMethod: 'eth_signTypedData_v4',
origin: 'https://metamask.github.io',
},
@@ -202,11 +224,12 @@ export const permitSingleSignatureMsg = {
},
status: 'unapproved',
time: 1716826404122,
- type: 'eth_signTypedData',
+ type: TransactionType.signTypedData,
msgParams: {
data: '{"types":{"PermitSingle":[{"name":"details","type":"PermitDetails"},{"name":"spender","type":"address"},{"name":"sigDeadline","type":"uint256"}],"PermitDetails":[{"name":"token","type":"address"},{"name":"amount","type":"uint160"},{"name":"expiration","type":"uint48"},{"name":"nonce","type":"uint48"}],"EIP712Domain":[{"name":"name","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}]},"domain":{"name":"Permit2","chainId":"1","verifyingContract":"0x000000000022d473030f116ddee9f6b43ac78ba3"},"primaryType":"PermitSingle","message":{"details":{"token":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","amount":"1461501637330902918203684832716283019655932542975","expiration":"1722887542","nonce":"5"},"spender":"0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad","sigDeadline":"1720297342"}}',
from: '0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
version: 'V4',
+ requestId: 16,
signatureMethod: 'eth_signTypedData_v4',
origin: 'https://metamask.github.io',
},
diff --git a/test/e2e/tests/confirmations/signatures/permit.spec.ts b/test/e2e/tests/confirmations/signatures/permit.spec.ts
index a8191a15f229..6dadf732c246 100644
--- a/test/e2e/tests/confirmations/signatures/permit.spec.ts
+++ b/test/e2e/tests/confirmations/signatures/permit.spec.ts
@@ -123,7 +123,7 @@ async function assertInfoValues(driver: Driver) {
});
const value = driver.findElement({ text: '3,000' });
const nonce = driver.findElement({ text: '0' });
- const deadline = driver.findElement({ text: '02 August 1971, 16:53' });
+ const deadline = driver.findElement({ text: '09 June 3554, 16:53' });
assert.ok(await origin, 'origin');
assert.ok(await contractPetName, 'contractPetName');
diff --git a/ui/components/app/confirm/info/row/date.stories.tsx b/ui/components/app/confirm/info/row/date.stories.tsx
index 971ba7624f3e..e0e6a9a07dec 100644
--- a/ui/components/app/confirm/info/row/date.stories.tsx
+++ b/ui/components/app/confirm/info/row/date.stories.tsx
@@ -18,9 +18,9 @@ const ConfirmInfoRowDateStory = {
},
};
-export const DefaultStory = ({ date }) =>
+ Estimated changes +
++ You're giving the spender permission to spend this many tokens from your account. +
++ Spending cap +
++ 3,000 +
++ 0xCcCCc...ccccC +
++ Spender +
++ 0x5B38D...eddC4 +
++ Request from +
++ metamask.github.io +
++ Interacting with +
++ 0xCcCCc...ccccC +
++ Message +
++ Primary type: +
++ Permit +
++ Owner: +
++ 0x935E7...05477 +
++ Spender: +
++ 0x5B38D...eddC4 +
++ Value: +
++ 3,000 +
++ Nonce: +
++ 0 +
++ Deadline: +
++ None
+ Types: +
++ PrimaryType: +
++ Domain: +
++ Message: +
++ 3000 +
+