From ff19cedd830fe63fad0117b7d912dabf2d3be65d Mon Sep 17 00:00:00 2001
From: digiwand <20778143+digiwand@users.noreply.github.com>
Date: Thu, 16 Jan 2025 07:37:26 -0800
Subject: [PATCH] feat: Redesign Signature Decoding Simulation (#12994)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## **Description**
Add Signature Decoding Simulation UI
This logic mirrors the extension with slight modifications due to
mobile/extension parity differences.
In addition:
- updated ValueDisplay value logic to no longer use useMemo
Todo in follow-up PRs:
- Add additional tests
https://github.com/MetaMask/metamask-mobile/issues/13023
- Add "Unlimited" text support
https://github.com/MetaMask/metamask-mobile/issues/13022
- Investigate "useExternalServices" setting. This does not seem to exist
in mobile https://github.com/MetaMask/metamask-mobile/issues/13024
## **Related issues**
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3876
Related: https://github.com/MetaMask/metamask-mobile/pull/12994
(Replaces Ramp/Box usages with View)
## **Manual testing steps**
1. Set REDESIGNED_SIGNATURE_REQUEST to true in js.env
2. Enable confirmation_redesign in Launch Darkly
3. Turn on Improved Signatures setting
4. Turn on Simulation setting
5. Test various v3 and v4 signTypedData signatures
- Example dapp: https://develop.d3bkcslj57l47p.amplifyapp.com/ → "Permit
2 - Single" button
## **Screenshots/Recordings**
### **Before**
### **After**
The values in this screenshot will be replaced by "Unlimited"
## **Pre-merge author checklist**
- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] 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.
---
.js.env.example | 3 +
.../Views/confirmations/Confirm/Confirm.tsx | 2 +-
.../TypedSignV3V4/Simulation/Simulation.tsx | 31 +++
.../Simulation/Static/Static.tsx | 55 +++++
.../TypedSignV3V4/Simulation/Static/index.ts | 1 +
.../TypedSignDecoded.test.tsx | 167 ++++++++++++++
.../TypedSignDecoded/TypedSignDecoded.tsx | 213 ++++++++++++++++++
.../Simulation/TypedSignDecoded/index.ts | 1 +
.../NativeValueDisplay/NativeValueDisplay.tsx | 153 +++++++++++++
.../components/NativeValueDisplay/index.ts | 1 +
.../ValueDisplay/ValueDisplay.styles.ts | 7 +-
.../components/ValueDisplay/ValueDisplay.tsx | 51 ++---
.../Info/TypedSignV3V4/Simulation/index.ts | 1 +
.../Info/TypedSignV3V4/TypedSignV3V4.tsx | 23 +-
.../components/SignatureRequest/Root/Root.tsx | 2 +-
.../confirmations/hooks/useApprovalRequest.ts | 6 +-
.../useConfirmationRedesignEnabled.test.ts | 2 +-
.../hooks/useConfirmationRedesignEnabled.ts | 4 +-
.../hooks/useTypedSignSimulationEnabled.ts | 66 ++++++
.../confirmations/utils/signature.test.ts | 14 +-
.../Views/confirmations/utils/signature.ts | 14 +-
app/core/AppConstants.ts | 1 +
app/core/Engine/Engine.ts | 4 +
app/selectors/currencyRateController.test.ts | 36 +++
app/selectors/currencyRateController.ts | 25 +-
app/util/number/index.js | 18 +-
app/util/number/index.test.ts | 37 +++
locales/languages/en.json | 11 +-
28 files changed, 873 insertions(+), 76 deletions(-)
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/Simulation.tsx
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/Static/Static.tsx
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/Static/index.ts
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/TypedSignDecoded/TypedSignDecoded.test.tsx
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/TypedSignDecoded/TypedSignDecoded.tsx
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/TypedSignDecoded/index.ts
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/components/NativeValueDisplay/NativeValueDisplay.tsx
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/components/NativeValueDisplay/index.ts
create mode 100644 app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/index.ts
create mode 100644 app/components/Views/confirmations/hooks/useTypedSignSimulationEnabled.ts
diff --git a/.js.env.example b/.js.env.example
index 38daeab2a2c..0d1d2764861 100644
--- a/.js.env.example
+++ b/.js.env.example
@@ -66,6 +66,9 @@ export SEGMENT_FLUSH_INTERVAL="1"
# example for flush when 1 event is queued
export SEGMENT_FLUSH_EVENT_LIMIT="1"
+# URL of the decoding API used to provide additional data from signature requests
+export DECODING_API_URL: 'https://signature-insights.api.cx.metamask.io/v1'
+
# URL of security alerts API used to validate dApp requests.
export SECURITY_ALERTS_API_URL="https://security-alerts.api.cx.metamask.io"
diff --git a/app/components/Views/confirmations/Confirm/Confirm.tsx b/app/components/Views/confirmations/Confirm/Confirm.tsx
index a13ec947e8d..4a18a99d7d1 100644
--- a/app/components/Views/confirmations/Confirm/Confirm.tsx
+++ b/app/components/Views/confirmations/Confirm/Confirm.tsx
@@ -8,7 +8,7 @@ import Footer from '../components/Confirm/Footer';
import Info from '../components/Confirm/Info';
import SignatureBlockaidBanner from '../components/Confirm/SignatureBlockaidBanner';
import Title from '../components/Confirm/Title';
-import useConfirmationRedesignEnabled from '../hooks/useConfirmationRedesignEnabled';
+import { useConfirmationRedesignEnabled } from '../hooks/useConfirmationRedesignEnabled';
import styleSheet from './Confirm.styles';
const Confirm = () => {
diff --git a/app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/Simulation.tsx b/app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/Simulation.tsx
new file mode 100644
index 00000000000..981a9355911
--- /dev/null
+++ b/app/components/Views/confirmations/components/Confirm/Info/TypedSignV3V4/Simulation/Simulation.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+
+import { useTypedSignSimulationEnabled } from '../../../../../hooks/useTypedSignSimulationEnabled';
+import { isRecognizedPermit } from '../../../../../utils/signature';
+import { useSignatureRequest } from '../../../../../hooks/useSignatureRequest';
+import DecodedSimulation from './TypedSignDecoded';
+import PermitSimulation from './TypedSignPermit';
+
+const TypedSignV3V4Simulation: React.FC