From 20139066f0debad2fc78eac4ba3c29cab1b60978 Mon Sep 17 00:00:00 2001 From: Christian Laino Date: Thu, 30 Sep 2021 18:09:35 -0300 Subject: [PATCH] new whitelist styles (#240) --- .../components/AllowAgent/index.jsx | 62 ++++++++++++-- .../components/AllowAgent/styles.js | 18 ++++ source/locales/en/translation.json | 2 +- .../components/Container/styles.js | 5 +- .../ui/CanisterInfo/components/Item/index.jsx | 84 ++++--------------- .../ui/CanisterInfo/components/Item/styles.js | 19 +++-- source/ui/IncomingAction/styles.js | 2 +- views/notification.html | 3 + 8 files changed, 109 insertions(+), 86 deletions(-) diff --git a/source/Pages/Notification/components/AllowAgent/index.jsx b/source/Pages/Notification/components/AllowAgent/index.jsx index df7739a7..73f3b599 100644 --- a/source/Pages/Notification/components/AllowAgent/index.jsx +++ b/source/Pages/Notification/components/AllowAgent/index.jsx @@ -17,13 +17,13 @@ import store from '@redux/store'; import { Layout } from '@components'; import extension from 'extensionizer'; import PropTypes from 'prop-types'; - +import { ChevronDown } from 'react-feather'; import { CONNECTION_STATUS } from '@shared/constants/connectionStatus'; import { setAccountInfo } from '@redux/wallet'; import { HANDLER_TYPES, sendMessage } from '@background/Keyring'; +import clsx from 'clsx'; import ErrorScreen from '../NotificationError'; import initConfig from '../../../../locales'; - import useStyles from './styles'; i18n.use(initReactI18next).init(initConfig); @@ -46,6 +46,15 @@ const AllowAgent = ({ const { url, icons } = metadata || {}; + const canisters = args?.canistersInfo || []; + const canistersLength = canisters.length; + const maxDispayCanisters = 2; + + const displayCanister = canistersLength < maxDispayCanisters + ? canistersLength : maxDispayCanisters; + + const [expand, setExpand] = useState(false); + const handleAllowAgent = async (status) => { const success = await portRPC.call('handleAllowAgent', [ url, @@ -68,13 +77,31 @@ const AllowAgent = ({ if (!args?.updateWhitelist || args?.showList) { extension.windows.update(extension.windows.WINDOW_ID_CURRENT, { - height: Math.min(422 + 37 * args?.whitelist.length || 0, 600), + height: 355 + + (canistersLength > 2 ? 76 : 30) + + 65 * (canistersLength > 2 ? 2 : canistersLength), }); } else { handleAllowAgent(CONNECTION_STATUS.accepted).then(() => window?.close?.()); } }, []); + const toggleExpand = () => { + let height; + + if (expand) { + height = 355 + 76 + 65 * Math.min(canistersLength, 2); + } else { + height = 355 + 76 + 65 * Math.min(canistersLength, 5); + } + + extension.windows.update(extension.windows.WINDOW_ID_CURRENT, { + height, + }); + + setExpand((prevState) => !prevState); + }; + return !args?.updateWhitelist || args?.showList ? ( @@ -92,11 +119,34 @@ const AllowAgent = ({ /> - {args?.canistersInfo?.map((canister) => ( - - ))} + { + canisters.slice(0, displayCanister).map((canister) => ( + + )) + } + { + expand + && canisters.slice(displayCanister).map((canister) => ( + + )) + } + { + canistersLength > maxDispayCanisters + && ( +
+ + {expand ? 'Collapse canisters' : `Review ${canistersLength - maxDispayCanisters} more canisters`} + + +
+ ) + } +