From 54f2ec4afc504631dc9c56b230d1d53b6a5a78f0 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Mon, 10 Jun 2024 22:39:23 -0700 Subject: [PATCH 1/6] multi rpc url editor --- app/_locales/en/messages.json | 3 + ui/pages/settings/networks-tab/index.scss | 19 +++ .../networks-form/networks-form.js | 27 +++-- .../networks-form/rpc-url-editor.tsx | 113 ++++++++++++++++++ 4 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index c5f144a224cd..d0bb0b61aeec 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1336,6 +1336,9 @@ "decryptRequest": { "message": "Decrypt request" }, + "defaultRpcUrl": { + "message": "Default RPC URL" + }, "delete": { "message": "Delete" }, diff --git a/ui/pages/settings/networks-tab/index.scss b/ui/pages/settings/networks-tab/index.scss index b8d1458a77ed..3819786d4d44 100644 --- a/ui/pages/settings/networks-tab/index.scss +++ b/ui/pages/settings/networks-tab/index.scss @@ -1,6 +1,25 @@ @use "design-system"; .networks-tab { + + // TODO: Matching behavior of existing headings on network form + // But seems weird, probably all should be text cursor. + &__rpc-text, &__rpc-header { + cursor: default + } + + &__rpc-popover { + z-index: 1; + } + + &__rpc-text:hover, &__rpc-add:hover{ + cursor: pointer; + } + + &__rpc-endpoint:hover, &__rpc-add:hover { + background-color: var(--color-background-default-hover); + } + &__imageclose { cursor: pointer; color: var(--color-icon-default); diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.js b/ui/pages/settings/networks-tab/networks-form/networks-form.js index b5a072ac3312..1aa7d9304047 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.js @@ -62,6 +62,7 @@ import { getMatchedChain, getMatchedSymbols, } from '../../../../helpers/utils/network-helper'; +import { RpcUrlEditor } from './rpc-url-editor'; /** * Attempts to convert the given chainId to a decimal string, for display @@ -760,17 +761,21 @@ const NetworksForm = ({ disabled={viewOnly} dataTestId="network-form-network-name" /> - { - setIsEditing(true); - setRpcUrl(value); - }} - titleText={t('rpcUrl')} - value={displayRpcUrl} - disabled={viewOnly} - dataTestId="network-form-rpc-url" - /> + {window.metamaskFeatureFlags?.networkMenuRedesign ? ( + + ) : ( + { + setIsEditing(true); + setRpcUrl(value); + }} + titleText={t('rpcUrl')} + value={displayRpcUrl} + disabled={viewOnly} + dataTestId="network-form-rpc-url" + /> + )} { + const t = useI18nContext(); + const [isOpen, setIsOpen] = useState(false); + const rpcDropdown = useRef(null); + + // TODO: real endpoints + const dummyRpcEndpoints = [ + 'https://palmn-mainnet.infura.io', + 'https://palm-mainnet.public.blastapi.io', + 'https://tatum.io/v3/blockchain/node/palm', + ]; + + return ( + <> + + {t('defaultRpcUrl')} + + setIsOpen(!isOpen)} + className="networks-tab__rpc-text" + display={Display.Flex} + justifyContent={JustifyContent.spaceBetween} + borderRadius={BorderRadius.MD} + borderColor={BorderColor.borderDefault} + borderWidth={1} + padding={2} + ref={rpcDropdown} + > + {dummyRpcEndpoints[0]} + + + + {dummyRpcEndpoints.map((rpcEndpoint) => ( + + {rpcEndpoint} + alert('TODO: delete confirmation modal')} + /> + + ))} + alert('TODO: add RPC modal')} + padding={4} + display={Display.Flex} + alignItems={AlignItems.center} + className="networks-tab__rpc-add" + > + + + Add RPC URL + + + + + ); +}; + +export default RpcUrlEditor; From 78d89b05dbd274dfbd416588f2658a23b9cb73cc Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Wed, 12 Jun 2024 20:50:53 -0700 Subject: [PATCH 2/6] localize + lint --- app/_locales/en/messages.json | 3 +++ ui/pages/settings/networks-tab/index.scss | 11 +++++++---- .../networks-tab/networks-form/rpc-url-editor.tsx | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index e9c9543f0670..d0145685c9ad 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -289,6 +289,9 @@ "addNfts": { "message": "Add NFTs" }, + "addRpcUrl": { + "message": "Add RPC URL" + }, "addSnapAccountToggle": { "message": "Enable \"Add account Snap (Beta)\"" }, diff --git a/ui/pages/settings/networks-tab/index.scss b/ui/pages/settings/networks-tab/index.scss index 3819786d4d44..af882ccc8e00 100644 --- a/ui/pages/settings/networks-tab/index.scss +++ b/ui/pages/settings/networks-tab/index.scss @@ -4,19 +4,22 @@ // TODO: Matching behavior of existing headings on network form // But seems weird, probably all should be text cursor. - &__rpc-text, &__rpc-header { - cursor: default + &__rpc-text, + &__rpc-header { + cursor: default; } &__rpc-popover { z-index: 1; } - &__rpc-text:hover, &__rpc-add:hover{ + &__rpc-text:hover, + &__rpc-add:hover { cursor: pointer; } - &__rpc-endpoint:hover, &__rpc-add:hover { + &__rpc-endpoint:hover, + &__rpc-add:hover { background-color: var(--color-background-default-hover); } diff --git a/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx b/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx index 6ee066215781..247a7956b40b 100644 --- a/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx +++ b/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx @@ -102,7 +102,7 @@ export const RpcUrlEditor = () => { size={IconSize.Sm} /> - Add RPC URL + {t('addRpcUrl')} From abcddff8aaf6627b0032756bf4a63889da25adee Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Wed, 12 Jun 2024 22:53:44 -0700 Subject: [PATCH 3/6] make clickable things accessible, add blue pill for selected one --- ui/pages/settings/networks-tab/index.scss | 40 ++++++++++++--- .../networks-form/rpc-url-editor.tsx | 50 +++++++++++++++---- 2 files changed, 72 insertions(+), 18 deletions(-) diff --git a/ui/pages/settings/networks-tab/index.scss b/ui/pages/settings/networks-tab/index.scss index af882ccc8e00..a9380e5b3744 100644 --- a/ui/pages/settings/networks-tab/index.scss +++ b/ui/pages/settings/networks-tab/index.scss @@ -4,23 +4,49 @@ // TODO: Matching behavior of existing headings on network form // But seems weird, probably all should be text cursor. - &__rpc-text, &__rpc-header { cursor: default; } - &__rpc-popover { - z-index: 1; + &__rpc-dropdown { + cursor: pointer; } - &__rpc-text:hover, - &__rpc-add:hover { + &__rpc-item { + position: relative; + } + + &__rpc-item:hover { cursor: pointer; + background-color: var(--color-background-default-hover); + } + + // These are s for accessibility, + // but I don't want the styling that comes with it + &__rpc-url:hover { + text-decoration: none !important; + color: var(--color-text-default) !important; } - &__rpc-endpoint:hover, &__rpc-add:hover { - background-color: var(--color-background-default-hover); + text-decoration: none !important; + } + + &__rpc-item--selected, + &__rpc-item--selected:hover { + background-color: var(--color-primary-muted); + } + + &__rpc-selected-pill { + width: 4px; + height: calc(100% - 8px); + position: absolute; + top: 4px; + left: 4px; + } + + &__rpc-popover { + z-index: 1; } &__imageclose { diff --git a/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx b/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx index 247a7956b40b..fe4db9fd7e09 100644 --- a/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx +++ b/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx @@ -1,8 +1,10 @@ import React, { useRef, useState } from 'react'; +import classnames from 'classnames'; import { Box, ButtonIcon, ButtonIconSize, + ButtonLink, Icon, IconName, IconSize, @@ -12,6 +14,7 @@ import { } from '../../../../components/component-library'; import { AlignItems, + BackgroundColor, BorderColor, BorderRadius, Display, @@ -23,10 +26,6 @@ import { import { useI18nContext } from '../../../../hooks/useI18nContext'; export const RpcUrlEditor = () => { - const t = useI18nContext(); - const [isOpen, setIsOpen] = useState(false); - const rpcDropdown = useRef(null); - // TODO: real endpoints const dummyRpcEndpoints = [ 'https://palmn-mainnet.infura.io', @@ -34,6 +33,13 @@ export const RpcUrlEditor = () => { 'https://tatum.io/v3/blockchain/node/palm', ]; + const t = useI18nContext(); + const rpcDropdown = useRef(null); + const [isOpen, setIsOpen] = useState(false); + const [currentRpcEndpoint, setCurrentRpcEndpoint] = useState( + dummyRpcEndpoints[0], + ); + return ( <> { setIsOpen(!isOpen)} - className="networks-tab__rpc-text" + className="networks-tab__rpc-dropdown" display={Display.Flex} justifyContent={JustifyContent.spaceBetween} borderRadius={BorderRadius.MD} @@ -55,7 +61,7 @@ export const RpcUrlEditor = () => { padding={2} ref={rpcDropdown} > - {dummyRpcEndpoints[0]} + {currentRpcEndpoint} { display={Display.Flex} justifyContent={JustifyContent.spaceBetween} key={rpcEndpoint} - className="networks-tab__rpc-endpoint" + onClick={() => setCurrentRpcEndpoint(rpcEndpoint)} + className={classnames('networks-tab__rpc-item', { + 'networks-tab__rpc-item--selected': + rpcEndpoint === currentRpcEndpoint, + })} > - {rpcEndpoint} + {rpcEndpoint === currentRpcEndpoint && ( + + )} + + {rpcEndpoint} + { padding={4} display={Display.Flex} alignItems={AlignItems.center} - className="networks-tab__rpc-add" + className="networks-tab__rpc-item" > - + {t('addRpcUrl')} - + From 18e2b997fb55fa1a8cc16a0b9774821a099390c0 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Thu, 13 Jun 2024 08:30:04 -0700 Subject: [PATCH 4/6] use 1 real rpc endpoint --- .../networks-tab/networks-form/networks-form.js | 2 +- .../networks-form/rpc-url-editor.tsx | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.js b/ui/pages/settings/networks-tab/networks-form/networks-form.js index 1aa7d9304047..6d74e2a67179 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.js @@ -762,7 +762,7 @@ const NetworksForm = ({ dataTestId="network-form-network-name" /> {window.metamaskFeatureFlags?.networkMenuRedesign ? ( - + ) : ( { +export const RpcUrlEditor = ({ currentRpcUrl }: { currentRpcUrl: string }) => { // TODO: real endpoints - const dummyRpcEndpoints = [ - 'https://palmn-mainnet.infura.io', - 'https://palm-mainnet.public.blastapi.io', - 'https://tatum.io/v3/blockchain/node/palm', + const dummyRpcUrls = [ + currentRpcUrl, + 'https://dummy-mainnet.public.blastapi.io', + 'https://dummy.io/v3/blockchain/node/dummy', ]; const t = useI18nContext(); const rpcDropdown = useRef(null); const [isOpen, setIsOpen] = useState(false); - const [currentRpcEndpoint, setCurrentRpcEndpoint] = useState( - dummyRpcEndpoints[0], - ); + const [currentRpcEndpoint, setCurrentRpcEndpoint] = useState(currentRpcUrl); return ( <> @@ -74,7 +72,7 @@ export const RpcUrlEditor = () => { position={PopoverPosition.Bottom} isOpen={isOpen} > - {dummyRpcEndpoints.map((rpcEndpoint) => ( + {dummyRpcUrls.map((rpcEndpoint) => ( Date: Fri, 14 Jun 2024 10:08:22 -0700 Subject: [PATCH 5/6] Text as button instead of ButtonLink --- ui/pages/settings/networks-tab/index.scss | 13 ---------- .../networks-form/rpc-url-editor.tsx | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/ui/pages/settings/networks-tab/index.scss b/ui/pages/settings/networks-tab/index.scss index a9380e5b3744..1da583785728 100644 --- a/ui/pages/settings/networks-tab/index.scss +++ b/ui/pages/settings/networks-tab/index.scss @@ -2,8 +2,6 @@ .networks-tab { - // TODO: Matching behavior of existing headings on network form - // But seems weird, probably all should be text cursor. &__rpc-header { cursor: default; } @@ -21,17 +19,6 @@ background-color: var(--color-background-default-hover); } - // These are s for accessibility, - // but I don't want the styling that comes with it - &__rpc-url:hover { - text-decoration: none !important; - color: var(--color-text-default) !important; - } - - &__rpc-add:hover { - text-decoration: none !important; - } - &__rpc-item--selected, &__rpc-item--selected:hover { background-color: var(--color-primary-muted); diff --git a/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx b/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx index c577131ee1df..99cd98776c07 100644 --- a/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx +++ b/ui/pages/settings/networks-tab/networks-form/rpc-url-editor.tsx @@ -4,7 +4,6 @@ import { Box, ButtonIcon, ButtonIconSize, - ButtonLink, Icon, IconName, IconSize, @@ -29,7 +28,7 @@ export const RpcUrlEditor = ({ currentRpcUrl }: { currentRpcUrl: string }) => { // TODO: real endpoints const dummyRpcUrls = [ currentRpcUrl, - 'https://dummy-mainnet.public.blastapi.io', + 'https://dummy.mainnet.public.blastapi.io', 'https://dummy.io/v3/blockchain/node/dummy', ]; @@ -60,7 +59,11 @@ export const RpcUrlEditor = ({ currentRpcUrl }: { currentRpcUrl: string }) => { ref={rpcDropdown} > {currentRpcEndpoint} - + { backgroundColor={BackgroundColor.primaryDefault} /> )} - {rpcEndpoint} - + { color={IconColor.primaryDefault} name={IconName.Add} size={IconSize.Sm} - // marginLeft={1} marginRight={2} /> - {t('addRpcUrl')} - + From 8dfde9995f3e95e3a8f7909219347818edbb7a7a Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Fri, 14 Jun 2024 10:28:15 -0700 Subject: [PATCH 6/6] lint --- ui/pages/settings/networks-tab/index.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/pages/settings/networks-tab/index.scss b/ui/pages/settings/networks-tab/index.scss index 1da583785728..6c179e3dc323 100644 --- a/ui/pages/settings/networks-tab/index.scss +++ b/ui/pages/settings/networks-tab/index.scss @@ -1,7 +1,6 @@ @use "design-system"; .networks-tab { - &__rpc-header { cursor: default; }