From 920e3facae2291399c0b6f795ddab6dabfebb94c Mon Sep 17 00:00:00 2001
From: secondl1ght <85003930+secondl1ght@users.noreply.github.com>
Date: Fri, 25 Oct 2024 14:28:40 -0600
Subject: [PATCH] refactor: app menus navigation and layout (#95)
---
messages/en.json | 14 +-
messages/es.json | 14 +-
src/components/button/LogoutButton.tsx | 21 +-
src/components/button/RefreshWallet.tsx | 25 ++-
src/components/button/VaultButtonV2.tsx | 52 +++--
src/components/button/WalletButton.tsx | 251 +++++++++++-----------
src/components/layout/AppLayout.tsx | 266 +++++++++++-------------
src/components/ui/button-v2.tsx | 7 +-
src/components/ui/button.tsx | 8 +-
src/components/ui/drawer.tsx | 2 +-
src/components/ui/dropdown-menu.tsx | 2 +-
src/components/ui/sheet.tsx | 16 +-
12 files changed, 353 insertions(+), 325 deletions(-)
diff --git a/messages/en.json b/messages/en.json
index 96925c48..bb50f96f 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -105,11 +105,23 @@
},
"Index": {
"accounts": "Accounts",
+ "beta": "Beta - Limit funds and use at your own risk.",
"contacts": "Contacts",
+ "create-wallet": "Create Wallet",
+ "full-refresh": "Full Refresh",
+ "help": "Help",
+ "home": "Home",
+ "loading": "Loading",
+ "logout": "Logout",
+ "new-wallet": "New Wallet",
+ "refresh": "Refresh",
+ "restore-wallet": "Restore Wallet",
+ "select-wallet": "Select Wallet",
"settings": "Settings",
"swaps": "Swaps",
"transactions": "Transactions",
- "wallet": "Wallet"
+ "wallet": "Wallet",
+ "wallets": "Wallets"
},
"Public": {
"404": {
diff --git a/messages/es.json b/messages/es.json
index dcca1a28..b1267f8b 100644
--- a/messages/es.json
+++ b/messages/es.json
@@ -105,11 +105,23 @@
},
"Index": {
"accounts": "Cuentas",
+ "beta": "Beta - Limita la cantidad de fondos y usa bajo tu propio riesgo.",
"contacts": "Contactos",
+ "create-wallet": "Crear Billetera",
+ "full-refresh": "Refrescar Balance",
+ "help": "Ayuda",
+ "home": "Casa",
+ "loading": "Cargando",
+ "logout": "Salir",
+ "new-wallet": "Nueva Billetera",
+ "refresh": "Refrescar",
+ "restore-wallet": "Restaurar Billetera",
+ "select-wallet": "Seleccionar Billetera",
"settings": "ConfiguraciĆ³n",
"swaps": "Intercambios",
"transactions": "Transacciones",
- "wallet": "Billetera"
+ "wallet": "Billetera",
+ "wallets": "Billeteras"
},
"Public": {
"404": {
diff --git a/src/components/button/LogoutButton.tsx b/src/components/button/LogoutButton.tsx
index cb213cb6..e3411e93 100644
--- a/src/components/button/LogoutButton.tsx
+++ b/src/components/button/LogoutButton.tsx
@@ -1,6 +1,7 @@
'use client';
import { LogOut } from 'lucide-react';
+import { useTranslations } from 'next-intl';
import { useLogoutMutation } from '@/graphql/mutations/__generated__/logout.generated';
import { useKeyStore } from '@/stores/keys';
@@ -12,6 +13,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
import { useToast } from '../ui/use-toast';
export const LogoutButtonWithTooltip = () => {
+ const t = useTranslations('Index');
+
const { toast } = useToast();
const clearKeys = useKeyStore(s => s.clear);
@@ -35,21 +38,22 @@ export const LogoutButtonWithTooltip = () => {
{t('logout')}
+ ); }; diff --git a/src/components/button/RefreshWallet.tsx b/src/components/button/RefreshWallet.tsx index db200182..2547e597 100644 --- a/src/components/button/RefreshWallet.tsx +++ b/src/components/button/RefreshWallet.tsx @@ -1,11 +1,12 @@ 'use client'; -import { Loader2, RefreshCcw } from 'lucide-react'; +import { RefreshCw, RotateCw } from 'lucide-react'; import { FC } from 'react'; import { useRefreshWalletMutation } from '@/graphql/mutations/__generated__/refreshWallet.generated'; +import { cn } from '@/utils/cn'; -import { CommandItem } from '../ui/command'; +import { DropdownMenuItem } from '../ui/dropdown-menu'; import { useToast } from '../ui/use-toast'; export const RefreshWallet: FC<{ @@ -26,13 +27,21 @@ export const RefreshWallet: FC<{ }); return ( -{t('unlocked')}
> ) : ( <> -{lockedTitle}
> )} @@ -309,6 +314,7 @@ const PasskeyVaultButton: FC<{ size?: 'md'; protectedSymmetricKey: string; passkeyId: string; + unstyled?: boolean; }> = ({ lockedTitle, className, @@ -316,6 +322,7 @@ const PasskeyVaultButton: FC<{ size, protectedSymmetricKey, passkeyId, + unstyled, }) => { const t = useTranslations('App.Wallet.Vault'); @@ -427,14 +434,15 @@ const PasskeyVaultButton: FC<{ type="button" variant={variant} size={size} - className={cn('flex items-center justify-center', className)} + className={cn('flex items-center justify-center space-x-2', className)} disabled={loading || addLoading} onClick={() => { setup({ variables: { id: passkeyId } }); }} + unstyled={unstyled} > -{lockedTitle}
); } @@ -444,13 +452,14 @@ const PasskeyVaultButton: FC<{ type="button" variant={variant} size={size} - className={cn('flex items-center justify-center', className)} + className={cn('flex items-center justify-center space-x-2', className)} onClick={() => { clearKeys(); }} + unstyled={unstyled} > -{t('unlocked')}
); }; @@ -460,7 +469,8 @@ export const VaultButton: FC<{ className?: string; variant?: Variants; size?: 'md'; -}> = ({ lockedTitle, className, variant, size }) => { + unstyled?: boolean; +}> = ({ lockedTitle, className, variant, size, unstyled }) => { const t = useTranslations(); const lockedTitleFinal = lockedTitle || t('App.Wallet.Vault.locked'); @@ -473,11 +483,12 @@ export const VaultButton: FC<{ type="button" variant={variant} size={size} - className={cn('flex items-center justify-center', className)} + className={cn('flex items-center justify-center space-x-2', className)} disabled + unstyled={unstyled} > -{lockedTitleFinal}
); } @@ -488,11 +499,12 @@ export const VaultButton: FC<{ type="button" variant={variant} size={size} - className={cn('flex items-center justify-center', className)} + className={cn('flex items-center justify-center space-x-2', className)} disabled + unstyled={unstyled} > -{t('Common.error')}
); } @@ -506,6 +518,7 @@ export const VaultButton: FC<{ size={size} protectedSymmetricKey={data.user.protected_symmetric_key} passkeyId={data.user.using_passkey_id} + unstyled={unstyled} /> ); } @@ -516,6 +529,7 @@ export const VaultButton: FC<{ className={className} variant={variant} size={size} + unstyled={unstyled} /> ); }; diff --git a/src/components/button/WalletButton.tsx b/src/components/button/WalletButton.tsx index 15c12267..989f4d3c 100644 --- a/src/components/button/WalletButton.tsx +++ b/src/components/button/WalletButton.tsx @@ -1,35 +1,45 @@ 'use client'; -import { CaretSortIcon, CheckIcon } from '@radix-ui/react-icons'; -import { CircleEqual, PlusCircle, Settings } from 'lucide-react'; +import { + Check, + ChevronsUpDown, + Lock, + Plus, + PlusCircle, + Settings2, + Unlock, +} from 'lucide-react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; -import { useEffect, useMemo, useState } from 'react'; +import { useTranslations } from 'next-intl'; +import { FC, useEffect, useMemo } from 'react'; import { useLocalStorage } from 'usehooks-ts'; import { Button } from '@/components/ui/button'; -import { - Command, - CommandGroup, - CommandItem, - CommandList, -} from '@/components/ui/command'; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from '@/components/ui/popover'; import { useUserQuery } from '@/graphql/queries/__generated__/user.generated'; import { useGetAllWalletsQuery } from '@/graphql/queries/__generated__/wallet.generated'; import { useChat, useContactStore } from '@/stores/contacts'; +import { useKeyStore } from '@/stores/keys'; import { cn } from '@/utils/cn'; import { LOCALSTORAGE_KEYS } from '@/utils/constants'; import { ROUTES } from '@/utils/routes'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '../ui/dropdown-menu'; import { RefreshWallet } from './RefreshWallet'; +import { VaultButton } from './VaultButtonV2'; + +export const WalletButton: FC<{ className?: string; cbk?: () => void }> = ({ + className, + cbk, +}) => { + const t = useTranslations('Index'); -export function WalletButton() { - const [open, setOpen] = useState(false); + const keys = useKeyStore(s => s.keys); const setCurrentContact = useContactStore(s => s.setCurrentContact); const setCurrentPaymentOption = useChat(s => s.setCurrentPaymentOption); @@ -66,124 +76,119 @@ export function WalletButton() { }, [data]); const buttonText = useMemo(() => { - if (loading) return 'Loading...'; - if (!wallets.length) return 'Create a wallet'; + if (loading) return t('loading') + '...'; + if (!wallets.length) return t('create-wallet'); if (value) { - return wallets.find(w => w.value === value)?.label || 'Select wallet...'; + return wallets.find(w => w.value === value)?.label || t('select-wallet'); } - }, [loading, wallets, value]); + }, [loading, wallets, value, t]); if (error) return null; if (!buttonText) return null; return ( -+ {t('wallets')} +
+ + {wallets.length + ? wallets.map(w => ( +