From c15743e2f4d672ae46c008869308b7cfc7d850be Mon Sep 17 00:00:00 2001 From: Gustavo Mauricio Date: Mon, 7 Nov 2022 14:56:18 +0000 Subject: [PATCH] UI/UX when no wallet is connected (#40) * navigation bar conditional renders on connected and credit accounts * remove address requirement from allowed coins fetch * fix: credit accounts positions when no wallet connected * remove unnecessary comments --- components/Navigation.tsx | 219 +++++++++++++++------------- components/Wallet.tsx | 7 +- hooks/useAllowedCoins.tsx | 3 +- hooks/useCreditAccountPositions.tsx | 4 +- 4 files changed, 125 insertions(+), 108 deletions(-) diff --git a/components/Navigation.tsx b/components/Navigation.tsx index 0e2e63c4..c4dfacd1 100644 --- a/components/Navigation.tsx +++ b/components/Navigation.tsx @@ -1,5 +1,6 @@ import React, { useMemo } from 'react' import Link from 'next/link' +import Image from 'next/image' import { useRouter } from 'next/router' import { Popover } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/24/solid' @@ -17,6 +18,7 @@ import useAccountStats from 'hooks/useAccountStats' import SemiCircleProgress from './SemiCircleProgress' import useWalletStore from 'stores/useWalletStore' import ArrowRightLine from 'components/Icons/arrow-right-line.svg' +import Button from './Button' // TODO: will require some tweaks depending on how lower viewport mocks pans out const MAX_VISIBLE_CREDIT_ACCOUNTS = 5 @@ -47,7 +49,7 @@ const Navigation = () => { const setSelectedAccount = useCreditManagerStore((s) => s.actions.setSelectedAccount) const toggleCreditManager = useCreditManagerStore((s) => s.actions.toggleCreditManager) - const { data: creditAccountsList } = useCreditAccounts() + const { data: creditAccountsList, isLoading: isLoadingCreditAccounts } = useCreditAccounts() const { mutate: createCreditAccount, isLoading: isLoadingCreate } = useCreateCreditAccount() const { mutate: deleteCreditAccount, isLoading: isLoadingDelete } = useDeleteCreditAccount( selectedAccount || '' @@ -62,13 +64,51 @@ const Navigation = () => { } }, [creditAccountsList]) + const isConnected = !!address + const hasCreditAccounts = creditAccountsList && creditAccountsList.length > 0 + + const rightSideContent = () => { + if ((!isConnected && !hasCreditAccounts) || isLoadingCreditAccounts) { + return null + } + + if (!hasCreditAccounts) { + return + } + + return ( +
+ {accountStats && ( + <> +

{formatCurrency(accountStats.netWorth)}

+ {/* TOOLTIP */} +
+ +
+ + + + )} +
+ +
+
+ ) + } + return (
{/* Main navigation bar */}
- mars + mars
@@ -81,117 +121,98 @@ const Navigation = () => {
{/* Sub navigation bar */} - {address && ( -
-
- - {firstCreditAccounts.map((account) => ( -
setSelectedAccount(account)} - > - Account {account} -
- ))} - {restCreditAccounts.length > 0 && ( +
+
+ + {isConnected && hasCreditAccounts && ( + <> + {firstCreditAccounts.map((account) => ( +
setSelectedAccount(account)} + > + Account {account} +
+ ))} + {restCreditAccounts.length > 0 && ( + + +
+ More + +
+
+ +
+ {restCreditAccounts.map((account) => ( +
setSelectedAccount(account)} + > + Account {account} +
+ ))} +
+
+
+ )}
- More + Manage
-
- {restCreditAccounts.map((account) => ( + {({ close }) => ( +
setSelectedAccount(account)} + className="mb-2 cursor-pointer hover:text-orange-500" + onClick={() => { + close() + createCreditAccount() + }} > - Account {account} + Create Account
- ))} -
+
{ + close() + deleteCreditAccount() + }} + > + Close Account +
+
alert('TODO')} + > + Transfer Balance +
+
alert('TODO')} + > + Rearrange +
+
+ )}
- )} - - -
- Manage - -
-
- - {({ close }) => ( -
-
{ - close() - createCreditAccount() - }} - > - Create Account -
-
{ - close() - deleteCreditAccount() - }} - > - Close Account -
-
alert('TODO')} - > - Transfer Balance -
-
alert('TODO')} - > - Rearrange -
-
- )} -
-
-
-
- {accountStats && ( - <> -

{formatCurrency(accountStats.netWorth)}

- {/* TOOLTIP */} -
- -
- - - - )} -
- -
-
+ + )}
- )} + {rightSideContent()} +
{(isLoadingCreate || isLoadingDelete) && ( -
+
)} diff --git a/components/Wallet.tsx b/components/Wallet.tsx index 6d1409f8..22fb0a5a 100644 --- a/components/Wallet.tsx +++ b/components/Wallet.tsx @@ -32,12 +32,7 @@ const WalletPopover = ({ children }: { children: React.ReactNode }) => { {data?.toFixed(2)}

- +

{address}