From 272c7948c77a059f5e74b9087c37739835266a9d Mon Sep 17 00:00:00 2001 From: katspaugh Date: Thu, 9 Nov 2023 13:06:25 +0100 Subject: [PATCH] Fix: redirect to Safe creation only if no added Safes --- .../welcome/SafeListDrawer/index.tsx | 15 +++++++--- src/components/welcome/WelcomeLogin/index.tsx | 28 +++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/components/welcome/SafeListDrawer/index.tsx b/src/components/welcome/SafeListDrawer/index.tsx index afa8f5418d..835fe11deb 100644 --- a/src/components/welcome/SafeListDrawer/index.tsx +++ b/src/components/welcome/SafeListDrawer/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React from 'react' import SafeList from '@/components/sidebar/SafeList' import { DataWidget } from '@/components/welcome/SafeListDrawer/DataWidget' import { Button, Drawer, Typography } from '@mui/material' @@ -8,15 +8,22 @@ import { selectTotalAdded } from '@/store/addedSafesSlice' import useOwnedSafes from '@/hooks/useOwnedSafes' import drawerCSS from '@/components/sidebar/Sidebar/styles.module.css' import css from './styles.module.css' +import ExternalStore from '@/services/ExternalStore' + +const { useStore, setStore } = new ExternalStore(false) + +export const openSafeListDrawer = () => { + setStore(true) +} const SafeListDrawer = () => { const numberOfAddedSafes = useAppSelector(selectTotalAdded) const ownedSafes = useOwnedSafes() const numberOfOwnedSafes = Object.values(ownedSafes).reduce((acc, curr) => acc + curr.length, 0) const totalNumberOfSafes = numberOfOwnedSafes + numberOfAddedSafes - const [showSidebar, setShowSidebar] = useState(false) + const showSidebar = useStore() - const closeSidebar = () => setShowSidebar(false) + const closeSidebar = () => setStore(false) if (totalNumberOfSafes <= 0) { return null @@ -39,7 +46,7 @@ const SafeListDrawer = () => { variant="contained" color="background" startIcon={} - onClick={() => setShowSidebar(true)} + onClick={() => setStore(true)} > My Safe Accounts{' '} diff --git a/src/components/welcome/WelcomeLogin/index.tsx b/src/components/welcome/WelcomeLogin/index.tsx index ad768bf84a..552253892b 100644 --- a/src/components/welcome/WelcomeLogin/index.tsx +++ b/src/components/welcome/WelcomeLogin/index.tsx @@ -10,27 +10,44 @@ import WalletLogin from './WalletLogin' import { LOAD_SAFE_EVENTS, CREATE_SAFE_EVENTS } from '@/services/analytics/events/createLoadSafe' import Track from '@/components/common/Track' import { trackEvent } from '@/services/analytics' +import { useAppSelector } from '@/store' +import { selectAllAddedSafes } from '@/store/addedSafesSlice' +import { openSafeListDrawer } from '../SafeListDrawer' +import { isEmpty } from 'lodash' + +const useHasSafes = () => { + const addedSafes = useAppSelector(selectAllAddedSafes) + return Object.values(addedSafes).some((chain) => !isEmpty(chain)) +} const WelcomeLogin = () => { const router = useRouter() const isSocialLoginEnabled = useHasFeature(FEATURES.SOCIAL_LOGIN) + const hasSafes = useHasSafes() - const continueToCreation = () => { - trackEvent(CREATE_SAFE_EVENTS.OPEN_SAFE_CREATION) - router.push({ pathname: AppRoutes.newSafe.create, query: router.query }) + const onLogin = () => { + if (hasSafes) { + openSafeListDrawer() + } else { + trackEvent(CREATE_SAFE_EVENTS.OPEN_SAFE_CREATION) + router.push({ pathname: AppRoutes.newSafe.create, query: router.query }) + } } return ( + Create Account + Choose how you would like to create your Safe Account - + + {isSocialLoginEnabled && ( <> @@ -40,13 +57,14 @@ const WelcomeLogin = () => { - + )} Already have a Safe Account? + Add existing one