Skip to content

Commit

Permalink
fix: PermitSingle, PermitBatch, PermitTransferFrom, PermitBatchTransf…
Browse files Browse the repository at this point in the history
…erFrom simulation "Spending cap" (#26684)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Fixes PermitSingle, PermitBatch, PermitTransferFrom,
PermitBatchTransferFrom simulation to use their respective provided
token and amount in token details.

Additionally:
- adjusts styles to have an 8px gap between each "Spending Cap" entry
and right align content
- create PermitSimulationValueDisplay component to separate individual
token contract value logic
- adds tests
- adds sentry error to capture exception in case token isn't provided
for the relevant primaryTypes

dev note: majority of the newlines come from updated and new test
snapshots

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26684?quickstart=1)

## **Related issues**

Fixes: #26591
(PermitSingle)
Fixes: #26592
(PermitBatch)
## **Manual testing steps**

Test PermitSingle & PermitBatch with Improved Signature setting enabled

See related issues for repro steps

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**
<img width="320"
src="https://github.com/user-attachments/assets/aac7fa8c-285a-4d2b-bcec-84c7fc6245bf">
<!-- [screenshots/recordings] -->
See Issue screenshots

### **After PermitBatch**

<!-- [screenshots/recordings] -->

![image](https://github.com/user-attachments/assets/4564530d-1c3d-430b-b821-15ed0fca6152)

## **Pre-merge author checklist**

- [ ] 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.

## **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.
  • Loading branch information
digiwand authored Sep 4, 2024
1 parent ce04ae8 commit 1801174
Show file tree
Hide file tree
Showing 12 changed files with 2,388 additions and 555 deletions.
38 changes: 38 additions & 0 deletions test/data/confirmations/typed_sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,41 @@ export const permitSignatureMsg = {
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: 'eth_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',
signatureMethod: 'eth_signTypedData_v4',
origin: 'https://metamask.github.io',
},
} as SignatureRequestType;

