Skip to content

Commit

Permalink
fix: fix sticky autodetection banner (#29061)
Browse files Browse the repository at this point in the history
<!--
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**

fix sticky autodetection banner
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

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

## **Related issues**

Fixes: #29059 

## **Manual testing steps**

1. Go to autodetected banner
2. click on ignore all
3. you should have allNetworks selected

## **Screenshots/Recordings**

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

### **Before**

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

### **After**






https://drive.google.com/file/d/11zcmgV1Bdq5wx9MkDlhxr8oDBr9DGB3d/view?usp=sharing




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

## **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/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-extension/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.

---------

Co-authored-by: Brian Bergeron <[email protected]>
  • Loading branch information
salimtb and bergeron authored Dec 10, 2024
1 parent 12aea26 commit 5789e1c
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DetectedTokenIgnoredPopover should match snapshot for ignore mode 1`] = `
<body>
<div
id="popover-content"
/>
<div />
<div
class="mm-modal detected-token-ignored-popover detected-token-ignored-popover--ignore"
>
<div
aria-hidden="true"
class="mm-box mm-modal-overlay mm-box--width-full mm-box--height-full mm-box--background-color-overlay-default"
/>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-lock-disabled="false"
>
<div
class="mm-box mm-modal-content mm-box--padding-top-4 mm-box--sm:padding-top-8 mm-box--md:padding-top-12 mm-box--padding-right-4 mm-box--padding-bottom-4 mm-box--sm:padding-bottom-8 mm-box--md:padding-bottom-12 mm-box--padding-left-4 mm-box--display-flex mm-box--justify-content-center mm-box--align-items-flex-start mm-box--width-screen mm-box--height-screen"
>
<section
aria-modal="true"
class="mm-box mm-modal-content__dialog mm-modal-content__dialog--size-sm mm-box--padding-4 mm-box--width-full mm-box--background-color-background-default mm-box--rounded-lg"
role="dialog"
style="overflow-y: auto;"
>
<div
class="mm-box mm-header-base mm-modal-header mm-box--margin-bottom-4 mm-box--display-flex mm-box--justify-content-space-between"
>
<div
class="mm-box"
>
<header
class="mm-box mm-text mm-text--heading-sm mm-text--text-align-center mm-box--color-text-default"
>
[areYouSure]
</header>
</div>
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-bottom-4 mm-box--color-text-default"
>
[ignoreTokenWarning]
</p>
<div
class="mm-box mm-box--display-flex mm-box--gap-4 mm-box--justify-content-center"
>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-button-base--block detected-token-ignored-popover__ignore-button mm-button-secondary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent mm-box--rounded-pill mm-box--border-color-primary-default box--border-style-solid box--border-width-1"
>
[cancel]
</button>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-button-base--block detected-token-ignored-popover__import-button mm-button-primary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill"
data-testid="detected-token-ignored-popover-confirm-button"
data-theme="light"
>
[confirm]
</button>
</div>
</section>
</div>
</div>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>
</body>
`;

exports[`DetectedTokenIgnoredPopover should match snapshot for import mode 1`] = `
<body>
<div
id="popover-content"
/>
<div />
<div
class="mm-modal detected-token-ignored-popover detected-token-ignored-popover--import"
>
<div
aria-hidden="true"
class="mm-box mm-modal-overlay mm-box--width-full mm-box--height-full mm-box--background-color-overlay-default"
/>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-lock-disabled="false"
>
<div
class="mm-box mm-modal-content mm-box--padding-top-4 mm-box--sm:padding-top-8 mm-box--md:padding-top-12 mm-box--padding-right-4 mm-box--padding-bottom-4 mm-box--sm:padding-bottom-8 mm-box--md:padding-bottom-12 mm-box--padding-left-4 mm-box--display-flex mm-box--justify-content-center mm-box--align-items-flex-start mm-box--width-screen mm-box--height-screen"
>
<section
aria-modal="true"
class="mm-box mm-modal-content__dialog mm-modal-content__dialog--size-sm mm-box--padding-4 mm-box--width-full mm-box--background-color-background-default mm-box--rounded-lg"
role="dialog"
style="overflow-y: auto;"
>
<div
class="mm-box mm-header-base mm-modal-header mm-box--margin-bottom-4 mm-box--display-flex mm-box--justify-content-space-between"
>
<div
class="mm-box"
>
<header
class="mm-box mm-text mm-text--heading-sm mm-text--text-align-center mm-box--color-text-default"
>
[importSelectedTokens]
</header>
</div>
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-bottom-4 mm-box--color-text-default"
>
[importSelectedTokensDescription]
</p>
<div
class="mm-box mm-box--display-flex mm-box--gap-4 mm-box--justify-content-center"
>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-button-base--block detected-token-ignored-popover__ignore-button mm-button-secondary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent mm-box--rounded-pill mm-box--border-color-primary-default box--border-style-solid box--border-width-1"
>
[cancel]
</button>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-lg mm-button-base--block detected-token-ignored-popover__import-button mm-button-primary mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill"
data-testid="detected-token-ignored-popover-confirm-button"
data-theme="light"
>
[confirm]
</button>
</div>
</section>
</div>
</div>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>
</body>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const DetectedTokenIgnoredPopover = ({
variant={BUTTON_VARIANT.PRIMARY}
onClick={handleClearTokensSelection}
size={BUTTON_SIZES.LG}
data-testid="detected-token-ignored-popover-confirm-button"
>
{t('confirm')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import DetectedTokenIgnoredPopover from './detected-token-ignored-popover';

describe('DetectedTokenIgnoredPopover', () => {
const defaultProps = {
partiallyIgnoreDetectedTokens: false,
onCancelIgnore: jest.fn(),
handleClearTokensSelection: jest.fn(),
isOpen: true,
};

const renderComponent = (props = {}) =>
render(<DetectedTokenIgnoredPopover {...defaultProps} {...props} />);

it('should match snapshot for ignore mode', () => {
const { baseElement } = renderComponent();
expect(baseElement).toMatchSnapshot();
});

it('should match snapshot for import mode', () => {
const { baseElement } = renderComponent({
partiallyIgnoreDetectedTokens: true,
});
expect(baseElement).toMatchSnapshot();
});

it('should call handleClearTokensSelection when the confirm button is clicked', () => {
renderComponent();
const confirmButton = screen.getByTestId(
'detected-token-ignored-popover-confirm-button',
);
fireEvent.click(confirmButton);
expect(defaultProps.handleClearTokensSelection).toHaveBeenCalled();
expect(defaultProps.handleClearTokensSelection).not.toThrow();
});
});
12 changes: 7 additions & 5 deletions ui/components/app/detected-token/detected-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ const DetectedToken = ({ setShowDetectedTokens }) => {

const promises = Object.entries(groupedByChainId).map(
async ([chainId, tokens]) => {
const chainConfig = allNetworks[chainId];
const { defaultRpcEndpointIndex } = chainConfig;
const { networkClientId: networkInstanceId } =
chainConfig.rpcEndpoints[defaultRpcEndpointIndex];
const { defaultRpcEndpointIndex, rpcEndpoints } =
allNetworks[chainId];
const networkInstanceId =
rpcEndpoints[defaultRpcEndpointIndex].networkClientId;

const tokensToIgnore = tokens.map((token) => token.address);

await dispatch(
ignoreTokens({
tokensToIgnore: tokens,
tokensToIgnore,
dontShowLoadingIndicator: true,
networkClientId: networkInstanceId,
}),
Expand Down

0 comments on commit 5789e1c

Please sign in to comment.