From 1c9ad39830658c6897ab0015a1c003540c510df6 Mon Sep 17 00:00:00 2001 From: Diogo Soares Date: Mon, 24 Oct 2022 17:13:26 +0200 Subject: [PATCH 1/9] create the Governance section on Dashboard --- .../GovernanceSection/GovernanceSection.tsx | 37 +++++++++++++++++++ src/components/dashboard/index.tsx | 5 +++ 2 files changed, 42 insertions(+) create mode 100644 src/components/dashboard/GovernanceSection/GovernanceSection.tsx diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx new file mode 100644 index 0000000000..6123547784 --- /dev/null +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -0,0 +1,37 @@ +import { Typography, Grid, Card, Box } from '@mui/material' +import { WidgetBody, WidgetContainer } from '@/components/dashboard/styled' + +const GovernanceSection = () => ( + + + + Governance + + + + + + + + + Claiming app + + + + + + + + + Snapshot + + + + + + + + +) + +export default GovernanceSection diff --git a/src/components/dashboard/index.tsx b/src/components/dashboard/index.tsx index 07f5009b28..024a723d99 100644 --- a/src/components/dashboard/index.tsx +++ b/src/components/dashboard/index.tsx @@ -4,6 +4,7 @@ import PendingTxsList from '@/components/dashboard/PendingTxs/PendingTxsList' import Overview from '@/components/dashboard/Overview/Overview' import { FeaturedApps } from '@/components/dashboard/FeaturedApps/FeaturedApps' import SafeAppsDashboardSection from '@/components/dashboard/SafeAppsDashboardSection/SafeAppsDashboardSection' +import GovernanceSection from '@/components/dashboard/GovernanceSection/GovernanceSection' const Dashboard = (): ReactElement => { return ( @@ -16,6 +17,10 @@ const Dashboard = (): ReactElement => { + + + + From 5b3f6818a522cd9fe3f530618866d07b53c1110e Mon Sep 17 00:00:00 2001 From: Diogo Soares <32431609+DiogoSoaress@users.noreply.github.com> Date: Thu, 10 Nov 2022 17:29:35 +0100 Subject: [PATCH 2/9] [Governance Visibility] Dashboard section (#1125) * dashboard section with placeholders * use MUI Accordion for the collapsible section * change expand icon color --- .../GovernanceSection/GovernanceSection.tsx | 68 +++++++++++-------- .../GovernanceSection/styles.module.css | 18 +++++ 2 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 src/components/dashboard/GovernanceSection/styles.module.css diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index 6123547784..bc1f709ff9 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -1,36 +1,50 @@ import { Typography, Grid, Card, Box } from '@mui/material' -import { WidgetBody, WidgetContainer } from '@/components/dashboard/styled' +import { WidgetBody } from '@/components/dashboard/styled' +import ExpandMoreIcon from '@mui/icons-material/ExpandMore' +import Accordion from '@mui/material/Accordion' +import AccordionSummary from '@mui/material/AccordionSummary' +import AccordionDetails from '@mui/material/AccordionDetails' +import css from './styles.module.css' const GovernanceSection = () => ( - - - Governance - + + }> +
+ + Governance + + + Use your SAFE tokens to vote on important proposals or participate in forum discussions. + +
+
- - - - - - - Claiming app - - - + ({ padding: `0 ${spacing(3)}` })}> + + + + + + + Snapshot + + + + + + + + + Claiming app + + + + - - - - - Snapshot - - - - - - -
+ + +
) diff --git a/src/components/dashboard/GovernanceSection/styles.module.css b/src/components/dashboard/GovernanceSection/styles.module.css new file mode 100644 index 0000000000..0bb82e73a3 --- /dev/null +++ b/src/components/dashboard/GovernanceSection/styles.module.css @@ -0,0 +1,18 @@ +.accordion { + box-shadow: none; + border: none; + background: transparent; +} + +.accordion :global .MuiAccordionSummary-root, +.accordion :global .MuiAccordionDetails-root { + padding: 0; +} + +.accordion :global .MuiAccordionSummary-root:hover { + background: inherit; +} + +.accordion :global .Mui-expanded.MuiAccordionSummary-root { + background: inherit; +} From 125a91f9cdaaaaa6de3792844f7defe3260f4263 Mon Sep 17 00:00:00 2001 From: Diogo Soares <32431609+DiogoSoaress@users.noreply.github.com> Date: Wed, 23 Nov 2022 17:01:21 +0100 Subject: [PATCH 3/9] feat: Dashboard governance widgets (#1149) * feat: load a mini safe app in dashboard's Governance section * fix card heights * display snapshot widget * fetch the claiming app and display the widgets * fix: accordion defaultExpanded and fix loading states flicker * responsive widgets grid * expandDefault true * no need to pass explicit boolean value. improve loading components --- .../GovernanceSection/GovernanceSection.tsx | 106 +++++++++++++----- src/components/dashboard/index.tsx | 4 +- src/components/safe-apps/AppFrame/index.tsx | 7 +- 3 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index bc1f709ff9..02dda3fabc 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -1,14 +1,28 @@ -import { Typography, Grid, Card, Box } from '@mui/material' +import { Typography, Grid, Card, Box, Alert } from '@mui/material' import { WidgetBody } from '@/components/dashboard/styled' import ExpandMoreIcon from '@mui/icons-material/ExpandMore' import Accordion from '@mui/material/Accordion' import AccordionSummary from '@mui/material/AccordionSummary' import AccordionDetails from '@mui/material/AccordionDetails' import css from './styles.module.css' +import SafeAppsErrorBoundary from '@/components/safe-apps/SafeAppsErrorBoundary' +import SafeAppsLoadError from '@/components/safe-apps/SafeAppsErrorBoundary/SafeAppsLoadError' +import AppFrame from '@/components/safe-apps/AppFrame' +import { useBrowserPermissions } from '@/hooks/safe-apps/permissions' +import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps' +import { SafeAppsTag } from '@/config/constants' -const GovernanceSection = () => ( - - +const CLAIMING_WIDGET_ID = '#claiming-widget' +const SNAPSHOT_WIDGET_ID = '#snapshot-widget' + +const GovernanceSection = () => { + const { getAllowedFeaturesList } = useBrowserPermissions() + const [claimingSafeApp, errorFetchingClaimingSafeApp] = useRemoteSafeApps(SafeAppsTag.SAFE_CLAIMING_APP) + const claimingApp = claimingSafeApp?.[0] + const fetchingSafeClaimingApp = !claimingApp && !errorFetchingClaimingSafeApp + + return ( + }>
@@ -21,31 +35,69 @@ const GovernanceSection = () => ( ({ padding: `0 ${spacing(3)}` })}> - - - - - - - Snapshot - - - - - - - - - Claiming app - - - + {claimingApp || fetchingSafeClaimingApp ? ( + + + + + {claimingApp ? ( + {}} />}> + + + ) : ( + + + Loading Snapshot... + + + )} + + + + + {claimingApp ? ( + {}} />}> + + + ) : ( + + + Loading Claiming app... + + + )} + + - - + + ) : ( + + There was an error fetching the Governance section. Please reload the page. + + )} - -) + ) +} export default GovernanceSection diff --git a/src/components/dashboard/index.tsx b/src/components/dashboard/index.tsx index 024a723d99..e58066a5bc 100644 --- a/src/components/dashboard/index.tsx +++ b/src/components/dashboard/index.tsx @@ -18,11 +18,11 @@ const Dashboard = (): ReactElement => { - + - + diff --git a/src/components/safe-apps/AppFrame/index.tsx b/src/components/safe-apps/AppFrame/index.tsx index 6b696be5a4..d99c48ae26 100644 --- a/src/components/safe-apps/AppFrame/index.tsx +++ b/src/components/safe-apps/AppFrame/index.tsx @@ -44,9 +44,10 @@ const UNKNOWN_APP_NAME = 'Unknown App' type AppFrameProps = { appUrl: string allowedFeaturesList: string + isQueueBarDisabled?: boolean } -const AppFrame = ({ appUrl, allowedFeaturesList }: AppFrameProps): ReactElement => { +const AppFrame = ({ appUrl, allowedFeaturesList, isQueueBarDisabled = false }: AppFrameProps): ReactElement => { const chainId = useChainId() const [txModalState, openTxModal, closeTxModal] = useTxModal() const [signMessageModalState, openSignMessageModal, closeSignMessageModal] = useSignMessageModal() @@ -62,7 +63,7 @@ const AppFrame = ({ appUrl, allowedFeaturesList }: AppFrameProps): ReactElement dismissQueueBar, transactions, } = useTransactionQueueBarState() - const queueBarVisible = transactions.results.length > 0 && !queueBarDismissed + const queueBarVisible = !isQueueBarDisabled && transactions.results.length > 0 && !queueBarDismissed const [remoteApp] = useSafeAppFromBackend(appUrl, safe.chainId) const { safeApp: safeAppFromManifest } = useSafeAppFromManifest(appUrl, safe.chainId) const { thirdPartyCookiesDisabled, setThirdPartyCookiesDisabled } = useThirdPartyCookies() @@ -227,7 +228,7 @@ const AppFrame = ({ appUrl, allowedFeaturesList }: AppFrameProps): ReactElement Date: Thu, 24 Nov 2022 18:15:47 +0100 Subject: [PATCH 4/9] feat: pass dark mode in the widgets url (#1219) * expandDefault true * no need to pass explicit boolean value. improve loading components * feat: pass dark mode in the widgets url * pass preferred them in a search parameter --- .../dashboard/GovernanceSection/GovernanceSection.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index 02dda3fabc..b961910139 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -11,11 +11,14 @@ import AppFrame from '@/components/safe-apps/AppFrame' import { useBrowserPermissions } from '@/hooks/safe-apps/permissions' import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps' import { SafeAppsTag } from '@/config/constants' +import { useDarkMode } from '@/hooks/useDarkMode' const CLAIMING_WIDGET_ID = '#claiming-widget' const SNAPSHOT_WIDGET_ID = '#snapshot-widget' const GovernanceSection = () => { + const isDarkMode = useDarkMode() + const theme = isDarkMode ? 'dark' : 'light' const { getAllowedFeaturesList } = useBrowserPermissions() const [claimingSafeApp, errorFetchingClaimingSafeApp] = useRemoteSafeApps(SafeAppsTag.SAFE_CLAIMING_APP) const claimingApp = claimingSafeApp?.[0] @@ -43,7 +46,7 @@ const GovernanceSection = () => { {claimingApp ? ( {}} />}> @@ -68,7 +71,7 @@ const GovernanceSection = () => { {claimingApp ? ( {}} />}> From 3ee67ba9fc5eba846808caff160b7c88f27e3047 Mon Sep 17 00:00:00 2001 From: Diogo Soares <32431609+DiogoSoaress@users.noreply.github.com> Date: Fri, 25 Nov 2022 15:33:24 +0100 Subject: [PATCH 5/9] feat: One governance widget (#1237) * feat: call only one widget from the safe-claiming app * rm unused Grid * use widgetWrapper for the loading component * add a custom fallback component * ammend load error copy * use different color in the placeholder as per design * feat: dark flag in URL hash (#1251) --- public/images/common/load.svg | 3 + .../GovernanceSection/GovernanceSection.tsx | 102 ++++++++---------- .../GovernanceSection/styles.module.css | 30 ++++++ 3 files changed, 78 insertions(+), 57 deletions(-) create mode 100644 public/images/common/load.svg diff --git a/public/images/common/load.svg b/public/images/common/load.svg new file mode 100644 index 0000000000..b9ffbf3cc4 --- /dev/null +++ b/public/images/common/load.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index b961910139..cee8776d6e 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -1,4 +1,4 @@ -import { Typography, Grid, Card, Box, Alert } from '@mui/material' +import { Typography, Card, Box, Alert } from '@mui/material' import { WidgetBody } from '@/components/dashboard/styled' import ExpandMoreIcon from '@mui/icons-material/ExpandMore' import Accordion from '@mui/material/Accordion' @@ -6,16 +6,14 @@ import AccordionSummary from '@mui/material/AccordionSummary' import AccordionDetails from '@mui/material/AccordionDetails' import css from './styles.module.css' import SafeAppsErrorBoundary from '@/components/safe-apps/SafeAppsErrorBoundary' -import SafeAppsLoadError from '@/components/safe-apps/SafeAppsErrorBoundary/SafeAppsLoadError' import AppFrame from '@/components/safe-apps/AppFrame' import { useBrowserPermissions } from '@/hooks/safe-apps/permissions' import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps' import { SafeAppsTag } from '@/config/constants' +import LoadIcon from '@/public/images/common/load.svg' +import palette from '@/styles/colors' import { useDarkMode } from '@/hooks/useDarkMode' -const CLAIMING_WIDGET_ID = '#claiming-widget' -const SNAPSHOT_WIDGET_ID = '#snapshot-widget' - const GovernanceSection = () => { const isDarkMode = useDarkMode() const theme = isDarkMode ? 'dark' : 'light' @@ -24,6 +22,24 @@ const GovernanceSection = () => { const claimingApp = claimingSafeApp?.[0] const fetchingSafeClaimingApp = !claimingApp && !errorFetchingClaimingSafeApp + const WidgetLoadError = () => ( + + + + + Couldn't load governance widget + + + + ) + + const WidgetLoadErrorFallback = () => ( + + + + + ) + return ( }> @@ -40,58 +56,30 @@ const GovernanceSection = () => { ({ padding: `0 ${spacing(3)}` })}> {claimingApp || fetchingSafeClaimingApp ? ( - - - - {claimingApp ? ( - {}} />}> - - - ) : ( - - - Loading Snapshot... - - - )} - - - - - {claimingApp ? ( - {}} />}> - - - ) : ( - - - Loading Claiming app... - - - )} - - - + + {claimingApp ? ( + }> + + + ) : ( + + + Loading section... + + + )} + ) : ( diff --git a/src/components/dashboard/GovernanceSection/styles.module.css b/src/components/dashboard/GovernanceSection/styles.module.css index 0bb82e73a3..97aacbec08 100644 --- a/src/components/dashboard/GovernanceSection/styles.module.css +++ b/src/components/dashboard/GovernanceSection/styles.module.css @@ -16,3 +16,33 @@ .accordion :global .Mui-expanded.MuiAccordionSummary-root { background: inherit; } + +.loadErrorWrapper { + display: flex; +} + +.widgetWrapper, +.loadErrorWrapper { + border: none; + height: 300px; +} + +/* iframe sm breakpoint + paddings */ +@media (max-width: 662px) { + .widgetWrapper, + .loadErrorWrapper { + height: 624px; + } + + .loadErrorWrapper{ + flex-direction: column; + } +} + +.loadErrorCard { + flex-grow: 1; +} + +.loadErrorCard:last-of-type { + min-width: 300px; +} From 5f936d917816de31bc9c0ef8d4f770e3369ea817 Mon Sep 17 00:00:00 2001 From: Diogo Soares <32431609+DiogoSoaress@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:43:18 +0100 Subject: [PATCH 6/9] fix: governance widgets CSS (#1254) * fix: Accordion only clickable on expandIcon * adjust AppFrame height for widgets * change the widget load error component * fix code style * improve classnames params --- public/images/common/load.svg | 3 -- public/images/common/network-error.svg | 19 +++++++++++ .../GovernanceSection/GovernanceSection.tsx | 33 ++++++++++++------ .../GovernanceSection/styles.module.css | 34 +++++++++++++++++-- src/components/safe-apps/AppFrame/index.tsx | 9 ++--- .../safe-apps/AppFrame/styles.module.css | 4 +++ 6 files changed, 82 insertions(+), 20 deletions(-) delete mode 100644 public/images/common/load.svg create mode 100644 public/images/common/network-error.svg diff --git a/public/images/common/load.svg b/public/images/common/load.svg deleted file mode 100644 index b9ffbf3cc4..0000000000 --- a/public/images/common/load.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/public/images/common/network-error.svg b/public/images/common/network-error.svg new file mode 100644 index 0000000000..50df59344d --- /dev/null +++ b/public/images/common/network-error.svg @@ -0,0 +1,19 @@ + + + + + + + diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index cee8776d6e..fd7d3792ad 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -1,4 +1,4 @@ -import { Typography, Card, Box, Alert } from '@mui/material' +import { Typography, Card, Box, Alert, IconButton, Link, SvgIcon } from '@mui/material' import { WidgetBody } from '@/components/dashboard/styled' import ExpandMoreIcon from '@mui/icons-material/ExpandMore' import Accordion from '@mui/material/Accordion' @@ -9,10 +9,10 @@ import SafeAppsErrorBoundary from '@/components/safe-apps/SafeAppsErrorBoundary' import AppFrame from '@/components/safe-apps/AppFrame' import { useBrowserPermissions } from '@/hooks/safe-apps/permissions' import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps' -import { SafeAppsTag } from '@/config/constants' -import LoadIcon from '@/public/images/common/load.svg' -import palette from '@/styles/colors' +import { SafeAppsTag, SAFE_APPS_SUPPORT_CHAT_URL } from '@/config/constants' import { useDarkMode } from '@/hooks/useDarkMode' +import { OpenInNew } from '@mui/icons-material' +import NetworkError from '@/public/images/common/network-error.svg' const GovernanceSection = () => { const isDarkMode = useDarkMode() @@ -24,10 +24,17 @@ const GovernanceSection = () => { const WidgetLoadError = () => ( - - - - Couldn't load governance widget + + + Couldn't load governance widgets + + + + You can try to reload the page and in case the problem persists, please reach out to us via{' '} + + Discord + + @@ -42,7 +49,13 @@ const GovernanceSection = () => { return ( - }> + + + + } + >
Governance @@ -63,7 +76,7 @@ const GovernanceSection = () => { key={theme} appUrl={`${claimingApp.url}#widget+${theme}`} allowedFeaturesList={getAllowedFeaturesList(claimingApp.url)} - isQueueBarDisabled + isWidget /> ) : ( diff --git a/src/components/dashboard/GovernanceSection/styles.module.css b/src/components/dashboard/GovernanceSection/styles.module.css index 97aacbec08..8d7bf29e47 100644 --- a/src/components/dashboard/GovernanceSection/styles.module.css +++ b/src/components/dashboard/GovernanceSection/styles.module.css @@ -9,12 +9,18 @@ padding: 0; } -.accordion :global .MuiAccordionSummary-root:hover { +.accordion:hover :global .MuiAccordionSummary-root, +.accordion :global .MuiAccordionSummary-root:hover, +.accordion :global .Mui-expanded.MuiAccordionSummary-root { background: inherit; } -.accordion :global .Mui-expanded.MuiAccordionSummary-root { - background: inherit; +.accordion :global .MuiAccordionSummary-root { + pointer-events: none; +} + +.accordion :global .MuiAccordionSummary-expandIconWrapper { + pointer-events: auto; } .loadErrorWrapper { @@ -40,9 +46,31 @@ } .loadErrorCard { + display: flex; + justify-content: center; + align-items: center; + padding: var(--space-2); + text-align: center; flex-grow: 1; } .loadErrorCard:last-of-type { min-width: 300px; } + +.loadErrorMsgContainer { + height: 100%; + display: flex; + flex-direction:column; + align-items:center; + justify-content: center; + gap: var(--space-2); + max-width: 80%; +} + +.loadErroricon { + font-size: 54px; + position: relative; + left: 3px; + top: 3px; +} diff --git a/src/components/safe-apps/AppFrame/index.tsx b/src/components/safe-apps/AppFrame/index.tsx index d99c48ae26..69b52c7b95 100644 --- a/src/components/safe-apps/AppFrame/index.tsx +++ b/src/components/safe-apps/AppFrame/index.tsx @@ -38,16 +38,17 @@ import PermissionsPrompt from '../PermissionsPrompt' import { PermissionStatus } from '../types' import css from './styles.module.css' +import classnames from 'classnames' const UNKNOWN_APP_NAME = 'Unknown App' type AppFrameProps = { appUrl: string allowedFeaturesList: string - isQueueBarDisabled?: boolean + isWidget?: boolean } -const AppFrame = ({ appUrl, allowedFeaturesList, isQueueBarDisabled = false }: AppFrameProps): ReactElement => { +const AppFrame = ({ appUrl, allowedFeaturesList, isWidget = false }: AppFrameProps): ReactElement => { const chainId = useChainId() const [txModalState, openTxModal, closeTxModal] = useTxModal() const [signMessageModalState, openSignMessageModal, closeSignMessageModal] = useSignMessageModal() @@ -63,7 +64,7 @@ const AppFrame = ({ appUrl, allowedFeaturesList, isQueueBarDisabled = false }: A dismissQueueBar, transactions, } = useTransactionQueueBarState() - const queueBarVisible = !isQueueBarDisabled && transactions.results.length > 0 && !queueBarDismissed + const queueBarVisible = !isWidget && transactions.results.length > 0 && !queueBarDismissed const [remoteApp] = useSafeAppFromBackend(appUrl, safe.chainId) const { safeApp: safeAppFromManifest } = useSafeAppFromManifest(appUrl, safe.chainId) const { thirdPartyCookiesDisabled, setThirdPartyCookiesDisabled } = useThirdPartyCookies() @@ -198,7 +199,7 @@ const AppFrame = ({ appUrl, allowedFeaturesList, isQueueBarDisabled = false }: A Safe Apps - Viewer - {remoteApp ? remoteApp.name : UNKNOWN_APP_NAME} -
+
{thirdPartyCookiesDisabled && setThirdPartyCookiesDisabled(false)} />} {appIsLoading && ( diff --git a/src/components/safe-apps/AppFrame/styles.module.css b/src/components/safe-apps/AppFrame/styles.module.css index 60ed8e1e43..7c4b611382 100644 --- a/src/components/safe-apps/AppFrame/styles.module.css +++ b/src/components/safe-apps/AppFrame/styles.module.css @@ -3,6 +3,10 @@ height: calc(100vh - var(--header-height)); } +.widgetWrapper { + height: 100%; +} + .iframe { height: 100%; width: 100%; From 2023e623f0bcdd4e8c858f68c61bae99686f5c37 Mon Sep 17 00:00:00 2001 From: Aaron Cook Date: Thu, 1 Dec 2022 13:13:30 +0100 Subject: [PATCH 7/9] fix: return `null` if no Claiming App on chain (#1284) * fix: return `null` if no Claiming App on chain * fix: reference deployed token address * fix: add address of token on Goerli * fix: add loading wrapper * fix: rename wrapper --- .../GovernanceSection/GovernanceSection.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index fd7d3792ad..77d2e547bb 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -13,6 +13,18 @@ import { SafeAppsTag, SAFE_APPS_SUPPORT_CHAT_URL } from '@/config/constants' import { useDarkMode } from '@/hooks/useDarkMode' import { OpenInNew } from '@mui/icons-material' import NetworkError from '@/public/images/common/network-error.svg' +import useChainId from '@/hooks/useChainId' +import { getSafeTokenAddress } from '@/components/common/SafeTokenWidget' + +// Prevent `GovernanceSection` hooks from needlessly being called +const GovernanceSectionWrapper = () => { + const chainId = useChainId() + if (!getSafeTokenAddress(chainId)) { + return null + } + + return +} const GovernanceSection = () => { const isDarkMode = useDarkMode() @@ -104,4 +116,4 @@ const GovernanceSection = () => { ) } -export default GovernanceSection +export default GovernanceSectionWrapper From 867e08d33052171571c3d3d03d592628c8726d76 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:59:38 +0100 Subject: [PATCH 8/9] Fix: use a non-tracking version of the AppFrame (#1307) * Fix: use a non-tracking version of the AppFrame * Clear communicator handlers * useAppIsLoading * Rename components * Extract getSafeInfo * AppFrameWrapperProps -> AppFrameProps --- .../GovernanceSection/GovernanceSection.tsx | 24 ++++++++-- .../GovernanceSection/styles.module.css | 6 +-- .../safe-apps/AppFrame/SafeAppIframe.tsx | 31 ++++++++++++ src/components/safe-apps/AppFrame/index.tsx | 48 +++++++------------ .../safe-apps/AppFrame/styles.module.css | 4 -- .../safe-apps/AppFrame/useAppCommunicator.ts | 2 +- .../safe-apps/AppFrame/useGetSafeInfo.ts | 28 +++++++++++ src/services/safe-apps/AppCommunicator.ts | 1 + 8 files changed, 101 insertions(+), 43 deletions(-) create mode 100644 src/components/safe-apps/AppFrame/SafeAppIframe.tsx create mode 100644 src/components/safe-apps/AppFrame/useGetSafeInfo.ts diff --git a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx index 77d2e547bb..24485f2728 100644 --- a/src/components/dashboard/GovernanceSection/GovernanceSection.tsx +++ b/src/components/dashboard/GovernanceSection/GovernanceSection.tsx @@ -6,7 +6,6 @@ import AccordionSummary from '@mui/material/AccordionSummary' import AccordionDetails from '@mui/material/AccordionDetails' import css from './styles.module.css' import SafeAppsErrorBoundary from '@/components/safe-apps/SafeAppsErrorBoundary' -import AppFrame from '@/components/safe-apps/AppFrame' import { useBrowserPermissions } from '@/hooks/safe-apps/permissions' import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps' import { SafeAppsTag, SAFE_APPS_SUPPORT_CHAT_URL } from '@/config/constants' @@ -15,6 +14,12 @@ import { OpenInNew } from '@mui/icons-material' import NetworkError from '@/public/images/common/network-error.svg' import useChainId from '@/hooks/useChainId' import { getSafeTokenAddress } from '@/components/common/SafeTokenWidget' +import SafeAppIframe from '@/components/safe-apps/AppFrame/SafeAppIframe' +import type { UseAppCommunicatorHandlers } from '@/components/safe-apps/AppFrame/useAppCommunicator' +import useAppCommunicator from '@/components/safe-apps/AppFrame/useAppCommunicator' +import { useCurrentChain } from '@/hooks/useChains' +import useAppIsLoading from '@/components/safe-apps/AppFrame/useAppIsLoading' +import useGetSafeInfo from '@/components/safe-apps/AppFrame/useGetSafeInfo' // Prevent `GovernanceSection` hooks from needlessly being called const GovernanceSectionWrapper = () => { @@ -30,10 +35,17 @@ const GovernanceSection = () => { const isDarkMode = useDarkMode() const theme = isDarkMode ? 'dark' : 'light' const { getAllowedFeaturesList } = useBrowserPermissions() - const [claimingSafeApp, errorFetchingClaimingSafeApp] = useRemoteSafeApps(SafeAppsTag.SAFE_CLAIMING_APP) - const claimingApp = claimingSafeApp?.[0] + const chain = useCurrentChain() + const [matchingApps, errorFetchingClaimingSafeApp] = useRemoteSafeApps(SafeAppsTag.SAFE_CLAIMING_APP) + const claimingApp = matchingApps?.[0] + const { iframeRef, setAppIsLoading } = useAppIsLoading() const fetchingSafeClaimingApp = !claimingApp && !errorFetchingClaimingSafeApp + // Initialize the app communicator + useAppCommunicator(iframeRef, claimingApp, chain, { + onGetSafeInfo: useGetSafeInfo(), + } as Partial as UseAppCommunicatorHandlers) + const WidgetLoadError = () => ( @@ -84,11 +96,13 @@ const GovernanceSection = () => { {claimingApp ? ( }> - setAppIsLoading(false)} /> ) : ( diff --git a/src/components/dashboard/GovernanceSection/styles.module.css b/src/components/dashboard/GovernanceSection/styles.module.css index 8d7bf29e47..df6c7c8820 100644 --- a/src/components/dashboard/GovernanceSection/styles.module.css +++ b/src/components/dashboard/GovernanceSection/styles.module.css @@ -40,7 +40,7 @@ height: 624px; } - .loadErrorWrapper{ + .loadErrorWrapper { flex-direction: column; } } @@ -61,8 +61,8 @@ .loadErrorMsgContainer { height: 100%; display: flex; - flex-direction:column; - align-items:center; + flex-direction: column; + align-items: center; justify-content: center; gap: var(--space-2); max-width: 80%; diff --git a/src/components/safe-apps/AppFrame/SafeAppIframe.tsx b/src/components/safe-apps/AppFrame/SafeAppIframe.tsx new file mode 100644 index 0000000000..6f107436a4 --- /dev/null +++ b/src/components/safe-apps/AppFrame/SafeAppIframe.tsx @@ -0,0 +1,31 @@ +import type { ReactElement } from 'react' +import css from './styles.module.css' + +type SafeAppIFrameProps = { + appUrl: string + allowedFeaturesList: string + title?: string + iframeRef?: React.MutableRefObject + onLoad?: () => void +} + +// see sandbox mdn docs for more details https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox +const IFRAME_SANDBOX_ALLOWED_FEATURES = + 'allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-forms allow-downloads allow-orientation-lock' + +const SafeAppIframe = ({ appUrl, allowedFeaturesList, iframeRef, onLoad, title }: SafeAppIFrameProps): ReactElement => { + return ( +