export const permitSingleSignatureMsg = {
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: 'eth_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',
signatureMethod: 'eth_signTypedData_v4',
origin: 'https://metamask.github.io',
},
} as SignatureRequestType;
Original file line number Diff line number Diff line change
Expand Up @@ -65,51 +65,55 @@ exports[`TypedSignInfo correctly renders permit sign type 1`] = `
style="margin-left: auto; max-width: 100%;"
>
<div
class="mm-box mm-box--display-flex"
class="mm-box"
>
<div
class="mm-box mm-box--margin-inline-end-1 mm-box--display-inline mm-box--min-width-0"
class="mm-box mm-box--display-flex mm-box--justify-content-flex-end"
>
<div
style="min-width: 0;"
class="mm-box mm-box--margin-inline-end-1 mm-box--display-inline mm-box--min-width-0"
>
<div
aria-describedby="tippy-tooltip-9"
class=""
data-original-title="3,000"
data-tooltipped=""
style="display: inline;"
tabindex="0"
style="min-width: 0;"
>
<p
class="mm-box mm-text mm-text--body-md mm-text--text-align-center mm-box--padding-inline-2 mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-xl"
data-testid="simulation-token-value"
style="padding-top: 1px; padding-bottom: 1px;"
<div
aria-describedby="tippy-tooltip-9"
class=""
data-original-title="3,000"
data-tooltipped=""
style="display: inline;"
tabindex="0"
>
3,000
</p>
<p
class="mm-box mm-text mm-text--body-md mm-text--text-align-center mm-box--padding-inline-2 mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-xl"
data-testid="simulation-token-value"
style="padding-top: 1px; padding-bottom: 1px;"
>
3,000
</p>
</div>
</div>
</div>
</div>
<div>
<div
class="name name__missing"
>
<span
class="mm-box name__icon mm-icon mm-icon--size-md mm-box--display-inline-block mm-box--color-inherit"
style="mask-image: url('./images/icons/question.svg');"
/>
<p
class="mm-box mm-text name__value mm-text--body-md mm-box--color-text-default"
<div>
<div
class="name name__missing"
>
0xCcCCc...ccccC
</p>
<span
class="mm-box name__icon mm-icon mm-icon--size-md mm-box--display-inline-block mm-box--color-inherit"
style="mask-image: url('./images/icons/question.svg');"
/>
<p
class="mm-box mm-text name__value mm-text--body-md mm-box--color-text-default"
>
0xCcCCc...ccccC
</p>
</div>
</div>
</div>
<div
class="mm-box"
/>
</div>
<div
class="mm-box"
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,51 +65,55 @@ exports[`PermitSimulation renders component correctly 1`] = `
style="margin-left: auto; max-width: 100%;"
>
<div
class="mm-box mm-box--display-flex"
class="mm-box"
>
<div
class="mm-box mm-box--margin-inline-end-1 mm-box--display-inline mm-box--min-width-0"
class="mm-box mm-box--display-flex mm-box--justify-content-flex-end"
>
<div
style="min-width: 0;"
class="mm-box mm-box--margin-inline-end-1 mm-box--display-inline mm-box--min-width-0"
>
<div
aria-describedby="tippy-tooltip-2"
class=""
data-original-title="30"
data-tooltipped=""
style="display: inline;"
tabindex="0"
style="min-width: 0;"
>
<p
class="mm-box mm-text mm-text--body-md mm-text--text-align-center mm-box--padding-inline-2 mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-xl"
data-testid="simulation-token-value"
style="padding-top: 1px; padding-bottom: 1px;"
<div
aria-describedby="tippy-tooltip-2"
class=""
data-original-title="30"
data-tooltipped=""
style="display: inline;"
tabindex="0"
>
30
</p>
<p
class="mm-box mm-text mm-text--body-md mm-text--text-align-center mm-box--padding-inline-2 mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-xl"
data-testid="simulation-token-value"
style="padding-top: 1px; padding-bottom: 1px;"
>
30
</p>
</div>
</div>
</div>
</div>
<div>
<div
class="name name__missing"
>
<span
class="mm-box name__icon mm-icon mm-icon--size-md mm-box--display-inline-block mm-box--color-inherit"
style="mask-image: url('./images/icons/question.svg');"
/>
<p
class="mm-box mm-text name__value mm-text--body-md mm-box--color-text-default"
<div>
<div
class="name name__missing"
>
0xCcCCc...ccccC
</p>
<span
class="mm-box name__icon mm-icon mm-icon--size-md mm-box--display-inline-block mm-box--color-inherit"
style="mask-image: url('./images/icons/question.svg');"
/>
<p
class="mm-box mm-text name__value mm-text--body-md mm-box--color-text-default"
>
0xCcCCc...ccccC
</p>
</div>
</div>
</div>
<div
class="mm-box"
/>
</div>
<div
class="mm-box"
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';

import { act } from 'react-dom/test-utils';
import { getMockTypedSignConfirmStateForRequest } from '../../../../../../../../test/data/confirmations/helper';
import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers';
import { permitSignatureMsg } from '../../../../../../../../test/data/confirmations/typed_sign';
import PermitSimulation from './permit-simulation';

jest.mock('../../../../../../../store/actions', () => {
return {
getTokenStandardAndDetails: jest.fn().mockResolvedValue({ decimals: 2 }),
};
});

describe('PermitSimulation', () => {
it('renders component correctly', () => {
it('renders component correctly', async () => {
const state = getMockTypedSignConfirmStateForRequest(permitSignatureMsg);
const mockStore = configureMockStore([])(state);
const { container } = renderWithConfirmContextProvider(
<PermitSimulation tokenDecimals={2} />,
mockStore,
);
expect(container).toMatchSnapshot();

await act(async () => {
const { container, findByText } = renderWithConfirmContextProvider(
<PermitSimulation />,
mockStore,
);

expect(await findByText('30')).toBeInTheDocument();
expect(container).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 1801174

Please sign in to comment.