From b0c0c353345dd2c9ce2a661ffb2be2afb7355454 Mon Sep 17 00:00:00 2001
From: George Marshall
Date: Fri, 13 Oct 2023 06:49:46 -0700
Subject: [PATCH] Fixing truncation and alignment in the network toggle
component (#21370)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## **Description**
Currently there is some truncation issues with long network names in the
privacy incoming transactions section. The truncation of the text is not
working which results in broken UI for longer network names
This PR adds some styles which resolve the issue as well as adding a
story for the network-toggle component for easier revision and review
## **Manual testing steps**
_1. Open the storybook build on this PR
_2. Search `NetworkToggle` and check the story in small screen sizes
_3. Pull this branch
_4. Go to Settings > Security & privacy > Incoming transactions section
## **Screenshots/Recordings**
### **Before**
https://github.com/MetaMask/metamask-extension/assets/8112138/9a7028ca-f70a-4833-94db-75e81b791206
### **After**
https://github.com/MetaMask/metamask-extension/assets/8112138/770cb8c7-f8ba-4a40-b941-1115bcbdd83c
## **Related issues**
_Fixes #21369_
## **Pre-merge author checklist**
- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained:
- [x] What problem this PR is solving.
- [x] How this problem was solved.
- [x] How reviewers can test my changes.
- [x] I’ve indicated what issue this PR is linked to: Fixes #21369
- [x] I’ve included tests if applicable.
- [x] I’ve documented any added code.
- [x] 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)).
- [x] I’ve properly set the pull request status:
- [x] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".
## **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.
---
ui/components/app/app-components.scss | 1 +
.../incoming-transaction-toggle.test.js.snap | 492 +++++++++---------
.../network-toggle.scss | 5 +
.../network-toggle.stories.tsx | 33 ++
.../network-toggle.tsx | 61 ++-
.../__snapshots__/security-tab.test.js.snap | 410 ++++++++-------
6 files changed, 549 insertions(+), 453 deletions(-)
create mode 100644 ui/components/app/incoming-trasaction-toggle/network-toggle.scss
create mode 100644 ui/components/app/incoming-trasaction-toggle/network-toggle.stories.tsx
diff --git a/ui/components/app/app-components.scss b/ui/components/app/app-components.scss
index 24bfd9146013..476901a28f62 100644
--- a/ui/components/app/app-components.scss
+++ b/ui/components/app/app-components.scss
@@ -49,6 +49,7 @@
@import 'multilayer-fee-message/index';
@import 'multiple-notifications/index';
@import 'network-display/index';
+@import 'ui/components/app/incoming-trasaction-toggle/network-toggle';
@import 'permission-page-container/index';
@import 'permissions-connect-footer/index';
@import 'permissions-connect-header/index';
diff --git a/ui/components/app/incoming-trasaction-toggle/__snapshots__/incoming-transaction-toggle.test.js.snap b/ui/components/app/incoming-trasaction-toggle/__snapshots__/incoming-transaction-toggle.test.js.snap
index 0113330cccdd..465ba53bbb89 100644
--- a/ui/components/app/incoming-trasaction-toggle/__snapshots__/incoming-transaction-toggle.test.js.snap
+++ b/ui/components/app/incoming-trasaction-toggle/__snapshots__/incoming-transaction-toggle.test.js.snap
@@ -16,11 +16,11 @@ exports[`IncomingTransactionToggle should render existing incoming transaction p
This relies on different third-party APIs for each network, which expose your Ethereum address and your IP address.
Ethereum Mainnet
-
+
+
Linea Mainnet
-
+
+
FANTOM
-
-
-
- Off
-
-
- On
-
-
-
+
+
Goerli
-
-
-
- Off
-
-
- On
-
-
-
+
+
Sepolia
-
-
-
- Off
-
-
- On
-
-
-
+
+
Linea Goerli
-
+
+
diff --git a/ui/components/app/incoming-trasaction-toggle/network-toggle.scss b/ui/components/app/incoming-trasaction-toggle/network-toggle.scss
new file mode 100644
index 000000000000..b77aeb653bf1
--- /dev/null
+++ b/ui/components/app/incoming-trasaction-toggle/network-toggle.scss
@@ -0,0 +1,5 @@
+.network-toggle-wrapper {
+ &__overflow-container {
+ overflow: hidden;
+ }
+}
diff --git a/ui/components/app/incoming-trasaction-toggle/network-toggle.stories.tsx b/ui/components/app/incoming-trasaction-toggle/network-toggle.stories.tsx
new file mode 100644
index 000000000000..18573fadba83
--- /dev/null
+++ b/ui/components/app/incoming-trasaction-toggle/network-toggle.stories.tsx
@@ -0,0 +1,33 @@
+import React from 'react';
+import { StoryFn, Meta } from '@storybook/react';
+import NetworkToggle from './network-toggle';
+
+export default {
+ title: 'Components/App/IncomingTransactionToggle/NetworkToggle',
+ component: NetworkToggle,
+ argTypes: {
+ chainId: {
+ control: 'text',
+ },
+ networkPreferences: {
+ control: 'object',
+ },
+ toggleSingleNetwork: {
+ action: 'toggleSingleNetwork',
+ },
+ },
+ args: {
+ networkPreferences: {
+ isShowIncomingTransactions: true,
+ label: 'Ethereum or long network name',
+ imageUrl: './images/ethereum.svg',
+ },
+ chainId: '0x1',
+ },
+} as Meta;
+
+export const DefaultStory: StoryFn = (args) => (
+
+);
+
+DefaultStory.storyName = 'Default';
diff --git a/ui/components/app/incoming-trasaction-toggle/network-toggle.tsx b/ui/components/app/incoming-trasaction-toggle/network-toggle.tsx
index bbaa5856502c..dd5f65a35f8d 100644
--- a/ui/components/app/incoming-trasaction-toggle/network-toggle.tsx
+++ b/ui/components/app/incoming-trasaction-toggle/network-toggle.tsx
@@ -61,44 +61,56 @@ const NetworkToggle = ({
marginBottom={6}
display={Display.Flex}
flexDirection={FlexDirection.Row}
+ gap={4}
justifyContent={JustifyContent.spaceBetween}
data-testid={`network-toggle-${chainId}`}
className="network-toggle-wrapper"
>
-
-
- {networkName.length > MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP ? (
-
+
+ {networkName.length > MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP ? (
+
+
{networkName}
-
- ) : (
- networkName
- )}
-
+
+
+ ) : (
+
+ {networkName}
+
+ )}
+
{
// For tests, we have localhost in the network list, but obviously
@@ -118,13 +130,14 @@ const NetworkToggle = ({
-
- toggleSingleNetwork(chainId, !value)}
- offLabel={t('off')}
- onLabel={t('on')}
- />
+
+ toggleSingleNetwork(chainId, !value)}
+ offLabel={t('off')}
+ onLabel={t('on')}
+ />
+
);
};
diff --git a/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap b/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap
index 7c52b3c8e7cc..ce6603ddd2cd 100644
--- a/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap
+++ b/ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap
@@ -306,11 +306,11 @@ exports[`Security Tab should match snapshot 1`] = `
This relies on different third-party APIs for each network, which expose your Ethereum address and your IP address.